hexrays sdk study
There are 20 examples in /ida_path/plugins/hexrays_sdk/plugins, you can learn from that, you can also see it at https://hex-rays.com/products/decompiler/manual/sdk/examples.shtml.They are all written in cpp.
get starts
there are some background information at https://hex-rays.com/blog/hex-rays-decompiler-primer/ and Hex-Rays SDK document.
Here is a template written in python. All you need to do is just edit func visit_expr or visit_insn or both.
import idaapi
import idc
class Handler(idaapi.ctree_visitor_t):
def __init__(self, cfunc):
idaapi.ctree_visitor_t.__init__(self, idaapi.CV_FAST)
self.cfunc = cfunc
#callback when visit every statement
def visit_expr(self, expr:idaapi.cexpr_t) -> "int":
return 0
#callback when visit every expression
def visit_insn(self, ins:idaapi.idaapi.cinsn_t) -> "int":
return 0
def main():
func = idaapi.get_func(idc.here()) # get current func
cfunc = idaapi.decompile(func.start_ea) # decompile func
handler = Handler(cfunc)
handler .apply_to(cfunc.body, None)
if __name__ == '__main__':
main()
note: if you want to handle the whole func, the return value of visit_expr and visit_insn must be zero or it will stop when you return 1.
Pratice
Get every xref of a func and print its args
Here is the code
import idaapi
import idc
class Handler(idaapi.ctree_visitor_t):
def __init__(self, cfunc):
idaapi.ctree_visitor_t.__init__(self, idaapi.CV_FAST)
self.cfunc = cfunc
def visit_expr(self, expr: idaapi.cexpr_t ) -> "int":
#only handle every call expr
if expr.op != idaapi.cot_call:
return 0
#get callee func name
func_name = idaapi.get_func_name(expr.x.obj_ea)
if( func_name == "target_funcname"):
#get caller func name
caller_name = idaapi.get_func_name(expr.ea)
out_str = f"{caller_name} call {func_name}("
#get arglist length
args = expr.a.size()
for i in range(args):
#get every arg
arg = expr.a[i]
if arg.op == idaapi.cot_num: #case arg type direct value
out_str += str(arg.n._value)
elif arg.op == idaapi.cot_obj: #case arg type string
if ida_bytes.get_strlit_contents(arg.obj_ea, -1, 0) == None:
continue
out_str += "\""
out_str += ida_bytes.get_strlit_contents(arg.obj_ea, -1, 0).decode().replace("\n", "\\n")
out_str += "\""
else:
out_str += f"a{i+1}"
out_str += ", " if i < args - 1 else ")"
print(out_str)
return 0
def main():
for func_addr in Functions():
#only handle the func in .text segment
if idc.get_segm_name(func_addr) != ".text":
continue
func = idaapi.decompile(func_addr)
handler = Handler(func)
handler.apply_to(func.body, None)
if __name__ == "__main__":
main()
If you want to do more pratice , you can rewrite the examples in python.
hexrays sdk study的更多相关文章
- Node.js SDK与fabric链码交互开发
1.本篇背景 前面已经对链码开发作了比较详细的介绍,并且对官方提供的 fabcar 链码进行了解读,本篇将介绍如何使用 Node.js SDK 与区块链网络中的链码进行交互. 本篇内容基本来自官方 H ...
- DICOM医学图像处理:Orthanc Plugin SDK实现WADO服务
背景: Orthanc是博主发现的一个很完美的DICOM和HTTP服务端开源软件,前几篇分别介绍了Orthanc的基本使用.Orthanc从0.8.0版本之后给出了Plugin SDK,通过该SDK可 ...
- 配置android sdk 环境
1:下载adnroid sdk安装包 官方下载地址无法打开,没有vpn,使用下面这个地址下载,地址:http://www.android-studio.org/
- 阿里云直播 C# SDK 如何使用
阿里云直播SDK的坑 1.直播云没有单独的SDK,直播部分被封装在CDN的相关SDK当中. 2.针对SDK,没有相关Demo. 3.针对SDK,没有相关的文档说明. 4.针对SDK的说明,官网上的说明 ...
- 使用Visual Studio SDK制作GLSL词法着色插件
使用Visual Studio SDK制作GLSL词法着色插件 我们在Visual Studio上开发OpenGL ES项目时,避免不了写Shader.这时在vs里直接编辑shader就会显得很方便. ...
- iOS开发之App间账号共享与SDK封装
上篇博客<iOS逆向工程之KeyChain与Snoop-it>中已经提到了,App间的数据共享可以使用KeyChian来实现.本篇博客就实战一下呢.开门见山,本篇博客会封装一个登录用的SD ...
- Intel Media SDK H264 encoder GOP setting
1 I帧,P帧,B帧,IDR帧,NAL单元 I frame:帧内编码帧,又称intra picture,I 帧通常是每个 GOP(MPEG 所使用的一种视频压缩技术)的第一个帧,经过适度地压缩,做为随 ...
- Android SDK 在线更新镜像服务器资源
本文转自:http://blog.kuoruan.com/24.html.感谢原作者. 什么是Android SDK SDK:(software development kit)软件开发工具包.被软件 ...
- TYPESDK手游聚合SDK服务端设计思路与架构之二:服务端设计
在前一篇文中,我们对一个聚合SDK服务端所需要实现的功能作了简单的分析.通过两个主要场景的功能流程图,我们可以看到,作为多款游戏要适配多个渠道的统一请求转发中心,TYPESDK服务端主要需要实现的功能 ...
- TYPESDK手游聚合SDK服务端设计思路与架构之一:应用场景分析
TYPESDK 服务端设计思路与架构之一:应用场景分析 作为一个渠道SDK统一接入框架,TYPESDK从一开始,所面对的需求场景就是多款游戏,通过一个统一的SDK服务端,能够同时接入几十个甚至几百个各 ...
随机推荐
- 小编亲身实操,教你配置phpstorm与xdebug的调试配置,不成功你骂我
开发php,还是找个专业的Ide较好,vscode毕竟在php上不专业,需要下载各种插件才行,还不支持多线程调试,因此小编下载了phpstorm,打算以后用phpstorm来开发php项目,断点调试代 ...
- void关键字
在C++中,void表示为无类型,主要有三个用途: (1)函数的 返回值用void,表示函数没有返回值. void func(int a, int b) { //函数体代码 return; } (2) ...
- TS 基础及在 Vue 中的实践:TypeScript 都发布 5.0 版本啦,现在不学更待何时!
大家好,我是 Kagol,OpenTiny 开源社区运营,TinyVue 跨端.跨框架组件库核心贡献者,专注于前端组件库建设和开源社区运营. 微软于3月16日发布了 TypeScript 5.0 版本 ...
- 使用 screw(螺丝钉) 快速生成数据库文档
一.框架介绍 回想起那个去年的7月份,第一份实习,组长让我写一份金蝶云的SQL文档,当时一看2000多张表,当时就猛吸一根烟,然后去gitee看看有没有好的框架快速生成 SQL 文档 ,由此找到了 s ...
- 【PWN】初见BROP
前言|与BROP的相遇 第一次BROP,它让我觉得pwn,或者说网安很妙,也很折磨 在遇到它之前,之前接触的题目都是简单的栈溢出,感觉没有啥有趣的,很简单,找gadget溢出就可以,一切都看得见 可遇 ...
- app稳定性测试-iOS篇
稳定性测试:测试应用程序在长时间运行过程中是否存在内存泄漏.崩溃等问题,以确保应用程序具有较高的稳定性和可靠性. 对于安卓端,官方提供了很好的稳定性测试工具:monkey. 相比较而言,iOS则没有, ...
- 如何快速在Ubuntu上搭建python环境?
如何快速在Ubuntu上搭建python环境? 一.准备好python源码包 使用curl命令获取python源码包的过程很缓慢且容易失败,因此提前去官网下载好后放在本地是最好的办法. 二.启动镜像并 ...
- vue之input输入框的几个事件
目录 事件简介 示例 事件简介 click 点击事件,一般不会用于input输入框,会用于按钮,用于输入框就有点像focus了,当点击输入框时会触发 blur 失去焦点事件,当失去焦点时会触发. fo ...
- [Java]排序算法>插入排序>【折半插入排序】(O(N*N)/稳定/N较大/无序/顺序存储)
1 折半插入排序 1.1 算法思想 相比于[直接插入排序]:采用"顺序查找法"查找当前记录在已排好序的序列中的插入位置, 折半插入排序利用"折半查找法"快速查出 ...
- 自己动手从零写桌面操作系统GrapeOS系列教程——4.1 在VirtualBox中安装CentOS
学习操作系统原理最好的方法是自己写一个简单的操作系统. 之前讲解开发环境时并没有介绍具体的安装过程,有网友反应CentOS的安装配置有问题,尤其是共享文件夹.本讲我们就来补充介绍一下在VirtualB ...