Frida Stalker 潜行者
Stalker是基于动态重新编译的代码跟踪器,可以跟踪指定线程,规定特定event发生时的行为等。
原理:它将代码指令复制到内存中的另一个位置,在该位置对其进行调整以适应新位置并包括其他跟踪指令。 如果应用程序在原始位置检查其代码,则会发现该代码是完整无缺的,因为它是被篡改的代码的副本。
基本使用:
function trace_entry(baseAddr,tatgetAddr){
Interceptor.attach(tatgetAddr, {
onEnter: function(args){
console.log("enter tatgetAddr====================================================================");
this.pid = Process.getCurrentThreadId();
Stalker.follow(this.pid,{
events:{// 暂时不需要这些 events,所以均设置为false
call:false,
ret:false,
exec:false,
block:false,
compile:false
},
onReceive:function(events){
},
transform: function (iterator) {
var instruction = iterator.next();
const startAddress = instruction.address;
// 从ida里面 找到 Java_com_baidu_searchbox_NativeBds_dae1 函数的 代码 在 0xE84 和 0x126C 之间
var isModule = startAddress.compare(baseAddr.add(0xE84)) >= 0 && startAddress.compare(baseAddr.add(0x126C)) < 0;
do{
if (isModule){
console.log(instruction.address.sub(baseAddr) + "\t:\t" + instruction);
}
iterator.keep();
} while ((instruction = iterator.next()) !== null);
},
onCallSummary:function(summary){
}
});
},onLeave: function(retval){
Stalker.unfollow(this.pid);
console.log("retval:"+retval);
console.log("leave tatgetAddr====================================================================");
}
});
}
其中,transform 遍历执行了当前的每一行汇编指令,默认显示的地址是实际内存地址,我们 instruction.address.sub(baseAddr) 减去了一个so的基地址,得到的就和ida中显示的地址一致了
参考:https://cloud.tencent.com/developer/article/2025433