GlobalMetadataFileInternals.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  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. #if SLIM_GLOBAL_METADATA_FILE
  51. #pragma pack(push, p2, 1)
  52. #endif
  53. typedef struct Il2CppInterfaceOffsetPair
  54. {
  55. TypeIndex interfaceTypeIndex;
  56. int32_t offset;
  57. } Il2CppInterfaceOffsetPair;
  58. typedef struct Il2CppTypeDefinition
  59. {
  60. StringIndex nameIndex;
  61. StringIndex namespaceIndex;
  62. TypeIndex byvalTypeIndex;
  63. TypeIndex declaringTypeIndex;
  64. TypeIndex parentIndex;
  65. TypeIndex elementTypeIndex; // we can probably remove this one. Only used for enums
  66. GenericContainerIndex genericContainerIndex;
  67. uint32_t flags;
  68. FieldIndex fieldStart;
  69. MethodIndex methodStart;
  70. EventIndex eventStart;
  71. PropertyIndex propertyStart;
  72. NestedTypeIndex nestedTypesStart;
  73. InterfacesIndex interfacesStart;
  74. VTableIndex vtableStart;
  75. InterfacesIndex interfaceOffsetsStart;
  76. uint16_t method_count;
  77. uint16_t property_count;
  78. uint16_t field_count;
  79. uint16_t event_count;
  80. uint16_t nested_type_count;
  81. uint16_t vtable_count;
  82. uint16_t interfaces_count;
  83. uint16_t interface_offsets_count;
  84. // bitfield to portably encode boolean values as single bits
  85. // 01 - valuetype;
  86. // 02 - enumtype;
  87. // 03 - has_finalize;
  88. // 04 - has_cctor;
  89. // 05 - is_blittable;
  90. // 06 - is_import_or_windows_runtime;
  91. // 07-10 - One of nine possible PackingSize values (0, 1, 2, 4, 8, 16, 32, 64, or 128)
  92. // 11 - PackingSize is default
  93. // 12 - ClassSize is default
  94. // 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)
  95. uint32_t bitfield;
  96. uint32_t token;
  97. } Il2CppTypeDefinition;
  98. typedef struct Il2CppFieldDefinition
  99. {
  100. StringIndex nameIndex;
  101. TypeIndex typeIndex;
  102. uint32_t token;
  103. } Il2CppFieldDefinition;
  104. typedef struct Il2CppFieldDefaultValue
  105. {
  106. FieldIndex fieldIndex;
  107. TypeIndex typeIndex;
  108. DefaultValueDataIndex dataIndex;
  109. } Il2CppFieldDefaultValue;
  110. typedef struct Il2CppFieldMarshaledSize
  111. {
  112. FieldIndex fieldIndex;
  113. TypeIndex typeIndex;
  114. int32_t size;
  115. } Il2CppFieldMarshaledSize;
  116. typedef struct Il2CppFieldRef
  117. {
  118. TypeIndex typeIndex;
  119. FieldIndex fieldIndex; // local offset into type fields
  120. } Il2CppFieldRef;
  121. typedef struct Il2CppParameterDefinition
  122. {
  123. StringIndex nameIndex;
  124. uint32_t token;
  125. TypeIndex typeIndex;
  126. } Il2CppParameterDefinition;
  127. typedef struct Il2CppParameterDefaultValue
  128. {
  129. ParameterIndex parameterIndex;
  130. TypeIndex typeIndex;
  131. DefaultValueDataIndex dataIndex;
  132. } Il2CppParameterDefaultValue;
  133. typedef struct Il2CppMethodDefinition
  134. {
  135. StringIndex nameIndex;
  136. TypeDefinitionIndex declaringType;
  137. TypeIndex returnType;
  138. #if SUPPORT_METHOD_RETURN_TYPE_CUSTOM_ATTRIBUTE
  139. uint32_t returnParameterToken;
  140. #endif
  141. ParameterIndex parameterStart;
  142. GenericContainerIndex genericContainerIndex;
  143. uint32_t token;
  144. uint16_t flags;
  145. uint16_t iflags;
  146. uint16_t slot;
  147. #if SLIM_GLOBAL_METADATA_FILE
  148. uint8_t parameterCount;
  149. #else
  150. uint16_t parameterCount;
  151. #endif
  152. } Il2CppMethodDefinition;
  153. typedef struct Il2CppEventDefinition
  154. {
  155. StringIndex nameIndex;
  156. TypeIndex typeIndex;
  157. MethodIndex add;
  158. MethodIndex remove;
  159. MethodIndex raise;
  160. uint32_t token;
  161. } Il2CppEventDefinition;
  162. typedef struct Il2CppPropertyDefinition
  163. {
  164. StringIndex nameIndex;
  165. MethodIndex get;
  166. MethodIndex set;
  167. uint32_t attrs;
  168. uint32_t token;
  169. } Il2CppPropertyDefinition;
  170. typedef struct Il2CppStringLiteral
  171. {
  172. uint32_t length;
  173. StringLiteralIndex dataIndex;
  174. } Il2CppStringLiteral;
  175. typedef struct Il2CppAssemblyNameDefinition
  176. {
  177. StringIndex nameIndex;
  178. StringIndex cultureIndex;
  179. StringIndex publicKeyIndex;
  180. uint32_t hash_alg;
  181. int32_t hash_len;
  182. uint32_t flags;
  183. int32_t major;
  184. int32_t minor;
  185. int32_t build;
  186. int32_t revision;
  187. uint8_t public_key_token[PUBLIC_KEY_BYTE_LENGTH];
  188. } Il2CppAssemblyNameDefinition;
  189. typedef struct Il2CppImageDefinition
  190. {
  191. StringIndex nameIndex;
  192. AssemblyIndex assemblyIndex;
  193. TypeDefinitionIndex typeStart;
  194. uint32_t typeCount;
  195. TypeDefinitionIndex exportedTypeStart;
  196. uint32_t exportedTypeCount;
  197. MethodIndex entryPointIndex;
  198. uint32_t token;
  199. CustomAttributeIndex customAttributeStart;
  200. uint32_t customAttributeCount;
  201. } Il2CppImageDefinition;
  202. typedef struct Il2CppAssemblyDefinition
  203. {
  204. ImageIndex imageIndex;
  205. uint32_t token;
  206. int32_t referencedAssemblyStart;
  207. int32_t referencedAssemblyCount;
  208. Il2CppAssemblyNameDefinition aname;
  209. } Il2CppAssemblyDefinition;
  210. typedef struct Il2CppCustomAttributeDataRange
  211. {
  212. uint32_t token;
  213. uint32_t startOffset;
  214. } Il2CppCustomAttributeDataRange;
  215. typedef struct Il2CppMetadataRange
  216. {
  217. int32_t start;
  218. int32_t length;
  219. } Il2CppMetadataRange;
  220. typedef struct Il2CppGenericContainer
  221. {
  222. /* index of the generic type definition or the generic method definition corresponding to this container */
  223. int32_t ownerIndex; // either index into Il2CppClass metadata array or Il2CppMethodDefinition array
  224. int32_t type_argc;
  225. /* If true, we're a generic method, otherwise a generic type definition. */
  226. int32_t is_method;
  227. /* Our type parameters. */
  228. GenericParameterIndex genericParameterStart;
  229. } Il2CppGenericContainer;
  230. typedef struct Il2CppGenericParameter
  231. {
  232. GenericContainerIndex ownerIndex; /* Type or method this parameter was defined in. */
  233. StringIndex nameIndex;
  234. GenericParameterConstraintIndex constraintsStart;
  235. int16_t constraintsCount;
  236. uint16_t num;
  237. uint16_t flags;
  238. } Il2CppGenericParameter;
  239. typedef struct Il2CppWindowsRuntimeTypeNamePair
  240. {
  241. StringIndex nameIndex;
  242. TypeIndex typeIndex;
  243. } Il2CppWindowsRuntimeTypeNamePair;
  244. #if SLIM_GLOBAL_METADATA_FILE
  245. #pragma pack(pop, p2)
  246. #endif
  247. #pragma pack(push, p1,4)
  248. typedef struct Il2CppGlobalMetadataHeader
  249. {
  250. int32_t sanity;
  251. int32_t version;
  252. int32_t stringLiteralOffset; // string data for managed code
  253. int32_t stringLiteralSize;
  254. int32_t stringLiteralDataOffset;
  255. int32_t stringLiteralDataSize;
  256. int32_t stringOffset; // string data for metadata
  257. int32_t stringSize;
  258. int32_t eventsOffset; // Il2CppEventDefinition
  259. int32_t eventsSize;
  260. int32_t propertiesOffset; // Il2CppPropertyDefinition
  261. int32_t propertiesSize;
  262. int32_t methodsOffset; // Il2CppMethodDefinition
  263. int32_t methodsSize;
  264. int32_t parameterDefaultValuesOffset; // Il2CppParameterDefaultValue
  265. int32_t parameterDefaultValuesSize;
  266. int32_t fieldDefaultValuesOffset; // Il2CppFieldDefaultValue
  267. int32_t fieldDefaultValuesSize;
  268. int32_t fieldAndParameterDefaultValueDataOffset; // uint8_t
  269. int32_t fieldAndParameterDefaultValueDataSize;
  270. int32_t fieldMarshaledSizesOffset; // Il2CppFieldMarshaledSize
  271. int32_t fieldMarshaledSizesSize;
  272. int32_t parametersOffset; // Il2CppParameterDefinition
  273. int32_t parametersSize;
  274. int32_t fieldsOffset; // Il2CppFieldDefinition
  275. int32_t fieldsSize;
  276. int32_t genericParametersOffset; // Il2CppGenericParameter
  277. int32_t genericParametersSize;
  278. int32_t genericParameterConstraintsOffset; // TypeIndex
  279. int32_t genericParameterConstraintsSize;
  280. int32_t genericContainersOffset; // Il2CppGenericContainer
  281. int32_t genericContainersSize;
  282. int32_t nestedTypesOffset; // TypeDefinitionIndex
  283. int32_t nestedTypesSize;
  284. int32_t interfacesOffset; // TypeIndex
  285. int32_t interfacesSize;
  286. int32_t vtableMethodsOffset; // EncodedMethodIndex
  287. int32_t vtableMethodsSize;
  288. int32_t interfaceOffsetsOffset; // Il2CppInterfaceOffsetPair
  289. int32_t interfaceOffsetsSize;
  290. int32_t typeDefinitionsOffset; // Il2CppTypeDefinition
  291. int32_t typeDefinitionsSize;
  292. int32_t imagesOffset; // Il2CppImageDefinition
  293. int32_t imagesSize;
  294. int32_t assembliesOffset; // Il2CppAssemblyDefinition
  295. int32_t assembliesSize;
  296. int32_t fieldRefsOffset; // Il2CppFieldRef
  297. int32_t fieldRefsSize;
  298. int32_t referencedAssembliesOffset; // int32_t
  299. int32_t referencedAssembliesSize;
  300. int32_t attributeDataOffset;
  301. int32_t attributeDataSize;
  302. int32_t attributeDataRangeOffset;
  303. int32_t attributeDataRangeSize;
  304. int32_t unresolvedIndirectCallParameterTypesOffset; // TypeIndex
  305. int32_t unresolvedIndirectCallParameterTypesSize;
  306. int32_t unresolvedIndirectCallParameterRangesOffset; // Il2CppMetadataRange
  307. int32_t unresolvedIndirectCallParameterRangesSize;
  308. int32_t windowsRuntimeTypeNamesOffset; // Il2CppWindowsRuntimeTypeNamePair
  309. int32_t windowsRuntimeTypeNamesSize;
  310. int32_t windowsRuntimeStringsOffset; // const char*
  311. int32_t windowsRuntimeStringsSize;
  312. int32_t exportedTypeDefinitionsOffset; // TypeDefinitionIndex
  313. int32_t exportedTypeDefinitionsSize;
  314. } Il2CppGlobalMetadataHeader;
  315. #pragma pack(pop, p1)
  316. typedef Il2CppCustomAttributeDataRange Il2CppCustomAttributeTypeRange;