GlobalMetadataFileInternals.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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. // The serialized size of some indexes may be one, two, or four bytes, dependending on how many elements the index needs
  12. // to represent. In general, we use the smallest possible representation of an index to minimize the size of the
  13. // serialized metadata. The structs in this file, and the indexes they contain, represent the *deserialized* form.
  14. // The serialized size is known only at runtime, so it can't be expressed statically here.
  15. // Values for EncodedMethodIndex:
  16. // Encoded index (1 bit)
  17. // MethodDef - 0
  18. // MethodSpec - 1
  19. // We use the top 3 bits to indicate what table to index into
  20. // Type Binary Hex
  21. // Il2CppClass 001 0x20000000
  22. // Il2CppType 010 0x40000000
  23. // MethodInfo 011 0x60000000
  24. // FieldInfo 100 0x80000000
  25. // StringLiteral 101 0xA0000000
  26. // MethodRef 110 0xC0000000
  27. // FieldRVA 111 0xE0000000
  28. typedef uint32_t EncodedMethodIndex;
  29. enum Il2CppMetadataUsage
  30. {
  31. kIl2CppMetadataUsageInvalid,
  32. kIl2CppMetadataUsageTypeInfo,
  33. kIl2CppMetadataUsageIl2CppType,
  34. kIl2CppMetadataUsageMethodDef,
  35. kIl2CppMetadataUsageFieldInfo,
  36. kIl2CppMetadataUsageStringLiteral,
  37. kIl2CppMetadataUsageMethodRef,
  38. kIl2CppMetadataUsageFieldRva
  39. };
  40. enum Il2CppInvalidMetadataUsageToken
  41. {
  42. kIl2CppInvalidMetadataUsageNoData = 0,
  43. kIl2CppInvalidMetadataUsageAmbiguousMethod = 1,
  44. };
  45. #ifdef __cplusplus
  46. static inline Il2CppMetadataUsage GetEncodedIndexType(EncodedMethodIndex index)
  47. {
  48. return (Il2CppMetadataUsage)((index & 0xE0000000) >> 29);
  49. }
  50. static inline uint32_t GetDecodedMethodIndex(EncodedMethodIndex index)
  51. {
  52. return (index & 0x1FFFFFFEU) >> 1;
  53. }
  54. #endif
  55. typedef struct Il2CppInterfaceOffsetPair
  56. {
  57. TypeIndex interfaceTypeIndex;
  58. int32_t offset;
  59. } Il2CppInterfaceOffsetPair;
  60. typedef struct Il2CppTypeDefinition
  61. {
  62. StringIndex nameIndex;
  63. StringIndex namespaceIndex;
  64. TypeIndex byvalTypeIndex;
  65. TypeIndex declaringTypeIndex;
  66. TypeIndex parentIndex;
  67. GenericContainerIndex genericContainerIndex;
  68. uint32_t flags;
  69. FieldIndex fieldStart;
  70. MethodIndex methodStart;
  71. EventIndex eventStart;
  72. PropertyIndex propertyStart;
  73. NestedTypeIndex nestedTypesStart;
  74. InterfacesIndex interfacesStart;
  75. VTableIndex vtableStart;
  76. InterfacesIndex interfaceOffsetsStart;
  77. uint16_t method_count;
  78. uint16_t property_count;
  79. uint16_t field_count;
  80. uint16_t event_count;
  81. uint16_t nested_type_count;
  82. uint16_t vtable_count;
  83. uint16_t interfaces_count;
  84. uint16_t interface_offsets_count;
  85. // bitfield to portably encode boolean values as single bits
  86. // 01 - valuetype;
  87. // 02 - enumtype;
  88. // 03 - has_finalize;
  89. // 04 - has_cctor;
  90. // 05 - is_blittable;
  91. // 06 - is_import_or_windows_runtime;
  92. // 07-10 - One of nine possible PackingSize values (0, 1, 2, 4, 8, 16, 32, 64, or 128)
  93. // 11 - PackingSize is default
  94. // 12 - ClassSize is default
  95. // 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)
  96. uint32_t bitfield;
  97. uint32_t token;
  98. } Il2CppTypeDefinition;
  99. typedef struct Il2CppFieldDefinition
  100. {
  101. StringIndex nameIndex;
  102. TypeIndex typeIndex;
  103. uint32_t token;
  104. } Il2CppFieldDefinition;
  105. typedef struct Il2CppFieldDefaultValue
  106. {
  107. FieldIndex fieldIndex;
  108. TypeIndex typeIndex;
  109. DefaultValueDataIndex dataIndex;
  110. } Il2CppFieldDefaultValue;
  111. typedef struct Il2CppFieldMarshaledSize
  112. {
  113. FieldIndex fieldIndex;
  114. TypeIndex typeIndex;
  115. int32_t size;
  116. } Il2CppFieldMarshaledSize;
  117. typedef struct Il2CppFieldRef
  118. {
  119. TypeIndex typeIndex;
  120. FieldIndex fieldIndex; // local offset into type fields
  121. } Il2CppFieldRef;
  122. typedef struct Il2CppParameterDefinition
  123. {
  124. StringIndex nameIndex;
  125. uint32_t token;
  126. TypeIndex typeIndex;
  127. } Il2CppParameterDefinition;
  128. typedef struct Il2CppParameterDefaultValue
  129. {
  130. ParameterIndex parameterIndex;
  131. TypeIndex typeIndex;
  132. DefaultValueDataIndex dataIndex;
  133. } Il2CppParameterDefaultValue;
  134. typedef struct Il2CppMethodDefinition
  135. {
  136. StringIndex nameIndex;
  137. TypeDefinitionIndex declaringType;
  138. TypeIndex returnType;
  139. uint32_t returnParameterToken;
  140. ParameterIndex parameterStart;
  141. GenericContainerIndex genericContainerIndex;
  142. uint32_t token;
  143. uint16_t flags;
  144. uint16_t iflags;
  145. uint16_t slot;
  146. uint16_t parameterCount;
  147. } Il2CppMethodDefinition;
  148. typedef struct Il2CppEventDefinition
  149. {
  150. StringIndex nameIndex;
  151. TypeIndex typeIndex;
  152. MethodIndex add;
  153. MethodIndex remove;
  154. MethodIndex raise;
  155. uint32_t token;
  156. } Il2CppEventDefinition;
  157. typedef struct Il2CppPropertyDefinition
  158. {
  159. StringIndex nameIndex;
  160. MethodIndex get;
  161. MethodIndex set;
  162. uint32_t attrs;
  163. uint32_t token;
  164. } Il2CppPropertyDefinition;
  165. typedef struct Il2CppStringLiteral
  166. {
  167. StringLiteralIndex dataIndex;
  168. } Il2CppStringLiteral;
  169. typedef struct Il2CppAssemblyNameDefinition
  170. {
  171. StringIndex nameIndex;
  172. StringIndex cultureIndex;
  173. StringIndex publicKeyIndex;
  174. uint32_t hash_alg;
  175. int32_t hash_len;
  176. uint32_t flags;
  177. int32_t major;
  178. int32_t minor;
  179. int32_t build;
  180. int32_t revision;
  181. uint8_t public_key_token[PUBLIC_KEY_BYTE_LENGTH];
  182. } Il2CppAssemblyNameDefinition;
  183. typedef struct Il2CppImageDefinition
  184. {
  185. StringIndex nameIndex;
  186. AssemblyIndex assemblyIndex;
  187. TypeDefinitionIndex typeStart;
  188. uint32_t typeCount;
  189. TypeDefinitionIndex exportedTypeStart;
  190. uint32_t exportedTypeCount;
  191. MethodIndex entryPointIndex;
  192. uint32_t token;
  193. CustomAttributeIndex customAttributeStart;
  194. uint32_t customAttributeCount;
  195. } Il2CppImageDefinition;
  196. typedef struct Il2CppAssemblyDefinition
  197. {
  198. ImageIndex imageIndex;
  199. uint32_t token;
  200. uint32_t moduleToken;
  201. int32_t referencedAssemblyStart;
  202. int32_t referencedAssemblyCount;
  203. Il2CppAssemblyNameDefinition aname;
  204. } Il2CppAssemblyDefinition;
  205. typedef struct Il2CppCustomAttributeDataRange
  206. {
  207. uint32_t token;
  208. uint32_t startOffset;
  209. } Il2CppCustomAttributeDataRange;
  210. typedef struct Il2CppMetadataRange
  211. {
  212. int32_t start;
  213. int32_t length;
  214. } Il2CppMetadataRange;
  215. typedef struct Il2CppGenericContainer
  216. {
  217. /* index of the generic type definition or the generic method definition corresponding to this container */
  218. int32_t ownerIndex; // either index into Il2CppClass metadata array or Il2CppMethodDefinition array
  219. int32_t type_argc;
  220. /* If true, we're a generic method, otherwise a generic type definition. */
  221. int32_t is_method;
  222. /* Our type parameters. */
  223. GenericParameterIndex genericParameterStart;
  224. } Il2CppGenericContainer;
  225. typedef struct Il2CppGenericParameter
  226. {
  227. GenericContainerIndex ownerIndex; /* Type or method this parameter was defined in. */
  228. StringIndex nameIndex;
  229. GenericParameterConstraintIndex constraintsStart;
  230. int16_t constraintsCount;
  231. uint16_t num;
  232. uint16_t flags;
  233. } Il2CppGenericParameter;
  234. typedef struct Il2CppWindowsRuntimeTypeNamePair
  235. {
  236. StringIndex nameIndex;
  237. TypeIndex typeIndex;
  238. } Il2CppWindowsRuntimeTypeNamePair;
  239. typedef struct Il2CppSectionMetadata
  240. {
  241. int32_t offset;
  242. int32_t size;
  243. int32_t count;
  244. } Il2CppSectionMetadata;
  245. #pragma pack(push, p1,4)
  246. typedef struct Il2CppGlobalMetadataHeader
  247. {
  248. uint32_t sanity;
  249. int32_t version;
  250. Il2CppSectionMetadata stringLiterals; // string data for managed code
  251. Il2CppSectionMetadata stringLiteralData;
  252. Il2CppSectionMetadata strings; // string data for metadata
  253. Il2CppSectionMetadata events; // Il2CppEventDefinition
  254. Il2CppSectionMetadata properties; // Il2CppPropertyDefinition
  255. Il2CppSectionMetadata methods; // Il2CppMethodDefinition
  256. Il2CppSectionMetadata parameterDefaultValues; // Il2CppParameterDefaultValue
  257. Il2CppSectionMetadata fieldDefaultValues; // Il2CppFieldDefaultValue
  258. Il2CppSectionMetadata fieldAndParameterDefaultValueData; // uint8_t
  259. Il2CppSectionMetadata fieldMarshaledSizes; // Il2CppFieldMarshaledSize
  260. Il2CppSectionMetadata parameters; // Il2CppParameterDefinition
  261. Il2CppSectionMetadata fields; // Il2CppFieldDefinition
  262. Il2CppSectionMetadata genericParameters; // Il2CppGenericParameter
  263. Il2CppSectionMetadata genericParameterConstraints; // TypeIndex
  264. Il2CppSectionMetadata genericContainers; // Il2CppGenericContainer
  265. Il2CppSectionMetadata nestedTypes; // TypeDefinitionIndex
  266. Il2CppSectionMetadata interfaces; // TypeIndex
  267. Il2CppSectionMetadata vtableMethods; // EncodedMethodIndex
  268. Il2CppSectionMetadata interfaceOffsets; // Il2CppInterfaceOffsetPair
  269. Il2CppSectionMetadata typeDefinitions; // Il2CppTypeDefinition
  270. Il2CppSectionMetadata images; // Il2CppImageDefinition
  271. Il2CppSectionMetadata assemblies; // Il2CppAssemblyDefinition
  272. Il2CppSectionMetadata fieldRefs; // Il2CppFieldRef
  273. Il2CppSectionMetadata referencedAssemblies; // int32_t
  274. Il2CppSectionMetadata attributeData;
  275. Il2CppSectionMetadata attributeDataRanges;
  276. Il2CppSectionMetadata unresolvedIndirectCallParameterTypes; // TypeIndex
  277. Il2CppSectionMetadata unresolvedIndirectCallParameterRanges; // Il2CppMetadataRange
  278. Il2CppSectionMetadata windowsRuntimeTypeNames; // Il2CppWindowsRuntimeTypeNamePair
  279. Il2CppSectionMetadata windowsRuntimeStrings; // const char*
  280. Il2CppSectionMetadata exportedTypeDefinitions; // TypeDefinitionIndex
  281. } Il2CppGlobalMetadataHeader;
  282. #pragma pack(pop, p1)