From a6d9291303eeca9b7873bf9f0af8add4dd12478f Mon Sep 17 00:00:00 2001 From: LukeFZ <17146677+LukeFZ@users.noreply.github.com> Date: Wed, 29 Nov 2023 21:22:51 +0100 Subject: [PATCH] add classes for ver 29, fix some stuff for v24 --- Il2CppInspector.Common/IL2CPP/Metadata.cs | 516 +++++----- .../IL2CPP/MetadataClasses.cs | 936 +++++++++--------- 2 files changed, 741 insertions(+), 711 deletions(-) diff --git a/Il2CppInspector.Common/IL2CPP/Metadata.cs b/Il2CppInspector.Common/IL2CPP/Metadata.cs index 98e6fb3..03ba8cd 100644 --- a/Il2CppInspector.Common/IL2CPP/Metadata.cs +++ b/Il2CppInspector.Common/IL2CPP/Metadata.cs @@ -1,250 +1,266 @@ -/* - Copyright 2017 Perfare - https://github.com/Perfare/Il2CppDumper - Copyright 2017-2021 Katy Coe - http://www.djkaty.com - https://github.com/djkaty - - All rights reserved. -*/ - -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection; -using NoisyCowStudios.Bin2Object; - -namespace Il2CppInspector -{ - public class Metadata : BinaryObjectStream - { - public Il2CppGlobalMetadataHeader Header { get; set; } - - public Il2CppAssemblyDefinition[] Assemblies { get; set; } - public Il2CppImageDefinition[] Images { get; set; } - public Il2CppTypeDefinition[] Types { get; set; } - public Il2CppMethodDefinition[] Methods { get; set; } - public Il2CppParameterDefinition[] Params { get; set; } - public Il2CppFieldDefinition[] Fields { get; set; } - public Il2CppFieldDefaultValue[] FieldDefaultValues { get; set; } - public Il2CppParameterDefaultValue[] ParameterDefaultValues { get; set; } - public Il2CppPropertyDefinition[] Properties { get; set; } - public Il2CppEventDefinition[] Events { get; set; } - public Il2CppGenericContainer[] GenericContainers { get; set; } - public Il2CppGenericParameter[] GenericParameters { get; set; } - public Il2CppCustomAttributeTypeRange[] AttributeTypeRanges { get; set; } - public Il2CppInterfaceOffsetPair[] InterfaceOffsets { get; set; } - public Il2CppMetadataUsageList[] MetadataUsageLists { get; set; } - public Il2CppMetadataUsagePair[] MetadataUsagePairs { get; set; } - public Il2CppFieldRef[] FieldRefs { get; set; } - - public int[] InterfaceUsageIndices { get; set; } - public int[] NestedTypeIndices { get; set; } - public int[] AttributeTypeIndices { get; set; } - public int[] GenericConstraintIndices { get; set; } - public uint[] VTableMethodIndices { get; set; } - public string[] StringLiterals { get; set; } - - public Dictionary Strings { get; private set; } = new Dictionary(); - - // Set if something in the metadata has been modified / decrypted - public bool IsModified { get; private set; } = false; - - // Status update callback - private EventHandler OnStatusUpdate { get; set; } - private void StatusUpdate(string status) => OnStatusUpdate?.Invoke(this, status); - - // Initialize metadata object from a stream - public static Metadata FromStream(MemoryStream stream, EventHandler statusCallback = null) { - // TODO: This should really be placed before the Metadata object is created, - // but for now this ensures it is called regardless of which client is in use - PluginHooks.LoadPipelineStarting(); - - var metadata = new Metadata(statusCallback); - stream.Position = 0; - stream.CopyTo(metadata); - metadata.Position = 0; - metadata.Initialize(); - return metadata; - } - - private Metadata(EventHandler statusCallback = null) : base() => OnStatusUpdate = statusCallback; - - private void Initialize() - { - // Pre-processing hook - var pluginResult = PluginHooks.PreProcessMetadata(this); - IsModified = pluginResult.IsStreamModified; - - StatusUpdate("Processing metadata"); - - // Read metadata header - Header = ReadObject(0); - - // Check for correct magic bytes - if (Header.signature != Il2CppConstants.MetadataSignature) { - throw new InvalidOperationException("The supplied metadata file is not valid."); - } - - // Set object versioning for Bin2Object from metadata version - Version = Header.version; - - if (Version < 16 || Version > 27) { - throw new InvalidOperationException($"The supplied metadata file is not of a supported version ({Header.version})."); - } - - // Rewind and read metadata header with the correct version settings - Header = ReadObject(0); - - // Sanity checking - // Unity.IL2CPP.MetadataCacheWriter.WriteLibIl2CppMetadata always writes the metadata information in the same order it appears in the header, - // with each block always coming directly after the previous block, 4-byte aligned. We can use this to check the integrity of the data and - // detect sub-versions. - - // For metadata v24.0, the header can either be either 0x110 (24.0, 24.1) or 0x108 (24.2) bytes long. Since 'stringLiteralOffset' is the first thing - // in the header after the sanity and version fields, and since it will always point directly to the first byte after the end of the header, - // we can use this value to determine the actual header length and therefore narrow down the metadata version to 24.0/24.1 or 24.2. - - if (!pluginResult.SkipValidation) { - var realHeaderLength = Header.stringLiteralOffset; - - if (realHeaderLength != Sizeof(typeof(Il2CppGlobalMetadataHeader))) { - if (Version == 24.0) { - Version = 24.2; - Header = ReadObject(0); - } - } - - if (realHeaderLength != Sizeof(typeof(Il2CppGlobalMetadataHeader))) { - throw new InvalidOperationException("Could not verify the integrity of the metadata file or accurately identify the metadata sub-version"); - } - } - - // Load all the relevant metadata using offsets provided in the header - if (Version >= 16) - Images = ReadArray(Header.imagesOffset, Header.imagesCount / Sizeof(typeof(Il2CppImageDefinition))); - - // As an additional sanity check, all images in the metadata should have Mono.Cecil.MetadataToken == 1 - // In metadata v24.1, two extra fields were added which will cause the below test to fail. - // In that case, we can then adjust the version number and reload - // Tokens were introduced in v19 - we don't bother testing earlier versions - if (Version >= 19 && Images.Any(x => x.token != 1)) - if (Version == 24.0) { - Version = 24.1; - - // No need to re-read the header, it's the same for both sub-versions - Images = ReadArray(Header.imagesOffset, Header.imagesCount / Sizeof(typeof(Il2CppImageDefinition))); - - if (Images.Any(x => x.token != 1)) - throw new InvalidOperationException("Could not verify the integrity of the metadata file image list"); - } - - Types = ReadArray(Header.typeDefinitionsOffset, Header.typeDefinitionsCount / Sizeof(typeof(Il2CppTypeDefinition))); - Methods = ReadArray(Header.methodsOffset, Header.methodsCount / Sizeof(typeof(Il2CppMethodDefinition))); - Params = ReadArray(Header.parametersOffset, Header.parametersCount / Sizeof(typeof(Il2CppParameterDefinition))); - Fields = ReadArray(Header.fieldsOffset, Header.fieldsCount / Sizeof(typeof(Il2CppFieldDefinition))); - FieldDefaultValues = ReadArray(Header.fieldDefaultValuesOffset, Header.fieldDefaultValuesCount / Sizeof(typeof(Il2CppFieldDefaultValue))); - Properties = ReadArray(Header.propertiesOffset, Header.propertiesCount / Sizeof(typeof(Il2CppPropertyDefinition))); - Events = ReadArray(Header.eventsOffset, Header.eventsCount / Sizeof(typeof(Il2CppEventDefinition))); - InterfaceUsageIndices = ReadArray(Header.interfacesOffset, Header.interfacesCount / sizeof(int)); - NestedTypeIndices = ReadArray(Header.nestedTypesOffset, Header.nestedTypesCount / sizeof(int)); - GenericContainers = ReadArray(Header.genericContainersOffset, Header.genericContainersCount / Sizeof(typeof(Il2CppGenericContainer))); - GenericParameters = ReadArray(Header.genericParametersOffset, Header.genericParametersCount / Sizeof(typeof(Il2CppGenericParameter))); - GenericConstraintIndices = ReadArray(Header.genericParameterConstraintsOffset, Header.genericParameterConstraintsCount / sizeof(int)); - InterfaceOffsets = ReadArray(Header.interfaceOffsetsOffset, Header.interfaceOffsetsCount / Sizeof(typeof(Il2CppInterfaceOffsetPair))); - VTableMethodIndices = ReadArray(Header.vtableMethodsOffset, Header.vtableMethodsCount / sizeof(uint)); - - if (Version >= 16) { - // In v24.4 hashValueIndex was removed from Il2CppAssemblyNameDefinition, which is a field in Il2CppAssemblyDefinition - // The number of images and assemblies should be the same. If they are not, we deduce that we are using v24.4 - // Note the version comparison matches both 24.2 and 24.3 here since 24.3 is tested for during binary loading - var assemblyCount = Header.assembliesCount / Sizeof(typeof(Il2CppAssemblyDefinition)); - if (Version == 24.2 && assemblyCount < Images.Length) - Version = 24.4; - - Assemblies = ReadArray(Header.assembliesOffset, Images.Length); - ParameterDefaultValues = ReadArray(Header.parameterDefaultValuesOffset, Header.parameterDefaultValuesCount / Sizeof(typeof(Il2CppParameterDefaultValue))); - } - if (Version >= 19 && Version < 27) { - MetadataUsageLists = ReadArray(Header.metadataUsageListsOffset, Header.metadataUsageListsCount / Sizeof(typeof(Il2CppMetadataUsageList))); - MetadataUsagePairs = ReadArray(Header.metadataUsagePairsOffset, Header.metadataUsagePairsCount / Sizeof(typeof(Il2CppMetadataUsagePair))); - } - if (Version >= 19) { - FieldRefs = ReadArray(Header.fieldRefsOffset, Header.fieldRefsCount / Sizeof(typeof(Il2CppFieldRef))); - } - if (Version >= 21) { - AttributeTypeIndices = ReadArray(Header.attributeTypesOffset, Header.attributeTypesCount / sizeof(int)); - AttributeTypeRanges = ReadArray(Header.attributesInfoOffset, Header.attributesInfoCount / Sizeof(typeof(Il2CppCustomAttributeTypeRange))); - } - - // Get all metadata strings - var pluginGetStringsResult = PluginHooks.GetStrings(this); - if (pluginGetStringsResult.IsDataModified && !pluginGetStringsResult.IsInvalid) - Strings = pluginGetStringsResult.Strings; - - else { - Position = Header.stringOffset; - - while (Position < Header.stringOffset + Header.stringCount) - Strings.Add((int) Position - Header.stringOffset, ReadNullTerminatedString()); - } - - // Get all string literals - var pluginGetStringLiteralsResult = PluginHooks.GetStringLiterals(this); - if (pluginGetStringLiteralsResult.IsDataModified) - StringLiterals = pluginGetStringLiteralsResult.StringLiterals.ToArray(); - - else { - var stringLiteralList = ReadArray(Header.stringLiteralOffset, Header.stringLiteralCount / Sizeof(typeof(Il2CppStringLiteral))); - - StringLiterals = new string[stringLiteralList.Length]; - for (var i = 0; i < stringLiteralList.Length; i++) - StringLiterals[i] = ReadFixedLengthString(Header.stringLiteralDataOffset + stringLiteralList[i].dataIndex, stringLiteralList[i].length); - } - - // Post-processing hook - IsModified |= PluginHooks.PostProcessMetadata(this).IsStreamModified; - } - - // Save metadata to file, overwriting if necessary - public void SaveToFile(string pathname) { - Position = 0; - using (var outFile = new FileStream(pathname, FileMode.Create, FileAccess.Write)) - CopyTo(outFile); - } - - public int Sizeof(Type type) => Sizeof(type, Version); - - public int Sizeof(Type type, double metadataVersion, int longSizeBytes = 8) { - - if (Reader.ObjectMappings.TryGetValue(type, out var streamType)) - type = streamType; - - int size = 0; - foreach (var i in type.GetTypeInfo().GetFields()) - { - // Only process fields for our selected object versioning (always process if none supplied) - var versions = i.GetCustomAttributes(false).Select(v => (v.Min, v.Max)).ToList(); - if (versions.Any() && !versions.Any(v => (v.Min <= metadataVersion || v.Min == -1) && (v.Max >= metadataVersion || v.Max == -1))) - continue; - - if (i.FieldType == typeof(long) || i.FieldType == typeof(ulong)) - size += longSizeBytes; - else if (i.FieldType == typeof(int) || i.FieldType == typeof(uint)) - size += 4; - else if (i.FieldType == typeof(short) || i.FieldType == typeof(ushort)) - size += 2; - - // Fixed-length array - else if (i.FieldType.IsArray) { - var attr = i.GetCustomAttribute(false) ?? - throw new InvalidOperationException("Array field " + i.Name + " must have ArrayLength attribute"); - size += attr.FixedSize; - } - - // Embedded object - else - size += Sizeof(i.FieldType, metadataVersion); - } - return size; - } - } -} +/* + Copyright 2017 Perfare - https://github.com/Perfare/Il2CppDumper + Copyright 2017-2021 Katy Coe - http://www.djkaty.com - https://github.com/djkaty + + All rights reserved. +*/ + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using NoisyCowStudios.Bin2Object; + +namespace Il2CppInspector +{ + public class Metadata : BinaryObjectStream + { + public Il2CppGlobalMetadataHeader Header { get; set; } + + public Il2CppAssemblyDefinition[] Assemblies { get; set; } + public Il2CppImageDefinition[] Images { get; set; } + public Il2CppTypeDefinition[] Types { get; set; } + public Il2CppMethodDefinition[] Methods { get; set; } + public Il2CppParameterDefinition[] Params { get; set; } + public Il2CppFieldDefinition[] Fields { get; set; } + public Il2CppFieldDefaultValue[] FieldDefaultValues { get; set; } + public Il2CppParameterDefaultValue[] ParameterDefaultValues { get; set; } + public Il2CppPropertyDefinition[] Properties { get; set; } + public Il2CppEventDefinition[] Events { get; set; } + public Il2CppGenericContainer[] GenericContainers { get; set; } + public Il2CppGenericParameter[] GenericParameters { get; set; } + public Il2CppCustomAttributeTypeRange[] AttributeTypeRanges { get; set; } + public Il2CppCustomAttributeDataRange[] AttributeDataRanges { get; set; } + public Il2CppInterfaceOffsetPair[] InterfaceOffsets { get; set; } + public Il2CppMetadataUsageList[] MetadataUsageLists { get; set; } + public Il2CppMetadataUsagePair[] MetadataUsagePairs { get; set; } + public Il2CppFieldRef[] FieldRefs { get; set; } + + public int[] InterfaceUsageIndices { get; set; } + public int[] NestedTypeIndices { get; set; } + public int[] AttributeTypeIndices { get; set; } + public int[] GenericConstraintIndices { get; set; } + public uint[] VTableMethodIndices { get; set; } + public string[] StringLiterals { get; set; } + + public Dictionary Strings { get; private set; } = new Dictionary(); + + // Set if something in the metadata has been modified / decrypted + public bool IsModified { get; private set; } = false; + + // Status update callback + private EventHandler OnStatusUpdate { get; set; } + private void StatusUpdate(string status) => OnStatusUpdate?.Invoke(this, status); + + // Initialize metadata object from a stream + public static Metadata FromStream(MemoryStream stream, EventHandler statusCallback = null) { + // TODO: This should really be placed before the Metadata object is created, + // but for now this ensures it is called regardless of which client is in use + PluginHooks.LoadPipelineStarting(); + + var metadata = new Metadata(statusCallback); + stream.Position = 0; + stream.CopyTo(metadata); + metadata.Position = 0; + metadata.Initialize(); + return metadata; + } + + private Metadata(EventHandler statusCallback = null) : base() => OnStatusUpdate = statusCallback; + + private void Initialize() + { + // Pre-processing hook + var pluginResult = PluginHooks.PreProcessMetadata(this); + IsModified = pluginResult.IsStreamModified; + + StatusUpdate("Processing metadata"); + + // Read metadata header + Header = ReadObject(0); + + // Check for correct magic bytes + if (Header.signature != Il2CppConstants.MetadataSignature) { + throw new InvalidOperationException("The supplied metadata file is not valid."); + } + + // Set object versioning for Bin2Object from metadata version + Version = Header.version; + + if (Version < 16 || Version > 29.1) { + throw new InvalidOperationException($"The supplied metadata file is not of a supported version ({Header.version})."); + } + + // Rewind and read metadata header with the correct version settings + Header = ReadObject(0); + + // Sanity checking + // Unity.IL2CPP.MetadataCacheWriter.WriteLibIl2CppMetadata always writes the metadata information in the same order it appears in the header, + // with each block always coming directly after the previous block, 4-byte aligned. We can use this to check the integrity of the data and + // detect sub-versions. + + // For metadata v24.0, the header can either be either 0x110 (24.0, 24.1) or 0x108 (24.2) bytes long. Since 'stringLiteralOffset' is the first thing + // in the header after the sanity and version fields, and since it will always point directly to the first byte after the end of the header, + // we can use this value to determine the actual header length and therefore narrow down the metadata version to 24.0/24.1 or 24.2. + + if (!pluginResult.SkipValidation) { + var realHeaderLength = Header.stringLiteralOffset; + + if (realHeaderLength != Sizeof(typeof(Il2CppGlobalMetadataHeader))) { + if (Version == 24.0) { + Version = 24.2; + Header = ReadObject(0); + } + } + + if (realHeaderLength != Sizeof(typeof(Il2CppGlobalMetadataHeader))) { + throw new InvalidOperationException("Could not verify the integrity of the metadata file or accurately identify the metadata sub-version"); + } + } + + // Load all the relevant metadata using offsets provided in the header + if (Version >= 16) + Images = ReadArray(Header.imagesOffset, Header.imagesCount / Sizeof(typeof(Il2CppImageDefinition))); + + // As an additional sanity check, all images in the metadata should have Mono.Cecil.MetadataToken == 1 + // In metadata v24.1, two extra fields were added which will cause the below test to fail. + // In that case, we can then adjust the version number and reload + // Tokens were introduced in v19 - we don't bother testing earlier versions + if (Version >= 19 && Images.Any(x => x.token != 1)) + if (Version == 24.0) { + Version = 24.1; + + // No need to re-read the header, it's the same for both sub-versions + Images = ReadArray(Header.imagesOffset, Header.imagesCount / Sizeof(typeof(Il2CppImageDefinition))); + + if (Images.Any(x => x.token != 1)) + throw new InvalidOperationException("Could not verify the integrity of the metadata file image list"); + } + + Types = ReadArray(Header.typeDefinitionsOffset, Header.typeDefinitionsCount / Sizeof(typeof(Il2CppTypeDefinition))); + Methods = ReadArray(Header.methodsOffset, Header.methodsCount / Sizeof(typeof(Il2CppMethodDefinition))); + Params = ReadArray(Header.parametersOffset, Header.parametersCount / Sizeof(typeof(Il2CppParameterDefinition))); + Fields = ReadArray(Header.fieldsOffset, Header.fieldsCount / Sizeof(typeof(Il2CppFieldDefinition))); + FieldDefaultValues = ReadArray(Header.fieldDefaultValuesOffset, Header.fieldDefaultValuesCount / Sizeof(typeof(Il2CppFieldDefaultValue))); + Properties = ReadArray(Header.propertiesOffset, Header.propertiesCount / Sizeof(typeof(Il2CppPropertyDefinition))); + Events = ReadArray(Header.eventsOffset, Header.eventsCount / Sizeof(typeof(Il2CppEventDefinition))); + InterfaceUsageIndices = ReadArray(Header.interfacesOffset, Header.interfacesCount / sizeof(int)); + NestedTypeIndices = ReadArray(Header.nestedTypesOffset, Header.nestedTypesCount / sizeof(int)); + GenericContainers = ReadArray(Header.genericContainersOffset, Header.genericContainersCount / Sizeof(typeof(Il2CppGenericContainer))); + GenericParameters = ReadArray(Header.genericParametersOffset, Header.genericParametersCount / Sizeof(typeof(Il2CppGenericParameter))); + GenericConstraintIndices = ReadArray(Header.genericParameterConstraintsOffset, Header.genericParameterConstraintsCount / sizeof(int)); + InterfaceOffsets = ReadArray(Header.interfaceOffsetsOffset, Header.interfaceOffsetsCount / Sizeof(typeof(Il2CppInterfaceOffsetPair))); + VTableMethodIndices = ReadArray(Header.vtableMethodsOffset, Header.vtableMethodsCount / sizeof(uint)); + + if (Version >= 16) { + // In v24.4 hashValueIndex was removed from Il2CppAssemblyNameDefinition, which is a field in Il2CppAssemblyDefinition + // The number of images and assemblies should be the same. If they are not, we deduce that we are using v24.4 + // Note the version comparison matches both 24.2 and 24.3 here since 24.3 is tested for during binary loading + var assemblyCount = Header.assembliesCount / Sizeof(typeof(Il2CppAssemblyDefinition)); + var changedAssemblyDefStruct = false; + if ((Version == 24.1 || Version == 24.2 || Version == 24.3) && assemblyCount < Images.Length) + { + if (Version == 24.1) + changedAssemblyDefStruct = true; + Version = 24.4; + } + + Assemblies = ReadArray(Header.assembliesOffset, Images.Length); + + if (changedAssemblyDefStruct) + Version = 24.1; + + ParameterDefaultValues = ReadArray(Header.parameterDefaultValuesOffset, Header.parameterDefaultValuesCount / Sizeof(typeof(Il2CppParameterDefaultValue))); + } + if (Version >= 19 && Version < 27) { + MetadataUsageLists = ReadArray(Header.metadataUsageListsOffset, Header.metadataUsageListsCount / Sizeof(typeof(Il2CppMetadataUsageList))); + MetadataUsagePairs = ReadArray(Header.metadataUsagePairsOffset, Header.metadataUsagePairsCount / Sizeof(typeof(Il2CppMetadataUsagePair))); + } + if (Version >= 19) { + FieldRefs = ReadArray(Header.fieldRefsOffset, Header.fieldRefsCount / Sizeof(typeof(Il2CppFieldRef))); + } + if (Version >= 21 && Version < 29) { + AttributeTypeIndices = ReadArray(Header.attributeTypesOffset, Header.attributeTypesCount / sizeof(int)); + AttributeTypeRanges = ReadArray(Header.attributesInfoOffset, Header.attributesInfoCount / Sizeof(typeof(Il2CppCustomAttributeTypeRange))); + } + + if (Version >= 29) + { + AttributeDataRanges = ReadArray(Header.attributeDataRangeOffset, + Header.attributeDataRangeSize / Sizeof(typeof(Il2CppCustomAttributeDataRange))); + } + + // Get all metadata strings + var pluginGetStringsResult = PluginHooks.GetStrings(this); + if (pluginGetStringsResult.IsDataModified && !pluginGetStringsResult.IsInvalid) + Strings = pluginGetStringsResult.Strings; + + else { + Position = Header.stringOffset; + + while (Position < Header.stringOffset + Header.stringCount) + Strings.Add((int) Position - Header.stringOffset, ReadNullTerminatedString()); + } + + // Get all string literals + var pluginGetStringLiteralsResult = PluginHooks.GetStringLiterals(this); + if (pluginGetStringLiteralsResult.IsDataModified) + StringLiterals = pluginGetStringLiteralsResult.StringLiterals.ToArray(); + + else { + var stringLiteralList = ReadArray(Header.stringLiteralOffset, Header.stringLiteralCount / Sizeof(typeof(Il2CppStringLiteral))); + + StringLiterals = new string[stringLiteralList.Length]; + for (var i = 0; i < stringLiteralList.Length; i++) + StringLiterals[i] = ReadFixedLengthString(Header.stringLiteralDataOffset + stringLiteralList[i].dataIndex, stringLiteralList[i].length); + } + + // Post-processing hook + IsModified |= PluginHooks.PostProcessMetadata(this).IsStreamModified; + } + + // Save metadata to file, overwriting if necessary + public void SaveToFile(string pathname) { + Position = 0; + using (var outFile = new FileStream(pathname, FileMode.Create, FileAccess.Write)) + CopyTo(outFile); + } + + public int Sizeof(Type type) => Sizeof(type, Version); + + public int Sizeof(Type type, double metadataVersion, int longSizeBytes = 8) { + + if (Reader.ObjectMappings.TryGetValue(type, out var streamType)) + type = streamType; + + int size = 0; + foreach (var i in type.GetTypeInfo().GetFields()) + { + // Only process fields for our selected object versioning (always process if none supplied) + var versions = i.GetCustomAttributes(false).Select(v => (v.Min, v.Max)).ToList(); + if (versions.Any() && !versions.Any(v => (v.Min <= metadataVersion || v.Min == -1) && (v.Max >= metadataVersion || v.Max == -1))) + continue; + + if (i.FieldType == typeof(long) || i.FieldType == typeof(ulong)) + size += longSizeBytes; + else if (i.FieldType == typeof(int) || i.FieldType == typeof(uint)) + size += 4; + else if (i.FieldType == typeof(short) || i.FieldType == typeof(ushort)) + size += 2; + + // Fixed-length array + else if (i.FieldType.IsArray) { + var attr = i.GetCustomAttribute(false) ?? + throw new InvalidOperationException("Array field " + i.Name + " must have ArrayLength attribute"); + size += attr.FixedSize; + } + + // Embedded object + else + size += Sizeof(i.FieldType, metadataVersion); + } + return size; + } + } +} diff --git a/Il2CppInspector.Common/IL2CPP/MetadataClasses.cs b/Il2CppInspector.Common/IL2CPP/MetadataClasses.cs index b9b839e..9dd6575 100644 --- a/Il2CppInspector.Common/IL2CPP/MetadataClasses.cs +++ b/Il2CppInspector.Common/IL2CPP/MetadataClasses.cs @@ -1,461 +1,475 @@ -/* - Copyright 2017 Perfare - https://github.com/Perfare/Il2CppDumper - Copyright 2017-2021 Katy Coe - http://www.djkaty.com - https://github.com/djkaty - - All rights reserved. -*/ - -using NoisyCowStudios.Bin2Object; - -namespace Il2CppInspector -{ - // Unity 4.6.1p5 - first release, no global-metadata.dat - // Unity 5.2.0f3 -> v15 - // Unity 5.3.0f4 -> v16 - // Unity 5.3.2f1 -> v19 - // Unity 5.3.3f1 -> v20 - // Unity 5.3.5f1 -> v21 - // Unity 5.5.0f3 -> v22 - // Unity 5.6.0f3 -> v23 - // Unity 2017.1.0f3 -> v24 - // Unity 2018.3.0f2 -> v24.1 - // Unity 2019.1.0f2 -> v24.2 - // Unity 2019.3.7f1 -> v24.3 - // Unity 2019.4.15f1 -> v24.4 - // Unity 2019.4.21f1 -> v24.5 - // Unity 2020.1.0f1 -> v24.3 - // Unity 2020.1.11f1 -> v24.4 - // Unity 2020.2.0f1 -> v27 - // Unity 2020.2.4f1 -> v27.1 - // Unity 2021.1.0f1 -> v27.2 - // https://unity3d.com/get-unity/download/archive - // Metadata version is written at the end of Unity.IL2CPP.MetadataCacheWriter.WriteLibIl2CppMetadata or WriteMetadata (Unity.IL2CPP.dll) - - // From il2cpp-metadata.h -#pragma warning disable CS0649 - public class Il2CppGlobalMetadataHeader - { - public uint signature; - public int version; - public int stringLiteralOffset; // string data for managed code - public int stringLiteralCount; - public int stringLiteralDataOffset; - public int stringLiteralDataCount; - public int stringOffset; // string data for metadata - public int stringCount; - public int eventsOffset; // Il2CppEventDefinition - public int eventsCount; - public int propertiesOffset; // Il2CppPropertyDefinition - public int propertiesCount; - public int methodsOffset; // Il2CppMethodDefinition - public int methodsCount; - - [Version(Min = 16)] - public int parameterDefaultValuesOffset; // Il2CppParameterDefaultValue - [Version(Min = 16)] - public int parameterDefaultValuesCount; - - public int fieldDefaultValuesOffset; // Il2CppFieldDefaultValue - public int fieldDefaultValuesCount; - public int fieldAndParameterDefaultValueDataOffset; // uint8_t - public int fieldAndParameterDefaultValueDataCount; - - [Version(Min = 16)] - public int fieldMarshaledSizesOffset; // Il2CppFieldMarshaledSize - [Version(Min = 16)] - public int fieldMarshaledSizesCount; - - public int parametersOffset; // Il2CppParameterDefinition - public int parametersCount; - public int fieldsOffset; // Il2CppFieldDefinition - public int fieldsCount; - public int genericParametersOffset; // Il2CppGenericParameter - public int genericParametersCount; - public int genericParameterConstraintsOffset; // TypeIndex - public int genericParameterConstraintsCount; - public int genericContainersOffset; // Il2CppGenericContainer - public int genericContainersCount; - public int nestedTypesOffset; // TypeDefinitionIndex - public int nestedTypesCount; - public int interfacesOffset; // TypeIndex - public int interfacesCount; - public int vtableMethodsOffset; // EncodedMethodIndex - public int vtableMethodsCount; - public int interfaceOffsetsOffset; // Il2CppInterfaceOffsetPair - public int interfaceOffsetsCount; - public int typeDefinitionsOffset; // Il2CppTypeDefinition - public int typeDefinitionsCount; - - [Version(Max = 24.1)] - public int rgctxEntriesOffset; // Il2CppRGCTXDefinition - [Version(Max = 24.1)] - public int rgctxEntriesCount; - - [Version(Min = 16)] - public int imagesOffset; // Il2CppImageDefinition - [Version(Min = 16)] - public int imagesCount; - [Version(Min = 16)] - public int assembliesOffset; // Il2CppAssemblyDefinition - [Version(Min = 16)] - public int assembliesCount; - - [Version(Min = 19, Max = 24.5)] - public int metadataUsageListsOffset; // Il2CppMetadataUsageList - [Version(Min = 19, Max = 24.5)] - public int metadataUsageListsCount; - [Version(Min = 19, Max = 24.5)] - public int metadataUsagePairsOffset; // Il2CppMetadataUsagePair - [Version(Min = 19, Max = 24.5)] - public int metadataUsagePairsCount; - [Version(Min = 19)] - public int fieldRefsOffset; // Il2CppFieldRef - [Version(Min = 19)] - public int fieldRefsCount; - [Version(Min = 20)] - public int referencedAssembliesOffset; // int32_t - [Version(Min = 20)] - public int referencedAssembliesCount; - - [Version(Min = 21)] - public int attributesInfoOffset; // Il2CppCustomAttributeTypeRange - [Version(Min = 21)] - public int attributesInfoCount; - [Version(Min = 21)] - public int attributeTypesOffset; // TypeIndex - [Version(Min = 21)] - public int attributeTypesCount; - - // Added in metadata v22 - [Version(Min = 22)] - public int unresolvedVirtualCallParameterTypesOffset; // TypeIndex - [Version(Min = 22)] - public int unresolvedVirtualCallParameterTypesCount; - [Version(Min = 22)] - public int unresolvedVirtualCallParameterRangesOffset; // Il2CppRange - [Version(Min = 22)] - public int unresolvedVirtualCallParameterRangesCount; - - // Added in metadata v23 - [Version(Min = 23)] - public int windowsRuntimeTypeNamesOffset; // Il2CppWindowsRuntimeTypeNamePair - [Version(Min = 23)] - public int windowsRuntimeTypeNamesSize; - - // Added in metadata v27 - [Version(Min = 27)] - public int windowsRuntimeStringsOffset; // const char* - [Version(Min = 27)] - public int windowsRuntimeStringsSize; - - // Added in metadata v24 - [Version(Min = 24)] - public int exportedTypeDefinitionsOffset; // TypeDefinitionIndex - [Version(Min = 24)] - public int exportedTypeDefinitionsCount; - } - - public class Il2CppImageDefinition - { - public int nameIndex; - public int assemblyIndex; - - public int typeStart; - public uint typeCount; - - [Version(Min = 24)] - public int exportedTypeStart; - [Version(Min = 24)] - public uint exportedTypeCount; - - public int entryPointIndex; - - [Version(Min = 19)] - public uint token; - - [Version(Min = 24.1)] - public int customAttributeStart; - [Version(Min = 24.1)] - public uint customAttributeCount; - } -#pragma warning restore CS0649 - - // Renamed from Il2CppAssembly somewhere after Unity 2017.2f3 up to Unity 2018.2.0f2 - public class Il2CppAssemblyDefinition - { - // They moved the position of aname in v16 from the top to the bottom of the struct - public Il2CppAssemblyNameDefinition aname => aname_pre16 ?? aname_post16; - - [Version(Max = 15)] - public Il2CppAssemblyNameDefinition aname_pre16; - - public int imageIndex; - - [Version(Min = 24.1)] - public uint token; - - [Version(Max = 24.0)] - public int customAttributeIndex; - - [Version(Min = 20)] - public int referencedAssemblyStart; - [Version(Min = 20)] - public int referencedAssemblyCount; - - [Version(Min = 16)] - public Il2CppAssemblyNameDefinition aname_post16; - } - - // Renamed from Il2CppAssemblyName somewhere after Unity 2017.2f3 up to Unity 2018.2.0f2 - public class Il2CppAssemblyNameDefinition - { - // They moved the position of publicKeyToken in v16 from the middle to the bottom of the struct - public byte[] publicKeyToken => publicKeyToken_post16; - - public int nameIndex; - public int cultureIndex; - [Version(Max = 24.3)] - public int hashValueIndex; - public int publicKeyIndex; - [Version(Max = 15), ArrayLength(FixedSize = 8)] - public byte[] publicKeyToken_pre16; - public uint hash_alg; - public int hash_len; - public uint flags; - public int major; - public int minor; - public int build; - public int revision; - [Version(Min = 16), ArrayLength(FixedSize = 8)] - public byte[] publicKeyToken_post16; - } - - public class Il2CppTypeDefinition - { - public int nameIndex; - public int namespaceIndex; - - // Removed in metadata v24.1 - [Version(Max = 24.0)] - public int customAttributeIndex; - - public int byvalTypeIndex; - [Version(Max = 24.5)] - public int byrefTypeIndex; - - public int declaringTypeIndex; - public int parentIndex; - public int elementTypeIndex; // we can probably remove this one. Only used for enums - - [Version(Max = 24.1)] - public int rgctxStartIndex; - [Version(Max = 24.1)] - public int rgctxCount; - - public int genericContainerIndex; - - // Removed in metadata v23 - [Version(Max = 22)] - public int delegateWrapperFromManagedToNativeIndex; // (was renamed to reversePInvokeWrapperIndex in v22) - [Version(Max = 22)] - public int marshalingFunctionsIndex; - [Version(Min = 21, Max = 22)] - public int ccwFunctionIndex; - [Version(Min = 21, Max = 22)] - public int guidIndex; - - public uint flags; - - public int fieldStart; - public int methodStart; - public int eventStart; - public int propertyStart; - public int nestedTypesStart; - public int interfacesStart; - public int vtableStart; - public int interfaceOffsetsStart; - - public ushort method_count; - public ushort property_count; - public ushort field_count; - public ushort event_count; - public ushort nested_type_count; - public ushort vtable_count; - public ushort interfaces_count; - public ushort interface_offsets_count; - - // bitfield to portably encode boolean values as single bits - // 01 - valuetype; - // 02 - enumtype; - // 03 - has_finalize; - // 04 - has_cctor; - // 05 - is_blittable; - // 06 - is_import; (from v22: is_import_or_windows_runtime) - // 07-10 - One of nine possible PackingSize values (0, 1, 2, 4, 8, 16, 32, 64, or 128) - public uint bitfield; - - [Version(Min = 19)] - public uint token; - } - - public class Il2CppMethodDefinition - { - public int nameIndex; - - [Version(Min = 16)] - public int declaringType; - - public int returnType; - public int parameterStart; - - [Version(Max = 24.0)] - public int customAttributeIndex; - - public int genericContainerIndex; - - [Version(Max = 24.1)] - public int methodIndex; - [Version(Max = 24.1)] - public int invokerIndex; - [Version(Max = 24.1)] - public int reversePInvokeWrapperIndex; // (was renamed from delegateWrapperIndex in v22) - [Version(Max = 24.1)] - public int rgctxStartIndex; - [Version(Max = 24.1)] - public int rgctxCount; - - public uint token; - public ushort flags; - public ushort iflags; - public ushort slot; - public ushort parameterCount; - } - - public class Il2CppParameterDefinition - { - public int nameIndex; - public uint token; - - [Version(Max = 24.0)] - public int customAttributeIndex; - - public int typeIndex; - } - - public class Il2CppParameterDefaultValue - { - public int parameterIndex; - public int typeIndex; - public int dataIndex; - } - - public class Il2CppFieldDefinition - { - public int nameIndex; - public int typeIndex; - - [Version(Max = 24.0)] - public int customAttributeIndex; - - [Version(Min = 19)] - public uint token; - } - - public class Il2CppFieldDefaultValue - { - public int fieldIndex; - public int typeIndex; - public int dataIndex; - } - - public class Il2CppPropertyDefinition - { - public int nameIndex; - public int get; - public int set; - public uint attrs; - - [Version(Max = 24.0)] - public int customAttributeIndex; - - [Version(Min = 19)] - public uint token; - } - - public class Il2CppEventDefinition - { - public int nameIndex; - public int typeIndex; - public int add; - public int remove; - public int raise; - - [Version(Max = 24.0)] - public int customAttributeIndex; - - [Version(Min = 19)] - public uint token; - } - - public class Il2CppGenericContainer - { - /* index of the generic type definition or the generic method definition corresponding to this container */ - public int ownerIndex; // either index into Il2CppClass metadata array or Il2CppMethodDefinition array - public int type_argc; - /* If true, we're a generic method, otherwise a generic type definition. */ - public int is_method; - /* Our type parameters. */ - public uint genericParameterStart; // GenericParameterIndex - } - - public class Il2CppGenericParameter - { - public int ownerIndex; /* Type or method this parameter was defined in. */ // GenericContainerIndex - public int nameIndex; // StringIndex - public short constraintsStart; // GenericParameterConstraintIndex - public short constraintsCount; - public ushort num; // Generic parameter position - public ushort flags; // GenericParameterAttributes - } - - public class Il2CppCustomAttributeTypeRange - { - [Version(Min = 24.1)] - public uint token; - - public int start; - public int count; - } - - public class Il2CppInterfaceOffsetPair - { - public int interfaceTypeIndex; - public int offset; - } - - // Removed in metadata v27 - public class Il2CppMetadataUsageList - { - public uint start; - public uint count; - } - - // Removed in metadata v27 - public class Il2CppMetadataUsagePair - { - public uint destinationindex; - public uint encodedSourceIndex; - } - - public class Il2CppStringLiteral - { - public int length; - public int dataIndex; - } - - public class Il2CppFieldRef - { - public int typeIndex; - public int fieldIndex; // local offset into type fields - } -} +/* + Copyright 2017 Perfare - https://github.com/Perfare/Il2CppDumper + Copyright 2017-2021 Katy Coe - http://www.djkaty.com - https://github.com/djkaty + + All rights reserved. +*/ + +using NoisyCowStudios.Bin2Object; + +namespace Il2CppInspector +{ + // Unity 4.6.1p5 - first release, no global-metadata.dat + // Unity 5.2.0f3 -> v15 + // Unity 5.3.0f4 -> v16 + // Unity 5.3.2f1 -> v19 + // Unity 5.3.3f1 -> v20 + // Unity 5.3.5f1 -> v21 + // Unity 5.5.0f3 -> v22 + // Unity 5.6.0f3 -> v23 + // Unity 2017.1.0f3 -> v24 + // Unity 2018.3.0f2 -> v24.1 + // Unity 2019.1.0f2 -> v24.2 + // Unity 2019.3.7f1 -> v24.3 + // Unity 2019.4.15f1 -> v24.4 + // Unity 2019.4.21f1 -> v24.5 + // Unity 2020.1.0f1 -> v24.3 + // Unity 2020.1.11f1 -> v24.4 + // Unity 2020.2.0f1 -> v27 + // Unity 2020.2.4f1 -> v27.1 + // Unity 2021.1.0f1 -> v27.2 + // https://unity3d.com/get-unity/download/archive + // Metadata version is written at the end of Unity.IL2CPP.MetadataCacheWriter.WriteLibIl2CppMetadata or WriteMetadata (Unity.IL2CPP.dll) + + // From il2cpp-metadata.h +#pragma warning disable CS0649 + public class Il2CppGlobalMetadataHeader + { + public uint signature; + public int version; + public int stringLiteralOffset; // string data for managed code + public int stringLiteralCount; + public int stringLiteralDataOffset; + public int stringLiteralDataCount; + public int stringOffset; // string data for metadata + public int stringCount; + public int eventsOffset; // Il2CppEventDefinition + public int eventsCount; + public int propertiesOffset; // Il2CppPropertyDefinition + public int propertiesCount; + public int methodsOffset; // Il2CppMethodDefinition + public int methodsCount; + + [Version(Min = 16)] + public int parameterDefaultValuesOffset; // Il2CppParameterDefaultValue + [Version(Min = 16)] + public int parameterDefaultValuesCount; + + public int fieldDefaultValuesOffset; // Il2CppFieldDefaultValue + public int fieldDefaultValuesCount; + public int fieldAndParameterDefaultValueDataOffset; // uint8_t + public int fieldAndParameterDefaultValueDataCount; + + [Version(Min = 16)] + public int fieldMarshaledSizesOffset; // Il2CppFieldMarshaledSize + [Version(Min = 16)] + public int fieldMarshaledSizesCount; + + public int parametersOffset; // Il2CppParameterDefinition + public int parametersCount; + public int fieldsOffset; // Il2CppFieldDefinition + public int fieldsCount; + public int genericParametersOffset; // Il2CppGenericParameter + public int genericParametersCount; + public int genericParameterConstraintsOffset; // TypeIndex + public int genericParameterConstraintsCount; + public int genericContainersOffset; // Il2CppGenericContainer + public int genericContainersCount; + public int nestedTypesOffset; // TypeDefinitionIndex + public int nestedTypesCount; + public int interfacesOffset; // TypeIndex + public int interfacesCount; + public int vtableMethodsOffset; // EncodedMethodIndex + public int vtableMethodsCount; + public int interfaceOffsetsOffset; // Il2CppInterfaceOffsetPair + public int interfaceOffsetsCount; + public int typeDefinitionsOffset; // Il2CppTypeDefinition + public int typeDefinitionsCount; + + [Version(Max = 24.1)] + public int rgctxEntriesOffset; // Il2CppRGCTXDefinition + [Version(Max = 24.1)] + public int rgctxEntriesCount; + + [Version(Min = 16)] + public int imagesOffset; // Il2CppImageDefinition + [Version(Min = 16)] + public int imagesCount; + [Version(Min = 16)] + public int assembliesOffset; // Il2CppAssemblyDefinition + [Version(Min = 16)] + public int assembliesCount; + + [Version(Min = 19, Max = 24.5)] + public int metadataUsageListsOffset; // Il2CppMetadataUsageList + [Version(Min = 19, Max = 24.5)] + public int metadataUsageListsCount; + [Version(Min = 19, Max = 24.5)] + public int metadataUsagePairsOffset; // Il2CppMetadataUsagePair + [Version(Min = 19, Max = 24.5)] + public int metadataUsagePairsCount; + [Version(Min = 19)] + public int fieldRefsOffset; // Il2CppFieldRef + [Version(Min = 19)] + public int fieldRefsCount; + [Version(Min = 20)] + public int referencedAssembliesOffset; // int32_t + [Version(Min = 20)] + public int referencedAssembliesCount; + + [Version(Min = 21, Max = 27.2)] + public int attributesInfoOffset; // Il2CppCustomAttributeTypeRange + [Version(Min = 21, Max = 27.2)] + public int attributesInfoCount; + [Version(Min = 21, Max = 27.2)] + public int attributeTypesOffset; // TypeIndex + [Version(Min = 21, Max = 27.2)] + public int attributeTypesCount; + [Version(Min = 29)] + public uint attributeDataOffset; + [Version(Min = 29)] + public int attributeDataSize; + [Version(Min = 29)] + public uint attributeDataRangeOffset; + [Version(Min = 29)] + public int attributeDataRangeSize; + + // Added in metadata v22 + [Version(Min = 22)] + public int unresolvedVirtualCallParameterTypesOffset; // TypeIndex + [Version(Min = 22)] + public int unresolvedVirtualCallParameterTypesCount; + [Version(Min = 22)] + public int unresolvedVirtualCallParameterRangesOffset; // Il2CppRange + [Version(Min = 22)] + public int unresolvedVirtualCallParameterRangesCount; + + // Added in metadata v23 + [Version(Min = 23)] + public int windowsRuntimeTypeNamesOffset; // Il2CppWindowsRuntimeTypeNamePair + [Version(Min = 23)] + public int windowsRuntimeTypeNamesSize; + + // Added in metadata v27 + [Version(Min = 27)] + public int windowsRuntimeStringsOffset; // const char* + [Version(Min = 27)] + public int windowsRuntimeStringsSize; + + // Added in metadata v24 + [Version(Min = 24)] + public int exportedTypeDefinitionsOffset; // TypeDefinitionIndex + [Version(Min = 24)] + public int exportedTypeDefinitionsCount; + } + + public class Il2CppImageDefinition + { + public int nameIndex; + public int assemblyIndex; + + public int typeStart; + public uint typeCount; + + [Version(Min = 24)] + public int exportedTypeStart; + [Version(Min = 24)] + public uint exportedTypeCount; + + public int entryPointIndex; + + [Version(Min = 19)] + public uint token; + + [Version(Min = 24.1)] + public int customAttributeStart; + [Version(Min = 24.1)] + public uint customAttributeCount; + } +#pragma warning restore CS0649 + + // Renamed from Il2CppAssembly somewhere after Unity 2017.2f3 up to Unity 2018.2.0f2 + public class Il2CppAssemblyDefinition + { + // They moved the position of aname in v16 from the top to the bottom of the struct + public Il2CppAssemblyNameDefinition aname => aname_pre16 ?? aname_post16; + + [Version(Max = 15)] + public Il2CppAssemblyNameDefinition aname_pre16; + + public int imageIndex; + + [Version(Min = 24.1)] + public uint token; + + [Version(Max = 24.0)] + public int customAttributeIndex; + + [Version(Min = 20)] + public int referencedAssemblyStart; + [Version(Min = 20)] + public int referencedAssemblyCount; + + [Version(Min = 16)] + public Il2CppAssemblyNameDefinition aname_post16; + } + + // Renamed from Il2CppAssemblyName somewhere after Unity 2017.2f3 up to Unity 2018.2.0f2 + public class Il2CppAssemblyNameDefinition + { + // They moved the position of publicKeyToken in v16 from the middle to the bottom of the struct + public byte[] publicKeyToken => publicKeyToken_post16; + + public int nameIndex; + public int cultureIndex; + [Version(Max = 24.3)] + public int hashValueIndex; + public int publicKeyIndex; + [Version(Max = 15), ArrayLength(FixedSize = 8)] + public byte[] publicKeyToken_pre16; + public uint hash_alg; + public int hash_len; + public uint flags; + public int major; + public int minor; + public int build; + public int revision; + [Version(Min = 16), ArrayLength(FixedSize = 8)] + public byte[] publicKeyToken_post16; + } + + public class Il2CppTypeDefinition + { + public int nameIndex; + public int namespaceIndex; + + // Removed in metadata v24.1 + [Version(Max = 24.0)] + public int customAttributeIndex; + + public int byvalTypeIndex; + [Version(Max = 24.5)] + public int byrefTypeIndex; + + public int declaringTypeIndex; + public int parentIndex; + public int elementTypeIndex; // we can probably remove this one. Only used for enums + + [Version(Max = 24.1)] + public int rgctxStartIndex; + [Version(Max = 24.1)] + public int rgctxCount; + + public int genericContainerIndex; + + // Removed in metadata v23 + [Version(Max = 22)] + public int delegateWrapperFromManagedToNativeIndex; // (was renamed to reversePInvokeWrapperIndex in v22) + [Version(Max = 22)] + public int marshalingFunctionsIndex; + [Version(Min = 21, Max = 22)] + public int ccwFunctionIndex; + [Version(Min = 21, Max = 22)] + public int guidIndex; + + public uint flags; + + public int fieldStart; + public int methodStart; + public int eventStart; + public int propertyStart; + public int nestedTypesStart; + public int interfacesStart; + public int vtableStart; + public int interfaceOffsetsStart; + + public ushort method_count; + public ushort property_count; + public ushort field_count; + public ushort event_count; + public ushort nested_type_count; + public ushort vtable_count; + public ushort interfaces_count; + public ushort interface_offsets_count; + + // bitfield to portably encode boolean values as single bits + // 01 - valuetype; + // 02 - enumtype; + // 03 - has_finalize; + // 04 - has_cctor; + // 05 - is_blittable; + // 06 - is_import; (from v22: is_import_or_windows_runtime) + // 07-10 - One of nine possible PackingSize values (0, 1, 2, 4, 8, 16, 32, 64, or 128) + public uint bitfield; + + [Version(Min = 19)] + public uint token; + } + + public class Il2CppMethodDefinition + { + public int nameIndex; + + [Version(Min = 16)] + public int declaringType; + + public int returnType; + public int parameterStart; + + [Version(Max = 24.0)] + public int customAttributeIndex; + + public int genericContainerIndex; + + [Version(Max = 24.1)] + public int methodIndex; + [Version(Max = 24.1)] + public int invokerIndex; + [Version(Max = 24.1)] + public int reversePInvokeWrapperIndex; // (was renamed from delegateWrapperIndex in v22) + [Version(Max = 24.1)] + public int rgctxStartIndex; + [Version(Max = 24.1)] + public int rgctxCount; + + public uint token; + public ushort flags; + public ushort iflags; + public ushort slot; + public ushort parameterCount; + } + + public class Il2CppParameterDefinition + { + public int nameIndex; + public uint token; + + [Version(Max = 24.0)] + public int customAttributeIndex; + + public int typeIndex; + } + + public class Il2CppParameterDefaultValue + { + public int parameterIndex; + public int typeIndex; + public int dataIndex; + } + + public class Il2CppFieldDefinition + { + public int nameIndex; + public int typeIndex; + + [Version(Max = 24.0)] + public int customAttributeIndex; + + [Version(Min = 19)] + public uint token; + } + + public class Il2CppFieldDefaultValue + { + public int fieldIndex; + public int typeIndex; + public int dataIndex; + } + + public class Il2CppPropertyDefinition + { + public int nameIndex; + public int get; + public int set; + public uint attrs; + + [Version(Max = 24.0)] + public int customAttributeIndex; + + [Version(Min = 19)] + public uint token; + } + + public class Il2CppEventDefinition + { + public int nameIndex; + public int typeIndex; + public int add; + public int remove; + public int raise; + + [Version(Max = 24.0)] + public int customAttributeIndex; + + [Version(Min = 19)] + public uint token; + } + + public class Il2CppGenericContainer + { + /* index of the generic type definition or the generic method definition corresponding to this container */ + public int ownerIndex; // either index into Il2CppClass metadata array or Il2CppMethodDefinition array + public int type_argc; + /* If true, we're a generic method, otherwise a generic type definition. */ + public int is_method; + /* Our type parameters. */ + public uint genericParameterStart; // GenericParameterIndex + } + + public class Il2CppGenericParameter + { + public int ownerIndex; /* Type or method this parameter was defined in. */ // GenericContainerIndex + public int nameIndex; // StringIndex + public short constraintsStart; // GenericParameterConstraintIndex + public short constraintsCount; + public ushort num; // Generic parameter position + public ushort flags; // GenericParameterAttributes + } + + public class Il2CppCustomAttributeTypeRange + { + [Version(Min = 24.1)] + public uint token; + + public int start; + public int count; + } + + public class Il2CppInterfaceOffsetPair + { + public int interfaceTypeIndex; + public int offset; + } + + // Removed in metadata v27 + public class Il2CppMetadataUsageList + { + public uint start; + public uint count; + } + + // Removed in metadata v27 + public class Il2CppMetadataUsagePair + { + public uint destinationindex; + public uint encodedSourceIndex; + } + + public class Il2CppStringLiteral + { + public int length; + public int dataIndex; + } + + public class Il2CppFieldRef + { + public int typeIndex; + public int fieldIndex; // local offset into type fields + } + + public class Il2CppCustomAttributeDataRange + { + public uint token; + public uint startOffset; + } +}