From 67f3fbe35c730609cced2bf188a14ca219b1c07c Mon Sep 17 00:00:00 2001 From: LukeFZ <17146677+LukeFZ@users.noreply.github.com> Date: Mon, 22 Dec 2025 21:55:10 +0100 Subject: [PATCH] preemptively check if MethodPointers/InvokerIndices are mapped to prevent exceptions --- Il2CppInspector.Common/IL2CPP/Il2CppBinary.cs | 33 ++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/Il2CppInspector.Common/IL2CPP/Il2CppBinary.cs b/Il2CppInspector.Common/IL2CPP/Il2CppBinary.cs index d57f98d..44f72d2 100644 --- a/Il2CppInspector.Common/IL2CPP/Il2CppBinary.cs +++ b/Il2CppInspector.Common/IL2CPP/Il2CppBinary.cs @@ -334,21 +334,38 @@ namespace Il2CppInspector // 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.ReadMappedUWordArray(module.MethodPointers, (int) module.MethodPointerCount)); - } catch (InvalidOperationException) { + if (Image.TryMapVATR(module.MethodPointers, out _)) + { + try + { + ModuleMethodPointers.Add(module, Image.ReadMappedUWordArray(module.MethodPointers, (int)module.MethodPointerCount)); + } + catch (InvalidOperationException) + { + ModuleMethodPointers.Add(module, new ulong[module.MethodPointerCount]); + } + } + else + { ModuleMethodPointers.Add(module, new ulong[module.MethodPointerCount]); } // Read method invoker pointer indices - one per method - try + if (Image.TryMapVATR(module.InvokerIndices, out _)) { - MethodInvokerIndices.Add(module, - Image.ReadMappedPrimitiveArray(module.InvokerIndices, (int)module.MethodPointerCount)); + try + { + MethodInvokerIndices.Add(module, + Image.ReadMappedPrimitiveArray(module.InvokerIndices, (int)module.MethodPointerCount)); + } + catch (InvalidOperationException) + { + MethodInvokerIndices.Add(module, [.. new int[(int)module.MethodPointerCount]]); + } } - catch (InvalidOperationException) + else { - MethodInvokerIndices.Add(module, [..new int[(int)module.MethodPointerCount]]); + MethodInvokerIndices.Add(module, [.. new int[(int)module.MethodPointerCount]]); } } }