-
-
[原创] 分享一个自制通用TreacArgs的IDA小脚本
-
2022-4-8 14:23
6848
-
[原创] 分享一个自制通用TreacArgs的IDA小脚本
一个自制通用TreacArgs的IDA小脚本
最近在学习ida python,突发奇想写了这个小脚本,可以Treac so中的所有函数 打印调用函数前后参数的值
找资料还找了好久最后发现ida官网有 开发文档
https://www.hex-rays.com/products/ida/support/idapython_docs/index.html
效果展示 :
效果还是很棒的,嘻嘻 我是菜鸡大佬勿喷
实现原理 :
通过 IDA python 查找代码大于10行的函数地址输出到 search_result 数组中
# 查找需要的函数
ea, ed = getSegAddr()
search_result = []
for func in idautils.Functions(ea, ed):
try:
functionName = str(idaapi.ida_funcs.get_func_name(func))
#只输出代码大于10行的函数地址
if len(list(idautils.FuncItems(func))) > 10:
# 如果是thumb模式,地址+1
arm_or_thumb = idc.get_sreg(func, "T")
if arm_or_thumb:
func += 1
search_result.append(hex(func))
except:
pass
so_path, so_name = getSoPathAndName()
search_result = [f"'{offset}'" for offset in search_result]
search_result = ", ".join(search_result)
在so拿到函数地址就可以通过frdia进行函数的hook
循环遍历search_result 数组传入Traceargs中即可
function Traceargs(funcPtr){
try{
var module = Process.findModuleByAddress(funcPtr);
//打印函数执行前后的参数
Interceptor.attach(funcPtr, {
onEnter: function(args){
this.args0 = args[0];
this.args1 = args[1];
this.args2 = args[2];
this.args3 = args[3];
this.logs = [];
//我设置的是只打印四个参数 有需求可以自己加
this.logs.push("SoName " + module.name + " 偏移 : " + ptr(funcPtr).sub(module.base) + "\\n");
this.logs.push("args0 onEnter: " + print_arg(this.args0));
this.logs.push("args1 onEnter: " + print_arg(this.args1));
this.logs.push("args2 onEnter: " + print_arg(this.args2));
this.logs.push("args3 onEnter: " + print_arg(this.args3));
//this.logs.push("args4 onEnter: " + print_arg(this.args4));
//this.logs.push("args5 onEnter: " + print_arg(this.args5));
//this.logs.push("args6 onEnter: " + print_arg(this.args6));
}, onLeave: function(retval){
this.logs.push("args0 onLeave: " + print_arg(this.args0));
this.logs.push("args1 onLeave: " + print_arg(this.args1));
this.logs.push("args2 onLeave: " + print_arg(this.args2));
this.logs.push("args3 onLeave: " + print_arg(this.args3));
//this.logs.push("args4 onLeave: " + print_arg(this.args4));
//this.logs.push("args5 onLeave: " + print_arg(this.args5));
//this.logs.push("args6 onLeave: " + print_arg(this.args6));
this.logs.push("retval onLeave: " + print_arg(retval));
console.log(this.logs);
}
});
}catch (e) {
console.log(e);
}
}
Traceargs的使用方法
下载Traceargs脚本
打开id安装目录的plugins文件夹将脚本复制进去
重启ida选择Edit->plugins ->选择traceargs运行即可会自动生成hook代码 复制代码到终端运行即可
下载地址
https://github.com/xiaotujinbnb/IDATraceMethod/tree/main
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课
最后于 2022-8-1 16:51
被王麻子本人编辑
,原因: