vfsfitvnm / frida-il2cpp-bridge

A Frida module to dump, trace or hijack any Il2Cpp application at runtime, without needing the global-metadata.dat file.

Home Page:https://github.com/vfsfitvnm/frida-il2cpp-bridge/wiki

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to get delegate method impl

commonuserlol opened this issue · comments

I have System.Action<T> argument which extends System.Delegate, can i get handle of callback to replace it implementation?

Note: I need to get method handle from argument, replacing all callbacks will cause a lot of repeating code

My current impl is:

const callbackPtr = callback.method<Il2Cpp.Object>("get_Method").invoke()
    .method<Il2Cpp.Object>("get_MethodHandle").invoke()
    .method<Il2Cpp.Object>("get_Value").invoke()
    .method<NativePointer>("ToPointer").invoke();
const callbackMethod = new Il2Cpp.Method<void>(callbackPtr);

where callback is System.Action<T>, but output is invalid

I see Il2Cpp.Delegate simply assign callback to System.IntPtr, so I did

const callbackPtr = callback.field<Il2Cpp.Object>("method_ptr").value;
console.log(`${callbackPtr} will be patched`);
const callbackMethod = new Il2Cpp.Method<void>(callbackPtr);
replaceCallback(callbackMethod);

where replaceCallback sets implementation for callbackMethod
but still error:

0x7669b404c0 will be patched
Error: access violation accessing 0xe8aa0003fd
    at get name (../../frida-il2cpp-bridge/dist/structs/type.ts:132)
    at call (native)
    at <anonymous> (../../frida-il2cpp-bridge/dist/utils/lazy.ts:10)
    at get isByReference (../../frida-il2cpp-bridge/dist/structs/type.ts:102)
    at call (native)
    at <anonymous> (../../frida-il2cpp-bridge/dist/utils/lazy.ts:10)
    at get fridaAlias (../../frida-il2cpp-bridge/dist/structs/type.ts:95)
    at call (native)
    at <anonymous> (../../frida-il2cpp-bridge/dist/utils/lazy.ts:10)
    at wrap (../../frida-il2cpp-bridge/dist/structs/method.ts:366)
    at set implementation (../../frida-il2cpp-bridge/dist/structs/method.ts:179)
    at replaceCallback (index.ts:144)
    at <anonymous> (index.ts:160)
    at call (native)
    at <anonymous> (../../frida-il2cpp-bridge/dist/structs/method.ts:361)