With the js script, the pc is right. All 0xa2808 pc instruction are br x8.
var lib = Process.findModuleByName("lib-native.so");
Stalker.follow(Process.getCurrentThreadId(), {
transform(it) {
var insn = it.next();
var addr = insn.address;
do {
if (addr.compare(lib.base) >= 0 && addr.compare(lib.base.add(lib.size)) === -1) {
it.putCallout(function (ctx) {
var nme = Instruction.parse(ptr(ctx.pc));
console.log("onReceive", lib.name + "!" + ptr(ctx.pc).sub(lib.base), nme);
})
}
it.keep();
} while (insn = it.next() !== null)
}
})
So I guess the gum_stalker_iterator_keep runs async, and *insn change when the on_ret callback was called.
I also try to malloc a new cs_insn struct and copy one to the on_ret callback, then release it. But the CModule doesn't found the malloc function when compiling.
The transform code in CModule looks like below
Everything runs right at the begining, but after a while the pc value is going wrong. I search the address 0xa2808 and found the instruction change.
With the js script, the pc is right. All 0xa2808 pc instruction are
br x8
.So I guess the
gum_stalker_iterator_keep
runs async, and*insn
change when theon_ret
callback was called.I also try to malloc a new
cs_insn
struct and copy one to theon_ret
callback, then release it. But the CModule doesn't found themalloc
function when compiling.