首页 > 其他分享 >hexrays sdk study

hexrays sdk study

时间:2023-01-19 17:47:16浏览次数:59  
标签:__ idaapi name get expr study hexrays func sdk

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.

标签:__,idaapi,name,get,expr,study,hexrays,func,sdk
From: https://www.cnblogs.com/awesome-red/p/17061872.html

相关文章

  • daily study 15
    初识指针2;野指针:指针指向的位置是不可知的1.int*p;*P=20;指针未初始化;2.intarr[10]={0};int*p=arr;inti=0;for(i=0;i<=10;i++){*p=i;p++;}越界访问;3.指针指向了空间释放in......
  • 美颜sdk人脸识别技术在其它领域有哪些作用?
    时下,美颜sdk人脸识别技术已经得到许多行业的认可,特别是在短视频、直播美颜sdk领域,已经成了核心技术,许多功能都需要基于它完成。随着用户需求的不断提高,人脸识别技术也在不停......
  • [ROC-RK3568-PC] 手把手教你编译Linux_SDK并打包Ubuntu系统固件
    ......
  • [ROC-RK3568-PC] 手把手教你编译Linux_SDK并打包Buildroot系统固件
    ✏️ROC-RK3568-PC入门篇连载进程:✅​​[ROC-RK3568-PC]手把手教你把出厂的Android系统烧写为Ubuntu系统​​✅​​​[ROC-RK3568-PC]手把手教你制作Ubuntu系统TF卡启动......
  • [RK356x] [Firefly-Linux] 10min带你了解Linux_SDK
    又是周末了,按照惯例,更新一篇,so这篇便是。之前我带大家讲述如何通过Linux_SDK编译与打包Ubuntu或Buildroot系统固件,现在就反过头来看看Linux_SDK的构造,要注意的是了解一下即......
  • daily study 14
    初识指针;指针是什么?在计算机科学中,指针(Pointer)是编程语言中的一个对象,利用地址,它的值直接指向(pointsto)存在电脑存储器中另一个地方的值。由于通过地址能找到所需......
  • 视频直播美颜sdk趣味功能的实现流程
    当下,随着直播、短视频等视频社交平台的进一步普及,大家已经逐渐无法离开这种新型的社交娱乐方式,其中一大部分原因是因为美颜sdk的加入,无论是强大的美颜功能,还是趣味拍摄方案,......
  • C++ REST SDK
    #include<iostream>#include<future>#include<string>#include<sstream>#include<stdexcept>#include<functional>#include<locale>#include<codecvt>//#......
  • daily study 13
    4.赋值操作符=,+=,-=,*=....复合赋值,一个=为赋值,==为判断支持连续赋值,从右赋到左5.单目操作符!,-,+,&,sizeof,~(对一个数的二进制位按位取反),--,++,*(间接访问操作符)sizeof(a),计算a所占字......
  • cita-sdk react16.9 依赖安装及运行问题经验记录
    运行环境查找选择node稳定版本发布时间,技术框架发布时间一致即可nodev10.18.0reactv16.9.0pythonv2.7.18安装cita-sdk一直报错上面两个错误一直循环报错,但最后......