首页
社区
课程
招聘
[原创] 分享一个自制通用TreacArgs的IDA小脚本
2022-4-8 14:23 6848

[原创] 分享一个自制通用TreacArgs的IDA小脚本

2022-4-8 14:23
6848

一个自制通用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的使用方法 

  1. 下载Traceargs脚本 

  2. 打开id安装目录的plugins文件夹将脚本复制进去

重启ida选择Edit->plugins ->选择traceargs运行即可会自动生成hook代码 复制代码到终端运行即可

下载地址

https://github.com/xiaotujinbnb/IDATraceMethod/tree/main


[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

最后于 2022-8-1 16:51 被王麻子本人编辑 ,原因:
上传的附件:
收藏
点赞7
打赏
分享
最新回复 (5)
雪    币: 8
能力值: ( LV1,RANK:0 )
在线值:
发帖
回帖
粉丝
mb_yqoccwgm 2022-4-8 18:28
2
0
大佬这个app样本是 节点精灵吗
雪    币: 269
能力值: ( LV1,RANK:0 )
在线值:
发帖
回帖
粉丝
小兔兔呀 2022-4-8 18:31
3
0
unable to intercept function at 0x76d2ae632d; please file a bug
雪    币: 1148
活跃值: (3379)
能力值: ( LV3,RANK:30 )
在线值:
发帖
回帖
粉丝
王麻子本人 2022-4-8 18:33
4
0
mb_yqoccwgm 大佬这个app样本是 节点精灵吗
这都能看出来吗
雪    币: 1148
活跃值: (3379)
能力值: ( LV3,RANK:30 )
在线值:
发帖
回帖
粉丝
王麻子本人 2022-4-8 18:34
5
0
小兔兔呀 unable to intercept function at 0x76d2ae632d; please file a bug
thumb状态hook的函数地址需要+1
雪    币: 95
活跃值: (188)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
万事笔通 2022-4-13 20:14
6
0
感谢分享 留下学习
游客
登录 | 注册 方可回帖
返回