mirror of
https://github.com/cemu-project/idapython.git
synced 2024-11-24 18:16:55 +01:00
c88a77e809
- added support for 'long' addresses - updated copyright notice in hexrays.i - added methods to remove or insert elements in the qlist<cinsn_t> list - added support for ctree_visitor_t / ctree_parentee_t / cfunc_parentee_t / user_lvar_visitor_t - updated vds3 sample - added vds4 and vds7 python samples (ported from their C++ counter parts)
63 lines
1.5 KiB
Python
63 lines
1.5 KiB
Python
""" It demonstrates how to iterate a cblock_t object.
|
|
|
|
Author: EiNSTeiN_ <einstein@g3nius.org>
|
|
|
|
This is a rewrite in Python of the vds7 example that comes with hexrays sdk.
|
|
"""
|
|
|
|
import idautils
|
|
import idaapi
|
|
import idc
|
|
|
|
import traceback
|
|
|
|
class cblock_visitor_t(idaapi.ctree_visitor_t):
|
|
|
|
def __init__(self):
|
|
idaapi.ctree_visitor_t.__init__(self, idaapi.CV_FAST)
|
|
return
|
|
|
|
def visit_insn(self, ins):
|
|
|
|
try:
|
|
if ins.op == idaapi.cit_block:
|
|
self.dump_block(ins.ea, ins.cblock)
|
|
except:
|
|
traceback.print_exc()
|
|
|
|
return 0
|
|
|
|
def dump_block(self, ea, b):
|
|
# iterate over all block instructions
|
|
print "dumping block %x" % (ea, )
|
|
for ins in b:
|
|
print " %x: insn %s" % (ins.ea, ins.opname)
|
|
|
|
return
|
|
|
|
class hexrays_callback_info(object):
|
|
|
|
def __init__(self):
|
|
return
|
|
|
|
def event_callback(self, event, *args):
|
|
|
|
try:
|
|
if event == idaapi.hxe_maturity:
|
|
cfunc, maturity = args
|
|
|
|
if maturity == idaapi.CMAT_BUILT:
|
|
cbv = cblock_visitor_t()
|
|
cbv.apply_to(cfunc.body, None)
|
|
|
|
except:
|
|
traceback.print_exc()
|
|
|
|
return 0
|
|
|
|
if idaapi.init_hexrays_plugin():
|
|
i = hexrays_callback_info()
|
|
idaapi.install_hexrays_callback(i.event_callback)
|
|
else:
|
|
print 'cblock visitor: hexrays is not available.'
|