mirror of
https://github.com/cea-sec/miasm
synced 2026-08-17 10:26:03 -04:00
Fix ida examples
This commit is contained in:
parent
b8af43b264
commit
eba583bfb8
4 changed files with 30 additions and 20 deletions
|
|
@ -17,6 +17,7 @@ from miasm.expression.expression import ExprLoc, ExprInt, ExprOp, ExprAssign
|
|||
from miasm.ir.symbexec_types import SymbExecCType
|
||||
from miasm.expression.parser import str_to_expr
|
||||
from miasm.analysis.cst_propag import add_state, propagate_cst_expr
|
||||
from miasm.core.locationdb import LocationDB
|
||||
|
||||
from utils import guess_machine
|
||||
|
||||
|
|
@ -264,13 +265,15 @@ def analyse_function():
|
|||
mn, dis_engine, ira = machine.mn, machine.dis_engine, machine.ira
|
||||
|
||||
bs = bin_stream_ida()
|
||||
mdis = dis_engine(bs, dont_dis_nulstart_bloc=True)
|
||||
loc_db = LocationDB()
|
||||
|
||||
mdis = dis_engine(bs, loc_db=loc_db, dont_dis_nulstart_bloc=True)
|
||||
if end is not None:
|
||||
mdis.dont_dis = [end]
|
||||
|
||||
|
||||
iraCallStackFixer = get_ira_call_fixer(ira)
|
||||
ir_arch = iraCallStackFixer(mdis.loc_db)
|
||||
ir_arch = iraCallStackFixer(loc_db)
|
||||
|
||||
asmcfg = mdis.dis_multiblock(addr)
|
||||
# Generate IR
|
||||
|
|
@ -308,8 +311,8 @@ def analyse_function():
|
|||
infos_types[expr] = set([objc])
|
||||
|
||||
# Add fake head
|
||||
lbl_real_start = ir_arch.loc_db.get_offset_location(addr)
|
||||
lbl_head = ir_arch.loc_db.get_or_create_name_location("start")
|
||||
lbl_real_start = loc_db.get_offset_location(addr)
|
||||
lbl_head = loc_db.get_or_create_name_location("start")
|
||||
|
||||
first_block = asmcfg.label2block(lbl_real_start)
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import ida_kernwin
|
|||
from miasm.core.bin_stream_ida import bin_stream_ida
|
||||
from miasm.core.asmblock import *
|
||||
from miasm.expression import expression as m2_expr
|
||||
from miasm.core.locationdb import LocationDB
|
||||
|
||||
from miasm.expression.simplifications import expr_simp
|
||||
from miasm.analysis.depgraph import DependencyGraph
|
||||
|
|
@ -216,14 +217,16 @@ def launch_depgraph():
|
|||
mn, dis_engine, ira = machine.mn, machine.dis_engine, machine.ira
|
||||
|
||||
bs = bin_stream_ida()
|
||||
mdis = dis_engine(bs, dont_dis_nulstart_bloc=True)
|
||||
ir_arch = ira(mdis.loc_db)
|
||||
loc_db = LocationDB()
|
||||
|
||||
mdis = dis_engine(bs, loc_db=loc_db, dont_dis_nulstart_bloc=True)
|
||||
ir_arch = ira(loc_db)
|
||||
|
||||
# Populate symbols with ida names
|
||||
for ad, name in idautils.Names():
|
||||
if name is None:
|
||||
continue
|
||||
mdis.loc_db.add_location(name, ad)
|
||||
loc_db.add_location(name, ad)
|
||||
|
||||
asmcfg = mdis.dis_multiblock(func.start_ea)
|
||||
|
||||
|
|
@ -238,7 +241,7 @@ def launch_depgraph():
|
|||
# Simplify assignments
|
||||
for irb in list(viewvalues(ircfg.blocks)):
|
||||
irs = []
|
||||
offset = ir_arch.loc_db.get_location_offset(irb.loc_key)
|
||||
offset = loc_db.get_location_offset(irb.loc_key)
|
||||
fix_stack = offset is not None and settings.unalias_stack
|
||||
for assignblk in irb:
|
||||
if fix_stack:
|
||||
|
|
@ -259,7 +262,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.start_ea)]))
|
||||
set([loc_db.get_offset_location(func.start_ea)]))
|
||||
|
||||
# Display the result
|
||||
comments = {}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ from miasm.ir.ir import IRBlock, AssignBlock
|
|||
from miasm.analysis.data_flow import load_from_int
|
||||
from utils import guess_machine, expr2colorstr
|
||||
from miasm.analysis.simplifier import IRCFGSimplifierCommon, IRCFGSimplifierSSA
|
||||
|
||||
from miasm.core.locationdb import LocationDB
|
||||
|
||||
|
||||
|
||||
|
|
@ -200,19 +200,21 @@ def build_graph(start_addr, type_graph, simplify=False, dontmodstack=True, loadi
|
|||
print(fname)
|
||||
|
||||
bs = bin_stream_ida()
|
||||
mdis = dis_engine(bs)
|
||||
ir_arch = IRADelModCallStack(mdis.loc_db)
|
||||
loc_db = LocationDB()
|
||||
|
||||
mdis = dis_engine(bs, loc_db=loc_db)
|
||||
ir_arch = IRADelModCallStack(loc_db)
|
||||
|
||||
|
||||
# populate symbols with ida names
|
||||
for addr, name in idautils.Names():
|
||||
if name is None:
|
||||
continue
|
||||
if (mdis.loc_db.get_offset_location(addr) or
|
||||
mdis.loc_db.get_name_location(name)):
|
||||
if (loc_db.get_offset_location(addr) or
|
||||
loc_db.get_name_location(name)):
|
||||
# Symbol alias
|
||||
continue
|
||||
mdis.loc_db.add_location(name, addr)
|
||||
loc_db.add_location(name, addr)
|
||||
|
||||
if verbose:
|
||||
print("start disasm")
|
||||
|
|
@ -220,7 +222,7 @@ def build_graph(start_addr, type_graph, simplify=False, dontmodstack=True, loadi
|
|||
print(hex(start_addr))
|
||||
|
||||
asmcfg = mdis.dis_multiblock(start_addr)
|
||||
entry_points = set([mdis.loc_db.get_offset_location(start_addr)])
|
||||
entry_points = set([loc_db.get_offset_location(start_addr)])
|
||||
if verbose:
|
||||
print("generating graph")
|
||||
open('asm_flow.dot', 'w').write(asmcfg.dot())
|
||||
|
|
@ -239,7 +241,7 @@ def build_graph(start_addr, type_graph, simplify=False, dontmodstack=True, loadi
|
|||
for dst, src in viewitems(assignblk)
|
||||
}
|
||||
irs.append(AssignBlock(new_assignblk, instr=assignblk.instr))
|
||||
ircfg.blocks[irb.loc_key] = IRBlock(irb.loc_db, irb.loc_key, irs)
|
||||
ircfg.blocks[irb.loc_key] = IRBlock(loc_db, irb.loc_key, irs)
|
||||
|
||||
if verbose:
|
||||
out = ircfg.dot()
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import idc
|
|||
|
||||
from miasm.expression.expression_helper import Variables_Identifier
|
||||
from miasm.expression.expression import ExprAssign
|
||||
from miasm.core.locationdb import LocationDB
|
||||
|
||||
from utils import expr2colorstr, translatorForm
|
||||
|
||||
|
|
@ -136,11 +137,12 @@ def symbolic_exec():
|
|||
from utils import guess_machine
|
||||
|
||||
start, end = idc.read_selection_start(), idc.read_selection_end()
|
||||
loc_db = LocationDB()
|
||||
|
||||
bs = bin_stream_ida()
|
||||
machine = guess_machine(addr=start)
|
||||
|
||||
mdis = machine.dis_engine(bs)
|
||||
mdis = machine.dis_engine(bs, loc_db=loc_db)
|
||||
|
||||
if start == idc.BADADDR and end == idc.BADADDR:
|
||||
start = idc.get_screen_ea()
|
||||
|
|
@ -148,7 +150,7 @@ def symbolic_exec():
|
|||
|
||||
mdis.dont_dis = [end]
|
||||
asmcfg = mdis.dis_multiblock(start)
|
||||
ira = machine.ira(loc_db=mdis.loc_db)
|
||||
ira = machine.ira(loc_db=loc_db)
|
||||
ircfg = ira.new_ircfg_from_asmcfg(asmcfg)
|
||||
|
||||
print("Run symbolic execution...")
|
||||
|
|
@ -161,7 +163,7 @@ def symbolic_exec():
|
|||
|
||||
view = symbolicexec_t()
|
||||
all_views.append(view)
|
||||
if not view.Create(modified, machine, mdis.loc_db,
|
||||
if not view.Create(modified, machine, loc_db,
|
||||
"Symbolic Execution - 0x%x to 0x%x"
|
||||
% (start, idc.prev_head(end))):
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue