diff options
| author | Fabrice Desclaux <fabrice.desclaux@cea.fr> | 2018-05-18 14:43:57 +0200 |
|---|---|---|
| committer | Fabrice Desclaux <fabrice.desclaux@cea.fr> | 2018-06-09 00:33:48 +0200 |
| commit | 61551fa78e9dd22ed1f982b4fe171fd6383c39a6 (patch) | |
| tree | b10543391f9a66ddd5e3f6852c30d96b169b623d /example/expression | |
| parent | a2637cdf0b40df074865d23a7fd71f082ad7f40a (diff) | |
| download | miasm-61551fa78e9dd22ed1f982b4fe171fd6383c39a6.tar.gz miasm-61551fa78e9dd22ed1f982b4fe171fd6383c39a6.zip | |
Core: replace AsmLabel by LocKey
Diffstat (limited to 'example/expression')
| -rw-r--r-- | example/expression/access_c.py | 6 | ||||
| -rw-r--r-- | example/expression/asm_to_ir.py | 8 | ||||
| -rw-r--r-- | example/expression/constant_propagation.py | 4 | ||||
| -rw-r--r-- | example/expression/graph_dataflow.py | 20 | ||||
| -rw-r--r-- | example/expression/solve_condition_stp.py | 19 |
5 files changed, 28 insertions, 29 deletions
diff --git a/example/expression/access_c.py b/example/expression/access_c.py index de158730..8856f6f8 100644 --- a/example/expression/access_c.py +++ b/example/expression/access_c.py @@ -100,7 +100,7 @@ def get_funcs_arg0(ctx, ira, lbl_head): for irb, index in find_call(ira): instr = irb[index].instr print 'Analysing references from:', hex(instr.offset), instr - g_list = g_dep.get(irb.label, set([element]), index, set([lbl_head])) + g_list = g_dep.get(irb.loc_key, set([element]), index, set([lbl_head])) for dep in g_list: emul_result = dep.emul(ctx) value = emul_result[element] @@ -143,11 +143,11 @@ dis_engine, ira = machine.dis_engine, machine.ira mdis = dis_engine(cont.bin_stream, symbol_pool=cont.symbol_pool) addr_head = 0 -blocks = mdis.dis_multiblock(addr_head) +asmcfg = mdis.dis_multiblock(addr_head) lbl_head = mdis.symbol_pool.getby_offset(addr_head) ir_arch_a = ira(mdis.symbol_pool) -for block in blocks: +for block in asmcfg.blocks: ir_arch_a.add_block(block) open('graph_irflow.dot', 'w').write(ir_arch_a.graph.dot()) diff --git a/example/expression/asm_to_ir.py b/example/expression/asm_to_ir.py index 786b860e..36965bfa 100644 --- a/example/expression/asm_to_ir.py +++ b/example/expression/asm_to_ir.py @@ -8,7 +8,7 @@ from miasm2.arch.x86.ira import ir_a_x86_32 from miasm2.analysis.data_flow import dead_simp # First, asm code -blocks, symbol_pool = parse_asm.parse_txt(mn_x86, 32, ''' +asmcfg, symbol_pool = parse_asm.parse_txt(mn_x86, 32, ''' main: MOV EAX, 1 MOV EBX, 2 @@ -25,17 +25,17 @@ loop: symbol_pool.set_offset(symbol_pool.getby_name("main"), 0x0) -for block in blocks: +for block in asmcfg.blocks: print block print "symbols:" print symbol_pool -patches = asmblock.asm_resolve_final(mn_x86, blocks, symbol_pool) +patches = asmblock.asm_resolve_final(mn_x86, asmcfg, symbol_pool) # Translate to IR ir_arch = ir_a_x86_32(symbol_pool) -for block in blocks: +for block in asmcfg.blocks: print 'add block' print block ir_arch.add_block(block) diff --git a/example/expression/constant_propagation.py b/example/expression/constant_propagation.py index 70394580..3a81d909 100644 --- a/example/expression/constant_propagation.py +++ b/example/expression/constant_propagation.py @@ -32,8 +32,8 @@ ir_arch = ira(mdis.symbol_pool) addr = int(args.address, 0) -blocks = mdis.dis_multiblock(addr) -for block in blocks: +asmcfg = mdis.dis_multiblock(addr) +for block in asmcfg.blocks: ir_arch.add_block(block) diff --git a/example/expression/graph_dataflow.py b/example/expression/graph_dataflow.py index dd7e37a1..9b45a52d 100644 --- a/example/expression/graph_dataflow.py +++ b/example/expression/graph_dataflow.py @@ -47,7 +47,7 @@ def intra_block_flow_symb(ir_arch, flow_graph, irblock, in_nodes, out_nodes): all_mems.update(get_expr_mem(n)) for n in all_mems: - node_n_w = get_node_name(irblock.label, 0, n) + node_n_w = get_node_name(irblock.loc_key, 0, n) if not n == src: continue o_r = n.arg.get_r(mem_read=False, cst_read=True) @@ -55,7 +55,7 @@ def intra_block_flow_symb(ir_arch, flow_graph, irblock, in_nodes, out_nodes): if n_r in current_nodes: node_n_r = current_nodes[n_r] else: - node_n_r = get_node_name(irblock.label, i, n_r) + node_n_r = get_node_name(irblock.loc_key, i, n_r) if not n_r in in_nodes: in_nodes[n_r] = node_n_r flow_graph.add_uniq_edge(node_n_r, node_n_w) @@ -69,13 +69,13 @@ def intra_block_flow_symb(ir_arch, flow_graph, irblock, in_nodes, out_nodes): if n_r in current_nodes: node_n_r = current_nodes[n_r] else: - node_n_r = get_node_name(irblock.label, 0, n_r) + node_n_r = get_node_name(irblock.loc_key, 0, n_r) if not n_r in in_nodes: in_nodes[n_r] = node_n_r flow_graph.add_node(node_n_r) for n_w in nodes_w: - node_n_w = get_node_name(irblock.label, 1, n_w) + node_n_w = get_node_name(irblock.loc_key, 1, n_w) out_nodes[n_w] = node_n_w flow_graph.add_node(node_n_w) @@ -96,8 +96,9 @@ def gen_block_data_flow_graph(ir_arch, ad, block_flow_cb): irblock_0 = None for irblock in ir_arch.blocks.values(): - label = ir_arch.symbol_pool.loc_key_to_label(irblock.label) - if label.offset == ad: + loc_key = irblock.loc_key + offset = ir_arch.symbol_pool.loc_key_to_offset(loc_key) + if offset == ad: irblock_0 = irblock break assert(irblock_0 is not None) @@ -120,7 +121,7 @@ def gen_block_data_flow_graph(ir_arch, ad, block_flow_cb): print 'OUT', [str(x) for x in irb_out_nodes[label]] print '*' * 20, 'interblock', '*' * 20 - inter_block_flow(ir_arch, flow_graph, irblock_0.label, irb_in_nodes, irb_out_nodes) + inter_block_flow(ir_arch, flow_graph, irblock_0.loc_key, irb_in_nodes, irb_out_nodes) # from graph_qt import graph_qt # graph_qt(flow_graph) @@ -133,15 +134,14 @@ ad = int(args.addr, 16) print 'disasm...' mdis = dis_x86_32(data) mdis.follow_call = True -ab = mdis.dis_multiblock(ad) +asmcfg = mdis.dis_multiblock(ad) print 'ok' print 'generating dataflow graph for:' ir_arch = ir_a_x86_32(mdis.symbol_pool) -blocks = ab -for block in blocks: +for block in asmcfg.blocks: print block ir_arch.add_block(block) for irblock in ir_arch.blocks.values(): diff --git a/example/expression/solve_condition_stp.py b/example/expression/solve_condition_stp.py index 76dff96c..42e6670c 100644 --- a/example/expression/solve_condition_stp.py +++ b/example/expression/solve_condition_stp.py @@ -54,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 addr_a.is_label() and - addr_b.is_int() or addr_b.is_label()): + if not (addr_a.is_int() or addr_a.is_loc() and + addr_b.is_int() or addr_b.is_loc()): print str(addr_a), str(addr_b) raise ValueError("Unsupported condition") if isinstance(addr_a, ExprInt): @@ -70,8 +70,7 @@ def emul_symb(ir_arch, mdis, states_todo, states_done): elif addr.is_int(): addr = int(addr.arg) states_todo.add((addr, symbexec.symbols.copy(), tuple(conds))) - elif addr.is_label(): - addr = ir_arch.symbol_pool.loc_key_to_label(addr.loc_key) + elif addr.is_loc(): states_todo.add((addr, symbexec.symbols.copy(), tuple(conds))) else: raise ValueError("Unsupported destination") @@ -93,7 +92,7 @@ if __name__ == '__main__': symbexec = SymbolicExecutionEngine(ir_arch, symbols_init) - blocks, symbol_pool = parse_asm.parse_txt(machine.mn, 32, ''' + asmcfg, symbol_pool = parse_asm.parse_txt(machine.mn, 32, ''' init: PUSH argv PUSH argc @@ -107,16 +106,16 @@ if __name__ == '__main__': ret_addr_lbl = symbol_pool.getby_name('ret_addr') init_lbl = symbol_pool.getby_name('init') - argc = ExprLoc(argc_lbl.loc_key, 32) - argv = ExprLoc(argv_lbl.loc_key, 32) - ret_addr = ExprLoc(ret_addr_lbl.loc_key, 32) + argc = ExprLoc(argc_lbl, 32) + argv = ExprLoc(argv_lbl, 32) + ret_addr = ExprLoc(ret_addr_lbl, 32) - block = list(blocks)[0] + block = asmcfg.loc_key_to_block(init_lbl) print block # add fake address and len to parsed instructions ir_arch.add_block(block) - irb = ir_arch.blocks[init_lbl.loc_key] + irb = ir_arch.blocks[init_lbl] symbexec.eval_updt_irblock(irb) symbexec.dump(ids=False) # reset ir_arch blocks |