diff --git a/Il2CppInspector/Il2CppBinary.cs b/Il2CppInspector/Il2CppBinary.cs index 80b204d..907efdb 100644 --- a/Il2CppInspector/Il2CppBinary.cs +++ b/Il2CppInspector/Il2CppBinary.cs @@ -26,7 +26,12 @@ namespace Il2CppInspector // type index => RVA in image where the list of field offsets for the type start (4 bytes per field) public int[] FieldOffsetData { get; private set; } - public List Types { get; } = new List(); + // Every defined type + public List Types { get; private set; } + + // From later versions of v24 onwards, this structure is stored for each module (image) + // One assembly may contain multiple modules + public Dictionary Modules { get; private set; } protected Il2CppBinary(IFileFormatReader stream) { Image = stream; @@ -53,7 +58,7 @@ namespace Il2CppInspector if (loc != 0) { var (code, metadata) = ConsiderCode(loc, Image.GlobalOffset); if (code != 0) { - Configure(subImage, code, metadata); + Configure(subImage, code, metadata); subImage.FinalizeInit(this); return true; } @@ -62,13 +67,32 @@ namespace Il2CppInspector } private void Configure(IFileFormatReader image, uint codeRegistration, uint metadataRegistration) { + // Root structures from which we find everything else CodeRegistration = image.ReadMappedObject(codeRegistration); MetadataRegistration = image.ReadMappedObject(metadataRegistration); - MethodPointers = image.ReadMappedArray(CodeRegistration.pmethodPointers, (int) CodeRegistration.methodPointersCount); + + // The global method pointer list was deprecated in later versions of v24 in favour of Il2CppCodeGenModule + if (Image.Stream.Version <= 24.0) + MethodPointers = image.ReadMappedArray(CodeRegistration.pmethodPointers, (int) CodeRegistration.methodPointersCount); + + // After v24 method pointers and RGCTX data were stored in Il2CppCodeGenModules + if (Image.Stream.Version >= 24.1) { + Modules = new Dictionary(); + + // Array of pointers to Il2CppCodeGenModule + var modules = image.ReadMappedObjectPointerArray(CodeRegistration.pcodeGenModules, (int) CodeRegistration.codeGenModulesCount); + + foreach (var module in modules) { + var name = image.ReadMappedNullTerminatedString(module.moduleName); + Modules.Add(name, module); + } + } + + // Field offset data. Metadata <=21.x uses a value-type array; >=21.x uses a pointer array FieldOffsetData = image.ReadMappedArray(MetadataRegistration.pfieldOffsets, MetadataRegistration.fieldOffsetsCount); - var types = image.ReadMappedArray(MetadataRegistration.ptypes, MetadataRegistration.typesCount); - for (int i = 0; i < MetadataRegistration.typesCount; i++) - Types.Add(image.ReadMappedObject(types[i])); + + // Type definitions (pointer array) + Types = image.ReadMappedObjectPointerArray(MetadataRegistration.ptypes, MetadataRegistration.typesCount); } } } diff --git a/Il2CppInspector/Reflection/Assembly.cs b/Il2CppInspector/Reflection/Assembly.cs index a401839..95f555c 100644 --- a/Il2CppInspector/Reflection/Assembly.cs +++ b/Il2CppInspector/Reflection/Assembly.cs @@ -14,6 +14,7 @@ namespace Il2CppInspector.Reflection { // IL2CPP-specific data public Il2CppReflector Model { get; } public Il2CppImageDefinition Definition { get; } + public Il2CppCodeGenModule Module { get; } public int Index { get; } // TODO: CustomAttributes @@ -41,6 +42,10 @@ namespace Il2CppInspector.Reflection { // TODO: Generate EntryPoint method from entryPointIndex } + // Find corresponding module (we'll need this for method pointers) + if (Model.Package.Metadata.Version >= 24.1) + Module = Model.Package.Binary.Modules[FullName]; + // Generate types in DefinedTypes from typeStart to typeStart+typeCount-1 for (var t = Definition.typeStart; t < Definition.typeStart + Definition.typeCount; t++) DefinedTypes.Add(new TypeInfo(Model.Package, t, this)); diff --git a/Il2CppInspector/Reflection/MethodInfo.cs b/Il2CppInspector/Reflection/MethodInfo.cs index 6a9ec9c..5102abe 100644 --- a/Il2CppInspector/Reflection/MethodInfo.cs +++ b/Il2CppInspector/Reflection/MethodInfo.cs @@ -33,11 +33,26 @@ namespace Il2CppInspector.Reflection base(declaringType) { Definition = pkg.Metadata.Methods[methodIndex]; Index = methodIndex; + Name = pkg.Strings[Definition.nameIndex]; + + // Find method pointer if (Definition.methodIndex >= 0) { - VirtualAddress = pkg.Binary.MethodPointers[Definition.methodIndex]; + + // Global method pointer array + if (pkg.Metadata.Version < 24.1) { + VirtualAddress = pkg.Binary.MethodPointers[Definition.methodIndex]; + } + + // Per-module method pointer array uses the bottom 24 bits of the method's metadata token + // Derived from il2cpp::vm::MetadataCache::GetMethodPointer + else { + var method = (Definition.token & 0xffffff) - 1; + pkg.Binary.Image.Position = pkg.Binary.Image.MapVATR(Assembly.Module.methodPointers + method * 4); + VirtualAddress = pkg.Binary.Image.ReadUInt32(); + } + HasBody = true; } - Name = pkg.Strings[Definition.nameIndex]; if ((Definition.flags & Il2CppConstants.METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == Il2CppConstants.METHOD_ATTRIBUTE_PRIVATE) Attributes |= MethodAttributes.Private;