Closed Kn0wns closed 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)
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
There is no error info when commenting recv.implementation = function (kcp, bytes, len)
Unfortunately you have to
// @ts-ignore <--- this one
recv.implementation = ...
(this is a TypeScript thing)
"build": "esbuild --bundle --outfile=hook.js src/main.ts"
include xxx.js
in main.ts
, write hook in xxx.js
Only recv has error info, but send has no error info
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
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)
}
}