mirror of
https://github.com/cea-sec/miasm
synced 2026-08-17 10:26:03 -04:00
Merge pull request #1185 from nofiv/IDAPython74
Ported IDAPython code to the 7.4 version
This commit is contained in:
commit
030d19ae95
6 changed files with 31 additions and 31 deletions
|
|
@ -27,13 +27,13 @@ class TypePropagationForm(ida_kernwin.Form):
|
|||
default_types_info = r"""ExprId("RDX", 64): char *"""
|
||||
archs = ["AMD64_unk", "X86_32_unk", "msp430_unk"]
|
||||
|
||||
func = ida_funcs.get_func(idc.ScreenEA())
|
||||
func_addr = func.startEA
|
||||
func = ida_funcs.get_func(idc.get_screen_ea())
|
||||
func_addr = func.start_ea
|
||||
|
||||
start_addr = idc.SelStart()
|
||||
start_addr = idc.read_selection_start()
|
||||
if start_addr == idc.BADADDR:
|
||||
start_addr = idc.ScreenEA()
|
||||
end_addr = idc.SelEnd()
|
||||
start_addr = idc.get_screen_ea()
|
||||
end_addr = idc.read_selection_end()
|
||||
|
||||
ida_kernwin.Form.__init__(self,
|
||||
r"""BUTTON YES* Launch
|
||||
|
|
@ -205,7 +205,7 @@ class SymbExecCTypeFix(SymbExecCType):
|
|||
)
|
||||
self.eval_updt_assignblk(assignblk)
|
||||
for offset, value in viewitems(offset2cmt):
|
||||
idc.MakeComm(offset, '\n'.join(value))
|
||||
idc.set_cmt(offset, '\n'.join(value), 0)
|
||||
print("%x\n" % offset, '\n'.join(value))
|
||||
|
||||
return self.eval_expr(self.ir_arch.IRDst)
|
||||
|
|
@ -227,8 +227,8 @@ def get_ira_call_fixer(ira):
|
|||
|
||||
def call_effects(self, ad, instr):
|
||||
print(hex(instr.offset), instr)
|
||||
stk_before = idc.GetSpd(instr.offset)
|
||||
stk_after = idc.GetSpd(instr.offset + instr.l)
|
||||
stk_before = idc.get_spd(instr.offset)
|
||||
stk_after = idc.get_spd(instr.offset + instr.l)
|
||||
stk_diff = stk_after - stk_before
|
||||
print(hex(stk_diff))
|
||||
call_assignblk = AssignBlock(
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class depGraphSettingsForm(ida_kernwin.Form):
|
|||
self.stk_args = {'ARG%d' % i:i for i in range(10)}
|
||||
self.stk_unalias_force = False
|
||||
|
||||
self.address = idc.ScreenEA()
|
||||
self.address = idc.get_screen_ea()
|
||||
cur_block = None
|
||||
for loc_key in ircfg.getby_offset(self.address):
|
||||
block = ircfg.get_block(loc_key)
|
||||
|
|
@ -54,7 +54,7 @@ class depGraphSettingsForm(ida_kernwin.Form):
|
|||
regs += list(self.stk_args)
|
||||
reg_default = regs[0]
|
||||
for i in range(10):
|
||||
opnd = idc.GetOpnd(self.address, i).upper()
|
||||
opnd = idc.print_operand(self.address, i).upper()
|
||||
if opnd in regs:
|
||||
reg_default = opnd
|
||||
break
|
||||
|
|
@ -128,7 +128,7 @@ Method to use:
|
|||
if value in self.stk_args:
|
||||
line = self.ircfg.blocks[self.loc_key][self.line_nb].instr
|
||||
arg_num = self.stk_args[value]
|
||||
stk_high = m2_expr.ExprInt(idc.GetSpd(line.offset), ir_arch.sp.size)
|
||||
stk_high = m2_expr.ExprInt(idc.get_spd(line.offset), ir_arch.sp.size)
|
||||
stk_off = m2_expr.ExprInt(self.ira.sp.size // 8 * arg_num, ir_arch.sp.size)
|
||||
element = m2_expr.ExprMem(self.mn.regs.regs_init[ir_arch.sp] + stk_high + stk_off, self.ira.sp.size)
|
||||
element = expr_simp(element)
|
||||
|
|
@ -161,8 +161,8 @@ def clean_lines():
|
|||
"Remove previous comments"
|
||||
global comments
|
||||
for offset in comments:
|
||||
idc.SetColor(offset, idc.CIC_ITEM, 0xffffff)
|
||||
idc.MakeComm(offset, "")
|
||||
idc.set_color(offset, idc.CIC_ITEM, 0xffffff)
|
||||
idc.set_cmt(offset, "", 0)
|
||||
comments = {}
|
||||
|
||||
def treat_element():
|
||||
|
|
@ -189,7 +189,7 @@ def treat_element():
|
|||
print("Unable to highlight %s" % node)
|
||||
continue
|
||||
comments[offset] = comments.get(offset, []) + [node.element]
|
||||
idc.SetColor(offset, idc.CIC_ITEM, settings.color)
|
||||
idc.set_color(offset, idc.CIC_ITEM, settings.color)
|
||||
|
||||
if graph.has_loop:
|
||||
print('Graph has dependency loop: symbolic execution is inexact')
|
||||
|
|
@ -197,7 +197,7 @@ def treat_element():
|
|||
print("Possible value: %s" % next(iter(viewvalues(graph.emul(ir_arch)))))
|
||||
|
||||
for offset, elements in viewitems(comments):
|
||||
idc.MakeComm(offset, ", ".join(map(str, elements)))
|
||||
idc.set_cmt(offset, ", ".join(map(str, elements)), 0)
|
||||
|
||||
def next_element():
|
||||
"Display the next element"
|
||||
|
|
@ -208,11 +208,11 @@ def next_element():
|
|||
def launch_depgraph():
|
||||
global graphs, comments, sol_nb, settings, addr, ir_arch, ircfg
|
||||
# Get the current function
|
||||
addr = idc.ScreenEA()
|
||||
addr = idc.get_screen_ea()
|
||||
func = ida_funcs.get_func(addr)
|
||||
|
||||
# Init
|
||||
machine = guess_machine(addr=func.startEA)
|
||||
machine = guess_machine(addr=func.start_ea)
|
||||
mn, dis_engine, ira = machine.mn, machine.dis_engine, machine.ira
|
||||
|
||||
bs = bin_stream_ida()
|
||||
|
|
@ -225,7 +225,7 @@ def launch_depgraph():
|
|||
continue
|
||||
mdis.loc_db.add_location(name, ad)
|
||||
|
||||
asmcfg = mdis.dis_multiblock(func.startEA)
|
||||
asmcfg = mdis.dis_multiblock(func.start_ea)
|
||||
|
||||
# Generate IR
|
||||
ircfg = ir_arch.new_ircfg_from_asmcfg(asmcfg)
|
||||
|
|
@ -242,7 +242,7 @@ def launch_depgraph():
|
|||
fix_stack = offset is not None and settings.unalias_stack
|
||||
for assignblk in irb:
|
||||
if fix_stack:
|
||||
stk_high = m2_expr.ExprInt(idc.GetSpd(assignblk.instr.offset), ir_arch.sp.size)
|
||||
stk_high = m2_expr.ExprInt(idc.get_spd(assignblk.instr.offset), ir_arch.sp.size)
|
||||
fix_dct = {ir_arch.sp: mn.regs.regs_init[ir_arch.sp] + stk_high}
|
||||
|
||||
new_assignblk = {}
|
||||
|
|
@ -259,7 +259,7 @@ def launch_depgraph():
|
|||
# Get dependency graphs
|
||||
dg = settings.depgraph
|
||||
graphs = dg.get(loc_key, elements, line_nb,
|
||||
set([ir_arch.loc_db.get_offset_location(func.startEA)]))
|
||||
set([ir_arch.loc_db.get_offset_location(func.start_ea)]))
|
||||
|
||||
# Display the result
|
||||
comments = {}
|
||||
|
|
|
|||
|
|
@ -196,7 +196,7 @@ def build_graph(start_addr, type_graph, simplify=False, dontmodstack=True, loadi
|
|||
if verbose:
|
||||
print("Arch", dis_engine)
|
||||
|
||||
fname = idc.GetInputFile()
|
||||
fname = idc.get_root_filename()
|
||||
if verbose:
|
||||
print(fname)
|
||||
|
||||
|
|
@ -330,8 +330,8 @@ def function_graph_ir():
|
|||
if not ret:
|
||||
return
|
||||
|
||||
func = ida_funcs.get_func(idc.ScreenEA())
|
||||
func_addr = func.startEA
|
||||
func = ida_funcs.get_func(idc.get_screen_ea())
|
||||
func_addr = func.start_ea
|
||||
|
||||
build_graph(
|
||||
func_addr,
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ def get_focused_view():
|
|||
|
||||
|
||||
class Hooks(idaapi.UI_Hooks):
|
||||
def finish_populating_tform_popup(self, form, popup):
|
||||
def finish_populating_widget_popup(self, form, popup):
|
||||
idaapi.attach_action_to_popup(form, popup, 'my:expand', None)
|
||||
idaapi.attach_action_to_popup(form, popup, 'my:translate', None)
|
||||
|
||||
|
|
@ -135,7 +135,7 @@ def symbolic_exec():
|
|||
|
||||
from utils import guess_machine
|
||||
|
||||
start, end = idc.SelStart(), idc.SelEnd()
|
||||
start, end = idc.read_selection_start(), idc.read_selection_end()
|
||||
|
||||
bs = bin_stream_ida()
|
||||
machine = guess_machine(addr=start)
|
||||
|
|
@ -143,7 +143,7 @@ def symbolic_exec():
|
|||
mdis = machine.dis_engine(bs)
|
||||
|
||||
if start == idc.BADADDR and end == idc.BADADDR:
|
||||
start = idc.ScreenEA()
|
||||
start = idc.get_screen_ea()
|
||||
end = idc.next_head(start) # Get next instruction address
|
||||
|
||||
mdis.dont_dis = [end]
|
||||
|
|
@ -197,7 +197,7 @@ idaapi.register_action(action_translate)
|
|||
|
||||
if __name__ == '__main__':
|
||||
idaapi.CompileLine('static key_F3() { RunPythonStatement("symbolic_exec()"); }')
|
||||
idc.AddHotkey("F3", "key_F3")
|
||||
idc.add_idc_hotkey("F3", "key_F3")
|
||||
|
||||
print("=" * 50)
|
||||
print("""Available commands:
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import miasm.expression.expression as m2_expr
|
|||
def guess_machine(addr=None):
|
||||
"Return an instance of Machine corresponding to the IDA guessed processor"
|
||||
|
||||
processor_name = GetLongPrm(INF_PROCNAME)
|
||||
processor_name = get_inf_attr(INF_PROCNAME)
|
||||
info = idaapi.get_inf_structure()
|
||||
|
||||
if info.is_64bit():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue