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
918 stars 191 forks source link

Can't invoke method correctly #503

Closed MinorPunk closed 3 months ago

MinorPunk commented 3 months ago

I want to serialize an C# Object, here's some of my codes.

const BinaryFormatter = Il2Cpp.corlib.class("System.Runtime.Serialization.Formatters.Binary.BinaryFormatter");
const MemoryStream = Il2Cpp.corlib.class("System.IO.MemoryStream");
Il2Cpp.gc.choose(someClass).forEach((instance: Il2Cpp.Object) => {
    const asset = ReturnedFromSomeMethod as Il2Cpp.Object;
    const bf = BinaryFormatter.new();
    bf.method('.ctor').invoke();
    const ms = MemoryStream.new();
    ms.method('.ctor').invoke();
    console.log(bf.method("Serialize"));
    console.log(ms);
    console.log(asset.handle);
    bf.method<void>("Serialize").invoke(ms, asset);
});

And here is the output

System.Void Serialize(System.IO.Stream serializationStream, System.Object graph); // 0x025dc958
System.IO.MemoryStream
0x6e5984b2a0
Error: abort was called                         
at invokeRaw (il2cpp/structs/method.ts:233)
at <anonymous> (index.ts:89)
at forEach (native)
at <anonymous> (index.ts:96)
at perform (il2cpp/perform.ts:15)

I have no ideas how to solve this, tried everything I can. Thanks for any help.

MinorPunk commented 3 months ago

frida-il2cpp-bridge version: 0.9.0 frida version: 16.2.1 Unity version: 2021.3.17f1