From a7027c886ecb79e6608110890bb285a7dd1661f7 Mon Sep 17 00:00:00 2001 From: Katy Coe Date: Tue, 28 Jan 2020 05:57:24 +0100 Subject: [PATCH] Minor tidying up --- Il2CppInspector/IL2CPP/Il2CppBinary.cs | 10 +++++----- Il2CppInspector/IL2CPP/Il2CppInspector.cs | 6 +++--- Il2CppInspector/IL2CPP/Il2CppModel.cs | 16 ++++++++-------- Il2CppInspector/Reflection/EventInfo.cs | 4 ++-- Il2CppInspector/Reflection/FieldInfo.cs | 4 ++-- Il2CppInspector/Reflection/ParameterInfo.cs | 4 ++-- Il2CppInspector/Reflection/TypeInfo.cs | 7 +++++-- 7 files changed, 27 insertions(+), 24 deletions(-) diff --git a/Il2CppInspector/IL2CPP/Il2CppBinary.cs b/Il2CppInspector/IL2CPP/Il2CppBinary.cs index 4667aff..c894515 100644 --- a/Il2CppInspector/IL2CPP/Il2CppBinary.cs +++ b/Il2CppInspector/IL2CPP/Il2CppBinary.cs @@ -47,7 +47,7 @@ namespace Il2CppInspector public List GenericInstances { get; private set; } // Every defined type - public List Types { get; private set; } + public List TypeReferences { get; private set; } // From v24.2 onwards, this structure is stored for each module (image) // One assembly may contain multiple modules @@ -189,13 +189,13 @@ namespace Il2CppInspector else FieldOffsetPointers = image.ReadMappedWordArray(MetadataRegistration.pfieldOffsets, (int)MetadataRegistration.fieldOffsetsCount); - // Type definitions (pointer array) - Types = image.ReadMappedObjectPointerArray(MetadataRegistration.ptypes, (int) MetadataRegistration.typesCount); + // Type references (pointer array) + TypeReferences = image.ReadMappedObjectPointerArray(MetadataRegistration.ptypes, (int) MetadataRegistration.typesCount); - // Custom attribute constructors + // Custom attribute constructors (function pointers) CustomAttributeGenerators = image.ReadMappedArray(CodeRegistration.customAttributeGenerators, (int) CodeRegistration.customAttributeCount); - // Generic method specs + // Generic type and method specs (open and closed constructed types) MethodSpecs = image.ReadMappedArray(MetadataRegistration.methodSpecs, (int) MetadataRegistration.methodSpecsCount); // Concrete generic class and method signatures diff --git a/Il2CppInspector/IL2CPP/Il2CppInspector.cs b/Il2CppInspector/IL2CPP/Il2CppInspector.cs index e6a87ed..70f8f38 100644 --- a/Il2CppInspector/IL2CPP/Il2CppInspector.cs +++ b/Il2CppInspector/IL2CPP/Il2CppInspector.cs @@ -55,7 +55,7 @@ namespace Il2CppInspector public Dictionary FieldDefaultValue { get; } = new Dictionary(); public Dictionary ParameterDefaultValue { get; } = new Dictionary(); public List FieldOffsets { get; } - public List TypeUsages => Binary.Types; + public List TypeReferences => Binary.TypeReferences; public List GenericInstances => Binary.GenericInstances; public Dictionary Modules => Binary.Modules; public ulong[] CustomAttributeGenerators => Binary.CustomAttributeGenerators; @@ -71,7 +71,7 @@ namespace Il2CppInspector // Get pointer in binary to default value var pValue = Metadata.Header.fieldAndParameterDefaultValueDataOffset + dataIndex; - var type = TypeUsages[typeIndex]; + var typeRef = TypeReferences[typeIndex]; // Default value is null if (pValue == 0) @@ -79,7 +79,7 @@ namespace Il2CppInspector object value = null; Metadata.Position = pValue; - switch (type.type) { + switch (typeRef.type) { case Il2CppTypeEnum.IL2CPP_TYPE_BOOLEAN: value = Metadata.ReadBoolean(); break; diff --git a/Il2CppInspector/IL2CPP/Il2CppModel.cs b/Il2CppInspector/IL2CPP/Il2CppModel.cs index a6c9bb6..c6d085b 100644 --- a/Il2CppInspector/IL2CPP/Il2CppModel.cs +++ b/Il2CppInspector/IL2CPP/Il2CppModel.cs @@ -23,14 +23,14 @@ namespace Il2CppInspector.Reflection // List of all type definitions by fully qualified name public Dictionary TypesByFullName { get; } = new Dictionary(); - // List of all type usages ordered by their type usage index - public TypeInfo[] TypesByUsageIndex { get; } + // List of all type references ordered by index + public TypeInfo[] TypeReferences { get; } // List of type usages that are initialized via pointers in the image public ConcurrentDictionary TypesByVirtualAddress { get; } = new ConcurrentDictionary(); // Every type - public IEnumerable Types => new IEnumerable[] {TypesByDefinitionIndex, TypesByUsageIndex, TypesByVirtualAddress.Values}.SelectMany(t => t); + public IEnumerable Types => new IEnumerable[] {TypesByDefinitionIndex, TypeReferences, TypesByVirtualAddress.Values}.SelectMany(t => t); // List of all methods ordered by their MethodDefinitionIndex public MethodBase[] MethodsByDefinitionIndex { get; } @@ -41,7 +41,7 @@ namespace Il2CppInspector.Reflection public Il2CppModel(Il2CppInspector package) { Package = package; TypesByDefinitionIndex = new TypeInfo[package.TypeDefinitions.Length]; - TypesByUsageIndex = new TypeInfo[package.TypeUsages.Count]; + TypeReferences = new TypeInfo[package.TypeReferences.Count]; MethodsByDefinitionIndex = new MethodBase[package.Methods.Length]; // Create Assembly objects from Il2Cpp package @@ -87,13 +87,13 @@ namespace Il2CppInspector.Reflection public TypeInfo GetTypeFromUsage(int typeUsageIndex, MemberTypes memberType = MemberTypes.All) { // Already generated type previously? - if (TypesByUsageIndex[typeUsageIndex] != null) - return TypesByUsageIndex[typeUsageIndex]; + if (TypeReferences[typeUsageIndex] != null) + return TypeReferences[typeUsageIndex]; - var usage = Package.TypeUsages[typeUsageIndex]; + var usage = Package.TypeReferences[typeUsageIndex]; var newUsage = getNewTypeUsage(usage, memberType); - TypesByUsageIndex[typeUsageIndex] = newUsage; + TypeReferences[typeUsageIndex] = newUsage; return newUsage; } diff --git a/Il2CppInspector/Reflection/EventInfo.cs b/Il2CppInspector/Reflection/EventInfo.cs index bf403e6..d933d29 100644 --- a/Il2CppInspector/Reflection/EventInfo.cs +++ b/Il2CppInspector/Reflection/EventInfo.cs @@ -1,5 +1,5 @@ /* - Copyright 2017-2019 Katy Coe - http://www.hearthcode.org - http://www.djkaty.com + Copyright 2017-2020 Katy Coe - http://www.hearthcode.org - http://www.djkaty.com All rights reserved. */ @@ -43,7 +43,7 @@ namespace Il2CppInspector.Reflection Name = pkg.Strings[Definition.nameIndex]; eventTypeUsage = Definition.typeIndex; - var eventType = pkg.TypeUsages[eventTypeUsage]; + var eventType = pkg.TypeReferences[eventTypeUsage]; if ((eventType.attrs & Il2CppConstants.FIELD_ATTRIBUTE_SPECIAL_NAME) == Il2CppConstants.FIELD_ATTRIBUTE_SPECIAL_NAME) Attributes |= EventAttributes.SpecialName; diff --git a/Il2CppInspector/Reflection/FieldInfo.cs b/Il2CppInspector/Reflection/FieldInfo.cs index 8f4ae15..03f06f9 100644 --- a/Il2CppInspector/Reflection/FieldInfo.cs +++ b/Il2CppInspector/Reflection/FieldInfo.cs @@ -1,5 +1,5 @@ /* - Copyright 2017-2019 Katy Coe - http://www.hearthcode.org - http://www.djkaty.com + Copyright 2017-2020 Katy Coe - http://www.hearthcode.org - http://www.djkaty.com All rights reserved. */ @@ -82,7 +82,7 @@ namespace Il2CppInspector.Reflection { Name = pkg.Strings[Definition.nameIndex]; fieldTypeUsage = Definition.typeIndex; - var fieldType = pkg.TypeUsages[fieldTypeUsage]; + var fieldType = pkg.TypeReferences[fieldTypeUsage]; if ((fieldType.attrs & Il2CppConstants.FIELD_ATTRIBUTE_FIELD_ACCESS_MASK) == Il2CppConstants.FIELD_ATTRIBUTE_PRIVATE) Attributes |= FieldAttributes.Private; diff --git a/Il2CppInspector/Reflection/ParameterInfo.cs b/Il2CppInspector/Reflection/ParameterInfo.cs index 9f5ccf9..04db528 100644 --- a/Il2CppInspector/Reflection/ParameterInfo.cs +++ b/Il2CppInspector/Reflection/ParameterInfo.cs @@ -1,5 +1,5 @@ /* - Copyright 2017-2019 Katy Coe - http://www.hearthcode.org - http://www.djkaty.com + Copyright 2017-2020 Katy Coe - http://www.hearthcode.org - http://www.djkaty.com All rights reserved. */ @@ -70,7 +70,7 @@ namespace Il2CppInspector.Reflection Position = paramIndex - declaringMethod.Definition.parameterStart; paramTypeUsage = Definition.typeIndex; - var paramType = pkg.TypeUsages[paramTypeUsage]; + var paramType = pkg.TypeReferences[paramTypeUsage]; if ((paramType.attrs & Il2CppConstants.PARAM_ATTRIBUTE_HAS_DEFAULT) != 0) Attributes |= ParameterAttributes.HasDefault; diff --git a/Il2CppInspector/Reflection/TypeInfo.cs b/Il2CppInspector/Reflection/TypeInfo.cs index 603298c..ba91b2c 100644 --- a/Il2CppInspector/Reflection/TypeInfo.cs +++ b/Il2CppInspector/Reflection/TypeInfo.cs @@ -440,7 +440,7 @@ namespace Il2CppInspector.Reflection { // Nested type? if (Definition.declaringTypeIndex >= 0) { - declaringTypeDefinitionIndex = (int) pkg.TypeUsages[Definition.declaringTypeIndex].datapoint; + declaringTypeDefinitionIndex = (int) pkg.TypeReferences[Definition.declaringTypeIndex].datapoint; MemberType |= MemberTypes.NestedType; } @@ -590,7 +590,7 @@ namespace Il2CppInspector.Reflection { // Nested type? if (genericTypeDef.Definition.declaringTypeIndex >= 0) { - declaringTypeDefinitionIndex = (int)model.Package.TypeUsages[genericTypeDef.Definition.declaringTypeIndex].datapoint; + declaringTypeDefinitionIndex = (int)model.Package.TypeReferences[genericTypeDef.Definition.declaringTypeIndex].datapoint; MemberType = memberType | MemberTypes.NestedType; } @@ -602,6 +602,9 @@ namespace Il2CppInspector.Reflection { // Get the instantiation var genericInstance = image.ReadMappedObject(generic.context.class_inst); + if (generic.context.method_inst != 0) + throw new InvalidOperationException("Generic method instance cannot be non-null when processing a generic class instance"); + // Get list of pointers to type parameters (both unresolved and concrete) var genericTypeArguments = image.ReadMappedWordArray(genericInstance.type_argv, (int)genericInstance.type_argc);