From 54ac9d7c1ab854281cc938b579639ce08e183e48 Mon Sep 17 00:00:00 2001 From: Katy Coe Date: Sat, 22 Aug 2020 03:30:17 +0200 Subject: [PATCH] IL2CPP: Fix crash when loading Il2CppCodeGenModule with no concrete methods (#58) --- Il2CppInspector.Common/IL2CPP/Il2CppBinary.cs | 9 ++++++++- Il2CppInspector.Common/Reflection/TypeModel.cs | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Il2CppInspector.Common/IL2CPP/Il2CppBinary.cs b/Il2CppInspector.Common/IL2CPP/Il2CppBinary.cs index 2cf485d..b0b599b 100644 --- a/Il2CppInspector.Common/IL2CPP/Il2CppBinary.cs +++ b/Il2CppInspector.Common/IL2CPP/Il2CppBinary.cs @@ -235,7 +235,14 @@ namespace Il2CppInspector CodeGenModulePointers.Add(name, mp.Pointer); // Read method pointers - ModuleMethodPointers.Add(module, Image.ReadMappedArray(module.methodPointers, (int) module.methodPointerCount)); + // If a module contains only interfaces, abstract methods and/or non-concrete generic methods, + // the entire method pointer array will be NULL values, causing the methodPointer to be mapped to .bss + // and therefore out of scope of the binary image + try { + ModuleMethodPointers.Add(module, Image.ReadMappedArray(module.methodPointers, (int) module.methodPointerCount)); + } catch (InvalidOperationException) { + ModuleMethodPointers.Add(module, new ulong[module.methodPointerCount]); + } // Read method invoker pointer indices - one per method MethodInvokerIndices.Add(module, Image.ReadMappedArray(module.invokerIndices, (int) module.methodPointerCount)); diff --git a/Il2CppInspector.Common/Reflection/TypeModel.cs b/Il2CppInspector.Common/Reflection/TypeModel.cs index 6d990f5..adfe949 100644 --- a/Il2CppInspector.Common/Reflection/TypeModel.cs +++ b/Il2CppInspector.Common/Reflection/TypeModel.cs @@ -146,6 +146,7 @@ namespace Il2CppInspector.Reflection .ToDictionary(g => g.Key, g => g.GroupBy(a => a.AttributeType).Select(g => g.First()).ToList()); // Create method invokers (one per signature, in invoker index order) + // Generic type definitions have an invoker index of -1 foreach (var method in MethodsByDefinitionIndex) { var index = package.GetInvokerIndex(method.DeclaringType.Assembly.ModuleDefinition, method.Definition); if (index != -1) { @@ -156,7 +157,6 @@ namespace Il2CppInspector.Reflection } } - // TODO: Some invokers are not initialized or missing, need to find out why // Create method invokers sourced from generic method invoker indices foreach (var spec in GenericMethods.Keys) { if (package.GenericMethodInvokerIndices.TryGetValue(spec, out var index)) {