GlobalMetadataFileInternals.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. #pragma once
  2. #include "il2cpp-metadata.h"
  3. // This file contains the structures specifying how we store converted metadata.
  4. // These structures have 3 constraints:
  5. // 1. These structures will be stored in an external file, and as such must not contain any pointers.
  6. // All references to other metadata should occur via an index into a corresponding table.
  7. // 2. These structures are assumed to be const. Either const structures in the binary or mapped as
  8. // readonly memory from an external file. Do not add any 'calculated' fields which will be written to at runtime.
  9. // 3. These structures should be optimized for size. Other structures are used at runtime which can
  10. // be larger to store cached information
  11. // Encoded index (1 bit)
  12. // MethodDef - 0
  13. // MethodSpec - 1
  14. // We use the top 3 bits to indicate what table to index into
  15. // Type Binary Hex
  16. // Il2CppClass 001 0x20000000
  17. // Il2CppType 010 0x40000000
  18. // MethodInfo 011 0x60000000
  19. // FieldInfo 100 0x80000000
  20. // StringLiteral 101 0xA0000000
  21. // MethodRef 110 0xC0000000
  22. // FieldRVA 111 0xE0000000
  23. typedef uint32_t EncodedMethodIndex;
  24. enum Il2CppMetadataUsage
  25. {
  26. kIl2CppMetadataUsageInvalid,
  27. kIl2CppMetadataUsageTypeInfo,
  28. kIl2CppMetadataUsageIl2CppType,
  29. kIl2CppMetadataUsageMethodDef,
  30. kIl2CppMetadataUsageFieldInfo,
  31. kIl2CppMetadataUsageStringLiteral,
  32. kIl2CppMetadataUsageMethodRef,
  33. kIl2CppMetadataUsageFieldRva
  34. };
  35. enum Il2CppInvalidMetadataUsageToken
  36. {
  37. kIl2CppInvalidMetadataUsageNoData = 0,
  38. kIl2CppInvalidMetadataUsageAmbiguousMethod = 1,
  39. };
  40. #ifdef __cplusplus
  41. static inline Il2CppMetadataUsage GetEncodedIndexType(EncodedMethodIndex index)
  42. {
  43. return (Il2CppMetadataUsage)((index & 0xE0000000) >> 29);
  44. }
  45. static inline uint32_t GetDecodedMethodIndex(EncodedMethodIndex index)
  46. {
  47. return (index & 0x1FFFFFFEU) >> 1;
  48. }
  49. #endif
  50. typedef struct Il2CppInterfaceOffsetPair
  51. {
  52. TypeIndex interfaceTypeIndex;
  53. int32_t offset;
  54. } Il2CppInterfaceOffsetPair;
  55. typedef struct Il2CppTypeDefinition
  56. {
  57. StringIndex nameIndex;
  58. StringIndex namespaceIndex;
  59. TypeIndex byvalTypeIndex;
  60. TypeIndex declaringTypeIndex;
  61. TypeIndex parentIndex;
  62. TypeIndex elementTypeIndex; // we can probably remove this one. Only used for enums
  63. GenericContainerIndex genericContainerIndex;
  64. uint32_t flags;
  65. FieldIndex fieldStart;
  66. MethodIndex methodStart;
  67. EventIndex eventStart;
  68. PropertyIndex propertyStart;
  69. NestedTypeIndex nestedTypesStart;
  70. InterfacesIndex interfacesStart;
  71. VTableIndex vtableStart;
  72. InterfacesIndex interfaceOffsetsStart;
  73. uint16_t method_count;
  74. uint16_t property_count;
  75. uint16_t field_count;
  76. uint16_t event_count;
  77. uint16_t nested_type_count;
  78. uint16_t vtable_count;
  79. uint16_t interfaces_count;
  80. uint16_t interface_offsets_count;
  81. // bitfield to portably encode boolean values as single bits
  82. // 01 - valuetype;
  83. // 02 - enumtype;
  84. // 03 - has_finalize;
  85. // 04 - has_cctor;
  86. // 05 - is_blittable;
  87. // 06 - is_import_or_windows_runtime;
  88. // 07-10 - One of nine possible PackingSize values (0, 1, 2, 4, 8, 16, 32, 64, or 128)
  89. // 11 - PackingSize is default
  90. // 12 - ClassSize is default
  91. // 13-16 - One of nine possible PackingSize values (0, 1, 2, 4, 8, 16, 32, 64, or 128) - the specified packing size (even for explicit layouts)
  92. uint32_t bitfield;
  93. uint32_t token;
  94. } Il2CppTypeDefinition;
  95. typedef struct Il2CppFieldDefinition
  96. {
  97. StringIndex nameIndex;
  98. TypeIndex typeIndex;
  99. uint32_t token;
  100. } Il2CppFieldDefinition;
  101. typedef struct Il2CppFieldDefaultValue
  102. {
  103. FieldIndex fieldIndex;
  104. TypeIndex typeIndex;
  105. DefaultValueDataIndex dataIndex;
  106. } Il2CppFieldDefaultValue;
  107. typedef struct Il2CppFieldMarshaledSize
  108. {
  109. FieldIndex fieldIndex;
  110. TypeIndex typeIndex;
  111. int32_t size;
  112. } Il2CppFieldMarshaledSize;
  113. typedef struct Il2CppFieldRef
  114. {
  115. TypeIndex typeIndex;
  116. FieldIndex fieldIndex; // local offset into type fields
  117. } Il2CppFieldRef;
  118. typedef struct Il2CppParameterDefinition
  119. {
  120. StringIndex nameIndex;
  121. uint32_t token;
  122. TypeIndex typeIndex;
  123. } Il2CppParameterDefinition;
  124. typedef struct Il2CppParameterDefaultValue
  125. {
  126. ParameterIndex parameterIndex;
  127. TypeIndex typeIndex;
  128. DefaultValueDataIndex dataIndex;
  129. } Il2CppParameterDefaultValue;
  130. typedef struct Il2CppMethodDefinition
  131. {
  132. StringIndex nameIndex;
  133. TypeDefinitionIndex declaringType;
  134. TypeIndex returnType;
  135. uint32_t returnParameterToken;
  136. ParameterIndex parameterStart;
  137. GenericContainerIndex genericContainerIndex;
  138. uint32_t token;
  139. uint16_t flags;
  140. uint16_t iflags;
  141. uint16_t slot;
  142. uint16_t parameterCount;
  143. } Il2CppMethodDefinition;
  144. typedef struct Il2CppEventDefinition
  145. {
  146. StringIndex nameIndex;
  147. TypeIndex typeIndex;
  148. MethodIndex add;
  149. MethodIndex remove;
  150. MethodIndex raise;
  151. uint32_t token;
  152. } Il2CppEventDefinition;
  153. typedef struct Il2CppPropertyDefinition
  154. {
  155. StringIndex nameIndex;
  156. MethodIndex get;
  157. MethodIndex set;
  158. uint32_t attrs;
  159. uint32_t token;
  160. } Il2CppPropertyDefinition;
  161. typedef struct Il2CppStringLiteral
  162. {
  163. uint32_t length;
  164. StringLiteralIndex dataIndex;
  165. } Il2CppStringLiteral;
  166. typedef struct Il2CppAssemblyNameDefinition
  167. {
  168. StringIndex nameIndex;
  169. StringIndex cultureIndex;
  170. StringIndex publicKeyIndex;
  171. uint32_t hash_alg;
  172. int32_t hash_len;
  173. uint32_t flags;
  174. int32_t major;
  175. int32_t minor;
  176. int32_t build;
  177. int32_t revision;
  178. uint8_t public_key_token[PUBLIC_KEY_BYTE_LENGTH];
  179. } Il2CppAssemblyNameDefinition;
  180. typedef struct Il2CppImageDefinition
  181. {
  182. StringIndex nameIndex;
  183. AssemblyIndex assemblyIndex;
  184. TypeDefinitionIndex typeStart;
  185. uint32_t typeCount;
  186. TypeDefinitionIndex exportedTypeStart;
  187. uint32_t exportedTypeCount;
  188. MethodIndex entryPointIndex;
  189. uint32_t token;
  190. CustomAttributeIndex customAttributeStart;
  191. uint32_t customAttributeCount;
  192. } Il2CppImageDefinition;
  193. typedef struct Il2CppAssemblyDefinition
  194. {
  195. ImageIndex imageIndex;
  196. uint32_t token;
  197. int32_t referencedAssemblyStart;
  198. int32_t referencedAssemblyCount;
  199. Il2CppAssemblyNameDefinition aname;
  200. } Il2CppAssemblyDefinition;
  201. typedef struct Il2CppCustomAttributeDataRange
  202. {
  203. uint32_t token;
  204. uint32_t startOffset;
  205. } Il2CppCustomAttributeDataRange;
  206. typedef struct Il2CppMetadataRange
  207. {
  208. int32_t start;
  209. int32_t length;
  210. } Il2CppMetadataRange;
  211. typedef struct Il2CppGenericContainer
  212. {
  213. /* index of the generic type definition or the generic method definition corresponding to this container */
  214. int32_t ownerIndex; // either index into Il2CppClass metadata array or Il2CppMethodDefinition array
  215. int32_t type_argc;
  216. /* If true, we're a generic method, otherwise a generic type definition. */
  217. int32_t is_method;
  218. /* Our type parameters. */
  219. GenericParameterIndex genericParameterStart;
  220. } Il2CppGenericContainer;
  221. typedef struct Il2CppGenericParameter
  222. {
  223. GenericContainerIndex ownerIndex; /* Type or method this parameter was defined in. */
  224. StringIndex nameIndex;
  225. GenericParameterConstraintIndex constraintsStart;
  226. int16_t constraintsCount;
  227. uint16_t num;
  228. uint16_t flags;
  229. } Il2CppGenericParameter;
  230. typedef struct Il2CppWindowsRuntimeTypeNamePair
  231. {
  232. StringIndex nameIndex;
  233. TypeIndex typeIndex;
  234. } Il2CppWindowsRuntimeTypeNamePair;
  235. #pragma pack(push, p1,4)
  236. typedef struct Il2CppGlobalMetadataHeader
  237. {
  238. int32_t sanity;
  239. int32_t version;
  240. int32_t stringLiteralOffset; // string data for managed code
  241. int32_t stringLiteralSize;
  242. int32_t stringLiteralDataOffset;
  243. int32_t stringLiteralDataSize;
  244. int32_t stringOffset; // string data for metadata
  245. int32_t stringSize;
  246. int32_t eventsOffset; // Il2CppEventDefinition
  247. int32_t eventsSize;
  248. int32_t propertiesOffset; // Il2CppPropertyDefinition
  249. int32_t propertiesSize;
  250. int32_t methodsOffset; // Il2CppMethodDefinition
  251. int32_t methodsSize;
  252. int32_t parameterDefaultValuesOffset; // Il2CppParameterDefaultValue
  253. int32_t parameterDefaultValuesSize;
  254. int32_t fieldDefaultValuesOffset; // Il2CppFieldDefaultValue
  255. int32_t fieldDefaultValuesSize;
  256. int32_t fieldAndParameterDefaultValueDataOffset; // uint8_t
  257. int32_t fieldAndParameterDefaultValueDataSize;
  258. int32_t fieldMarshaledSizesOffset; // Il2CppFieldMarshaledSize
  259. int32_t fieldMarshaledSizesSize;
  260. int32_t parametersOffset; // Il2CppParameterDefinition
  261. int32_t parametersSize;
  262. int32_t fieldsOffset; // Il2CppFieldDefinition
  263. int32_t fieldsSize;
  264. int32_t genericParametersOffset; // Il2CppGenericParameter
  265. int32_t genericParametersSize;
  266. int32_t genericParameterConstraintsOffset; // TypeIndex
  267. int32_t genericParameterConstraintsSize;
  268. int32_t genericContainersOffset; // Il2CppGenericContainer
  269. int32_t genericContainersSize;
  270. int32_t nestedTypesOffset; // TypeDefinitionIndex
  271. int32_t nestedTypesSize;
  272. int32_t interfacesOffset; // TypeIndex
  273. int32_t interfacesSize;
  274. int32_t vtableMethodsOffset; // EncodedMethodIndex
  275. int32_t vtableMethodsSize;
  276. int32_t interfaceOffsetsOffset; // Il2CppInterfaceOffsetPair
  277. int32_t interfaceOffsetsSize;
  278. int32_t typeDefinitionsOffset; // Il2CppTypeDefinition
  279. int32_t typeDefinitionsSize;
  280. int32_t imagesOffset; // Il2CppImageDefinition
  281. int32_t imagesSize;
  282. int32_t assembliesOffset; // Il2CppAssemblyDefinition
  283. int32_t assembliesSize;
  284. int32_t fieldRefsOffset; // Il2CppFieldRef
  285. int32_t fieldRefsSize;
  286. int32_t referencedAssembliesOffset; // int32_t
  287. int32_t referencedAssembliesSize;
  288. int32_t attributeDataOffset;
  289. int32_t attributeDataSize;
  290. int32_t attributeDataRangeOffset;
  291. int32_t attributeDataRangeSize;
  292. int32_t unresolvedIndirectCallParameterTypesOffset; // TypeIndex
  293. int32_t unresolvedIndirectCallParameterTypesSize;
  294. int32_t unresolvedIndirectCallParameterRangesOffset; // Il2CppMetadataRange
  295. int32_t unresolvedIndirectCallParameterRangesSize;
  296. int32_t windowsRuntimeTypeNamesOffset; // Il2CppWindowsRuntimeTypeNamePair
  297. int32_t windowsRuntimeTypeNamesSize;
  298. int32_t windowsRuntimeStringsOffset; // const char*
  299. int32_t windowsRuntimeStringsSize;
  300. int32_t exportedTypeDefinitionsOffset; // TypeDefinitionIndex
  301. int32_t exportedTypeDefinitionsSize;
  302. } Il2CppGlobalMetadataHeader;
  303. #pragma pack(pop, p1)