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/expression | |
| 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/expression')
| -rw-r--r-- | example/expression/graph_dataflow.py | 8 | ||||
| -rw-r--r-- | example/expression/solve_condition_stp.py | 32 |
2 files changed, 19 insertions, 21 deletions
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 = {} |