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 create object[] instance? #317

Closed broqdev closed 1 year ago

broqdev commented 1 year ago

Hey, first great tool. Thank you for the work!

I'm trying to invoke https://docs.unity3d.com/ScriptReference/AndroidJavaObject.CallStatic.html , which is

public void CallStatic(string methodName, params object[] args);

I have successfully done that by using a empty System.Object[] object. But when I try to do something like

CallStatic("MyMethod", [0, 1, "test"])

I cannot find a proper way to do that. I have tried Il2Cpp.Array.array, or System.Object[].ctor. But all got errors. Could you please help to show some way for doing that?

vfsfitvnm commented 1 year ago

Hi, here you are:

Il2Cpp.array(Il2Cpp.corlib.class("System.Object"), [ ... ]);

Beware of you can only pass Il2Cpp.Objects.

Full example:

const SystemInt32 = Il2Cpp.corlib.class("System.Int32");
const SystemObject = Il2Cpp.corlib.class("System.Object");

const zeroBoxed = SystemInt32.new();
zeroBoxed.m_value.value = 0;

const oneBoxed = SystemInt32.new();
oneBoxed.m_value.value = 1;

const test = Il2Cpp.string("test");

CallStatic.invoke(Il2Cpp.string("MyMethod"), Il2Cpp.array(SystemObject, [zeroBoxed, oneBoxed, test]));
broqdev commented 1 year ago

verified it works. Thanks!