diff options
| author | Fabrice Desclaux <fabrice.desclaux@cea.fr> | 2017-12-11 14:26:23 +0100 |
|---|---|---|
| committer | Fabrice Desclaux <fabrice.desclaux@cea.fr> | 2018-06-08 17:35:05 +0200 |
| commit | a2637cdf0b40df074865d23a7fd71f082ad7f40a (patch) | |
| tree | f6c958ca8481e6e29760078e5d1bdc2d2b64da53 /example | |
| parent | dadfaabc3fff5edb9bf4ef7e7e8c4cfc4baccb94 (diff) | |
| download | miasm-a2637cdf0b40df074865d23a7fd71f082ad7f40a.tar.gz miasm-a2637cdf0b40df074865d23a7fd71f082ad7f40a.zip | |
Expr: Add new word ExprLoc
This word represents a location in the binary. Thus, the hack of ExprId containing an AsmLabel ends here.
Diffstat (limited to 'example')
| -rw-r--r-- | example/disasm/callback.py | 10 | ||||
| -rw-r--r-- | example/disasm/full.py | 2 | ||||
| -rw-r--r-- | example/expression/graph_dataflow.py | 8 | ||||
| -rw-r--r-- | example/expression/solve_condition_stp.py | 32 | ||||
| -rw-r--r-- | example/ida/graph_ir.py | 10 |
5 files changed, 30 insertions, 32 deletions
diff --git a/example/disasm/callback.py b/example/disasm/callback.py index a9bef20b..6b7b2b81 100644 --- a/example/disasm/callback.py +++ b/example/disasm/callback.py @@ -1,5 +1,5 @@ from miasm2.core.bin_stream import bin_stream_str -from miasm2.core.asmblock import AsmLabel, AsmConstraint, expr_is_label +from miasm2.core.asmblock import AsmLabel, AsmConstraint from miasm2.arch.x86.disasm import dis_x86_32, cb_x86_funcs @@ -23,10 +23,12 @@ def cb_x86_callpop(cur_bloc, symbol_pool, *args, **kwargs): return ## The destination must be a label dst = last_instr.args[0] - if not expr_is_label(dst): + if not dst.is_label(): return + + label = symbol_pool.loc_key_to_label(dst.loc_key) ## The destination must be the next instruction - if dst.name.offset != last_instr.offset + last_instr.l: + if label.offset != last_instr.offset + last_instr.l: return # Update instruction instance @@ -34,7 +36,7 @@ def cb_x86_callpop(cur_bloc, symbol_pool, *args, **kwargs): # Update next blocks to process in the disassembly engine cur_bloc.bto.clear() - cur_bloc.add_cst(dst.name.offset, AsmConstraint.c_next, symbol_pool) + cur_bloc.add_cst(label.offset, AsmConstraint.c_next, symbol_pool) # Prepare a tiny shellcode diff --git a/example/disasm/full.py b/example/disasm/full.py index 84c856e1..e693a687 100644 --- a/example/disasm/full.py +++ b/example/disasm/full.py @@ -155,7 +155,7 @@ while not finish and todo: # Generate dotty graph -all_blocks = AsmCFG() +all_blocks = AsmCFG(mdis.symbol_pool) for blocks in all_funcs_blocks.values(): all_blocks += blocks diff --git a/example/expression/graph_dataflow.py b/example/expression/graph_dataflow.py index 26fdd2ec..dd7e37a1 100644 --- a/example/expression/graph_dataflow.py +++ b/example/expression/graph_dataflow.py @@ -24,7 +24,7 @@ def node_x_2_id(n, x): def get_node_name(label, i, n): - n_name = (label.name, i, n) + n_name = (label, i, n) return n_name @@ -93,9 +93,11 @@ def gen_block_data_flow_graph(ir_arch, ad, block_flow_cb): dead_simp(ir_arch) + irblock_0 = None for irblock in ir_arch.blocks.values(): - if irblock.label.offset == ad: + label = ir_arch.symbol_pool.loc_key_to_label(irblock.label) + if label.offset == ad: irblock_0 = irblock break assert(irblock_0 is not None) @@ -144,8 +146,6 @@ for block in blocks: ir_arch.add_block(block) for irblock in ir_arch.blocks.values(): print irblock - if irblock.label.offset != 0: - continue if args.symb: diff --git a/example/expression/solve_condition_stp.py b/example/expression/solve_condition_stp.py index 201d9f26..76dff96c 100644 --- a/example/expression/solve_condition_stp.py +++ b/example/expression/solve_condition_stp.py @@ -5,9 +5,8 @@ from pdb import pm from miasm2.analysis.machine import Machine from miasm2.expression.expression import ExprInt, ExprCond, ExprId, \ - get_expr_ids, ExprAff + get_expr_ids, ExprAff, ExprLoc from miasm2.core.bin_stream import bin_stream_str -from miasm2.core import asmblock from miasm2.ir.symbexec import SymbolicExecutionEngine, get_block from miasm2.expression.simplifications import expr_simp from miasm2.core import parse_asm @@ -55,8 +54,8 @@ def emul_symb(ir_arch, mdis, states_todo, states_done): cond_group_b = {addr.cond: ExprInt(1, addr.cond.size)} addr_a = expr_simp(symbexec.eval_expr(addr.replace_expr(cond_group_a), {})) addr_b = expr_simp(symbexec.eval_expr(addr.replace_expr(cond_group_b), {})) - if not (addr_a.is_int() or asmblock.expr_is_label(addr_a) and - addr_b.is_int() or asmblock.expr_is_label(addr_b)): + if not (addr_a.is_int() or addr_a.is_label() and + addr_b.is_int() or addr_b.is_label()): print str(addr_a), str(addr_b) raise ValueError("Unsupported condition") if isinstance(addr_a, ExprInt): @@ -68,11 +67,11 @@ def emul_symb(ir_arch, mdis, states_todo, states_done): elif addr == ret_addr: print 'Return address reached' continue - elif isinstance(addr, ExprInt): + elif addr.is_int(): addr = int(addr.arg) states_todo.add((addr, symbexec.symbols.copy(), tuple(conds))) - elif asmblock.expr_is_label(addr): - addr = addr.name + elif addr.is_label(): + addr = ir_arch.symbol_pool.loc_key_to_label(addr.loc_key) states_todo.add((addr, symbexec.symbols.copy(), tuple(conds))) else: raise ValueError("Unsupported destination") @@ -95,6 +94,7 @@ if __name__ == '__main__': symbexec = SymbolicExecutionEngine(ir_arch, symbols_init) blocks, symbol_pool = parse_asm.parse_txt(machine.mn, 32, ''' + init: PUSH argv PUSH argc PUSH ret_addr @@ -105,22 +105,20 @@ if __name__ == '__main__': argc_lbl = symbol_pool.getby_name('argc') argv_lbl = symbol_pool.getby_name('argv') ret_addr_lbl = symbol_pool.getby_name('ret_addr') + init_lbl = symbol_pool.getby_name('init') - argc = ExprId(argc_lbl, 32) - argv = ExprId(argv_lbl, 32) - ret_addr = ExprId(ret_addr_lbl, 32) + argc = ExprLoc(argc_lbl.loc_key, 32) + argv = ExprLoc(argv_lbl.loc_key, 32) + ret_addr = ExprLoc(ret_addr_lbl.loc_key, 32) - b = list(blocks)[0] - print b + block = list(blocks)[0] + print block # add fake address and len to parsed instructions - for i, line in enumerate(b.lines): - line.offset, line.l = i, 1 - ir_arch.add_block(b) - irb = get_block(ir_arch, mdis, 0) + ir_arch.add_block(block) + irb = ir_arch.blocks[init_lbl.loc_key] symbexec.eval_updt_irblock(irb) symbexec.dump(ids=False) - # reset ir_arch blocks ir_arch.blocks = {} diff --git a/example/ida/graph_ir.py b/example/ida/graph_ir.py index 6dfa1f7d..fad793ff 100644 --- a/example/ida/graph_ir.py +++ b/example/ida/graph_ir.py @@ -6,7 +6,7 @@ import idc import idautils from miasm2.core.bin_stream_ida import bin_stream_ida -from miasm2.core.asmblock import expr_is_label, AsmLabel, is_int +from miasm2.core.asmblock import AsmLabel, is_int from miasm2.expression.simplifications import expr_simp from miasm2.analysis.data_flow import dead_simp from miasm2.ir.ir import AssignBlock, IRBlock @@ -74,13 +74,11 @@ class GraphMiasmIR(idaapi.GraphViewer): continue all_dst = self.ir_arch.dst_trackback(irblock) for dst in all_dst: - if not expr_is_label(dst): + if not dst.is_label(): continue - - dst = dst.name - if not dst in self.ir_arch.blocks: + if not dst.loc_key in self.ir_arch.blocks: continue - dst_block = self.ir_arch.blocks[dst] + dst_block = self.ir_arch.blocks[dst.loc_key] node1 = addr_id[irblock] node2 = addr_id[dst_block] self.AddEdge(node1, node2) |