Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get delegate method impl #488

Open
commonuserlol opened this issue Feb 19, 2024 · 1 comment
Open

How to get delegate method impl #488

commonuserlol opened this issue Feb 19, 2024 · 1 comment

Comments

@commonuserlol
Copy link

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

@commonuserlol
Copy link
Author

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant