il2cpp-metadata.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. #pragma once
  2. #include "il2cpp-config.h"
  3. #include <stdint.h>
  4. // This file contains the structures specifying how we store converted metadata.
  5. // These structures have 3 constraints:
  6. // 1. These structures will be stored in an external file, and as such must not contain any pointers.
  7. // All references to other metadata should occur via an index into a corresponding table.
  8. // 2. These structures are assumed to be const. Either const structures in the binary or mapped as
  9. // readonly memory from an external file. Do not add any 'calculated' fields which will be written to at runtime.
  10. // 3. These structures should be optimized for size. Other structures are used at runtime which can
  11. // be larger to store cached information
  12. typedef int32_t TypeIndex;
  13. typedef int32_t TypeDefinitionIndex;
  14. typedef int32_t FieldIndex;
  15. typedef int32_t DefaultValueIndex;
  16. typedef int32_t DefaultValueDataIndex;
  17. typedef int32_t CustomAttributeIndex;
  18. typedef int32_t ParameterIndex;
  19. typedef int32_t MethodIndex;
  20. typedef int32_t GenericMethodIndex;
  21. typedef int32_t PropertyIndex;
  22. typedef int32_t EventIndex;
  23. typedef int32_t GenericContainerIndex;
  24. typedef int32_t GenericParameterIndex;
  25. typedef int16_t GenericParameterConstraintIndex;
  26. typedef int32_t NestedTypeIndex;
  27. typedef int32_t InterfacesIndex;
  28. typedef int32_t VTableIndex;
  29. typedef int32_t InterfaceOffsetIndex;
  30. typedef int32_t RGCTXIndex;
  31. typedef int32_t StringIndex;
  32. typedef int32_t StringLiteralIndex;
  33. typedef int32_t GenericInstIndex;
  34. typedef int32_t ImageIndex;
  35. typedef int32_t AssemblyIndex;
  36. typedef int32_t InteropDataIndex;
  37. const TypeIndex kTypeIndexInvalid = -1;
  38. const TypeDefinitionIndex kTypeDefinitionIndexInvalid = -1;
  39. const DefaultValueDataIndex kDefaultValueIndexNull = -1;
  40. const EventIndex kEventIndexInvalid = -1;
  41. const FieldIndex kFieldIndexInvalid = -1;
  42. const MethodIndex kMethodIndexInvalid = -1;
  43. const PropertyIndex kPropertyIndexInvalid = -1;
  44. const GenericContainerIndex kGenericContainerIndexInvalid = -1;
  45. const GenericParameterIndex kGenericParameterIndexInvalid = -1;
  46. const RGCTXIndex kRGCTXIndexInvalid = -1;
  47. const StringLiteralIndex kStringLiteralIndexInvalid = -1;
  48. const InteropDataIndex kInteropDataIndexInvalid = -1;
  49. // Encoded index (1 bit)
  50. // MethodDef - 0
  51. // MethodSpec - 1
  52. // We use the top 3 bits to indicate what table to index into
  53. // Type Binary Hex
  54. // Il2CppClass 001 0x20000000
  55. // Il2CppType 010 0x40000000
  56. // MethodInfo 011 0x60000000
  57. // FieldInfo 100 0x80000000
  58. // StringLiteral 101 0xA0000000
  59. // MethodRef 110 0xC0000000
  60. typedef uint32_t EncodedMethodIndex;
  61. enum Il2CppMetadataUsage
  62. {
  63. kIl2CppMetadataUsageInvalid,
  64. kIl2CppMetadataUsageTypeInfo,
  65. kIl2CppMetadataUsageIl2CppType,
  66. kIl2CppMetadataUsageMethodDef,
  67. kIl2CppMetadataUsageFieldInfo,
  68. kIl2CppMetadataUsageStringLiteral,
  69. kIl2CppMetadataUsageMethodRef,
  70. };
  71. static inline Il2CppMetadataUsage GetEncodedIndexType(EncodedMethodIndex index)
  72. {
  73. return (Il2CppMetadataUsage)((index & 0xE0000000) >> 29);
  74. }
  75. static inline uint32_t GetDecodedMethodIndex(EncodedMethodIndex index)
  76. {
  77. return index & 0x1FFFFFFFU;
  78. }
  79. struct Il2CppImage;
  80. struct Il2CppType;
  81. struct Il2CppTypeDefinitionMetadata;
  82. union Il2CppRGCTXDefinitionData
  83. {
  84. int32_t rgctxDataDummy;
  85. MethodIndex methodIndex;
  86. TypeIndex typeIndex;
  87. };
  88. enum Il2CppRGCTXDataType
  89. {
  90. IL2CPP_RGCTX_DATA_INVALID,
  91. IL2CPP_RGCTX_DATA_TYPE,
  92. IL2CPP_RGCTX_DATA_CLASS,
  93. IL2CPP_RGCTX_DATA_METHOD,
  94. IL2CPP_RGCTX_DATA_ARRAY,
  95. };
  96. struct Il2CppRGCTXDefinition
  97. {
  98. Il2CppRGCTXDataType type;
  99. Il2CppRGCTXDefinitionData data;
  100. };
  101. struct Il2CppInterfaceOffsetPair
  102. {
  103. TypeIndex interfaceTypeIndex;
  104. int32_t offset;
  105. };
  106. struct Il2CppTypeDefinition
  107. {
  108. StringIndex nameIndex;
  109. StringIndex namespaceIndex;
  110. CustomAttributeIndex customAttributeIndex;
  111. TypeIndex byvalTypeIndex;
  112. TypeIndex byrefTypeIndex;
  113. TypeIndex declaringTypeIndex;
  114. TypeIndex parentIndex;
  115. TypeIndex elementTypeIndex; // we can probably remove this one. Only used for enums
  116. RGCTXIndex rgctxStartIndex;
  117. int32_t rgctxCount;
  118. GenericContainerIndex genericContainerIndex;
  119. uint32_t flags;
  120. FieldIndex fieldStart;
  121. MethodIndex methodStart;
  122. EventIndex eventStart;
  123. PropertyIndex propertyStart;
  124. NestedTypeIndex nestedTypesStart;
  125. InterfacesIndex interfacesStart;
  126. VTableIndex vtableStart;
  127. InterfacesIndex interfaceOffsetsStart;
  128. uint16_t method_count;
  129. uint16_t property_count;
  130. uint16_t field_count;
  131. uint16_t event_count;
  132. uint16_t nested_type_count;
  133. uint16_t vtable_count;
  134. uint16_t interfaces_count;
  135. uint16_t interface_offsets_count;
  136. // bitfield to portably encode boolean values as single bits
  137. // 01 - valuetype;
  138. // 02 - enumtype;
  139. // 03 - has_finalize;
  140. // 04 - has_cctor;
  141. // 05 - is_blittable;
  142. // 06 - is_import_or_windows_runtime;
  143. // 07-10 - One of nine possible PackingSize values (0, 1, 2, 4, 8, 16, 32, 64, or 128)
  144. uint32_t bitfield;
  145. uint32_t token;
  146. };
  147. struct Il2CppFieldDefinition
  148. {
  149. StringIndex nameIndex;
  150. TypeIndex typeIndex;
  151. CustomAttributeIndex customAttributeIndex;
  152. uint32_t token;
  153. };
  154. struct Il2CppFieldDefaultValue
  155. {
  156. FieldIndex fieldIndex;
  157. TypeIndex typeIndex;
  158. DefaultValueDataIndex dataIndex;
  159. };
  160. struct Il2CppFieldMarshaledSize
  161. {
  162. FieldIndex fieldIndex;
  163. TypeIndex typeIndex;
  164. int32_t size;
  165. };
  166. struct Il2CppFieldRef
  167. {
  168. TypeIndex typeIndex;
  169. FieldIndex fieldIndex; // local offset into type fields
  170. };
  171. struct Il2CppParameterDefinition
  172. {
  173. StringIndex nameIndex;
  174. uint32_t token;
  175. CustomAttributeIndex customAttributeIndex;
  176. TypeIndex typeIndex;
  177. };
  178. struct Il2CppParameterDefaultValue
  179. {
  180. ParameterIndex parameterIndex;
  181. TypeIndex typeIndex;
  182. DefaultValueDataIndex dataIndex;
  183. };
  184. struct Il2CppMethodDefinition
  185. {
  186. StringIndex nameIndex;
  187. TypeDefinitionIndex declaringType;
  188. TypeIndex returnType;
  189. ParameterIndex parameterStart;
  190. CustomAttributeIndex customAttributeIndex;
  191. GenericContainerIndex genericContainerIndex;
  192. MethodIndex methodIndex;
  193. MethodIndex invokerIndex;
  194. MethodIndex reversePInvokeWrapperIndex;
  195. RGCTXIndex rgctxStartIndex;
  196. int32_t rgctxCount;
  197. uint32_t token;
  198. uint16_t flags;
  199. uint16_t iflags;
  200. uint16_t slot;
  201. uint16_t parameterCount;
  202. };
  203. struct Il2CppEventDefinition
  204. {
  205. StringIndex nameIndex;
  206. TypeIndex typeIndex;
  207. MethodIndex add;
  208. MethodIndex remove;
  209. MethodIndex raise;
  210. CustomAttributeIndex customAttributeIndex;
  211. uint32_t token;
  212. };
  213. struct Il2CppPropertyDefinition
  214. {
  215. StringIndex nameIndex;
  216. MethodIndex get;
  217. MethodIndex set;
  218. uint32_t attrs;
  219. CustomAttributeIndex customAttributeIndex;
  220. uint32_t token;
  221. };
  222. struct Il2CppMethodSpec
  223. {
  224. MethodIndex methodDefinitionIndex;
  225. GenericInstIndex classIndexIndex;
  226. GenericInstIndex methodIndexIndex;
  227. };
  228. struct Il2CppStringLiteral
  229. {
  230. uint32_t length;
  231. StringLiteralIndex dataIndex;
  232. };
  233. struct Il2CppGenericMethodIndices
  234. {
  235. MethodIndex methodIndex;
  236. MethodIndex invokerIndex;
  237. };
  238. struct Il2CppGenericMethodFunctionsDefinitions
  239. {
  240. GenericMethodIndex genericMethodIndex;
  241. Il2CppGenericMethodIndices indices;
  242. };
  243. const int kPublicKeyByteLength = 8;
  244. struct Il2CppAssemblyName
  245. {
  246. StringIndex nameIndex;
  247. StringIndex cultureIndex;
  248. StringIndex hashValueIndex;
  249. StringIndex publicKeyIndex;
  250. uint32_t hash_alg;
  251. int32_t hash_len;
  252. uint32_t flags;
  253. int32_t major;
  254. int32_t minor;
  255. int32_t build;
  256. int32_t revision;
  257. uint8_t publicKeyToken[kPublicKeyByteLength];
  258. };
  259. struct Il2CppImageDefinition
  260. {
  261. StringIndex nameIndex;
  262. AssemblyIndex assemblyIndex;
  263. TypeDefinitionIndex typeStart;
  264. uint32_t typeCount;
  265. TypeDefinitionIndex exportedTypeStart;
  266. uint32_t exportedTypeCount;
  267. MethodIndex entryPointIndex;
  268. uint32_t token;
  269. };
  270. struct Il2CppAssembly
  271. {
  272. ImageIndex imageIndex;
  273. CustomAttributeIndex customAttributeIndex;
  274. int32_t referencedAssemblyStart;
  275. int32_t referencedAssemblyCount;
  276. Il2CppAssemblyName aname;
  277. };
  278. struct Il2CppMetadataUsageList
  279. {
  280. uint32_t start;
  281. uint32_t count;
  282. };
  283. struct Il2CppMetadataUsagePair
  284. {
  285. uint32_t destinationIndex;
  286. uint32_t encodedSourceIndex;
  287. };
  288. struct Il2CppCustomAttributeTypeRange
  289. {
  290. int32_t start;
  291. int32_t count;
  292. };
  293. struct Il2CppRange
  294. {
  295. int32_t start;
  296. int32_t length;
  297. };
  298. struct Il2CppWindowsRuntimeTypeNamePair
  299. {
  300. StringIndex nameIndex;
  301. TypeIndex typeIndex;
  302. };
  303. #pragma pack(push, p1,4)
  304. struct Il2CppGlobalMetadataHeader
  305. {
  306. int32_t sanity;
  307. int32_t version;
  308. int32_t stringLiteralOffset; // string data for managed code
  309. int32_t stringLiteralCount;
  310. int32_t stringLiteralDataOffset;
  311. int32_t stringLiteralDataCount;
  312. int32_t stringOffset; // string data for metadata
  313. int32_t stringCount;
  314. int32_t eventsOffset; // Il2CppEventDefinition
  315. int32_t eventsCount;
  316. int32_t propertiesOffset; // Il2CppPropertyDefinition
  317. int32_t propertiesCount;
  318. int32_t methodsOffset; // Il2CppMethodDefinition
  319. int32_t methodsCount;
  320. int32_t parameterDefaultValuesOffset; // Il2CppParameterDefaultValue
  321. int32_t parameterDefaultValuesCount;
  322. int32_t fieldDefaultValuesOffset; // Il2CppFieldDefaultValue
  323. int32_t fieldDefaultValuesCount;
  324. int32_t fieldAndParameterDefaultValueDataOffset; // uint8_t
  325. int32_t fieldAndParameterDefaultValueDataCount;
  326. int32_t fieldMarshaledSizesOffset; // Il2CppFieldMarshaledSize
  327. int32_t fieldMarshaledSizesCount;
  328. int32_t parametersOffset; // Il2CppParameterDefinition
  329. int32_t parametersCount;
  330. int32_t fieldsOffset; // Il2CppFieldDefinition
  331. int32_t fieldsCount;
  332. int32_t genericParametersOffset; // Il2CppGenericParameter
  333. int32_t genericParametersCount;
  334. int32_t genericParameterConstraintsOffset; // TypeIndex
  335. int32_t genericParameterConstraintsCount;
  336. int32_t genericContainersOffset; // Il2CppGenericContainer
  337. int32_t genericContainersCount;
  338. int32_t nestedTypesOffset; // TypeDefinitionIndex
  339. int32_t nestedTypesCount;
  340. int32_t interfacesOffset; // TypeIndex
  341. int32_t interfacesCount;
  342. int32_t vtableMethodsOffset; // EncodedMethodIndex
  343. int32_t vtableMethodsCount;
  344. int32_t interfaceOffsetsOffset; // Il2CppInterfaceOffsetPair
  345. int32_t interfaceOffsetsCount;
  346. int32_t typeDefinitionsOffset; // Il2CppTypeDefinition
  347. int32_t typeDefinitionsCount;
  348. int32_t rgctxEntriesOffset; // Il2CppRGCTXDefinition
  349. int32_t rgctxEntriesCount;
  350. int32_t imagesOffset; // Il2CppImageDefinition
  351. int32_t imagesCount;
  352. int32_t assembliesOffset; // Il2CppAssemblyDefinition
  353. int32_t assembliesCount;
  354. int32_t metadataUsageListsOffset; // Il2CppMetadataUsageList
  355. int32_t metadataUsageListsCount;
  356. int32_t metadataUsagePairsOffset; // Il2CppMetadataUsagePair
  357. int32_t metadataUsagePairsCount;
  358. int32_t fieldRefsOffset; // Il2CppFieldRef
  359. int32_t fieldRefsCount;
  360. int32_t referencedAssembliesOffset; // int32_t
  361. int32_t referencedAssembliesCount;
  362. int32_t attributesInfoOffset; // Il2CppCustomAttributeTypeRange
  363. int32_t attributesInfoCount;
  364. int32_t attributeTypesOffset; // TypeIndex
  365. int32_t attributeTypesCount;
  366. int32_t unresolvedVirtualCallParameterTypesOffset; // TypeIndex
  367. int32_t unresolvedVirtualCallParameterTypesCount;
  368. int32_t unresolvedVirtualCallParameterRangesOffset; // Il2CppRange
  369. int32_t unresolvedVirtualCallParameterRangesCount;
  370. int32_t windowsRuntimeTypeNamesOffset; // Il2CppWindowsRuntimeTypeNamePair
  371. int32_t windowsRuntimeTypeNamesSize;
  372. int32_t exportedTypeDefinitionsOffset; // TypeDefinitionIndex
  373. int32_t exportedTypeDefinitionsCount;
  374. };
  375. #pragma pack(pop, p1)
  376. #if RUNTIME_MONO
  377. #pragma pack(push, p1,4)
  378. struct Il2CppGlobalMonoMetadataHeader
  379. {
  380. int32_t sanity;
  381. int32_t version;
  382. int32_t stringOffset; // string data for metadata
  383. int32_t stringCount;
  384. int32_t methodInfoMappingOffset; // hash -> MonoMethodInfo mapping
  385. int32_t methodInfoMappingCount;
  386. int32_t genericMethodInfoMappingOffset; // hash -> generic MonoMethodInfo mapping
  387. int32_t genericMethodInfoMappingCount;
  388. int32_t rgctxIndicesOffset; // runtime generic context indices
  389. int32_t rgctxIndicesCount;
  390. int32_t rgctxInfoOffset; // runtime generic context info
  391. int32_t rgctxInfoCount;
  392. int32_t monoStringOffset; // mono strings
  393. int32_t monoStringCount;
  394. int32_t methodMetadataOffset; // method metadata
  395. int32_t methodMetadataCount;
  396. int32_t genericArgumentIndicesOffset; // generic argument indices
  397. int32_t genericArgumentIndicesCount;
  398. int32_t typeTableOffset; // type table
  399. int32_t typeTableCount;
  400. int32_t fieldTableOffset; // field table
  401. int32_t fieldTableCount;
  402. int32_t methodIndexTableOffset; // method index table
  403. int32_t methodIndexTableCount;
  404. int32_t genericMethodIndexTableOffset; // generic method index table
  405. int32_t genericMethodIndexTableCount;
  406. int32_t metaDataUsageListsTableOffset; // meta data usage lists table
  407. int32_t metaDataUsageListsTableCount;
  408. int32_t metaDataUsagePairsTableOffset; // meta data usage pairs table
  409. int32_t metaDataUsagePairsTableCount;
  410. int32_t assemblyNameTableOffset; // assembly names
  411. int32_t assemblyNameTableCount;
  412. };
  413. #pragma pack(pop, p1)
  414. #endif