From 1f738a60c676de1a41ca0236f8feb7e94a571373 Mon Sep 17 00:00:00 2001 From: Katy Coe Date: Sat, 15 Aug 2020 06:28:48 +0200 Subject: [PATCH] IL2CPP: Load metadata v27; mark broken areas with TODO --- Il2CppInspector.Common/IL2CPP/Il2CppBinary.cs | 5 ++++- Il2CppInspector.Common/IL2CPP/Il2CppInspector.cs | 1 + Il2CppInspector.Common/IL2CPP/ImageScan.cs | 1 + Il2CppInspector.Common/IL2CPP/Metadata.cs | 6 ++++-- Il2CppInspector.Common/Reflection/TypeInfo.cs | 4 +++- Il2CppInspector.Common/Reflection/TypeModel.cs | 2 ++ 6 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Il2CppInspector.Common/IL2CPP/Il2CppBinary.cs b/Il2CppInspector.Common/IL2CPP/Il2CppBinary.cs index e3c24de..d9e2298 100644 --- a/Il2CppInspector.Common/IL2CPP/Il2CppBinary.cs +++ b/Il2CppInspector.Common/IL2CPP/Il2CppBinary.cs @@ -267,7 +267,10 @@ namespace Il2CppInspector TypeReferences = Image.ReadMappedObjectPointerArray(MetadataRegistration.ptypes, (int) MetadataRegistration.typesCount); // Custom attribute constructors (function pointers) - CustomAttributeGenerators = Image.ReadMappedArray(CodeRegistration.customAttributeGenerators, (int) CodeRegistration.customAttributeCount); + // TODO: Custom attribute generator load is broken in metadata v27 - this was moved to Il2CppCodeGenModule + if (Image.Version < 27) { + CustomAttributeGenerators = Image.ReadMappedArray(CodeRegistration.customAttributeGenerators, (int) CodeRegistration.customAttributeCount); + } // Method.Invoke function pointers MethodInvokePointers = Image.ReadMappedArray(CodeRegistration.invokerPointers, (int) CodeRegistration.invokerPointersCount); diff --git a/Il2CppInspector.Common/IL2CPP/Il2CppInspector.cs b/Il2CppInspector.Common/IL2CPP/Il2CppInspector.cs index abbf1bc..b1598c9 100644 --- a/Il2CppInspector.Common/IL2CPP/Il2CppInspector.cs +++ b/Il2CppInspector.Common/IL2CPP/Il2CppInspector.cs @@ -127,6 +127,7 @@ namespace Il2CppInspector return ((ulong) pValue, value); } + // TODO: The resolution of metadata usages is broken for metadata v27 (MetadataUsageLists, MetadataUsagePairs no longer exist) private List buildMetadataUsages() { var usages = new Dictionary(); diff --git a/Il2CppInspector.Common/IL2CPP/ImageScan.cs b/Il2CppInspector.Common/IL2CPP/ImageScan.cs index b451946..d1823c9 100644 --- a/Il2CppInspector.Common/IL2CPP/ImageScan.cs +++ b/Il2CppInspector.Common/IL2CPP/ImageScan.cs @@ -148,6 +148,7 @@ namespace Il2CppInspector var mrSize = (ulong) Metadata.Sizeof(typeof(Il2CppMetadataRegistration), Image.Version, Image.Bits / 8); vas = FindAllMappedWords(imageBytes, (ulong) metadata.Types.Length).Select(a => a - mrSize + ptrSize * 4); + // TODO: The metadata usages heuristic no longer works in metadata v27 foreach (var va in vas) { var mr = Image.ReadMappedObject(va); if (mr.metadataUsagesCount == (ulong) metadata.MetadataUsageLists.Length) diff --git a/Il2CppInspector.Common/IL2CPP/Metadata.cs b/Il2CppInspector.Common/IL2CPP/Metadata.cs index ccb708c..8ce7dcc 100644 --- a/Il2CppInspector.Common/IL2CPP/Metadata.cs +++ b/Il2CppInspector.Common/IL2CPP/Metadata.cs @@ -57,7 +57,7 @@ namespace Il2CppInspector // Rewind and read metadata header in full Header = ReadObject(0); - if (Version < 16 || Version > 24) + if (Version < 16 || Version > 27) { throw new InvalidOperationException($"The supplied metadata file is not of a supported version ({Header.version})."); } @@ -122,9 +122,11 @@ namespace Il2CppInspector Assemblies = ReadArray(Header.assembliesOffset, Header.assembliesCount / Sizeof(typeof(Il2CppAssemblyDefinition))); ParameterDefaultValues = ReadArray(Header.parameterDefaultValuesOffset, Header.parameterDefaultValuesCount / Sizeof(typeof(Il2CppParameterDefaultValue))); } - if (Version >= 19) { + 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) { diff --git a/Il2CppInspector.Common/Reflection/TypeInfo.cs b/Il2CppInspector.Common/Reflection/TypeInfo.cs index a5d2a40..8f8ccb1 100644 --- a/Il2CppInspector.Common/Reflection/TypeInfo.cs +++ b/Il2CppInspector.Common/Reflection/TypeInfo.cs @@ -803,7 +803,9 @@ namespace Il2CppInspector.Reflection // Pass-by-reference type // NOTE: This should actually always evaluate to false in the current implementation - IsByRef = Index == Definition.byrefTypeIndex; + // This field is no longer present in metadata v27 + // IsByRef = Index == Definition.byrefTypeIndex; + IsByRef = false; // Add all implemented interfaces implementedInterfaceReferences = new TypeRef[Definition.interfaces_count]; diff --git a/Il2CppInspector.Common/Reflection/TypeModel.cs b/Il2CppInspector.Common/Reflection/TypeModel.cs index 9eacd40..007224b 100644 --- a/Il2CppInspector.Common/Reflection/TypeModel.cs +++ b/Il2CppInspector.Common/Reflection/TypeModel.cs @@ -198,6 +198,8 @@ namespace Il2CppInspector.Reflection // It appears that TypeRef can be -1 if the generic depth recursion limit // (--maximum-recursive-generic-depth=) is reached in Il2Cpp. In this case, // no generic instance type is generated, so we just produce a null TypeInfo here. + + // TODO: Generic type definition index resolution is broken in metadata v27 (replaced with Il2CppType *type) if ((generic.typeDefinitionIndex & 0xffff_ffff) == 0x0000_0000_ffff_ffff) return null;