diff --git a/Il2CppInspector/IL2CPP/Il2CppBinary.cs b/Il2CppInspector/IL2CPP/Il2CppBinary.cs index d4d7235..372014b 100644 --- a/Il2CppInspector/IL2CPP/Il2CppBinary.cs +++ b/Il2CppInspector/IL2CPP/Il2CppBinary.cs @@ -26,6 +26,9 @@ namespace Il2CppInspector // Only for >=v24.2 public Dictionary ModuleMethodPointers { get; set; } = new Dictionary(); + // Only for >=v24.2. In earlier versions, invoker indices are stored in Il2CppMethodDefinition in the metadata file + public Dictionary MethodInvokerIndices { 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: @@ -40,6 +43,10 @@ namespace Il2CppInspector // Generated functions which call constructors on custom attributes public ulong[] CustomAttributeGenerators { get; private set; } + // IL2CPP-generated functions which implement MethodBase.Invoke with a unique signature per invoker, defined in Il2CppInvokerTable.cpp + // One invoker specifies a return type and argument list. Multiple methods with the same signature can be invoked with the same invoker + public ulong[] MethodInvokePointers { get; private set; } + // Generic method specs for vtables public Il2CppMethodSpec[] MethodSpecs { get; private set; } @@ -171,6 +178,9 @@ namespace Il2CppInspector // Read method pointers ModuleMethodPointers.Add(module, image.ReadMappedArray(module.methodPointers, (int) module.methodPointerCount)); + + // Read method invoker pointer indices - one per method + MethodInvokerIndices.Add(module, image.ReadMappedArray(module.invokerIndices, (int) module.methodPointerCount)); } } @@ -202,6 +212,16 @@ namespace Il2CppInspector // Custom attribute constructors (function pointers) CustomAttributeGenerators = image.ReadMappedArray(CodeRegistration.customAttributeGenerators, (int) CodeRegistration.customAttributeCount); + + // Method.Invoke function pointers + MethodInvokePointers = image.ReadMappedArray(CodeRegistration.invokerPointers, (int) CodeRegistration.invokerPointersCount); + + // TODO: Function pointers as shown below + // reversePInvokeWrappers + // <=22: delegateWrappersFromManagedToNative, marshalingFunctions; + // >=21 <=22: ccwMarhsalingFunctions + // >=22: unresolvedVirtualCallPointers + // >=23: interopData // Generic type and method specs (open and closed constructed types) MethodSpecs = image.ReadMappedArray(MetadataRegistration.methodSpecs, (int) MetadataRegistration.methodSpecsCount); diff --git a/Il2CppInspector/IL2CPP/Il2CppInspector.cs b/Il2CppInspector/IL2CPP/Il2CppInspector.cs index 3f2a329..3298553 100644 --- a/Il2CppInspector/IL2CPP/Il2CppInspector.cs +++ b/Il2CppInspector/IL2CPP/Il2CppInspector.cs @@ -59,6 +59,7 @@ namespace Il2CppInspector public List GenericInstances => Binary.GenericInstances; public Dictionary Modules => Binary.Modules; public ulong[] CustomAttributeGenerators => Binary.CustomAttributeGenerators; + public ulong[] MethodInvokePointers => Binary.MethodInvokePointers; public Il2CppMethodSpec[] MethodSpecs => Binary.MethodSpecs; public Dictionary GenericMethodPointers => Binary.GenericMethodPointers; @@ -202,6 +203,7 @@ namespace Il2CppInspector Binary.ModuleMethodPointers.SelectMany(module => module.Value).ToList(); sortedFunctionPointers.AddRange(CustomAttributeGenerators); + sortedFunctionPointers.AddRange(MethodInvokePointers); sortedFunctionPointers.AddRange(GenericMethodPointers.Values); sortedFunctionPointers.Sort(); sortedFunctionPointers = sortedFunctionPointers.Distinct().ToList(); @@ -279,6 +281,17 @@ namespace Il2CppInspector return null; } + // Get a method invoker index from a method definition + public int GetInvokerIndex(Il2CppCodeGenModule module, Il2CppMethodDefinition methodDef) { + if (Version <= 24.1) { + return methodDef.invokerIndex; + } + + // Version >= 24.2 + var methodInModule = (methodDef.token & 0xffffff); + return Binary.MethodInvokerIndices[module][methodInModule - 1]; + } + public static List LoadFromFile(string codeFile, string metadataFile) { // Load the metadata file Metadata metadata;