From f5e98678bb706b206ad3232c67004027b03f96cc Mon Sep 17 00:00:00 2001 From: Katy Coe Date: Wed, 13 Nov 2019 17:12:31 +0100 Subject: [PATCH] IL2CPP: Load all Il2CppCodeGenModule method pointers into memory at init time --- Il2CppInspector/Il2CppBinary.cs | 6 ++++++ Il2CppInspector/Il2CppInspector.cs | 6 ++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Il2CppInspector/Il2CppBinary.cs b/Il2CppInspector/Il2CppBinary.cs index 2f5392c..c223d46 100644 --- a/Il2CppInspector/Il2CppBinary.cs +++ b/Il2CppInspector/Il2CppBinary.cs @@ -23,6 +23,9 @@ namespace Il2CppInspector // Only for <=v24.1 public ulong[] GlobalMethodPointers { get; set; } + // Only for >=v24.2 + public Dictionary ModuleMethodPointers { get; set; } = new Dictionary(); + // NOTE: In versions <21 and earlier releases of v21, use FieldOffsets: // global field index => field offset // In versions >=22 and later releases of v21, use FieldOffsetPointers: @@ -153,6 +156,9 @@ namespace Il2CppInspector foreach (var module in modules) { var name = image.ReadMappedNullTerminatedString(module.moduleName); Modules.Add(name, module); + + // Read method pointers + ModuleMethodPointers.Add(module, image.ReadMappedArray(module.methodPointers, (int) module.methodPointerCount)); } } diff --git a/Il2CppInspector/Il2CppInspector.cs b/Il2CppInspector/Il2CppInspector.cs index 4ca8be6..b56462e 100644 --- a/Il2CppInspector/Il2CppInspector.cs +++ b/Il2CppInspector/Il2CppInspector.cs @@ -170,12 +170,10 @@ namespace Il2CppInspector // In the event of an exception, the method pointer is not set in the file // This probably means it has been optimized away by the compiler, or is an unused generic method try { - BinaryImage.Position = BinaryImage.MapVATR(module.methodPointers + (ulong)((method - 1) * (BinaryImage.Bits / 8))); - // Remove ARM Thumb marker LSB if necessary - return (ulong) BinaryImage.ReadWord() & 0xffff_ffff_ffff_fffe; + return Binary.ModuleMethodPointers[module][method - 1] & 0xffff_ffff_ffff_fffe; } - catch (Exception) { } + catch (IndexOutOfRangeException) { } return 0; }