IL2CPP: Load metadata v27; mark broken areas with TODO

This commit is contained in:
Katy Coe
2020-08-15 06:28:48 +02:00
parent 0d9c01ecaa
commit 1f738a60c6
6 changed files with 15 additions and 4 deletions

View File

@@ -267,7 +267,10 @@ namespace Il2CppInspector
TypeReferences = Image.ReadMappedObjectPointerArray<Il2CppType>(MetadataRegistration.ptypes, (int) MetadataRegistration.typesCount); TypeReferences = Image.ReadMappedObjectPointerArray<Il2CppType>(MetadataRegistration.ptypes, (int) MetadataRegistration.typesCount);
// Custom attribute constructors (function pointers) // Custom attribute constructors (function pointers)
// TODO: Custom attribute generator load is broken in metadata v27 - this was moved to Il2CppCodeGenModule
if (Image.Version < 27) {
CustomAttributeGenerators = Image.ReadMappedArray<ulong>(CodeRegistration.customAttributeGenerators, (int) CodeRegistration.customAttributeCount); CustomAttributeGenerators = Image.ReadMappedArray<ulong>(CodeRegistration.customAttributeGenerators, (int) CodeRegistration.customAttributeCount);
}
// Method.Invoke function pointers // Method.Invoke function pointers
MethodInvokePointers = Image.ReadMappedArray<ulong>(CodeRegistration.invokerPointers, (int) CodeRegistration.invokerPointersCount); MethodInvokePointers = Image.ReadMappedArray<ulong>(CodeRegistration.invokerPointers, (int) CodeRegistration.invokerPointersCount);

View File

@@ -127,6 +127,7 @@ namespace Il2CppInspector
return ((ulong) pValue, value); return ((ulong) pValue, value);
} }
// TODO: The resolution of metadata usages is broken for metadata v27 (MetadataUsageLists, MetadataUsagePairs no longer exist)
private List<MetadataUsage> buildMetadataUsages() private List<MetadataUsage> buildMetadataUsages()
{ {
var usages = new Dictionary<uint, MetadataUsage>(); var usages = new Dictionary<uint, MetadataUsage>();

View File

@@ -148,6 +148,7 @@ namespace Il2CppInspector
var mrSize = (ulong) Metadata.Sizeof(typeof(Il2CppMetadataRegistration), Image.Version, Image.Bits / 8); 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); 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) { foreach (var va in vas) {
var mr = Image.ReadMappedObject<Il2CppMetadataRegistration>(va); var mr = Image.ReadMappedObject<Il2CppMetadataRegistration>(va);
if (mr.metadataUsagesCount == (ulong) metadata.MetadataUsageLists.Length) if (mr.metadataUsagesCount == (ulong) metadata.MetadataUsageLists.Length)

View File

@@ -57,7 +57,7 @@ namespace Il2CppInspector
// Rewind and read metadata header in full // Rewind and read metadata header in full
Header = ReadObject<Il2CppGlobalMetadataHeader>(0); Header = ReadObject<Il2CppGlobalMetadataHeader>(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})."); throw new InvalidOperationException($"The supplied metadata file is not of a supported version ({Header.version}).");
} }
@@ -122,9 +122,11 @@ namespace Il2CppInspector
Assemblies = ReadArray<Il2CppAssemblyDefinition>(Header.assembliesOffset, Header.assembliesCount / Sizeof(typeof(Il2CppAssemblyDefinition))); Assemblies = ReadArray<Il2CppAssemblyDefinition>(Header.assembliesOffset, Header.assembliesCount / Sizeof(typeof(Il2CppAssemblyDefinition)));
ParameterDefaultValues = ReadArray<Il2CppParameterDefaultValue>(Header.parameterDefaultValuesOffset, Header.parameterDefaultValuesCount / Sizeof(typeof(Il2CppParameterDefaultValue))); ParameterDefaultValues = ReadArray<Il2CppParameterDefaultValue>(Header.parameterDefaultValuesOffset, Header.parameterDefaultValuesCount / Sizeof(typeof(Il2CppParameterDefaultValue)));
} }
if (Version >= 19) { if (Version >= 19 && Version < 27) {
MetadataUsageLists = ReadArray<Il2CppMetadataUsageList>(Header.metadataUsageListsOffset, Header.metadataUsageListsCount / Sizeof(typeof(Il2CppMetadataUsageList))); MetadataUsageLists = ReadArray<Il2CppMetadataUsageList>(Header.metadataUsageListsOffset, Header.metadataUsageListsCount / Sizeof(typeof(Il2CppMetadataUsageList)));
MetadataUsagePairs = ReadArray<Il2CppMetadataUsagePair>(Header.metadataUsagePairsOffset, Header.metadataUsagePairsCount / Sizeof(typeof(Il2CppMetadataUsagePair))); MetadataUsagePairs = ReadArray<Il2CppMetadataUsagePair>(Header.metadataUsagePairsOffset, Header.metadataUsagePairsCount / Sizeof(typeof(Il2CppMetadataUsagePair)));
}
if (Version >= 19) {
FieldRefs = ReadArray<Il2CppFieldRef>(Header.fieldRefsOffset, Header.fieldRefsCount / Sizeof(typeof(Il2CppFieldRef))); FieldRefs = ReadArray<Il2CppFieldRef>(Header.fieldRefsOffset, Header.fieldRefsCount / Sizeof(typeof(Il2CppFieldRef)));
} }
if (Version >= 21) { if (Version >= 21) {

View File

@@ -803,7 +803,9 @@ namespace Il2CppInspector.Reflection
// Pass-by-reference type // Pass-by-reference type
// NOTE: This should actually always evaluate to false in the current implementation // 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 // Add all implemented interfaces
implementedInterfaceReferences = new TypeRef[Definition.interfaces_count]; implementedInterfaceReferences = new TypeRef[Definition.interfaces_count];

View File

@@ -198,6 +198,8 @@ namespace Il2CppInspector.Reflection
// It appears that TypeRef can be -1 if the generic depth recursion limit // It appears that TypeRef can be -1 if the generic depth recursion limit
// (--maximum-recursive-generic-depth=) is reached in Il2Cpp. In this case, // (--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. // 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) if ((generic.typeDefinitionIndex & 0xffff_ffff) == 0x0000_0000_ffff_ffff)
return null; return null;