diff options
| author | Fabrice Desclaux <fabrice.desclaux@cea.fr> | 2017-07-07 12:20:08 +0200 |
|---|---|---|
| committer | Fabrice Desclaux <fabrice.desclaux@cea.fr> | 2017-07-07 12:43:04 +0200 |
| commit | 4fcd0faa925d8d33db3622430548e932443d6f02 (patch) | |
| tree | 245ae1df0ef337cc764a595a6026513536209c88 | |
| parent | 84d93930af5faee327784bed0646ef4eecf8328b (diff) | |
| download | miasm-4fcd0faa925d8d33db3622430548e932443d6f02.tar.gz miasm-4fcd0faa925d8d33db3622430548e932443d6f02.zip | |
Asmblock: rename bloc
| -rw-r--r-- | example/disasm/callback.py | 4 | ||||
| -rw-r--r-- | example/disasm/file.py | 2 | ||||
| -rw-r--r-- | example/disasm/full.py | 2 | ||||
| -rw-r--r-- | example/disasm/function.py | 2 | ||||
| -rw-r--r-- | example/expression/access_c.py | 2 | ||||
| -rw-r--r-- | example/expression/graph_dataflow.py | 2 | ||||
| -rw-r--r-- | example/expression/solve_condition_stp.py | 2 | ||||
| -rw-r--r-- | example/ida/ctype_propagation.py | 4 | ||||
| -rw-r--r-- | example/ida/depgraph.py | 2 | ||||
| -rw-r--r-- | example/ida/graph_ir.py | 2 | ||||
| -rw-r--r-- | example/ida/symbol_exec.py | 2 | ||||
| -rw-r--r-- | example/jitter/unpack_upx.py | 2 | ||||
| -rw-r--r-- | example/symbol_exec/depgraph.py | 2 | ||||
| -rw-r--r-- | example/symbol_exec/single_instr.py | 2 | ||||
| -rw-r--r-- | miasm2/analysis/dse.py | 2 | ||||
| -rw-r--r-- | miasm2/core/asmblock.py | 47 | ||||
| -rw-r--r-- | miasm2/jitter/jitcore.py | 2 | ||||
| -rw-r--r-- | test/core/asmblock.py | 14 |
18 files changed, 57 insertions, 40 deletions
diff --git a/example/disasm/callback.py b/example/disasm/callback.py index 06159138..5aae7f6f 100644 --- a/example/disasm/callback.py +++ b/example/disasm/callback.py @@ -46,7 +46,7 @@ bin_stream = bin_stream_str(shellcode) mdis = dis_x86_32(bin_stream) print "Without callback:\n" -blocks = mdis.dis_multibloc(0) +blocks = mdis.dis_multiblock(0) print "\n".join(str(block) for block in blocks) # Enable callback @@ -59,7 +59,7 @@ mdis.job_done.clear() print "=" * 40 print "With callback:\n" -blocks_after = mdis.dis_multibloc(0) +blocks_after = mdis.dis_multiblock(0) print "\n".join(str(block) for block in blocks_after) # Ensure the callback has been called diff --git a/example/disasm/file.py b/example/disasm/file.py index db5cd96b..88ba6162 100644 --- a/example/disasm/file.py +++ b/example/disasm/file.py @@ -13,6 +13,6 @@ cont = Container.from_stream(open(sys.argv[1])) mdis = dis_x86_32(cont.bin_stream) # Inform the engine to avoid disassembling null instructions mdis.dont_dis_nulstart_bloc = True -blocks = mdis.dis_multibloc(addr) +blocks = mdis.dis_multiblock(addr) open('graph.dot', 'w').write(blocks.dot()) diff --git a/example/disasm/full.py b/example/disasm/full.py index 3e35ed6c..ad85f7dc 100644 --- a/example/disasm/full.py +++ b/example/disasm/full.py @@ -121,7 +121,7 @@ while not finish and todo: if ad in done: continue done.add(ad) - allblocks = mdis.dis_multibloc(ad) + allblocks = mdis.dis_multiblock(ad) log.info('func ok %.16x (%d)' % (ad, len(all_funcs))) diff --git a/example/disasm/function.py b/example/disasm/function.py index 1fe1754f..89f65abb 100644 --- a/example/disasm/function.py +++ b/example/disasm/function.py @@ -8,7 +8,7 @@ from miasm2.arch.x86.disasm import dis_x86_32 # RET shellcode = '\xb8\xef\xbe7\x13\xb9\x04\x00\x00\x00\xc1\xc0\x08\xe2\xfb\xc3' mdis = dis_x86_32(shellcode) -blocks = mdis.dis_multibloc(0) +blocks = mdis.dis_multiblock(0) for block in blocks: print block diff --git a/example/expression/access_c.py b/example/expression/access_c.py index a3de66f7..7255e23a 100644 --- a/example/expression/access_c.py +++ b/example/expression/access_c.py @@ -157,7 +157,7 @@ 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_multibloc(addr_head) +blocks = mdis.dis_multiblock(addr_head) lbl_head = mdis.symbol_pool.getby_offset(addr_head) ir_arch_a = ira(mdis.symbol_pool) diff --git a/example/expression/graph_dataflow.py b/example/expression/graph_dataflow.py index 2661e72f..120cd73a 100644 --- a/example/expression/graph_dataflow.py +++ b/example/expression/graph_dataflow.py @@ -151,7 +151,7 @@ ad = int(args.addr, 16) print 'disasm...' mdis = dis_x86_32(data) mdis.follow_call = True -ab = mdis.dis_multibloc(ad) +ab = mdis.dis_multiblock(ad) print 'ok' diff --git a/example/expression/solve_condition_stp.py b/example/expression/solve_condition_stp.py index 93ebdd4e..c9d4c7af 100644 --- a/example/expression/solve_condition_stp.py +++ b/example/expression/solve_condition_stp.py @@ -37,7 +37,7 @@ def get_block(ir_arch, mdis, ad): l = mdis.symbol_pool.getby_offset_create(ad) if not l in ir_arch.blocks: ad = l.offset - b = mdis.dis_bloc(ad) + b = mdis.dis_block(ad) ir_arch.add_block(b) b = ir_arch.get_block(l) if b is None: diff --git a/example/ida/ctype_propagation.py b/example/ida/ctype_propagation.py index abeabfd8..a48179e9 100644 --- a/example/ida/ctype_propagation.py +++ b/example/ida/ctype_propagation.py @@ -60,7 +60,7 @@ def get_block(ir_arch, mdis, addr): mdis.job_done.clear() lbl = ir_arch.get_label(addr) if not lbl in ir_arch.blocks: - block = mdis.dis_bloc(lbl.offset) + block = mdis.dis_block(lbl.offset) ir_arch.add_block(block) irblock = ir_arch.get_block(lbl) if irblock is None: @@ -165,7 +165,7 @@ def analyse_function(): # Get the current function func = ida_funcs.get_func(idc.ScreenEA()) addr = func.startEA - blocks = mdis.dis_multibloc(addr) + blocks = mdis.dis_multiblock(addr) # Generate IR for block in blocks: ir_arch.add_block(block) diff --git a/example/ida/depgraph.py b/example/ida/depgraph.py index 503ed2a3..915f14bc 100644 --- a/example/ida/depgraph.py +++ b/example/ida/depgraph.py @@ -214,7 +214,7 @@ def launch_depgraph(): # Get the current function addr = idc.ScreenEA() func = ida_funcs.get_func(addr) - blocks = mdis.dis_multibloc(func.startEA) + blocks = mdis.dis_multiblock(func.startEA) # Generate IR for block in blocks: diff --git a/example/ida/graph_ir.py b/example/ida/graph_ir.py index d9645748..9a65617b 100644 --- a/example/ida/graph_ir.py +++ b/example/ida/graph_ir.py @@ -138,7 +138,7 @@ def build_graph(verbose=False, simplify=False): if verbose: print hex(addr) - blocks = mdis.dis_multibloc(addr) + blocks = mdis.dis_multiblock(addr) if verbose: print "generating graph" diff --git a/example/ida/symbol_exec.py b/example/ida/symbol_exec.py index d71a1646..3d4a64fa 100644 --- a/example/ida/symbol_exec.py +++ b/example/ida/symbol_exec.py @@ -87,7 +87,7 @@ def symbolic_exec(): start, end = idc.SelStart(), idc.SelEnd() mdis.dont_dis = [end] - blocks = mdis.dis_multibloc(start) + blocks = mdis.dis_multiblock(start) ira = machine.ira() for block in blocks: ira.add_block(block) diff --git a/example/jitter/unpack_upx.py b/example/jitter/unpack_upx.py index 8160e51b..f9b0aed1 100644 --- a/example/jitter/unpack_upx.py +++ b/example/jitter/unpack_upx.py @@ -53,7 +53,7 @@ if options.verbose is True: # Ensure there is one and only one leave (for OEP discovering) mdis = sb.machine.dis_engine(sb.jitter.bs) mdis.dont_dis_nulstart_bloc = True -ab = mdis.dis_multibloc(sb.entry_point) +ab = mdis.dis_multiblock(sb.entry_point) leaves = list(ab.get_bad_blocks_predecessors()) assert(len(leaves) == 1) diff --git a/example/symbol_exec/depgraph.py b/example/symbol_exec/depgraph.py index 75942ec1..4d518cb3 100644 --- a/example/symbol_exec/depgraph.py +++ b/example/symbol_exec/depgraph.py @@ -59,7 +59,7 @@ if args.rename_args: init_ctx[e_mem] = ExprId("arg%d" % i) # Disassemble the targeted function -blocks = mdis.dis_multibloc(int(args.func_addr, 0)) +blocks = mdis.dis_multiblock(int(args.func_addr, 0)) # Generate IR for block in blocks: diff --git a/example/symbol_exec/single_instr.py b/example/symbol_exec/single_instr.py index 1d520d3a..263c0252 100644 --- a/example/symbol_exec/single_instr.py +++ b/example/symbol_exec/single_instr.py @@ -14,7 +14,7 @@ asm = machine.mn.asm(line)[0] # Get back block bin_stream = bin_stream_str(asm) mdis = machine.dis_engine(bin_stream) -asm_block = mdis.dis_bloc(START_ADDR) +asm_block = mdis.dis_block(START_ADDR) # Translate ASM -> IR ira = machine.ira(mdis.symbol_pool) diff --git a/miasm2/analysis/dse.py b/miasm2/analysis/dse.py index a2cb205e..329323e2 100644 --- a/miasm2/analysis/dse.py +++ b/miasm2/analysis/dse.py @@ -301,7 +301,7 @@ class DSEEngine(object): self.ir_arch.blocks.clear()# = {} ## Update current state - asm_block = self.mdis.dis_bloc(cur_addr) + asm_block = self.mdis.dis_block(cur_addr) self.ir_arch.add_block(asm_block) self.addr_to_cacheblocks[cur_addr] = dict(self.ir_arch.blocks) diff --git a/miasm2/core/asmblock.py b/miasm2/core/asmblock.py index 965b22c4..6cbe37a4 100644 --- a/miasm2/core/asmblock.py +++ b/miasm2/core/asmblock.py @@ -1386,7 +1386,7 @@ class disasmEngine(object): # Override options if needed self.__dict__.update(kwargs) - def _dis_bloc(self, offset): + def _dis_block(self, offset): """Disassemble the block at offset @offset Return the created AsmBlock and future offsets to disassemble """ @@ -1519,44 +1519,61 @@ class disasmEngine(object): symbol_pool=self.symbol_pool) return cur_block, offsets_to_dis - def dis_bloc(self, offset): + def dis_block(self, offset): """Disassemble the block at offset @offset and return the created AsmBlock @offset: targeted offset to disassemble """ - current_block, _ = self._dis_bloc(offset) + current_block, _ = self._dis_block(offset) return current_block - def dis_multibloc(self, offset, blocs=None): + def dis_bloc(self, offset): + """ + DEPRECATED function + Use dis_block instead of dis_bloc + """ + warnings.warn('DEPRECATION WARNING: use "dis_block" instead of "dis_bloc"') + return self.dis_block(offset) + + def dis_multiblock(self, offset, blocks=None): """Disassemble every block reachable from @offset regarding specific disasmEngine conditions Return an AsmCFG instance containing disassembled blocks @offset: starting offset - @blocs: (optional) AsmCFG instance of already disassembled blocks to + @blocks: (optional) AsmCFG instance of already disassembled blocks to merge with """ log_asmblock.info("dis bloc all") - if blocs is None: - blocs = AsmCFG() + if blocks is None: + blocks = AsmCFG() todo = [offset] bloc_cpt = 0 while len(todo): bloc_cpt += 1 if self.blocs_wd is not None and bloc_cpt > self.blocs_wd: - log_asmblock.debug("blocs watchdog reached at %X", int(offset)) + log_asmblock.debug("blocks watchdog reached at %X", int(offset)) break target_offset = int(todo.pop(0)) if (target_offset is None or target_offset in self.job_done): continue - cur_block, nexts = self._dis_bloc(target_offset) + cur_block, nexts = self._dis_block(target_offset) todo += nexts - blocs.add_node(cur_block) + blocks.add_node(cur_block) + + blocks.apply_splitting(self.symbol_pool, + dis_block_callback=self.dis_bloc_callback, + mn=self.arch, attrib=self.attrib, + pool_bin=self.bin_stream) + return blocks + + def dis_multibloc(self, offset, blocs=None): + """ + DEPRECATED function + Use dis_multiblock instead of dis_multibloc + """ + warnings.warn('DEPRECATION WARNING: use "dis_multiblock" instead of "dis_multibloc"') + return self.dis_multiblock(offset, blocs) - blocs.apply_splitting(self.symbol_pool, - dis_block_callback=self.dis_bloc_callback, - mn=self.arch, attrib=self.attrib, - pool_bin=self.bin_stream) - return blocs diff --git a/miasm2/jitter/jitcore.py b/miasm2/jitter/jitcore.py index 22c9757b..6c4d197e 100644 --- a/miasm2/jitter/jitcore.py +++ b/miasm2/jitter/jitcore.py @@ -143,7 +143,7 @@ class JitCore(object): # Disassemble it try: - cur_block = self.mdis.dis_bloc(addr) + cur_block = self.mdis.dis_block(addr) except IOError: # vm_exception_flag is set label = self.ir_arch.symbol_pool.getby_offset_create(addr) diff --git a/test/core/asmblock.py b/test/core/asmblock.py index 79bf47be..666c4665 100644 --- a/test/core/asmblock.py +++ b/test/core/asmblock.py @@ -15,17 +15,17 @@ cont = Container.from_string(data) # Test Disasm engine mdis = dis_x86_32(cont.bin_stream) ## Disassembly of one block -first_block = mdis.dis_bloc(0) +first_block = mdis.dis_block(0) assert len(first_block.lines) == 5 print first_block ## Disassembly of several block, with cache -blocks = mdis.dis_multibloc(0) +blocks = mdis.dis_multiblock(0) assert len(blocks) == 0 ## Test cache mdis.job_done.clear() -blocks = mdis.dis_multibloc(0) +blocks = mdis.dis_multiblock(0) assert len(blocks) == 17 ## Equality between assembly lines is not yet implemented assert len(blocks.heads()) == 1 @@ -202,11 +202,11 @@ data2 = "31c0eb0c31c9750c31d2eb0c31ffebf831dbebf031edebfc31f6ebf031e4c3".decode( cont2 = Container.from_string(data2) mdis = dis_x86_32(cont2.bin_stream) ## Elements to merge -blocks = mdis.dis_multibloc(0) +blocks = mdis.dis_multiblock(0) ## Block alone -blocks.add_node(mdis.dis_bloc(0x1c)) +blocks.add_node(mdis.dis_block(0x1c)) ## Bad block -blocks.add_node(mdis.dis_bloc(len(data2))) +blocks.add_node(mdis.dis_block(len(data2))) ## Dump the graph before merging open("graph3.dot", "w").write(blocks.dot()) ## Apply merging @@ -285,7 +285,7 @@ assert blocks.edges2constraint[(tob, newb)] == AsmConstraint.c_to data = "74097405b8020000007405b803000000b804000000c3".decode('hex') cont = Container.from_string(data) mdis = dis_x86_32(cont.bin_stream) -blocks = mdis.dis_multibloc(0) +blocks = mdis.dis_multiblock(0) ## Check resulting disasm assert len(blocks.nodes()) == 6 blocks.sanity_check() |