IDApython 笔记
Last updated on October 7, 2023 pm
IDApython学习笔记
基本指令 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ea = here() asm = idc.GetDisasm(ea) op = idc.print_insn_mnem(ea) operand = idc.print_operand(ea,0 ) _prev_ins = idc.prev_head(ea) _next_ins = idc.next_head(ea) _prev_addr = idc.prev_addr(ea) _next_addr = idc.next_addr(ea) seg_name = idc.get_segm_name(ea) for seg in Segments(): print (seg)for func in Functions(): print (idc.get_func_name(func))
函数 基本指令 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 name = idc.get_func_name(ea) func = ida_funcs.get_func(ea) func = idaapi.get_func(ea) func_start = func.start_ea func_end = func.end_ea func_start = idc.get_func_attr(ea, FUNCATTR_START) func_end = idc.get_func_attr(ea,FUNCATTR_END) idc.get_prev_fchunk(ea) idc.get_prev_func(ea) idc.get_next_fchunk(ea) idc.get_next_func(ea)
交叉引用 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 xrefs = XrefsFrom(ea,0 )for xref in xrefs: xref.frm xref.to xrefx = XrefsTo(ea,0 )for xref in xrefs: xref.frm xref.to xref = CodeRefsFrom(ea,0 ) xref = CodeRefsTo(ea,0 ) ref = ida_xref.get_first_dref_to(addr) nex_ref = ida_xref.ger_next_derf_to(addr,ref) func_addr =idc.get_name_ea_simple(func_name)
一些个交叉引用使用方式 patch掉所有call危险函数的地方
1 2 3 4 5 6 7 8 danger_func = ['gets' ,'free' ]for func in danger_func: func_addr = idc.get_name_ea_simple(func) xrefs = CodeRefsTo(func_addr,0 ) for xref in xrefs: if idc.GetDisasm(xref).startswith('call' ): len = next_head(xref) - xref idaapi.patch_bytes(xref,b'\x90' *len )
处理ea到end之间所有的数据
1 2 3 4 5 for addr in range (ea,end,4 ): xrefs = XrefsTo(ea) for xref in xrefs: if 'mov' in GetDisasm(xref.frm):
Block 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ea = here() func = idaapi.get_func(ea) CFG = idaapi.FlowChart(func) for blocks in CFG: print (blocks.start_ea) print (block.end_ea) print () for succ in blocks.succs(): print (succ.start_ea) print (succ.end_ea) for pred in blocks.preds() print (pred.start_ea) print (pred.end_ea)
获取数据 1 2 3 4 5 6 idc.get_wide_byte(ea) // 获取单字节 idc.get_wide_word(ea) // 获取一个字 idc.get_wide_dword(ea) // 获取双字 idc.get_qword(ea) // 获取四字 idc.GetFloat(ea) idc.GetDouble(ea)
补丁 1 2 3 4 patch_byte(ea, value) patch_word(ea, value) patch_dword(ea, value) patch_qword(ea, value)
IDApython 笔记
http://example.com/2023/06/24/IDApython/