GlobalMetadataFileInternals.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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. ParameterIndex parameterStart;
  136. GenericContainerIndex genericContainerIndex;
  137. uint32_t token;
  138. uint16_t flags;
  139. uint16_t iflags;
  140. uint16_t slot;
  141. uint16_t parameterCount;
  142. } Il2CppMethodDefinition;
  143. typedef struct Il2CppEventDefinition
  144. {
  145. StringIndex nameIndex;
  146. TypeIndex typeIndex;
  147. MethodIndex add;
  148. MethodIndex remove;
  149. MethodIndex raise;
  150. uint32_t token;
  151. } Il2CppEventDefinition;
  152. typedef struct Il2CppPropertyDefinition
  153. {
  154. StringIndex nameIndex;
  155. MethodIndex get;
  156. MethodIndex set;
  157. uint32_t attrs;
  158. uint32_t token;
  159. } Il2CppPropertyDefinition;
  160. typedef struct Il2CppStringLiteral
  161. {
  162. uint32_t length;
  163. StringLiteralIndex dataIndex;
  164. } Il2CppStringLiteral;
  165. typedef struct Il2CppAssemblyNameDefinition
  166. {
  167. StringIndex nameIndex;
  168. StringIndex cultureIndex;
  169. StringIndex publicKeyIndex;
  170. uint32_t hash_alg;
  171. int32_t hash_len;
  172. uint32_t flags;
  173. int32_t major;
  174. int32_t minor;
  175. int32_t build;
  176. int32_t revision;
  177. uint8_t public_key_token[PUBLIC_KEY_BYTE_LENGTH];
  178. } Il2CppAssemblyNameDefinition;
  179. typedef struct Il2CppImageDefinition
  180. {
  181. StringIndex nameIndex;
  182. AssemblyIndex assemblyIndex;
  183. TypeDefinitionIndex typeStart;
  184. uint32_t typeCount;
  185. TypeDefinitionIndex exportedTypeStart;
  186. uint32_t exportedTypeCount;
  187. MethodIndex entryPointIndex;
  188. uint32_t token;
  189. CustomAttributeIndex customAttributeStart;
  190. uint32_t customAttributeCount;
  191. } Il2CppImageDefinition;
  192. typedef struct Il2CppAssemblyDefinition
  193. {
  194. ImageIndex imageIndex;
  195. uint32_t token;
  196. int32_t referencedAssemblyStart;
  197. int32_t referencedAssemblyCount;
  198. Il2CppAssemblyNameDefinition aname;
  199. } Il2CppAssemblyDefinition;
  200. typedef struct Il2CppCustomAttributeDataRange
  201. {
  202. uint32_t token;
  203. uint32_t startOffset;
  204. } Il2CppCustomAttributeDataRange;
  205. typedef struct Il2CppMetadataRange
  206. {
  207. int32_t start;
  208. int32_t length;
  209. } Il2CppMetadataRange;
  210. typedef struct Il2CppGenericContainer
  211. {
  212. /* index of the generic type definition or the generic method definition corresponding to this container */
  213. int32_t ownerIndex; // either index into Il2CppClass metadata array or Il2CppMethodDefinition array
  214. int32_t type_argc;
  215. /* If true, we're a generic method, otherwise a generic type definition. */
  216. int32_t is_method;
  217. /* Our type parameters. */
  218. GenericParameterIndex genericParameterStart;
  219. } Il2CppGenericContainer;
  220. typedef struct Il2CppGenericParameter
  221. {
  222. GenericContainerIndex ownerIndex; /* Type or method this parameter was defined in. */
  223. StringIndex nameIndex;
  224. GenericParameterConstraintIndex constraintsStart;
  225. int16_t constraintsCount;
  226. uint16_t num;
  227. uint16_t flags;
  228. } Il2CppGenericParameter;
  229. typedef struct Il2CppWindowsRuntimeTypeNamePair
  230. {
  231. StringIndex nameIndex;
  232. TypeIndex typeIndex;
  233. } Il2CppWindowsRuntimeTypeNamePair;
  234. #pragma pack(push, p1,4)
  235. typedef struct Il2CppGlobalMetadataHeader
  236. {
  237. int32_t sanity;
  238. int32_t version;
  239. int32_t stringLiteralOffset; // string data for managed code
  240. int32_t stringLiteralSize;
  241. int32_t stringLiteralDataOffset;
  242. int32_t stringLiteralDataSize;
  243. int32_t stringOffset; // string data for metadata
  244. int32_t stringSize;
  245. int32_t eventsOffset; // Il2CppEventDefinition
  246. int32_t eventsSize;
  247. int32_t propertiesOffset; // Il2CppPropertyDefinition
  248. int32_t propertiesSize;
  249. int32_t methodsOffset; // Il2CppMethodDefinition
  250. int32_t methodsSize;
  251. int32_t parameterDefaultValuesOffset; // Il2CppParameterDefaultValue
  252. int32_t parameterDefaultValuesSize;
  253. int32_t fieldDefaultValuesOffset; // Il2CppFieldDefaultValue
  254. int32_t fieldDefaultValuesSize;
  255. int32_t fieldAndParameterDefaultValueDataOffset; // uint8_t
  256. int32_t fieldAndParameterDefaultValueDataSize;
  257. int32_t fieldMarshaledSizesOffset; // Il2CppFieldMarshaledSize
  258. int32_t fieldMarshaledSizesSize;
  259. int32_t parametersOffset; // Il2CppParameterDefinition
  260. int32_t parametersSize;
  261. int32_t fieldsOffset; // Il2CppFieldDefinition
  262. int32_t fieldsSize;
  263. int32_t genericParametersOffset; // Il2CppGenericParameter
  264. int32_t genericParametersSize;
  265. int32_t genericParameterConstraintsOffset; // TypeIndex
  266. int32_t genericParameterConstraintsSize;
  267. int32_t genericContainersOffset; // Il2CppGenericContainer
  268. int32_t genericContainersSize;
  269. int32_t nestedTypesOffset; // TypeDefinitionIndex
  270. int32_t nestedTypesSize;
  271. int32_t interfacesOffset; // TypeIndex
  272. int32_t interfacesSize;
  273. int32_t vtableMethodsOffset; // EncodedMethodIndex
  274. int32_t vtableMethodsSize;
  275. int32_t interfaceOffsetsOffset; // Il2CppInterfaceOffsetPair
  276. int32_t interfaceOffsetsSize;
  277. int32_t typeDefinitionsOffset; // Il2CppTypeDefinition
  278. int32_t typeDefinitionsSize;
  279. int32_t imagesOffset; // Il2CppImageDefinition
  280. int32_t imagesSize;
  281. int32_t assembliesOffset; // Il2CppAssemblyDefinition
  282. int32_t assembliesSize;
  283. int32_t fieldRefsOffset; // Il2CppFieldRef
  284. int32_t fieldRefsSize;
  285. int32_t referencedAssembliesOffset; // int32_t
  286. int32_t referencedAssembliesSize;
  287. int32_t attributeDataOffset;
  288. int32_t attributeDataSize;
  289. int32_t attributeDataRangeOffset;
  290. int32_t attributeDataRangeSize;
  291. int32_t unresolvedIndirectCallParameterTypesOffset; // TypeIndex
  292. int32_t unresolvedIndirectCallParameterTypesSize;
  293. int32_t unresolvedIndirectCallParameterRangesOffset; // Il2CppMetadataRange
  294. int32_t unresolvedIndirectCallParameterRangesSize;
  295. int32_t windowsRuntimeTypeNamesOffset; // Il2CppWindowsRuntimeTypeNamePair
  296. int32_t windowsRuntimeTypeNamesSize;
  297. int32_t windowsRuntimeStringsOffset; // const char*
  298. int32_t windowsRuntimeStringsSize;
  299. int32_t exportedTypeDefinitionsOffset; // TypeDefinitionIndex
  300. int32_t exportedTypeDefinitionsSize;
  301. } Il2CppGlobalMetadataHeader;
  302. #pragma pack(pop, p1)