GlobalMetadataFileInternals.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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. typedef uint32_t EncodedMethodIndex;
  23. enum Il2CppMetadataUsage
  24. {
  25. kIl2CppMetadataUsageInvalid,
  26. kIl2CppMetadataUsageTypeInfo,
  27. kIl2CppMetadataUsageIl2CppType,
  28. kIl2CppMetadataUsageMethodDef,
  29. kIl2CppMetadataUsageFieldInfo,
  30. kIl2CppMetadataUsageStringLiteral,
  31. kIl2CppMetadataUsageMethodRef,
  32. };
  33. #ifdef __cplusplus
  34. static inline Il2CppMetadataUsage GetEncodedIndexType(EncodedMethodIndex index)
  35. {
  36. return (Il2CppMetadataUsage)((index & 0xE0000000) >> 29);
  37. }
  38. static inline uint32_t GetDecodedMethodIndex(EncodedMethodIndex index)
  39. {
  40. return (index & 0x1FFFFFFEU) >> 1;
  41. }
  42. #endif
  43. typedef struct Il2CppInterfaceOffsetPair
  44. {
  45. TypeIndex interfaceTypeIndex;
  46. int32_t offset;
  47. } Il2CppInterfaceOffsetPair;
  48. typedef struct Il2CppTypeDefinition
  49. {
  50. StringIndex nameIndex;
  51. StringIndex namespaceIndex;
  52. TypeIndex byvalTypeIndex;
  53. TypeIndex declaringTypeIndex;
  54. TypeIndex parentIndex;
  55. TypeIndex elementTypeIndex; // we can probably remove this one. Only used for enums
  56. GenericContainerIndex genericContainerIndex;
  57. uint32_t flags;
  58. FieldIndex fieldStart;
  59. MethodIndex methodStart;
  60. EventIndex eventStart;
  61. PropertyIndex propertyStart;
  62. NestedTypeIndex nestedTypesStart;
  63. InterfacesIndex interfacesStart;
  64. VTableIndex vtableStart;
  65. InterfacesIndex interfaceOffsetsStart;
  66. uint16_t method_count;
  67. uint16_t property_count;
  68. uint16_t field_count;
  69. uint16_t event_count;
  70. uint16_t nested_type_count;
  71. uint16_t vtable_count;
  72. uint16_t interfaces_count;
  73. uint16_t interface_offsets_count;
  74. // bitfield to portably encode boolean values as single bits
  75. // 01 - valuetype;
  76. // 02 - enumtype;
  77. // 03 - has_finalize;
  78. // 04 - has_cctor;
  79. // 05 - is_blittable;
  80. // 06 - is_import_or_windows_runtime;
  81. // 07-10 - One of nine possible PackingSize values (0, 1, 2, 4, 8, 16, 32, 64, or 128)
  82. // 11 - PackingSize is default
  83. // 12 - ClassSize is default
  84. // 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)
  85. uint32_t bitfield;
  86. uint32_t token;
  87. } Il2CppTypeDefinition;
  88. typedef struct Il2CppFieldDefinition
  89. {
  90. StringIndex nameIndex;
  91. TypeIndex typeIndex;
  92. uint32_t token;
  93. } Il2CppFieldDefinition;
  94. typedef struct Il2CppFieldDefaultValue
  95. {
  96. FieldIndex fieldIndex;
  97. TypeIndex typeIndex;
  98. DefaultValueDataIndex dataIndex;
  99. } Il2CppFieldDefaultValue;
  100. typedef struct Il2CppFieldMarshaledSize
  101. {
  102. FieldIndex fieldIndex;
  103. TypeIndex typeIndex;
  104. int32_t size;
  105. } Il2CppFieldMarshaledSize;
  106. typedef struct Il2CppFieldRef
  107. {
  108. TypeIndex typeIndex;
  109. FieldIndex fieldIndex; // local offset into type fields
  110. } Il2CppFieldRef;
  111. typedef struct Il2CppParameterDefinition
  112. {
  113. StringIndex nameIndex;
  114. uint32_t token;
  115. TypeIndex typeIndex;
  116. } Il2CppParameterDefinition;
  117. typedef struct Il2CppParameterDefaultValue
  118. {
  119. ParameterIndex parameterIndex;
  120. TypeIndex typeIndex;
  121. DefaultValueDataIndex dataIndex;
  122. } Il2CppParameterDefaultValue;
  123. typedef struct Il2CppMethodDefinition
  124. {
  125. StringIndex nameIndex;
  126. TypeDefinitionIndex declaringType;
  127. TypeIndex returnType;
  128. ParameterIndex parameterStart;
  129. GenericContainerIndex genericContainerIndex;
  130. uint32_t token;
  131. uint16_t flags;
  132. uint16_t iflags;
  133. uint16_t slot;
  134. uint16_t parameterCount;
  135. } Il2CppMethodDefinition;
  136. typedef struct Il2CppEventDefinition
  137. {
  138. StringIndex nameIndex;
  139. TypeIndex typeIndex;
  140. MethodIndex add;
  141. MethodIndex remove;
  142. MethodIndex raise;
  143. uint32_t token;
  144. } Il2CppEventDefinition;
  145. typedef struct Il2CppPropertyDefinition
  146. {
  147. StringIndex nameIndex;
  148. MethodIndex get;
  149. MethodIndex set;
  150. uint32_t attrs;
  151. uint32_t token;
  152. } Il2CppPropertyDefinition;
  153. typedef struct Il2CppStringLiteral
  154. {
  155. uint32_t length;
  156. StringLiteralIndex dataIndex;
  157. } Il2CppStringLiteral;
  158. typedef struct Il2CppAssemblyNameDefinition
  159. {
  160. StringIndex nameIndex;
  161. StringIndex cultureIndex;
  162. StringIndex publicKeyIndex;
  163. uint32_t hash_alg;
  164. int32_t hash_len;
  165. uint32_t flags;
  166. int32_t major;
  167. int32_t minor;
  168. int32_t build;
  169. int32_t revision;
  170. uint8_t public_key_token[PUBLIC_KEY_BYTE_LENGTH];
  171. } Il2CppAssemblyNameDefinition;
  172. typedef struct Il2CppImageDefinition
  173. {
  174. StringIndex nameIndex;
  175. AssemblyIndex assemblyIndex;
  176. TypeDefinitionIndex typeStart;
  177. uint32_t typeCount;
  178. TypeDefinitionIndex exportedTypeStart;
  179. uint32_t exportedTypeCount;
  180. MethodIndex entryPointIndex;
  181. uint32_t token;
  182. CustomAttributeIndex customAttributeStart;
  183. uint32_t customAttributeCount;
  184. } Il2CppImageDefinition;
  185. typedef struct Il2CppAssemblyDefinition
  186. {
  187. ImageIndex imageIndex;
  188. uint32_t token;
  189. int32_t referencedAssemblyStart;
  190. int32_t referencedAssemblyCount;
  191. Il2CppAssemblyNameDefinition aname;
  192. } Il2CppAssemblyDefinition;
  193. typedef struct Il2CppCustomAttributeTypeRange
  194. {
  195. uint32_t token;
  196. int32_t start;
  197. int32_t count;
  198. } Il2CppCustomAttributeTypeRange;
  199. typedef struct Il2CppMetadataRange
  200. {
  201. int32_t start;
  202. int32_t length;
  203. } Il2CppMetadataRange;
  204. typedef struct Il2CppGenericContainer
  205. {
  206. /* index of the generic type definition or the generic method definition corresponding to this container */
  207. int32_t ownerIndex; // either index into Il2CppClass metadata array or Il2CppMethodDefinition array
  208. int32_t type_argc;
  209. /* If true, we're a generic method, otherwise a generic type definition. */
  210. int32_t is_method;
  211. /* Our type parameters. */
  212. GenericParameterIndex genericParameterStart;
  213. } Il2CppGenericContainer;
  214. typedef struct Il2CppGenericParameter
  215. {
  216. GenericContainerIndex ownerIndex; /* Type or method this parameter was defined in. */
  217. StringIndex nameIndex;
  218. GenericParameterConstraintIndex constraintsStart;
  219. int16_t constraintsCount;
  220. uint16_t num;
  221. uint16_t flags;
  222. } Il2CppGenericParameter;
  223. typedef struct Il2CppWindowsRuntimeTypeNamePair
  224. {
  225. StringIndex nameIndex;
  226. TypeIndex typeIndex;
  227. } Il2CppWindowsRuntimeTypeNamePair;
  228. #pragma pack(push, p1,4)
  229. typedef struct Il2CppGlobalMetadataHeader
  230. {
  231. int32_t sanity;
  232. int32_t version;
  233. int32_t stringLiteralOffset; // string data for managed code
  234. int32_t stringLiteralCount;
  235. int32_t stringLiteralDataOffset;
  236. int32_t stringLiteralDataCount;
  237. int32_t stringOffset; // string data for metadata
  238. int32_t stringCount;
  239. int32_t eventsOffset; // Il2CppEventDefinition
  240. int32_t eventsCount;
  241. int32_t propertiesOffset; // Il2CppPropertyDefinition
  242. int32_t propertiesCount;
  243. int32_t methodsOffset; // Il2CppMethodDefinition
  244. int32_t methodsCount;
  245. int32_t parameterDefaultValuesOffset; // Il2CppParameterDefaultValue
  246. int32_t parameterDefaultValuesCount;
  247. int32_t fieldDefaultValuesOffset; // Il2CppFieldDefaultValue
  248. int32_t fieldDefaultValuesCount;
  249. int32_t fieldAndParameterDefaultValueDataOffset; // uint8_t
  250. int32_t fieldAndParameterDefaultValueDataCount;
  251. int32_t fieldMarshaledSizesOffset; // Il2CppFieldMarshaledSize
  252. int32_t fieldMarshaledSizesCount;
  253. int32_t parametersOffset; // Il2CppParameterDefinition
  254. int32_t parametersCount;
  255. int32_t fieldsOffset; // Il2CppFieldDefinition
  256. int32_t fieldsCount;
  257. int32_t genericParametersOffset; // Il2CppGenericParameter
  258. int32_t genericParametersCount;
  259. int32_t genericParameterConstraintsOffset; // TypeIndex
  260. int32_t genericParameterConstraintsCount;
  261. int32_t genericContainersOffset; // Il2CppGenericContainer
  262. int32_t genericContainersCount;
  263. int32_t nestedTypesOffset; // TypeDefinitionIndex
  264. int32_t nestedTypesCount;
  265. int32_t interfacesOffset; // TypeIndex
  266. int32_t interfacesCount;
  267. int32_t vtableMethodsOffset; // EncodedMethodIndex
  268. int32_t vtableMethodsCount;
  269. int32_t interfaceOffsetsOffset; // Il2CppInterfaceOffsetPair
  270. int32_t interfaceOffsetsCount;
  271. int32_t typeDefinitionsOffset; // Il2CppTypeDefinition
  272. int32_t typeDefinitionsCount;
  273. int32_t imagesOffset; // Il2CppImageDefinition
  274. int32_t imagesCount;
  275. int32_t assembliesOffset; // Il2CppAssemblyDefinition
  276. int32_t assembliesCount;
  277. int32_t fieldRefsOffset; // Il2CppFieldRef
  278. int32_t fieldRefsCount;
  279. int32_t referencedAssembliesOffset; // int32_t
  280. int32_t referencedAssembliesCount;
  281. int32_t attributesInfoOffset; // Il2CppCustomAttributeTypeRange
  282. int32_t attributesInfoCount;
  283. int32_t attributeTypesOffset; // TypeIndex
  284. int32_t attributeTypesCount;
  285. int32_t unresolvedVirtualCallParameterTypesOffset; // TypeIndex
  286. int32_t unresolvedVirtualCallParameterTypesCount;
  287. int32_t unresolvedVirtualCallParameterRangesOffset; // Il2CppMetadataRange
  288. int32_t unresolvedVirtualCallParameterRangesCount;
  289. int32_t windowsRuntimeTypeNamesOffset; // Il2CppWindowsRuntimeTypeNamePair
  290. int32_t windowsRuntimeTypeNamesSize;
  291. int32_t windowsRuntimeStringsOffset; // const char*
  292. int32_t windowsRuntimeStringsSize;
  293. int32_t exportedTypeDefinitionsOffset; // TypeDefinitionIndex
  294. int32_t exportedTypeDefinitionsCount;
  295. } Il2CppGlobalMetadataHeader;
  296. #pragma pack(pop, p1)