diff options
Diffstat (limited to 'example')
| -rwxr-xr-x | example/asm/shellcode.py | 12 | ||||
| -rw-r--r-- | example/asm/simple.py | 10 | ||||
| -rw-r--r-- | example/disasm/full.py | 36 | ||||
| -rw-r--r-- | example/expression/asm_to_ir.py | 16 | ||||
| -rw-r--r-- | example/expression/graph_dataflow.py | 26 | ||||
| -rw-r--r-- | example/expression/solve_condition_stp.py | 22 | ||||
| -rw-r--r-- | example/ida/depgraph.py | 10 | ||||
| -rw-r--r-- | example/ida/graph_ir.py | 6 | ||||
| -rw-r--r-- | example/ida/symbol_exec.py | 6 |
9 files changed, 72 insertions, 72 deletions
diff --git a/example/asm/shellcode.py b/example/asm/shellcode.py index 3ff11489..20fa02d8 100755 --- a/example/asm/shellcode.py +++ b/example/asm/shellcode.py @@ -64,7 +64,7 @@ else: with open(args.source) as fstream: source = fstream.read() -blocs, symbol_pool = parse_asm.parse_txt(machine.mn, attrib, source) +blocks, symbol_pool = parse_asm.parse_txt(machine.mn, attrib, source) # Fix shellcode addrs symbol_pool.set_offset(symbol_pool.getby_name("main"), addr_main) @@ -73,14 +73,14 @@ if args.PE: symbol_pool.set_offset(symbol_pool.getby_name_create("MessageBoxA"), pe.DirImport.get_funcvirt('USER32.dll', 'MessageBoxA')) -# Print and graph firsts blocs before patching it -for bloc in blocs: - print bloc -open("graph.dot", "w").write(blocs.dot()) +# Print and graph firsts blocks before patching it +for block in blocks: + print block +open("graph.dot", "w").write(blocks.dot()) # Apply patches patches = asmbloc.asm_resolve_final(machine.mn, - blocs, + blocks, symbol_pool, dst_interval) if args.encrypt: diff --git a/example/asm/simple.py b/example/asm/simple.py index d7623908..7ab403f4 100644 --- a/example/asm/simple.py +++ b/example/asm/simple.py @@ -6,7 +6,7 @@ from miasm2.core import parse_asm, asmbloc # Assemble code -blocs, symbol_pool = parse_asm.parse_txt(mn_x86, 32, ''' +blocks, symbol_pool = parse_asm.parse_txt(mn_x86, 32, ''' main: MOV EAX, 1 MOV EBX, 2 @@ -25,11 +25,11 @@ loop: symbol_pool.set_offset(symbol_pool.getby_name("main"), 0x0) # Spread information and resolve instructions offset -patches = asmbloc.asm_resolve_final(mn_x86, blocs, symbol_pool) +patches = asmbloc.asm_resolve_final(mn_x86, blocks, symbol_pool) -# Show resolved blocs -for bloc in blocs: - print bloc +# Show resolved blocks +for block in blocks: + print block # Print offset -> bytes pprint(patches) diff --git a/example/disasm/full.py b/example/disasm/full.py index 6bea91cd..5fc9008a 100644 --- a/example/disasm/full.py +++ b/example/disasm/full.py @@ -108,7 +108,7 @@ for ad in addrs: done = set() all_funcs = set() -all_funcs_blocs = {} +all_funcs_blocks = {} done_interval = interval() @@ -121,27 +121,27 @@ while not finish and todo: if ad in done: continue done.add(ad) - ab = mdis.dis_multibloc(ad) + allblocks = mdis.dis_multibloc(ad) log.info('func ok %.16x (%d)' % (ad, len(all_funcs))) all_funcs.add(ad) - all_funcs_blocs[ad] = ab - for b in ab: - for l in b.lines: + all_funcs_blocks[ad] = allblocks + for block in allblocks: + for l in block.lines: done_interval += interval([(l.offset, l.offset + l.l)]) if args.funcswatchdog is not None: args.funcswatchdog -= 1 if args.recurfunctions: - for b in ab: - i = b.get_subcall_instr() - if not i: + for block in allblocks: + instr = block.get_subcall_instr() + if not isntr: continue - for d in i.getdstflow(mdis.symbol_pool): - if not (isinstance(d, ExprId) and isinstance(d.name, asm_label)): + for dest in instr.getdstflow(mdis.symbol_pool): + if not (isinstance(dest, ExprId) and isinstance(dest.name, asm_label)): continue - todo.append((mdis, i, d.name.offset)) + todo.append((mdis, instr, dest.name.offset)) if args.funcswatchdog is not None and args.funcswatchdog <= 0: finish = True @@ -155,13 +155,13 @@ while not finish and todo: # Generate dotty graph -all_blocs = AsmCFG() -for blocs in all_funcs_blocs.values(): - all_blocs += blocs +all_blocks = AsmCFG() +for blocks in all_funcs_blocks.values(): + all_blocks += blocks log.info('generate graph file') -open('graph_execflow.dot', 'w').write(all_blocs.dot(offset=True)) +open('graph_execflow.dot', 'w').write(all_blocks.dot(offset=True)) log.info('generate intervals') @@ -192,9 +192,9 @@ if args.gen_ir: ir_arch_a.blocks = {} for ad, all_block in all_funcs_blocks.items(): log.info("generating IR... %x" % ad) - for b in all_bloc: - ir_arch_a.add_bloc(b) - ir_arch.add_bloc(b) + for block in all_block: + ir_arch_a.add_bloc(block) + ir_arch.add_bloc(block) log.info("Print blocks (without analyse)") for label, block in ir_arch.blocks.iteritems(): diff --git a/example/expression/asm_to_ir.py b/example/expression/asm_to_ir.py index 552ddd36..4193f31d 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 # First, asm code -blocs, symbol_pool = parse_asm.parse_txt(mn_x86, 32, ''' +blocks, symbol_pool = parse_asm.parse_txt(mn_x86, 32, ''' main: MOV EAX, 1 MOV EBX, 2 @@ -25,20 +25,20 @@ loop: symbol_pool.set_offset(symbol_pool.getby_name("main"), 0x0) -for b in blocs: - print b +for block in blocks: + print block print "symbols:" print symbol_pool -patches = asmbloc.asm_resolve_final(mn_x86, blocs, symbol_pool) +patches = asmbloc.asm_resolve_final(mn_x86, blocks, symbol_pool) # Translate to IR ir_arch = ir_a_x86_32(symbol_pool) -for b in blocs: - print 'add bloc' - print b - ir_arch.add_bloc(b) +for block in blocks: + print 'add block' + print block + ir_arch.add_bloc(block) # Display IR for lbl, irblock in ir_arch.blocks.items(): diff --git a/example/expression/graph_dataflow.py b/example/expression/graph_dataflow.py index 0b01956f..bd767165 100644 --- a/example/expression/graph_dataflow.py +++ b/example/expression/graph_dataflow.py @@ -49,12 +49,12 @@ def get_modified_symbols(sb): return out -def intra_bloc_flow_symb(ir_arch, flow_graph, irbloc): +def intra_bloc_flow_symb(ir_arch, flow_graph, irblock): symbols_init = ir_arch.arch.regs.regs_init.copy() sb = SymbolicExecutionEngine(ir_arch, symbols_init) - sb.emulbloc(irbloc) + sb.emulbloc(irblock) print '*' * 40 - print irbloc + print irblock in_nodes = {} out_nodes = {} @@ -68,7 +68,7 @@ def intra_bloc_flow_symb(ir_arch, flow_graph, irbloc): all_mems.update(get_expr_mem(n)) for n in all_mems: - node_n_w = get_node_name(irbloc.label, 0, n) + node_n_w = get_node_name(irblock.label, 0, n) if not n == src: continue o_r = n.arg.get_r(mem_read=False, cst_read=True) @@ -76,7 +76,7 @@ def intra_bloc_flow_symb(ir_arch, flow_graph, irbloc): if n_r in current_nodes: node_n_r = current_nodes[n_r] else: - node_n_r = get_node_name(irbloc.label, i, n_r) + node_n_r = get_node_name(irblock.label, 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) @@ -89,20 +89,20 @@ def intra_bloc_flow_symb(ir_arch, flow_graph, irbloc): if n_r in current_nodes: node_n_r = current_nodes[n_r] else: - node_n_r = get_node_name(irbloc.label, 0, n_r) + node_n_r = get_node_name(irblock.label, 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(irbloc.label, 1, n_w) + node_n_w = get_node_name(irblock.label, 1, n_w) out_nodes[n_w] = node_n_w flow_graph.add_node(node_n_w) flow_graph.add_uniq_edge(node_n_r, node_n_w) - irbloc.in_nodes = in_nodes - irbloc.out_nodes = out_nodes + irblock.in_nodes = in_nodes + irblock.out_nodes = out_nodes def node2str(self, node): @@ -121,7 +121,7 @@ def gen_block_data_flow_graph(ir_arch, ad, block_flow_cb): if irblock.label.offset == ad: irblock_0 = irblock break - assert(irbloc_0 is not None) + assert(irblock_0 is not None) flow_graph = DiGraph() flow_graph.node2str = lambda n: node2str(flow_graph, n) @@ -133,8 +133,8 @@ def gen_block_data_flow_graph(ir_arch, ad, block_flow_cb): print 'IN', [str(x) for x in irblock.in_nodes] print 'OUT', [str(x) for x in irblock.out_nodes] - print '*' * 20, 'interbloc', '*' * 20 - inter_bloc_flow(ir_arch, flow_graph, irbloc_0.label) + print '*' * 20, 'interblock', '*' * 20 + inter_bloc_flow(ir_arch, flow_graph, irblock_0.label) # from graph_qt import graph_qt # graph_qt(flow_graph) @@ -169,7 +169,7 @@ if args.symb: else: block_flow_cb = intra_bloc_flow_raw -gen_bloc_data_flow_graph(ir_arch, ad, block_flow_cb) +gen_block_data_flow_graph(ir_arch, ad, block_flow_cb) print '*' * 40 print """ diff --git a/example/expression/solve_condition_stp.py b/example/expression/solve_condition_stp.py index 1f0f2967..5d3ebc59 100644 --- a/example/expression/solve_condition_stp.py +++ b/example/expression/solve_condition_stp.py @@ -35,7 +35,7 @@ if not args: sys.exit(0) -def get_bloc(ir_arch, mdis, ad): +def get_block(ir_arch, mdis, ad): if isinstance(ad, asmbloc.asm_label): l = ad else: @@ -46,7 +46,7 @@ def get_bloc(ir_arch, mdis, ad): ir_arch.add_bloc(b) b = ir_arch.get_bloc(l) if b is None: - raise LookupError('no bloc found at that address: %s' % l) + raise LookupError('no block found at that address: %s' % l) return b @@ -62,11 +62,11 @@ def emul_symb(ir_arch, mdis, states_todo, states_done): sb.symbols = symbols.copy() if ir_arch.pc in sb.symbols: del(sb.symbols[ir_arch.pc]) - b = get_bloc(ir_arch, mdis, ad) + b = get_block(ir_arch, mdis, ad) - print 'run bloc' + print 'run block' print b - # print blocs[ad] + # print blocks[ad] ad = sb.emulbloc(b) print 'final state' sb.dump_id() @@ -161,20 +161,20 @@ if __name__ == '__main__': sb = SymbolicExecutionEngine(ir_arch, symbols_init) - blocs, symbol_pool = parse_asm.parse_txt(mn_x86, 32, ''' + blocks, symbol_pool = parse_asm.parse_txt(mn_x86, 32, ''' PUSH argv PUSH argc PUSH ret_addr ''') - b = list(blocs)[0] + b = list(blocks)[0] print b # add fake address and len to parsed instructions - for i, l in enumerate(b.lines): - l.offset, l.l = i, 1 + for i, line in enumerate(b.lines): + line.offset, line.l = i, 1 ir_arch.add_bloc(b) - irb = get_bloc(ir_arch, mdis, 0) + irb = get_block(ir_arch, mdis, 0) sb.emulbloc(irb) sb.dump_mem() @@ -185,7 +185,7 @@ if __name__ == '__main__': states_done = set() states_todo.add((uint32(ad), sb.symbols, ())) - # emul blocs, propagate states + # emul blocks, propagate states emul_symb(ir_arch, mdis, states_todo, states_done) all_info = [] diff --git a/example/ida/depgraph.py b/example/ida/depgraph.py index 9024f2af..50c73a54 100644 --- a/example/ida/depgraph.py +++ b/example/ida/depgraph.py @@ -21,8 +21,8 @@ class depGraphSettingsForm(Form): self.stk_unalias_force = False self.address = ScreenEA() - cur_bloc = list(ira.getby_offset(self.address))[0] - for line_nb, l in enumerate(cur_bloc.lines): + cur_block = list(ira.getby_offset(self.address))[0] + for line_nb, l in enumerate(cur_block.lines): if l.offset == self.address: break cur_label = str(cur_block.label) @@ -151,11 +151,11 @@ for ad, name in Names(): # Get the current function addr = ScreenEA() func = idaapi.get_func(addr) -blocs = mdis.dis_multibloc(func.startEA) +blocks = mdis.dis_multibloc(func.startEA) # Generate IR -for bloc in blocs: - ir_arch.add_bloc(bloc) +for block in blocks: + ir_arch.add_bloc(block) # Get settings settings = depGraphSettingsForm(ir_arch) diff --git a/example/ida/graph_ir.py b/example/ida/graph_ir.py index 252dc612..250eebfc 100644 --- a/example/ida/graph_ir.py +++ b/example/ida/graph_ir.py @@ -125,10 +125,10 @@ open('asm_flow.dot', 'w').write(ab.dot()) print "generating IR... %x" % ad -for b in ab: +for block in ab: print 'ADD' - print b - ir_arch.add_bloc(b) + print block + ir_arch.add_bloc(block) print "IR ok... %x" % ad diff --git a/example/ida/symbol_exec.py b/example/ida/symbol_exec.py index edb6287b..70e1cfc1 100644 --- a/example/ida/symbol_exec.py +++ b/example/ida/symbol_exec.py @@ -87,10 +87,10 @@ def symbolic_exec(): start, end = SelStart(), SelEnd() mdis.dont_dis = [end] - blocs = mdis.dis_multibloc(start) + blocks = mdis.dis_multibloc(start) ira = machine.ira() - for bloc in blocs: - ira.add_bloc(bloc) + for block in blocks: + ira.add_bloc(block) print "Run symbolic execution..." sb = SymbolicExecutionEngine(ira, machine.mn.regs.regs_init) |