IL2CPP: Fix incorrect resolution of FieldRefs in MetadataUsages

This commit is contained in:
Katy Coe
2020-01-28 00:30:47 +01:00
parent 8a27b45775
commit aafbfc946d
4 changed files with 14 additions and 5 deletions

View File

@@ -51,6 +51,7 @@ namespace Il2CppInspector
public int[] NestedTypeIndices => Metadata.NestedTypeIndices;
public int[] AttributeTypeIndices => Metadata.AttributeTypeIndices;
public uint[] VTableMethodIndices => Metadata.VTableMethodIndices;
public Il2CppFieldRef[] FieldRefs => Metadata.FieldRefs;
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; }

View File

@@ -144,10 +144,10 @@ namespace Il2CppInspector.Reflection
return $"{method.DeclaringType.Name}.{method.Name}";
case MetadataUsageType.FieldInfo:
var field = Package.Fields[usage.SourceIndex];
type = GetTypeFromUsage(field.typeIndex);
var fieldName = Package.Strings[field.nameIndex];
return $"{type.Name}.{fieldName}";
var fieldRef = Package.FieldRefs[usage.SourceIndex];
type = GetTypeFromUsage(fieldRef.typeIndex);
var field = type.DeclaredFields.First(f => f.Index == type.Definition.fieldStart + fieldRef.fieldIndex);
return $"{type.Name}.{field.Name}";
case MetadataUsageType.StringLiteral:
return Package.StringLiterals[usage.SourceIndex];

View File

@@ -36,6 +36,7 @@ namespace Il2CppInspector
public Il2CppInterfaceOffsetPair[] InterfaceOffsets { get; }
public Il2CppMetadataUsageList[] MetadataUsageLists { get; }
public Il2CppMetadataUsagePair[] MetadataUsagePairs { get; }
public Il2CppFieldRef[] FieldRefs { get; }
public int[] InterfaceUsageIndices { get; }
public int[] NestedTypeIndices { get; }
@@ -127,6 +128,7 @@ namespace Il2CppInspector
if (Version >= 19) {
MetadataUsageLists = ReadArray<Il2CppMetadataUsageList>(Header.metadataUsageListsOffset, Header.metadataUsageListsCount / Sizeof(typeof(Il2CppMetadataUsageList)));
MetadataUsagePairs = ReadArray<Il2CppMetadataUsagePair>(Header.metadataUsagePairsOffset, Header.metadataUsagePairsCount / Sizeof(typeof(Il2CppMetadataUsagePair)));
FieldRefs = ReadArray<Il2CppFieldRef>(Header.fieldRefsOffset, Header.fieldRefsCount / Sizeof(typeof(Il2CppFieldRef)));
}
if (Version >= 21) {
AttributeTypeIndices = ReadArray<int>(Header.attributeTypesOffset, Header.attributeTypesCount / sizeof(int));

View File

@@ -439,4 +439,10 @@ namespace Il2CppInspector
public int length;
public int dataIndex;
}
public class Il2CppFieldRef
{
public int typeIndex;
public int fieldIndex; // local offset into type fields
}
}