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
1.06k stars 204 forks source link

show Error: expected an integer #542

Closed Kn0wns closed 3 months ago

Kn0wns commented 3 months ago

image

Kn0wns commented 3 months ago

The current approach, although effective, appears to be rather cumbersome. I would like to inquire about the reason behind the unavailability of switching to the frida native type for processing.

function arrayToBuffer(array) {
    const buffer = new ArrayBuffer(array.length);
    const view = new Uint8Array(buffer);
    for (let i = 0; i < array.length; i++) {
        view[i] = array[i];
    }
    return buffer;
}

const buff = memoryStream.method("ToArray", 0).invoke();  // System.Byte[] ToArray();
let s = buff.toString().replace('[', "").replace(']', '').split(',')
arrayToBuffer(s)
Kn0wns commented 3 months ago

The solution has been identified by me.

let bytes = memoryStream.method("ToArray", 0).invoke();  // System.Byte[] ToArray();
let arrayBuffer = ptr(bytes.elements).readByteArray(bytes.length);

a new problem has been encountered, and although there is an error message, this does not prevent the script from working properly image

There is no error info when commenting recv.implementation = function (kcp, bytes, len)

vfsfitvnm commented 3 months ago

Unfortunately you have to

// @ts-ignore <--- this one
recv.implementation = ...

(this is a TypeScript thing)

Kn0wns commented 3 months ago

"build": "esbuild --bundle --outfile=hook.js src/main.ts" include xxx.js in main.ts, write hook in xxx.js image

Kn0wns commented 3 months ago

Only recv has error info, but send has no error info

vfsfitvnm commented 3 months ago

That's a runtime error, somewhere in your code Frida is expecting an integer, but you are passing something else. I guess ickp_recv returns an System.IntXX, but your implementation is not returning any value

Kn0wns commented 3 months ago

Perfect. I thought like frida hook native, don't need to call return

function recv() {
    let KCP = Il2Cpp.domain.assembly("Game.Runtime").image.class('Sining.KCP')
    let recv = KCP.method("ikcp_recv")
    recv.implementation = function (kcp, bytes, len) {
        let arrayBuffer = ptr(bytes.elements).readByteArray(bytes.length);
        let pack = unpack(arrayBuffer);
        let PbHex = pbBuf(bytes, pack);
        log.i(`recv`, `${JSON.stringify(pack)} ${opcodeMapping[pack.OpCode]} ${PbHex}`)
        return this.method("ikcp_recv").invoke(kcp, bytes, len)
    }
}