版权归作者所有,如有转发,请注明文章出处:https://cyrus-studio.github.io/blog/
Frida Stalker
Frida 的 Stalker 是一个强大的代码追踪工具。
主要功能
-
指令级跟踪:Stalker 可精确到指令级别,对应用的原生代码进行实时监控。
-
代码插桩:支持在指定指令前后插入自定义的代码逻辑。
-
内存访问监控:可以监视内存读写操作,分析数据流向。
-
自定义回调:提供回调函数,方便记录和分析执行轨迹。
文档:https://frida.re/docs/javascript-api/#stalker
相关文章:
Frida Stalker Trace
指令跟踪
在 Stalker.follow 的 transform 回调函数中 处理目标线程执行的每一条汇编指令。

iterator 是一个 指令迭代器对象,它让你能够 逐条处理目标线程将要执行的原始机器指令。
iterator 支持的方法
| 方法 | 作用 |
|---|---|
| next() | 获取下一条指令 |
| keep() | 保留指令(否则会被跳过) |
| putCallout(fn) | 插入 JS 回调(运行在主线程) |
通过实现 transform 回调 trace 指定函数,打印地址、指令、模块信息
function getModuleByAddressSafe(address) {
try {
// 尝试获取模块
var module = Process.getModuleByAddress(address);
// 如果模块存在,返回模块
if (module) {
return module;
} else {
// 如果没有找到模块,返回 null
return null;
}
} catch (e) {
// 捕获异常,返回 null
return null;
}
}
/**
* 指令跟踪
*
* @param targetModuleName 目标模块名
* @param targetSymbol 函数偏移(或导出名)
*/
function trace(targetModuleName, targetSymbol) {
// 获取模块基地址
const base = Module.findBaseAddress(targetModuleName);
if (base === null) {
console.error("模块未加载:" + targetModuleName);
return;
}
let targetFuncAddr;
if (typeof targetSymbol === "string") {
targetFuncAddr = Module.findExportByName(targetModuleName, targetSymbol);
} else {
targetFuncAddr = base.add(ptr(targetSymbol));
}
if (!targetFuncAddr) {
console.error("找不到函数地址");
return;
}
console.log("目标函数地址: " + targetFuncAddr);
// 拦截目标函数,开始跟踪当前线程
Interceptor.attach(targetFuncAddr, {
onEnter(args) {
let tid = Process.getCurrentThreadId()
this.tid = tid
console.log(`进入函数,开始 trace [${tid}]`);
Stalker.follow(tid, {
events: {
call: false,
ret: false,
exec: true,
block: false,
compile: false
},
transform(iterator) {
let instruction = iterator.next
Frida Stalker实现指令跟踪与寄存器监控

最低0.47元/天 解锁文章
5184

被折叠的 条评论
为什么被折叠?



