vfsfitvnm / frida-il2cpp-bridge

A Frida module to dump, trace or hijack any Il2Cpp application at runtime, without needing the global-metadata.dat file.
https://github.com/vfsfitvnm/frida-il2cpp-bridge/wiki
MIT License
946 stars 194 forks source link

How to invoke non-static method? #352

Closed m2k2v closed 12 months ago

m2k2v commented 12 months ago

hi. I have some problems with invoking methods from another class. this is my code : AssemblyCSharp.class("class_one").method("alex_methods").implementation = function(this: Il2Cpp.Class | Il2Cpp.Object, param, a, b, c){ // Checks some Ifs. then : AssemblyCSharp.class("another_class").method("my_method").invoke(1) }

Error : cannot invoke non-static method my_method as it must be invoked throught a Il2Cpp.Object, not a Il2Cpp.Class

350030173 commented 12 months ago

my_method must be static

bluewave41 commented 12 months ago

A method needs to be static to be called without an instance. This is generally (if not always) the same for every language.

You can get the loaded instances of a class with Il2Cpp.gc.choose(assembly.class('class_one')) which returns an array you can filter.

If the method doesn't need to be part of a specific class you should be able to do something like

const obj = assembly.class('class_one').new();
obj.method('whatever').invoke();

or

const obj = assembly.class('class_one').alloc();
obj.method('.ctor').invoke();
obj.method('whatever').invoke();

If it doesn't have a default constructor to create a new object.

vfsfitvnm commented 12 months ago

^^ this

and this: https://github.com/vfsfitvnm/frida-il2cpp-bridge/issues/196#issuecomment-1171074665