Minor tidying up

This commit is contained in:
Katy Coe
2020-01-28 05:57:24 +01:00
parent feed8aa378
commit a7027c886e
7 changed files with 27 additions and 24 deletions

View File

@@ -47,7 +47,7 @@ namespace Il2CppInspector
public List<Il2CppGenericInst> GenericInstances { get; private set; }
// Every defined type
public List<Il2CppType> Types { get; private set; }
public List<Il2CppType> 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<Il2CppType>(MetadataRegistration.ptypes, (int) MetadataRegistration.typesCount);
// Type references (pointer array)
TypeReferences = image.ReadMappedObjectPointerArray<Il2CppType>(MetadataRegistration.ptypes, (int) MetadataRegistration.typesCount);
// Custom attribute constructors
// Custom attribute constructors (function pointers)
CustomAttributeGenerators = image.ReadMappedArray<ulong>(CodeRegistration.customAttributeGenerators, (int) CodeRegistration.customAttributeCount);
// Generic method specs
// Generic type and method specs (open and closed constructed types)
MethodSpecs = image.ReadMappedArray<Il2CppMethodSpec>(MetadataRegistration.methodSpecs, (int) MetadataRegistration.methodSpecsCount);
// Concrete generic class and method signatures

View File

@@ -55,7 +55,7 @@ namespace Il2CppInspector
public Dictionary<int, (ulong, object)> FieldDefaultValue { get; } = new Dictionary<int, (ulong, object)>();
public Dictionary<int, (ulong, object)> ParameterDefaultValue { get; } = new Dictionary<int, (ulong, object)>();
public List<long> FieldOffsets { get; }
public List<Il2CppType> TypeUsages => Binary.Types;
public List<Il2CppType> TypeReferences => Binary.TypeReferences;
public List<Il2CppGenericInst> GenericInstances => Binary.GenericInstances;
public Dictionary<string, Il2CppCodeGenModule> 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;

View File

@@ -23,14 +23,14 @@ namespace Il2CppInspector.Reflection
// List of all type definitions by fully qualified name
public Dictionary<string, TypeInfo> TypesByFullName { get; } = new Dictionary<string, TypeInfo>();
// 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<ulong, TypeInfo> TypesByVirtualAddress { get; } = new ConcurrentDictionary<ulong, TypeInfo>();
// Every type
public IEnumerable<TypeInfo> Types => new IEnumerable<TypeInfo>[] {TypesByDefinitionIndex, TypesByUsageIndex, TypesByVirtualAddress.Values}.SelectMany(t => t);
public IEnumerable<TypeInfo> Types => new IEnumerable<TypeInfo>[] {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;
}

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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<Il2CppGenericInst>(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);