diff options
| author | Ajax <commial@gmail.com> | 2018-07-02 19:12:53 +0200 |
|---|---|---|
| committer | Ajax <commial@gmail.com> | 2018-07-03 14:28:18 +0200 |
| commit | d314460a5a19be1f3334baedf0105d9b72fc8620 (patch) | |
| tree | 967c5856dcf37980cf80a2ea48cc7ee0e008e1bd | |
| parent | 68fac2e86cc61eba9adfe520fa0e04a7e8943450 (diff) | |
| download | miasm-d314460a5a19be1f3334baedf0105d9b72fc8620.tar.gz miasm-d314460a5a19be1f3334baedf0105d9b72fc8620.zip | |
Update symbol_pool's deprecated API -> LocationDB
56 files changed, 198 insertions, 272 deletions
diff --git a/example/asm/shellcode.py b/example/asm/shellcode.py index 331e4d69..9be5b517 100755 --- a/example/asm/shellcode.py +++ b/example/asm/shellcode.py @@ -71,11 +71,12 @@ loc_db = LocationDB() asmcfg, loc_db = parse_asm.parse_txt(machine.mn, attrib, source, loc_db) # Fix shellcode addrs -loc_db.set_offset(loc_db.getby_name("main"), addr_main) +loc_db.set_location_offset(loc_db.get_name_location("main"), addr_main) if args.PE: - loc_db.set_offset(loc_db.getby_name_create("MessageBoxA"), - pe.DirImport.get_funcvirt('USER32.dll', 'MessageBoxA')) + loc_db.set_location_offset(loc_db.get_or_create_name_location("MessageBoxA"), + pe.DirImport.get_funcvirt('USER32.dll', + 'MessageBoxA')) # Print and graph firsts blocks before patching it for block in asmcfg.blocks: @@ -89,10 +90,10 @@ patches = asmblock.asm_resolve_final(machine.mn, dst_interval) if args.encrypt: # Encrypt code - loc_start = loc_db.getby_name_create(args.encrypt[0]) - loc_stop = loc_db.getby_name_create(args.encrypt[1]) - ad_start = loc_db.loc_key_to_offset(loc_start) - ad_stop = loc_db.loc_key_to_offset(loc_stop) + loc_start = loc_db.get_or_create_name_location(args.encrypt[0]) + loc_stop = loc_db.get_or_create_name_location(args.encrypt[1]) + ad_start = loc_db.get_location_offset(loc_start) + ad_stop = loc_db.get_location_offset(loc_stop) new_patches = dict(patches) for ad, val in patches.items(): diff --git a/example/asm/simple.py b/example/asm/simple.py index 068d3627..5480e2f5 100644 --- a/example/asm/simple.py +++ b/example/asm/simple.py @@ -22,7 +22,7 @@ loop: ''') # Set 'main' loc_key's offset -loc_db.set_offset(loc_db.getby_name("main"), 0x0) +loc_db.set_location_offset(loc_db.get_name_location("main"), 0x0) # Spread information and resolve instructions offset patches = asmblock.asm_resolve_final(mn_x86, asmcfg, loc_db) diff --git a/example/disasm/callback.py b/example/disasm/callback.py index 85090070..b9a09c09 100644 --- a/example/disasm/callback.py +++ b/example/disasm/callback.py @@ -27,7 +27,7 @@ def cb_x86_callpop(cur_bloc, loc_db, *args, **kwargs): return loc_key = dst.loc_key - offset = loc_db.loc_key_to_offset(loc_key) + offset = loc_db.get_location_offset(loc_key) ## The destination must be the next instruction if offset != last_instr.offset + last_instr.l: return diff --git a/example/disasm/full.py b/example/disasm/full.py index 1e5d2334..ddf91e29 100644 --- a/example/disasm/full.py +++ b/example/disasm/full.py @@ -99,8 +99,8 @@ for addr in args.address: addrs.append(int(addr, 0)) except ValueError: # Second chance, try with symbol - loc_key = mdis.loc_db.getby_name(addr) - offset = mdis.loc_db.loc_key_to_offset(loc_key) + loc_key = mdis.loc_db.get_name_location(addr) + offset = mdis.loc_db.get_location_offset(loc_key) addrs.append(offset) if len(addrs) == 0 and default_addr is not None: @@ -143,7 +143,7 @@ while not finish and todo: for dest in instr.getdstflow(mdis.loc_db): if not dest.is_loc(): continue - offset = mdis.loc_db.loc_key_to_offset(dest.loc_key) + offset = mdis.loc_db.get_location_offset(dest.loc_key) todo.append((mdis, instr, offset)) if args.funcswatchdog is not None and args.funcswatchdog <= 0: diff --git a/example/expression/access_c.py b/example/expression/access_c.py index 9b92d201..8e440cc1 100644 --- a/example/expression/access_c.py +++ b/example/expression/access_c.py @@ -144,7 +144,7 @@ dis_engine, ira = machine.dis_engine, machine.ira mdis = dis_engine(cont.bin_stream, loc_db=cont.loc_db) addr_head = 0 asmcfg = mdis.dis_multiblock(addr_head) -lbl_head = mdis.loc_db.getby_offset(addr_head) +lbl_head = mdis.loc_db.get_offset_location(addr_head) ir_arch_a = ira(mdis.loc_db) for block in asmcfg.blocks: diff --git a/example/expression/asm_to_ir.py b/example/expression/asm_to_ir.py index 421d0884..6db07e9b 100644 --- a/example/expression/asm_to_ir.py +++ b/example/expression/asm_to_ir.py @@ -24,7 +24,7 @@ loop: ''') -loc_db.set_offset(loc_db.getby_name("main"), 0x0) +loc_db.set_location_offset(loc_db.get_name_location("main"), 0x0) for block in asmcfg.blocks: print block diff --git a/example/expression/graph_dataflow.py b/example/expression/graph_dataflow.py index d0d5564a..dd9d3e9b 100644 --- a/example/expression/graph_dataflow.py +++ b/example/expression/graph_dataflow.py @@ -97,7 +97,7 @@ def gen_block_data_flow_graph(ir_arch, ad, block_flow_cb): irblock_0 = None for irblock in ir_arch.blocks.values(): loc_key = irblock.loc_key - offset = ir_arch.loc_db.loc_key_to_offset(loc_key) + offset = ir_arch.loc_db.get_location_offset(loc_key) if offset == ad: irblock_0 = irblock break diff --git a/example/expression/solve_condition_stp.py b/example/expression/solve_condition_stp.py index b941f092..41b812cd 100644 --- a/example/expression/solve_condition_stp.py +++ b/example/expression/solve_condition_stp.py @@ -101,10 +101,10 @@ if __name__ == '__main__': loc_db=mdis.loc_db) - argc_lbl = loc_db.getby_name('argc') - argv_lbl = loc_db.getby_name('argv') - ret_addr_lbl = loc_db.getby_name('ret_addr') - init_lbl = loc_db.getby_name('init') + argc_lbl = loc_db.get_name_location('argc') + argv_lbl = loc_db.get_name_location('argv') + ret_addr_lbl = loc_db.get_name_location('ret_addr') + init_lbl = loc_db.get_name_location('init') argc = ExprLoc(argc_lbl, 32) argv = ExprLoc(argv_lbl, 32) diff --git a/example/ida/ctype_propagation.py b/example/ida/ctype_propagation.py index 9a81baef..f236cf26 100644 --- a/example/ida/ctype_propagation.py +++ b/example/ida/ctype_propagation.py @@ -304,8 +304,8 @@ def analyse_function(): infos_types[expr] = set([objc]) # Add fake head - lbl_real_start = ir_arch.loc_db.getby_offset(addr) - lbl_head = ir_arch.loc_db.getby_name_create("start") + lbl_real_start = ir_arch.loc_db.get_offset_location(addr) + lbl_head = ir_arch.loc_db.get_or_create_name_location("start") first_block = asmcfg.label2block(lbl_real_start) diff --git a/example/ida/depgraph.py b/example/ida/depgraph.py index 8e635203..1ba7bee7 100644 --- a/example/ida/depgraph.py +++ b/example/ida/depgraph.py @@ -28,7 +28,7 @@ class depGraphSettingsForm(ida_kernwin.Form): self.address = idc.ScreenEA() cur_block = None for block in ira.getby_offset(self.address): - offset = self.ira.loc_db.loc_key_to_offset(block.loc_key) + offset = self.ira.loc_db.get_location_offset(block.loc_key) if offset is not None: # Only one block non-generated assert cur_block is None @@ -230,7 +230,7 @@ def launch_depgraph(): # Simplify affectations for irb in ir_arch.blocks.values(): irs = [] - offset = ir_arch.loc_db.loc_key_to_offset(irb.loc_key) + offset = ir_arch.loc_db.get_location_offset(irb.loc_key) fix_stack = offset is not None and settings.unalias_stack for assignblk in irb: if fix_stack: @@ -251,7 +251,7 @@ def launch_depgraph(): # Get dependency graphs dg = settings.depgraph graphs = dg.get(loc_key, elements, line_nb, - set([ir_arch.loc_db.getby_offset(func.startEA)])) + set([ir_arch.loc_db.get_offset_location(func.startEA)])) # Display the result comments = {} diff --git a/example/ida/graph_ir.py b/example/ida/graph_ir.py index 955dee62..50895b88 100644 --- a/example/ida/graph_ir.py +++ b/example/ida/graph_ir.py @@ -36,7 +36,7 @@ def label_str(self): def color_irblock(irblock, ir_arch): out = [] - lbl = idaapi.COLSTR(ir_arch.loc_db.str_loc_key(irblock.loc_key), idaapi.SCOLOR_INSN) + lbl = idaapi.COLSTR(ir_arch.loc_db.pretty_str(irblock.loc_key), idaapi.SCOLOR_INSN) out.append(lbl) for assignblk in irblock: for dst, src in sorted(assignblk.iteritems()): @@ -118,8 +118,8 @@ def build_graph(verbose=False, simplify=False): for addr, name in idautils.Names(): if name is None: continue - if (mdis.loc_db.getby_offset(addr) or - mdis.loc_db.getby_name(name)): + if (mdis.loc_db.get_offset_location(addr) or + mdis.loc_db.get_name_location(name)): # Symbol alias continue mdis.loc_db.add_location(name, addr) diff --git a/example/ida/utils.py b/example/ida/utils.py index 254617ba..c66475f2 100644 --- a/example/ida/utils.py +++ b/example/ida/utils.py @@ -98,7 +98,7 @@ class TranslatorIDA(Translator): def from_ExprLoc(self, expr): if self.loc_db is not None: - out = self.loc_db.str_loc_key(expr.loc_key) + out = self.loc_db.pretty_str(expr.loc_key) else: out = str(expr) out = idaapi.COLSTR(out, idaapi.SCOLOR_REG) diff --git a/example/jitter/sandbox_call.py b/example/jitter/sandbox_call.py index 5fc50a9c..3eb0b86e 100644 --- a/example/jitter/sandbox_call.py +++ b/example/jitter/sandbox_call.py @@ -15,8 +15,8 @@ sb = Sandbox_Linux_arml(options.filename, options, globals()) with open(options.filename, "rb") as fdesc: cont = Container.from_stream(fdesc) - loc_key = cont.loc_db.getby_name("md5_starts") - addr_to_call = cont.loc_db.loc_key_to_offset(loc_key) + loc_key = cont.loc_db.get_name_location("md5_starts") + addr_to_call = cont.loc_db.get_location_offset(loc_key) # Calling md5_starts(malloc(0x64)) addr = linobjs.heap.alloc(sb.jitter, 0x64) diff --git a/example/jitter/unpack_upx.py b/example/jitter/unpack_upx.py index 6b7b4f50..665fa15a 100644 --- a/example/jitter/unpack_upx.py +++ b/example/jitter/unpack_upx.py @@ -60,7 +60,7 @@ assert(len(leaves) == 1) l = leaves.pop() logging.info(l) -end_offset = mdis.loc_db.loc_key_to_offset(l) +end_offset = mdis.loc_db.get_location_offset(l) logging.info('final offset') logging.info(hex(end_offset)) diff --git a/miasm2/analysis/binary.py b/miasm2/analysis/binary.py index ae3b964e..16e573bb 100644 --- a/miasm2/analysis/binary.py +++ b/miasm2/analysis/binary.py @@ -217,7 +217,7 @@ class ContainerELF(Container): log.warning("Same offset (%s) for %s and %s", (hex(offset), name, - self._loc_db.getby_offset(offset))) + self._loc_db.get_offset_location(offset))) continue diff --git a/miasm2/analysis/depgraph.py b/miasm2/analysis/depgraph.py index 6532a3ef..f5a2b043 100644 --- a/miasm2/analysis/depgraph.py +++ b/miasm2/analysis/depgraph.py @@ -298,7 +298,7 @@ class DependencyResult(DependencyState): # Eval the block loc_db = LocationDB() - temp_loc = loc_db.getby_name_create("Temp") + temp_loc = loc_db.get_or_create_name_location("Temp") symb_exec = SymbolicExecutionEngine(self._ira, ctx_init) symb_exec.eval_updt_irblock(IRBlock(temp_loc, assignblks), step=step) diff --git a/miasm2/analysis/disasm_cb.py b/miasm2/analysis/disasm_cb.py index 54832104..bb8223e8 100644 --- a/miasm2/analysis/disasm_cb.py +++ b/miasm2/analysis/disasm_cb.py @@ -49,7 +49,7 @@ def arm_guess_subcall( l = cur_bloc.lines[-1] if lr_val.arg != l.offset + l.l: continue - l = loc_db.getby_offset_create(int(lr_val)) + l = loc_db.get_or_create_offset_location(int(lr_val)) c = AsmConstraintNext(l) to_add.add(c) @@ -111,7 +111,7 @@ def arm_guess_jump_table( for ad in addrs: offsets_to_dis.add(ad) - l = loc_db.getby_offset_create(ad) + l = loc_db.get_or_create_offset_location(ad) c = AsmConstraintTo(l) cur_bloc.addto(c) diff --git a/miasm2/analysis/dse.py b/miasm2/analysis/dse.py index e2758d6c..87d11e0a 100644 --- a/miasm2/analysis/dse.py +++ b/miasm2/analysis/dse.py @@ -348,7 +348,7 @@ class DSEEngine(object): self.symb.run_block_at(cur_addr) if not (isinstance(next_addr_concrete, ExprLoc) and - self.ir_arch.loc_db.loc_key_to_offset( + self.ir_arch.loc_db.get_location_offset( next_addr_concrete.loc_key ) is None): # Not a lbl_gen, exit diff --git a/miasm2/arch/aarch64/arch.py b/miasm2/arch/aarch64/arch.py index 79b76743..529621c4 100644 --- a/miasm2/arch/aarch64/arch.py +++ b/miasm2/arch/aarch64/arch.py @@ -276,7 +276,7 @@ class aarch64_arg(m_arg): if isinstance(value.name, ExprId): fixed_size.add(value.name.size) return value.name - loc_key = loc_db.getby_name_create(value.name) + loc_key = loc_db.get_or_create_name_location(value.name) return ExprLoc(loc_key, size_hint) if isinstance(value, AstInt): assert size_hint is not None @@ -316,7 +316,7 @@ class instruction_aarch64(instruction): return str(expr) elif expr.is_loc(): if loc_db is not None: - return loc_db.str_loc_key(expr.loc_key) + return loc_db.pretty_str(expr.loc_key) else: return str(expr) elif isinstance(expr, m2_expr.ExprOp) and expr.op in shift_expr: @@ -374,7 +374,7 @@ class instruction_aarch64(instruction): if not expr.is_int(): return addr = expr.arg + self.offset - loc_key = loc_db.getby_offset_create(addr) + loc_key = loc_db.get_or_create_offset_location(addr) self.args[index] = m2_expr.ExprLoc(loc_key, expr.size) def breakflow(self): diff --git a/miasm2/arch/arm/arch.py b/miasm2/arch/arm/arch.py index 498de94c..1810cd6a 100644 --- a/miasm2/arch/arm/arch.py +++ b/miasm2/arch/arm/arch.py @@ -349,7 +349,7 @@ class instruction_arm(instruction): return str(expr) elif expr.is_loc(): if loc_db is not None: - return loc_db.str_loc_key(expr.loc_key) + return loc_db.pretty_str(expr.loc_key) else: return str(expr) if isinstance(expr, ExprOp) and expr.op in expr2shift_dct: @@ -430,7 +430,7 @@ class instruction_arm(instruction): addr = expr.arg + self.offset else: addr = expr.arg + self.offset - loc_key = loc_db.getby_offset_create(addr) + loc_key = loc_db.get_or_create_offset_location(addr) self.args[0] = ExprLoc(loc_key, expr.size) def breakflow(self): @@ -512,7 +512,7 @@ class instruction_armt(instruction_arm): else: addr = expr.arg + self.offset - loc_key = loc_db.getby_offset_create(addr) + loc_key = loc_db.get_or_create_offset_location(addr) dst = ExprLoc(loc_key, expr.size) if self.name in ["CBZ", "CBNZ"]: @@ -780,7 +780,7 @@ class arm_arg(m_arg): return arg.name if arg.name in gpregs.str: return None - loc_key = loc_db.getby_name_create(arg.name) + loc_key = loc_db.get_or_create_name_location(arg.name) return ExprLoc(loc_key, 32) if isinstance(arg, AstOp): args = [self.asm_ast_to_expr(tmp, loc_db) for tmp in arg.args] diff --git a/miasm2/arch/arm/disasm.py b/miasm2/arch/arm/disasm.py index 41034211..5e21778d 100644 --- a/miasm2/arch/arm/disasm.py +++ b/miasm2/arch/arm/disasm.py @@ -24,7 +24,7 @@ def cb_arm_fix_call(mn, cur_bloc, loc_db, offsets_to_dis, *args, **kwargs): return if not l2.args[1] in values: return - loc_key_cst = loc_db.getby_offset_create(l1.offset + 4) + loc_key_cst = loc_db.get_or_create_offset_location(l1.offset + 4) cur_bloc.add_cst(loc_key_cst, AsmConstraint.c_next) offsets_to_dis.add(l1.offset + 4) diff --git a/miasm2/arch/arm/sem.py b/miasm2/arch/arm/sem.py index 6e311f8e..a3d12514 100644 --- a/miasm2/arch/arm/sem.py +++ b/miasm2/arch/arm/sem.py @@ -441,8 +441,8 @@ def sdiv(ir, instr, a, b, c=None): if c is None: b, c = a, b - loc_div = ExprLoc(ir.loc_db.gen_loc_key(), ir.IRDst.size) - loc_except = ExprId(ir.loc_db.gen_loc_key(), ir.IRDst.size) + loc_div = ExprLoc(ir.loc_db.add_location(), ir.IRDst.size) + loc_except = ExprId(ir.loc_db.add_location(), ir.IRDst.size) loc_next = ExprLoc(ir.get_next_loc_key(instr), ir.IRDst.size) e.append(ExprAff(ir.IRDst, ExprCond(c, loc_div, loc_except))) @@ -474,8 +474,8 @@ def udiv(ir, instr, a, b, c=None): - loc_div = ExprLoc(ir.loc_db.gen_loc_key(), ir.IRDst.size) - loc_except = ExprLoc(ir.loc_db.gen_loc_key(), ir.IRDst.size) + loc_div = ExprLoc(ir.loc_db.add_location(), ir.IRDst.size) + loc_except = ExprLoc(ir.loc_db.add_location(), ir.IRDst.size) loc_next = ExprLoc(ir.get_next_loc_key(instr), ir.IRDst.size) e.append(ExprAff(ir.IRDst, ExprCond(c, loc_div, loc_except))) @@ -1266,7 +1266,7 @@ def add_condition_expr(ir, instr, cond, instr_ir, extra_ir): loc_next = ir.get_next_loc_key(instr) loc_next_expr = ExprLoc(loc_next, 32) - loc_do = ir.loc_db.gen_loc_key() + loc_do = ir.loc_db.add_location() loc_do_expr = ExprLoc(loc_do, 32) dst_cond = ExprCond(cond, loc_do_expr, loc_next_expr) @@ -1556,7 +1556,7 @@ class ir_arml(IntermediateRepresentation): instr = block.lines[index] # Add conditionnal jump to current irblock - loc_do = self.loc_db.gen_loc_key() + loc_do = self.loc_db.add_location() loc_next = self.get_next_loc_key(instr) if hint: diff --git a/miasm2/arch/mips32/arch.py b/miasm2/arch/mips32/arch.py index a47c606b..974644dc 100644 --- a/miasm2/arch/mips32/arch.py +++ b/miasm2/arch/mips32/arch.py @@ -65,7 +65,7 @@ class instruction_mips32(cpu.instruction): return str(expr) elif expr.is_loc(): if loc_db is not None: - return loc_db.str_loc_key(expr.loc_key) + return loc_db.pretty_str(expr.loc_key) else: return str(expr) assert(isinstance(expr, ExprMem)) @@ -97,7 +97,7 @@ class instruction_mips32(cpu.instruction): if self.name in ["J", 'JAL']: expr = self.args[0].arg addr = (self.offset & (0xFFFFFFFF ^ ((1<< 28)-1))) + expr - loc_key = loc_db.getby_offset_create(addr) + loc_key = loc_db.get_or_create_offset_location(addr) self.args[0] = ExprLoc(loc_key, expr.size) return @@ -107,7 +107,7 @@ class instruction_mips32(cpu.instruction): if not isinstance(expr, ExprInt): return addr = expr.arg + self.offset - loc_key = loc_db.getby_offset_create(addr) + loc_key = loc_db.get_or_create_offset_location(addr) self.args[ndx] = ExprLoc(loc_key, expr.size) def breakflow(self): @@ -265,7 +265,7 @@ class mips32_arg(cpu.m_arg): return arg.name if arg.name in gpregs.str: return None - loc_key = loc_db.getby_name_create(arg.name) + loc_key = loc_db.get_or_create_name_location(arg.name) return ExprLoc(loc_key, 32) if isinstance(arg, AstOp): args = [self.asm_ast_to_expr(tmp, loc_db) for tmp in arg.args] diff --git a/miasm2/arch/mips32/ira.py b/miasm2/arch/mips32/ira.py index 791e67bf..53c2c6b3 100644 --- a/miasm2/arch/mips32/ira.py +++ b/miasm2/arch/mips32/ira.py @@ -28,7 +28,7 @@ class ir_a_mips32l(ir_mips32l, ira): new_irblocks.append(irb) continue if lr_val.is_loc(): - offset = self.loc_db.loc_key_to_offset(lr_val.loc_key) + offset = self.loc_db.get_location_offset(lr_val.loc_key) if offset is not None: lr_val = ExprInt(offset, 32) if not lr_val.is_int(): diff --git a/miasm2/arch/mips32/jit.py b/miasm2/arch/mips32/jit.py index 0c4eb85b..a0df64d6 100644 --- a/miasm2/arch/mips32/jit.py +++ b/miasm2/arch/mips32/jit.py @@ -70,7 +70,7 @@ class mipsCGen(CGen): """ loc_key = self.get_block_post_label(block) - offset = self.ir_arch.loc_db.loc_key_to_offset(loc_key) + offset = self.ir_arch.loc_db.get_location_offset(loc_key) out = (self.CODE_RETURN_NO_EXCEPTION % (loc_key, self.C_PC, m2_expr.ExprId('branch_dst_irdst', 32), diff --git a/miasm2/arch/mips32/sem.py b/miasm2/arch/mips32/sem.py index df13cd2c..acf7370f 100644 --- a/miasm2/arch/mips32/sem.py +++ b/miasm2/arch/mips32/sem.py @@ -490,10 +490,10 @@ class ir_mips32l(IntermediateRepresentation): return instr_ir, new_extra_ir def get_next_instr(self, instr): - return self.loc_db.getby_offset_create(instr.offset + 4) + return self.loc_db.get_or_create_offset_location(instr.offset + 4) def get_next_break_loc_key(self, instr): - return self.loc_db.getby_offset_create(instr.offset + 8) + return self.loc_db.get_or_create_offset_location(instr.offset + 8) class ir_mips32b(ir_mips32l): def __init__(self, loc_db=None): diff --git a/miasm2/arch/msp430/arch.py b/miasm2/arch/msp430/arch.py index 7c739561..ecf4cb13 100644 --- a/miasm2/arch/msp430/arch.py +++ b/miasm2/arch/msp430/arch.py @@ -69,7 +69,7 @@ class msp430_arg(m_arg): index = gpregs.str.index(name) reg = gpregs.expr[index] return reg - loc_key = loc_db.getby_name_create(value.name) + loc_key = loc_db.get_or_create_name_location(value.name) return ExprLoc(loc_key, 16) if isinstance(value, AstOp): args = [self.asm_ast_to_expr(tmp, loc_db) for tmp in value.args] @@ -109,7 +109,7 @@ class instruction_msp430(instruction): o = str(expr) elif expr.is_loc(): if loc_db is not None: - return loc_db.str_loc_key(expr.loc_key) + return loc_db.pretty_str(expr.loc_key) else: return str(expr) elif isinstance(expr, ExprOp) and expr.op == "autoinc": @@ -138,7 +138,7 @@ class instruction_msp430(instruction): else: addr = expr.arg + int(self.offset) - loc_key = loc_db.getby_offset_create(addr) + loc_key = loc_db.get_or_create_offset_location(addr) self.args[0] = ExprLoc(loc_key, expr.size) def breakflow(self): diff --git a/miasm2/arch/ppc/arch.py b/miasm2/arch/ppc/arch.py index 94b2b903..c100cde3 100644 --- a/miasm2/arch/ppc/arch.py +++ b/miasm2/arch/ppc/arch.py @@ -40,7 +40,7 @@ class ppc_arg(m_arg): return arg.name if arg.name in gpregs.str: return None - loc_key = loc_db.getby_name_create(arg.name) + loc_key = loc_db.get_or_create_name_location(arg.name) return ExprLoc(loc_key, 32) if isinstance(arg, AstOp): args = [self.asm_ast_to_expr(tmp, loc_db) for tmp in arg.args] @@ -131,7 +131,7 @@ class instruction_ppc(instruction): ad = e.arg + self.offset else: ad = e.arg - loc_key = loc_db.getby_offset_create(ad) + loc_key = loc_db.get_or_create_offset_location(ad) s = ExprLoc(loc_key, e.size) self.args[address_index] = s diff --git a/miasm2/arch/ppc/sem.py b/miasm2/arch/ppc/sem.py index 77e4973a..678ab041 100644 --- a/miasm2/arch/ppc/sem.py +++ b/miasm2/arch/ppc/sem.py @@ -606,8 +606,8 @@ def mn_do_store(ir, instr, arg1, arg2, arg3=None): ret.append(ExprAff(arg2, address)) if is_stwcx: - loc_do = ExprLoc(ir.loc_db.gen_loc_key(), ir.IRDst.size) - loc_dont = ExprLoc(ir.loc_db.gen_loc_key(), ir.IRDst.size) + loc_do = ExprLoc(ir.loc_db.add_location(), ir.IRDst.size) + loc_dont = ExprLoc(ir.loc_db.add_location(), ir.IRDst.size) loc_next = ExprLoc(ir.get_next_loc_key(instr), ir.IRDst.size) flags = [ ExprAff(CR0_LT, ExprInt(0,1)), ExprAff(CR0_GT, ExprInt(0,1)), @@ -916,9 +916,9 @@ class ir_ppc32b(IntermediateRepresentation): return instr_ir, extra_ir def get_next_instr(self, instr): - l = self.loc_db.getby_offset_create(instr.offset + 4) + l = self.loc_db.get_or_create_offset_location(instr.offset + 4) return l def get_next_break_loc_key(self, instr): - l = self.loc_db.getby_offset_create(instr.offset + 4) + l = self.loc_db.get_or_create_offset_location(instr.offset + 4) return l diff --git a/miasm2/arch/sh4/arch.py b/miasm2/arch/sh4/arch.py index 46e316f8..d5e9820e 100644 --- a/miasm2/arch/sh4/arch.py +++ b/miasm2/arch/sh4/arch.py @@ -102,7 +102,7 @@ class sh4_arg(m_arg): return arg.name if arg.name in gpregs.str: return None - loc_key = loc_db.getby_name_create(arg.name) + loc_key = loc_db.get_or_create_name_location(arg.name) return ExprLoc(loc_key, 32) if isinstance(arg, AstOp): args = [self.asm_ast_to_expr(tmp, loc_db) for tmp in arg.args] @@ -411,7 +411,7 @@ class instruction_sh4(instruction): return str(expr) elif expr.is_loc(): if loc_db is not None: - return loc_db.str_loc_key(expr.loc_key) + return loc_db.pretty_str(expr.loc_key) else: return str(expr) assert(isinstance(expr, ExprMem)) @@ -443,7 +443,7 @@ class instruction_sh4(instruction): ad = e.arg+8+self.offset else: ad = e.arg+8+self.offset - l = loc_db.getby_offset_create(ad) + l = loc_db.get_or_create_offset_location(ad) s = ExprId(l, e.size) self.args[0] = s """ @@ -826,7 +826,7 @@ addop("bf", [bs('10001011'), s08imm]) def dstflow2label(self, loc_db): e = self.args[0].expr ad = e.arg*2+4+self.offset - l = loc_db.getby_offset_create(ad) + l = loc_db.get_or_create_offset_location(ad) s = ExprId(l, e.size) self.args[0].expr = s """ @@ -849,7 +849,7 @@ addop("bra", [bs('1010'), s12imm]) def dstflow2label(self, loc_db): e = self.args[0].expr ad = e.arg*2+4+self.offset - l = loc_db.getby_offset_create(ad) + l = loc_db.get_or_create_offset_location(ad) s = ExprId(l, e.size) self.args[0].expr = s """ diff --git a/miasm2/arch/x86/arch.py b/miasm2/arch/x86/arch.py index 3a537c01..815eaee6 100644 --- a/miasm2/arch/x86/arch.py +++ b/miasm2/arch/x86/arch.py @@ -272,7 +272,7 @@ class x86_arg(m_arg): if value.name in ["FAR"]: return None - loc_key = loc_db.getby_name_create(value.name) + loc_key = loc_db.get_or_create_name_location(value.name) return ExprLoc(loc_key, size_hint) if isinstance(value, AstOp): # First pass to retreive fixed_size @@ -476,7 +476,7 @@ class instruction_x86(instruction): if not expr.is_int(): return addr = expr.arg + int(self.offset) - loc_key = loc_db.getby_offset_create(addr) + loc_key = loc_db.get_or_create_offset_location(addr) self.args[0] = ExprLoc(loc_key, expr.size) def breakflow(self): @@ -514,7 +514,7 @@ class instruction_x86(instruction): def getdstflow(self, loc_db): if self.additional_info.g1.value & 6 and self.name in repeat_mn: addr = int(self.offset) - loc_key = loc_db.getby_offset_create(addr) + loc_key = loc_db.get_or_create_offset_location(addr) return [ExprLoc(loc_key, self.v_opmode())] return [self.args[0]] @@ -564,7 +564,7 @@ class instruction_x86(instruction): o = str(expr) elif expr.is_loc(): if loc_db is not None: - o = loc_db.str_loc_key(expr.loc_key) + o = loc_db.pretty_str(expr.loc_key) else: o = str(expr) elif ((isinstance(expr, ExprOp) and expr.op == 'far' and diff --git a/miasm2/core/asmblock.py b/miasm2/core/asmblock.py index 1aa057bd..c8af4056 100644 --- a/miasm2/core/asmblock.py +++ b/miasm2/core/asmblock.py @@ -74,7 +74,7 @@ class AsmConstraint(object): else: return "%s:%s" % ( self.c_t, - loc_db.str_loc_key(self.loc_key) + loc_db.pretty_str(self.loc_key) ) def __str__(self): @@ -142,7 +142,7 @@ class AsmBlock(object): if loc_db is None: out.append(str(self.loc_key)) else: - out.append(loc_db.str_loc_key(self.loc_key)) + out.append(loc_db.pretty_str(self.loc_key)) for instr in self.lines: out.append(instr.to_string(loc_db)) @@ -168,11 +168,11 @@ class AsmBlock(object): self.bto.add(c) def split(self, loc_db, offset): - loc_key = loc_db.getby_offset_create(offset) + loc_key = loc_db.get_or_create_offset_location(offset) log_asmblock.debug('split at %x', offset) i = -1 offsets = [x.offset for x in self.lines] - offset = loc_db.loc_key_to_offset(loc_key) + offset = loc_db.get_location_offset(loc_key) if offset not in offsets: log_asmblock.warning( 'cannot split bloc at %X ' % offset + @@ -540,7 +540,7 @@ class AsmCFG(DiGraph): if self.loc_db is None: loc_key_name = str(node) else: - loc_key_name = self.loc_db.str_loc_key(node) + loc_key_name = self.loc_db.pretty_str(node) yield self.DotCellDescription(text=loc_key_name, attr={'align': 'center', 'colspan': 2, @@ -777,7 +777,7 @@ class AsmCFG(DiGraph): # offset block_dst = [] for loc_key in self.pendings: - offset = loc_db.loc_key_to_offset(loc_key) + offset = loc_db.get_location_offset(loc_key) if offset is not None: block_dst.append(offset) @@ -812,7 +812,7 @@ class AsmCFG(DiGraph): # The new block destinations may need to be disassembled if dis_block_callback: offsets_to_dis = set( - self.loc_db.loc_key_to_offset(constraint.loc_key) + self.loc_db.get_location_offset(constraint.loc_key) for constraint in new_b.bto ) dis_block_callback(cur_bloc=new_b, @@ -919,8 +919,8 @@ def fix_expr_val(expr, symbols): # Example: # toto: # .dword label - loc_key = symbols.getby_name(e.name) - offset = symbols.loc_key_to_offset(loc_key) + loc_key = symbols.get_name_location(e.name) + offset = symbols.get_location_offset(loc_key) e = ExprInt(offset, e.size) return e result = expr.visit(expr_calc) @@ -936,10 +936,10 @@ def fix_loc_offset(loc_db, loc_key, offset, modified): to @modified @loc_db: current loc_db """ - loc_offset = loc_db.loc_key_to_offset(loc_key) + loc_offset = loc_db.get_location_offset(loc_key) if loc_offset == offset: return - loc_db.set_offset(loc_key, offset) + loc_db.set_location_offset(loc_key, offset, force=True) modified.add(loc_key) @@ -961,7 +961,7 @@ class BlockChain(object): self.pinned_block_idx = None for i, block in enumerate(self.blocks): loc_key = block.loc_key - if self.loc_db.loc_key_to_offset(loc_key) is not None: + if self.loc_db.get_location_offset(loc_key) is not None: if self.pinned_block_idx is not None: raise ValueError("Multiples pinned block detected") self.pinned_block_idx = i @@ -980,7 +980,7 @@ class BlockChain(object): return loc = self.blocks[self.pinned_block_idx].loc_key - offset_base = self.loc_db.loc_key_to_offset(loc) + offset_base = self.loc_db.get_location_offset(loc) assert(offset_base % self.blocks[self.pinned_block_idx].alignment == 0) self.offset_min = offset_base @@ -1009,7 +1009,7 @@ class BlockChain(object): # Propagate offset to blocks before pinned block pinned_block = self.blocks[self.pinned_block_idx] - offset = self.loc_db.loc_key_to_offset(pinned_block.loc_key) + offset = self.loc_db.get_location_offset(pinned_block.loc_key) if offset % pinned_block.alignment != 0: raise RuntimeError('Bad alignment') @@ -1022,7 +1022,7 @@ class BlockChain(object): modified_loc_keys) # Propagate offset to blocks after pinned block - offset = self.loc_db.loc_key_to_offset(pinned_block.loc_key) + pinned_block.size + offset = self.loc_db.get_location_offset(pinned_block.loc_key) + pinned_block.size last_block = pinned_block for block in self.blocks[self.pinned_block_idx + 1:]: @@ -1050,7 +1050,7 @@ class BlockChainWedge(object): def merge(self, chain): """Best effort merge two block chains Return the list of resulting blockchains""" - self.loc_db.set_offset(chain.blocks[0].loc_key, self.offset_max) + self.loc_db.set_location_offset(chain.blocks[0].loc_key, self.offset_max) chain.place() return [self, chain] @@ -1197,7 +1197,7 @@ def assemble_block(mnemo, block, loc_db, conservative=False): # Assemble an instruction saved_args = list(instr.args) - instr.offset = loc_db.loc_key_to_offset(block.loc_key) + offset_i + instr.offset = loc_db.get_location_offset(block.loc_key) + offset_i # Replace instruction's arguments by resolved ones instr.args = instr.resolve_args_with_symbols(loc_db) @@ -1297,7 +1297,7 @@ def asm_resolve_final(mnemo, asmcfg, loc_db, dst_interval=None): output_interval = interval() for block in asmcfg.blocks: - offset = loc_db.loc_key_to_offset(block.loc_key) + offset = loc_db.get_location_offset(block.loc_key) for instr in block.lines: if not instr.data: # Empty line @@ -1404,7 +1404,7 @@ class disasmEngine(object): delayslot_count = self.arch.delayslot offsets_to_dis = set() add_next_offset = False - loc_key = self.loc_db.getby_offset_create(offset) + loc_key = self.loc_db.get_or_create_offset_location(offset) cur_block = AsmBlock(loc_key) log_asmblock.debug("dis at %X", int(offset)) while not in_delayslot or delayslot_count > 0: @@ -1419,12 +1419,12 @@ class disasmEngine(object): else: # Block is not empty, stop the desassembly pass and add a # constraint to the next block - loc_key_cst = self.loc_db.getby_offset_create(offset) + loc_key_cst = self.loc_db.get_or_create_offset_location(offset) cur_block.add_cst(loc_key_cst, AsmConstraint.c_next) break if lines_cpt > 0 and offset in self.split_dis: - loc_key_cst = self.loc_db.getby_offset_create(offset) + loc_key_cst = self.loc_db.get_or_create_offset_location(offset) cur_block.add_cst(loc_key_cst, AsmConstraint.c_next) offsets_to_dis.add(offset) break @@ -1435,7 +1435,7 @@ class disasmEngine(object): break if offset in job_done: - loc_key_cst = self.loc_db.getby_offset_create(offset) + loc_key_cst = self.loc_db.get_or_create_offset_location(offset) cur_block.add_cst(loc_key_cst, AsmConstraint.c_next) break @@ -1462,7 +1462,7 @@ class disasmEngine(object): else: # Block is not empty, stop the desassembly pass and add a # constraint to the next block - loc_key_cst = self.loc_db.getby_offset_create(off_i) + loc_key_cst = self.loc_db.get_or_create_offset_location(off_i) cur_block.add_cst(loc_key_cst, AsmConstraint.c_next) break @@ -1475,7 +1475,7 @@ class disasmEngine(object): else: # Block is not empty, stop the desassembly pass and add a # constraint to the next block - loc_key_cst = self.loc_db.getby_offset_create(off_i) + loc_key_cst = self.loc_db.get_or_create_offset_location(off_i) cur_block.add_cst(loc_key_cst, AsmConstraint.c_next) break @@ -1505,7 +1505,7 @@ class disasmEngine(object): if not dst.is_loc(): continue loc_key = dst.loc_key - loc_key_offset = self.loc_db.loc_key_to_offset(loc_key) + loc_key_offset = self.loc_db.get_location_offset(loc_key) known_dsts.append(loc_key) if loc_key_offset in self.dont_dis_retcall_funcs: add_next_offset = False @@ -1517,11 +1517,11 @@ class disasmEngine(object): delayslot_count = instr.delayslot for c in cur_block.bto: - loc_key_offset = self.loc_db.loc_key_to_offset(c.loc_key) + loc_key_offset = self.loc_db.get_location_offset(c.loc_key) offsets_to_dis.add(loc_key_offset) if add_next_offset: - loc_key_cst = self.loc_db.getby_offset_create(offset) + loc_key_cst = self.loc_db.get_or_create_offset_location(offset) cur_block.add_cst(loc_key_cst, AsmConstraint.c_next) offsets_to_dis.add(offset) diff --git a/miasm2/core/cpu.py b/miasm2/core/cpu.py index 3b36c8d4..dc6fc392 100644 --- a/miasm2/core/cpu.py +++ b/miasm2/core/cpu.py @@ -1022,18 +1022,18 @@ class instruction(object): fixed_expr = {} for exprloc in loc_keys: loc_key = exprloc.loc_key - name = symbols.loc_key_to_name(loc_key) + names = symbols.get_location_names(loc_key) # special symbols - if name == '$': + if '$' in names: fixed_expr[exprloc] = self.get_asm_offset(exprloc) continue - if name == '_': + if '_' in names: fixed_expr[exprloc] = self.get_asm_next_offset(exprloc) continue - if symbols.getby_name(name) is None: + if not names: raise ValueError('Unresolved symbol: %r' % exprloc) - offset = symbols.loc_key_to_offset(loc_key) + offset = symbols.get_location_offset(loc_key) if offset is None: raise ValueError( 'The offset of loc_key "%s" cannot be determined' % name @@ -1534,7 +1534,7 @@ class cls_mn(object): args = [] for d in dst: if isinstance(d, m2_expr.ExprInt): - l = loc_db.getby_offset_create(int(d)) + l = loc_db.get_or_create_offset_location(int(d)) a = m2_expr.ExprId(l.name, d.size) else: diff --git a/miasm2/core/parse_asm.py b/miasm2/core/parse_asm.py index e40351cd..7efa17d0 100644 --- a/miasm2/core/parse_asm.py +++ b/miasm2/core/parse_asm.py @@ -67,7 +67,7 @@ def guess_next_new_label(loc_db): gen_name = "loc_%.8X" while True: name = gen_name % i - label = loc_db.getby_name(name) + label = loc_db.get_name_location(name) if label is None: return loc_db.add_location(name) i += 1 @@ -121,7 +121,7 @@ def parse_txt(mnemo, attrib, txt, loc_db=None): match_re = LABEL_RE.match(line) if match_re: label_name = match_re.group(1) - label = loc_db.getby_name_create(label_name) + label = loc_db.get_or_create_name_location(label_name) lines.append(label) continue # directive @@ -190,7 +190,7 @@ def parse_txt(mnemo, attrib, txt, loc_db=None): match_re = LABEL_RE.match(line) if match_re: label_name = match_re.group(1) - label = loc_db.getby_name_create(label_name) + label = loc_db.get_or_create_name_location(label_name) lines.append(label) continue diff --git a/miasm2/core/sembuilder.py b/miasm2/core/sembuilder.py index a6ec40f0..ab1af953 100644 --- a/miasm2/core/sembuilder.py +++ b/miasm2/core/sembuilder.py @@ -146,12 +146,12 @@ class SemBuilder(object): loc_end_expr = "loc_end_expr = ExprLoc(loc_end, ir.IRDst.size)" out = ast.parse(loc_end).body out += ast.parse(loc_end_expr).body - loc_if = "loc_if = ir.loc_db.gen_loc_key()" + loc_if = "loc_if = ir.loc_db.add_location()" loc_if_expr = "loc_if_expr = ExprLoc(loc_if, ir.IRDst.size)" out += ast.parse(loc_if).body out += ast.parse(loc_if_expr).body if loc_else: - loc_else = "loc_else = ir.loc_db.gen_loc_key()" + loc_else = "loc_else = ir.loc_db.add_location()" loc_else_expr = "loc_else_expr = ExprLoc(loc_else, ir.IRDst.size)" out += ast.parse(loc_else).body out += ast.parse(loc_else_expr).body diff --git a/miasm2/ir/ir.py b/miasm2/ir/ir.py index 234be181..8ee35ed5 100644 --- a/miasm2/ir/ir.py +++ b/miasm2/ir/ir.py @@ -357,7 +357,7 @@ class IRBlock(object): def __str__(self): out = [] - out.append('loc_key_%s' % self.loc_key.key) + out.append(str(self.loc_key)) for assignblk in self: for dst, src in assignblk.iteritems(): out.append('\t%s = %s' % (dst, src)) @@ -416,14 +416,23 @@ class DiGraphIR(DiGraph): if self.loc_db is None: name = str(expr) else: - name = self.loc_db.loc_key_to_name(expr.loc_key) + names = self.loc_db.get_location_names(expr.loc_key) + if not names: + name = self.loc_db.pretty_str(expr.loc_key) + else: + # Use only one name for readability + name = sorted(names)[0] return m2_expr.ExprId(name, expr.size) def node2lines(self, node): if self.loc_db is None: node_name = str(node) else: - node_name = self.loc_db.loc_key_to_name(node) + names = self.loc_db.get_location_names(node) + if not names: + node_name = self.loc_db.pretty_str(node) + else: + node_name = "".join("%s:\n" % name for name in names) yield self.DotCellDescription( text="%s" % node_name, attr={ @@ -530,7 +539,7 @@ class IntermediateRepresentation(object): except (ValueError, TypeError): return None - return self.loc_db.getby_offset_create(addr) + return self.loc_db.get_or_create_offset_location(addr) def get_block(self, addr): """Returns the irbloc associated to an ExprId/ExprInt/loc_key/int @@ -551,7 +560,7 @@ class IntermediateRepresentation(object): def add_instr(self, line, loc_key=None, gen_pc_updt=False): if loc_key is None: - loc_key = self.loc_db.gen_loc_key() + loc_key = self.loc_db.add_location() block = AsmBlock(loc_key) block.lines = [line] self.add_block(block, gen_pc_updt) @@ -687,9 +696,9 @@ class IntermediateRepresentation(object): if block.lines: line = block.lines[-1] if line.offset is not None: - loc_key = self.loc_db.getby_offset_create(line.offset + line.l) + loc_key = self.loc_db.get_or_create_offset_location(line.offset + line.l) if loc_key is None: - loc_key = self.loc_db.gen_loc_key() + loc_key = self.loc_db.add_location() block.add_cst(loc_key, AsmConstraint.c_next) else: loc_key = next_loc_key @@ -724,18 +733,18 @@ class IntermediateRepresentation(object): def get_loc_key_for_instr(self, instr): """Returns the loc_key associated to an instruction @instr: current instruction""" - return self.loc_db.getby_offset_create(instr.offset) + return self.loc_db.get_or_create_offset_location(instr.offset) def gen_loc_key_and_expr(self, size): """ Return a loc_key and it's corresponding ExprLoc @size: size of expression """ - loc_key = self.loc_db.gen_loc_key() + loc_key = self.loc_db.add_location() return loc_key, m2_expr.ExprLoc(loc_key, size) def get_next_loc_key(self, instr): - loc_key = self.loc_db.getby_offset_create(instr.offset + instr.l) + loc_key = self.loc_db.get_or_create_offset_location(instr.offset + instr.l) return loc_key def simplify(self, simplifier): @@ -825,7 +834,7 @@ class IntermediateRepresentation(object): self._graph.add_node(lbl) for dst in self.dst_trackback(block): if dst.is_int(): - dst_lbl = self.loc_db.getby_offset_create(int(dst)) + dst_lbl = self.loc_db.get_or_create_offset_location(int(dst)) dst = m2_expr.ExprLoc(dst_lbl.loc_key, self.pc.size) if dst.is_loc(): self._graph.add_edge(lbl, dst.loc_key) diff --git a/miasm2/ir/symbexec.py b/miasm2/ir/symbexec.py index 09113311..288a46e4 100644 --- a/miasm2/ir/symbexec.py +++ b/miasm2/ir/symbexec.py @@ -19,7 +19,7 @@ def get_block(ir_arch, mdis, addr): """Get IRBlock at address @addr""" lbl = ir_arch.get_loc_key(addr) if not lbl in ir_arch.blocks: - offset = mdis.loc_db.loc_key_to_offset(lbl) + offset = mdis.loc_db.get_location_offset(lbl) block = mdis.dis_block(offset) ir_arch.add_block(block) irblock = ir_arch.get_block(lbl) @@ -892,7 +892,7 @@ class SymbolicExecutionEngine(object): def eval_exprloc(self, expr, **kwargs): """[DEV]: Evaluate an ExprLoc using the current state""" - offset = self.ir_arch.loc_db.loc_key_to_offset(expr.loc_key) + offset = self.ir_arch.loc_db.get_location_offset(expr.loc_key) if offset is not None: ret = ExprInt(offset, expr.size) else: diff --git a/miasm2/ir/symbexec_top.py b/miasm2/ir/symbexec_top.py index e0976c9b..5fe12996 100644 --- a/miasm2/ir/symbexec_top.py +++ b/miasm2/ir/symbexec_top.py @@ -128,7 +128,7 @@ class SymbExecTopNoMem(SymbolicExecutionEngine): return ret def eval_exprloc(self, expr, **kwargs): - offset = self.ir_arch.loc_db.loc_key_to_offset(expr.loc_key) + offset = self.ir_arch.loc_db.get_location_offset(expr.loc_key) if offset is not None: ret = ExprInt(offset, expr.size) else: diff --git a/miasm2/ir/translators/C.py b/miasm2/ir/translators/C.py index 28222803..cafec7c8 100644 --- a/miasm2/ir/translators/C.py +++ b/miasm2/ir/translators/C.py @@ -55,7 +55,7 @@ class TranslatorC(Translator): if self.loc_db is None: return str(loc_key) - offset = self.loc_db.loc_key_to_offset(loc_key) + offset = self.loc_db.get_location_offset(loc_key) if offset is None: return str(loc_key) diff --git a/miasm2/ir/translators/smt2.py b/miasm2/ir/translators/smt2.py index f5e69163..1a513bfb 100644 --- a/miasm2/ir/translators/smt2.py +++ b/miasm2/ir/translators/smt2.py @@ -141,20 +141,13 @@ class TranslatorSMT2(Translator): def from_ExprLoc(self, expr): loc_key = expr.loc_key - if self.loc_db is None: + if self.loc_db is None or self.loc_db.get_location_offset(loc_key) is None: if str(loc_key) not in self._bitvectors: self._bitvectors[str(loc_key)] = expr.size return str(loc_key) - offset = self.loc_db.loc_key_to_offset(loc_key) - name = self.loc_db.loc_key_to_name(loc_key) - - if offset is None: - return bit_vec_val(str(offset), expr.size) - name = "|{}|".format(str(name)) - if name not in self._bitvectors: - self._bitvectors[name] = expr.size - return name + offset = self.loc_db.get_location_offset(loc_key) + return bit_vec_val(str(offset), expr.size) def from_ExprMem(self, expr): addr = self.from_expr(expr.arg) diff --git a/miasm2/ir/translators/z3_ir.py b/miasm2/ir/translators/z3_ir.py index bfb29d06..887c68d0 100644 --- a/miasm2/ir/translators/z3_ir.py +++ b/miasm2/ir/translators/z3_ir.py @@ -138,12 +138,9 @@ class TranslatorZ3(Translator): # No loc_db, fallback to default name return z3.BitVec(str(expr), expr.size) loc_key = expr.loc_key - offset = self.loc_db.loc_key_to_offset(loc_key) - name = self.loc_db.loc_key_to_name(loc_key) + offset = self.loc_db.get_location_offset(loc_key) if offset is not None: return z3.BitVecVal(offset, expr.size) - if name is not None: - return z3.BitVec(name, expr.size) # fallback to default name return z3.BitVec(str(loc_key), expr.size) diff --git a/miasm2/jitter/codegen.py b/miasm2/jitter/codegen.py index cf8f1711..10140fd2 100644 --- a/miasm2/jitter/codegen.py +++ b/miasm2/jitter/codegen.py @@ -143,7 +143,7 @@ class CGen(object): new_assignblk = dict(assignblk) if self.ir_arch.IRDst not in assignblk: offset = instr.offset + instr.l - loc_key = self.ir_arch.loc_db.getby_offset_create(offset) + loc_key = self.ir_arch.loc_db.get_or_create_offset_location(offset) dst = ExprLoc(loc_key, self.ir_arch.IRDst.size) new_assignblk[self.ir_arch.IRDst] = dst irs = [AssignBlock(new_assignblk, instr)] @@ -290,12 +290,12 @@ class CGen(object): "((%s)?(%s):(%s))" % (cond, src1b, src2b)) if isinstance(expr, ExprInt): offset = int(expr) - loc_key = self.ir_arch.loc_db.getby_offset_create(offset) + loc_key = self.ir_arch.loc_db.get_or_create_offset_location(offset) self.add_label_index(dst2index, loc_key) return ("%s" % dst2index[loc_key], hex(offset)) if expr.is_loc(): loc_key = expr.loc_key - offset = self.ir_arch.loc_db.loc_key_to_offset(expr.loc_key) + offset = self.ir_arch.loc_db.get_location_offset(expr.loc_key) if offset is not None: self.add_label_index(dst2index, loc_key) return ("%s" % dst2index[loc_key], hex(offset)) @@ -367,7 +367,7 @@ class CGen(object): return out assert isinstance(dst, LocKey) - offset = self.ir_arch.loc_db.loc_key_to_offset(dst) + offset = self.ir_arch.loc_db.get_location_offset(dst) if offset is None: # Generate goto for local labels return ['goto %s;' % dst] @@ -518,7 +518,7 @@ class CGen(object): last_instr = block.lines[-1] offset = last_instr.offset + last_instr.l - return self.ir_arch.loc_db.getby_offset_create(offset) + return self.ir_arch.loc_db.get_or_create_offset_location(offset) def gen_init(self, block): """ @@ -528,7 +528,7 @@ class CGen(object): instr_offsets = [line.offset for line in block.lines] post_label = self.get_block_post_label(block) - post_offset = self.ir_arch.loc_db.loc_key_to_offset(post_label) + post_offset = self.ir_arch.loc_db.get_location_offset(post_label) instr_offsets.append(post_offset) lbl_start = block.loc_key return (self.CODE_INIT % lbl_start).split("\n"), instr_offsets @@ -564,7 +564,7 @@ class CGen(object): """ loc_key = self.get_block_post_label(block) - offset = self.ir_arch.loc_db.loc_key_to_offset(loc_key) + offset = self.ir_arch.loc_db.get_location_offset(loc_key) dst = self.dst_to_c(offset) code = self.CODE_RETURN_NO_EXCEPTION % (loc_key, self.C_PC, dst, dst) return code.split('\n') diff --git a/miasm2/jitter/jitcore.py b/miasm2/jitter/jitcore.py index 8084fe56..a26d4c9f 100644 --- a/miasm2/jitter/jitcore.py +++ b/miasm2/jitter/jitcore.py @@ -101,7 +101,7 @@ class JitCore(object): cur_block.ad_max = cur_block.lines[-1].offset + cur_block.lines[-1].l else: # 1 byte block for unknown mnemonic - offset = ir_arch.loc_db.loc_key_to_offset(cur_block.loc_key) + offset = ir_arch.loc_db.get_location_offset(cur_block.loc_key) cur_block.ad_min = offset cur_block.ad_max = offset+1 @@ -138,7 +138,7 @@ class JitCore(object): # Get the block if isinstance(addr, LocKey): - addr = self.ir_arch.loc_db.loc_key_to_offset(addr) + addr = self.ir_arch.loc_db.get_location_offset(addr) if addr is None: raise RuntimeError("Unknown offset for LocKey") @@ -253,13 +253,13 @@ class JitCore(object): try: for irblock in block.blocks: # Remove offset -> jitted block link - offset = self.ir_arch.loc_db.loc_key_to_offset(irblock.loc_key) + offset = self.ir_arch.loc_db.get_location_offset(irblock.loc_key) if offset in self.offset_to_jitted_func: del(self.offset_to_jitted_func[offset]) except AttributeError: # The block has never been translated in IR - offset = self.ir_arch.loc_db.loc_key_to_offset(block.loc_key) + offset = self.ir_arch.loc_db.get_location_offset(block.loc_key) if offset in self.offset_to_jitted_func: del(self.offset_to_jitted_func[offset]) @@ -293,7 +293,7 @@ class JitCore(object): @block: asmblock """ block_raw = "".join(line.b for line in block.lines) - offset = self.ir_arch.loc_db.loc_key_to_offset(block.loc_key) + offset = self.ir_arch.loc_db.get_location_offset(block.loc_key) block_hash = md5("%X_%s_%s_%s_%s" % (offset, self.arch_name, self.log_mn, diff --git a/miasm2/jitter/jitcore_gcc.py b/miasm2/jitter/jitcore_gcc.py index c7ffdd01..dbaa2a08 100644 --- a/miasm2/jitter/jitcore_gcc.py +++ b/miasm2/jitter/jitcore_gcc.py @@ -28,7 +28,7 @@ class JitCore_Gcc(JitCore_Cc_Base): lib = ctypes.cdll.LoadLibrary(fname_so) func = getattr(lib, self.FUNCNAME) addr = ctypes.cast(func, ctypes.c_void_p).value - offset = self.ir_arch.loc_db.loc_key_to_offset(label) + offset = self.ir_arch.loc_db.get_location_offset(label) self.offset_to_jitted_func[offset] = addr self.states[offset] = lib diff --git a/miasm2/jitter/jitcore_llvm.py b/miasm2/jitter/jitcore_llvm.py index 397c73f9..ea4f20ec 100644 --- a/miasm2/jitter/jitcore_llvm.py +++ b/miasm2/jitter/jitcore_llvm.py @@ -118,5 +118,5 @@ class JitCore_LLVM(jitcore.JitCore): # Store a pointer on the function jitted code loc_key = block.loc_key - offset = self.ir_arch.loc_db.loc_key_to_offset(loc_key) + offset = self.ir_arch.loc_db.get_location_offset(loc_key) self.offset_to_jitted_func[offset] = ptr diff --git a/miasm2/jitter/jitcore_python.py b/miasm2/jitter/jitcore_python.py index 5ca07c38..fa751a68 100644 --- a/miasm2/jitter/jitcore_python.py +++ b/miasm2/jitter/jitcore_python.py @@ -127,7 +127,7 @@ class JitCore_Python(jitcore.JitCore): raise NotImplementedError("Type not handled: %s" % ad) # Associate myfunc with current loc_key - offset = self.ir_arch.loc_db.loc_key_to_offset(loc_key) + offset = self.ir_arch.loc_db.get_location_offset(loc_key) assert offset is not None self.offset_to_jitted_func[offset] = myfunc diff --git a/miasm2/jitter/llvmconvert.py b/miasm2/jitter/llvmconvert.py index 09aafa71..d63351cc 100644 --- a/miasm2/jitter/llvmconvert.py +++ b/miasm2/jitter/llvmconvert.py @@ -625,7 +625,7 @@ class LLVMFunction(): return ret if expr.is_loc(): - offset = self.llvm_context.ir_arch.loc_db.loc_key_to_offset(expr.loc_key) + offset = self.llvm_context.ir_arch.loc_db.get_location_offset(expr.loc_key) ret = llvm_ir.Constant(LLVMType.IntType(expr.size), offset) self.update_cache(expr, ret) return ret @@ -1099,13 +1099,13 @@ class LLVMFunction(): self.main_stream = False if isinstance(dst, ExprInt): - loc_key = self.llvm_context.ir_arch.loc_db.getby_offset_create(int(dst)) + loc_key = self.llvm_context.ir_arch.loc_db.get_or_create_offset_location(int(dst)) dst = ExprLoc(loc_key, dst.size) if isinstance(dst, ExprLoc): loc_key = dst.loc_key bbl = self.get_basic_block_by_loc_key(loc_key) - offset = self.llvm_context.ir_arch.loc_db.loc_key_to_offset(loc_key) + offset = self.llvm_context.ir_arch.loc_db.get_location_offset(loc_key) if bbl is not None: # "local" jump, inside this function if offset is None: @@ -1234,7 +1234,7 @@ class LLVMFunction(): ExprId("status", 32)) self.affect(t_size(m2_csts.EXCEPT_UNK_MNEMO), m2_exception_flag) - offset = self.llvm_context.ir_arch.loc_db.loc_key_to_offset(asmblock.loc_key) + offset = self.llvm_context.ir_arch.loc_db.get_location_offset(asmblock.loc_key) self.set_ret(LLVMType.IntType(64)(offset)) def gen_finalize(self, asmblock, codegen): @@ -1280,7 +1280,7 @@ class LLVMFunction(): # Else Block builder.position_at_end(else_block) PC = self.llvm_context.PC - next_label_offset = self.llvm_context.ir_arch.loc_db.loc_key_to_offset(next_label) + next_label_offset = self.llvm_context.ir_arch.loc_db.get_location_offset(next_label) to_ret = LLVMType.IntType(PC.size)(next_label_offset) self.affect(to_ret, PC) self.set_ret(to_ret) @@ -1317,7 +1317,7 @@ class LLVMFunction(): # Create basic blocks (for label branchs) entry_bbl, builder = self.entry_bbl, self.builder for instr in asmblock.lines: - lbl = self.llvm_context.ir_arch.loc_db.getby_offset_create(instr.offset) + lbl = self.llvm_context.ir_arch.loc_db.get_or_create_offset_location(instr.offset) self.append_basic_block(lbl) # TODO: merge duplicate code with CGen @@ -1333,7 +1333,7 @@ class LLVMFunction(): default_value=eltype(0)) self.local_vars_pointers[element.name] = ptr loc_key = codegen.get_block_post_label(asmblock) - offset = self.llvm_context.ir_arch.loc_db.loc_key_to_offset(loc_key) + offset = self.llvm_context.ir_arch.loc_db.get_location_offset(loc_key) instr_offsets.append(offset) self.append_basic_block(loc_key) diff --git a/test/analysis/depgraph.py b/test/analysis/depgraph.py index a7d3a148..f0772cca 100644 --- a/test/analysis/depgraph.py +++ b/test/analysis/depgraph.py @@ -100,79 +100,6 @@ class IRATest(ira): return set([self.ret_reg, self.sp]) -def bloc2graph(irgraph, label=False, lines=True): - """Render dot graph of @blocks""" - - escape_chars = re.compile('[' + re.escape('{}') + ']') - label_attr = 'colspan="2" align="center" bgcolor="grey"' - edge_attr = 'label = "%s" color="%s" style="bold"' - td_attr = 'align="left"' - block_attr = 'shape="Mrecord" fontname="Courier New"' - - out = ["digraph asm_graph {"] - fix_chars = lambda x: '\\' + x.group() - - # Generate basic blocks - out_blocks = [] - for label in irgraph.graph.nodes(): - if isinstance(label, LocKey): - label_name = irgraph.loc_db.loc_key_to_name(label) - else: - label_name = str(label) - - if hasattr(irgraph, 'blocks'): - irblock = irgraph.blocks[label] - else: - irblock = None - if isinstance(label, LocKey): - out_block = '%s [\n' % label_name - else: - out_block = '%s [\n' % label - out_block += "%s " % block_attr - out_block += 'label =<<table border="0" cellborder="0" cellpadding="3">' - - block_label = '<tr><td %s>%s</td></tr>' % ( - label_attr, label_name) - block_html_lines = [] - if lines and irblock is not None: - for assignblk in irblock: - for dst, src in assignblk.iteritems(): - if False: - out_render = "%.8X</td><td %s> " % (0, td_attr) - else: - out_render = "" - out_render += escape_chars.sub(fix_chars, "%s = %s" % (dst, src)) - block_html_lines.append(out_render) - block_html_lines.append(" ") - block_html_lines.pop() - block_html_lines = ('<tr><td %s>' % td_attr + - ('</td></tr><tr><td %s>' % td_attr).join(block_html_lines) + - '</td></tr>') - out_block += "%s " % block_label - out_block += block_html_lines + "</table>> ];" - out_blocks.append(out_block) - - out += out_blocks - # Generate links - for src, dst in irgraph.graph.edges(): - if isinstance(src, LocKey): - src_name = irgraph.loc_db.loc_key_to_name(src) - else: - src_name = str(src) - if isinstance(dst, LocKey): - dst_name = irgraph.loc_db.loc_key_to_name(dst) - else: - dst_name = str(dst) - - edge_color = "black" - out.append('%s -> %s' % (src_name, - dst_name) + - '[' + edge_attr % ("", edge_color) + '];') - - out.append("}") - return '\n'.join(out) - - def dg2graph(graph, label=False, lines=True): """Render dot graph of @blocks""" @@ -189,7 +116,7 @@ def dg2graph(graph, label=False, lines=True): out_blocks = [] for node in graph.nodes(): if isinstance(node, DependencyNode): - name = loc_db.loc_key_to_name(node.loc_key) + name = loc_db.pretty_str(node.loc_key) node_name = "%s %s %s" % (name, node.element, node.line_nb) @@ -642,7 +569,7 @@ def flatNode(node): element = int(node.element.arg) else: RuntimeError("Unsupported type '%s'" % type(enode.element)) - name = loc_db.loc_key_to_name(node.loc_key) + name = loc_db.pretty_str(node.loc_key) return (name, element, node.line_nb) @@ -741,7 +668,7 @@ def match_results(resultsA, resultsB, nodes): def get_flat_init_depnodes(depnodes): out = [] for node in depnodes: - name = loc_db.loc_key_to_name(node.loc_key) + name = loc_db.pretty_str(node.loc_key) out.append((name, node.element.name, node.line_nb, @@ -1026,7 +953,6 @@ for test_nb, test in enumerate([(G1_IRA, G1_INPUT), g_ira, (depnodes, heads) = test open("graph_%02d.dot" % (test_nb + 1), "w").write(g_ira.graph.dot()) - open("graph_%02d.dot" % (test_nb + 1), "w").write(bloc2graph(g_ira)) # Different options suffix_key_list = ["", "_nosimp", "_nomem", "_nocall", diff --git a/test/analysis/dse.py b/test/analysis/dse.py index 56de4d4e..a05d8595 100644 --- a/test/analysis/dse.py +++ b/test/analysis/dse.py @@ -77,7 +77,7 @@ class DSETest(object): ) # fix shellcode addr - loc_db.set_offset(loc_db.getby_name("main"), 0x0) + loc_db.set_location_offset(loc_db.get_name_location("main"), 0x0) output = StrPatchwork() patches = asm_resolve_final(mn_x86, blocks, loc_db) for offset, raw in patches.items(): diff --git a/test/arch/aarch64/unit/asm_test.py b/test/arch/aarch64/unit/asm_test.py index d3221ec0..677d474f 100644 --- a/test/arch/aarch64/unit/asm_test.py +++ b/test/arch/aarch64/unit/asm_test.py @@ -25,7 +25,7 @@ class Asm_Test(object): blocks, loc_db = parse_asm.parse_txt(mn_aarch64, 'l', self.TXT, loc_db = self.myjit.ir_arch.loc_db) # fix shellcode addr - loc_db.set_offset(loc_db.getby_name("main"), 0x0) + loc_db.set_location_offset(loc_db.get_name_location("main"), 0x0) s = StrPatchwork() patches = asmblock.asm_resolve_final(mn_aarch64, blocks, loc_db) for offset, raw in patches.items(): diff --git a/test/arch/mips32/unit/asm_test.py b/test/arch/mips32/unit/asm_test.py index be26bf49..da792874 100644 --- a/test/arch/mips32/unit/asm_test.py +++ b/test/arch/mips32/unit/asm_test.py @@ -27,7 +27,7 @@ class Asm_Test(object): blocks, loc_db = parse_asm.parse_txt(mn_mips32, 'l', self.TXT, loc_db=self.myjit.ir_arch.loc_db) # fix shellcode addr - loc_db.set_offset(loc_db.getby_name("main"), 0x0) + loc_db.set_location_offset(loc_db.get_name_location("main"), 0x0) s = StrPatchwork() patches = asmblock.asm_resolve_final(mn_mips32, blocks, loc_db) for offset, raw in patches.items(): diff --git a/test/arch/x86/sem.py b/test/arch/x86/sem.py index 23b22245..a2493d12 100755 --- a/test/arch/x86/sem.py +++ b/test/arch/x86/sem.py @@ -49,10 +49,10 @@ def compute(ir, mode, asm, inputstate={}, debug=False): def compute_txt(ir, mode, txt, inputstate={}, debug=False): asmcfg, loc_db = parse_asm.parse_txt(mn, mode, txt) - loc_db.set_offset(loc_db.getby_name("main"), 0x0) + loc_db.set_location_offset(loc_db.get_name_location("main"), 0x0) patches = asmblock.asm_resolve_final(mn, asmcfg, loc_db) interm = ir(loc_db) - lbl = loc_db.getby_name("main") + lbl = loc_db.get_name_location("main") for bbl in asmcfg.blocks: interm.add_block(bbl) return symb_exec(lbl, interm, inputstate, debug) diff --git a/test/arch/x86/unit/asm_test.py b/test/arch/x86/unit/asm_test.py index e626768d..91da1942 100644 --- a/test/arch/x86/unit/asm_test.py +++ b/test/arch/x86/unit/asm_test.py @@ -43,7 +43,7 @@ class Asm_Test(object): blocks, loc_db = parse_asm.parse_txt(mn_x86, self.arch_attrib, self.TXT, loc_db = self.myjit.ir_arch.loc_db) # fix shellcode addr - loc_db.set_offset(loc_db.getby_name("main"), 0x0) + loc_db.set_location_offset(loc_db.get_name_location("main"), 0x0) s = StrPatchwork() patches = asmblock.asm_resolve_final(mn_x86, blocks, loc_db) for offset, raw in patches.items(): diff --git a/test/arch/x86/unit/mn_strings.py b/test/arch/x86/unit/mn_strings.py index a6facd08..8ca148e5 100755 --- a/test/arch/x86/unit/mn_strings.py +++ b/test/arch/x86/unit/mn_strings.py @@ -21,8 +21,8 @@ class Test_SCAS(Asm_Test_32): def check(self): assert(self.myjit.cpu.ECX == len(self.MYSTRING)) - mystr = self.myjit.ir_arch.loc_db.getby_name('mystr') - assert(self.myjit.cpu.EDI == self.myjit.ir_arch.loc_db.loc_key_to_offset(mystr) + len(self.MYSTRING)+1) + mystr = self.myjit.ir_arch.loc_db.get_name_location('mystr') + assert(self.myjit.cpu.EDI == self.myjit.ir_arch.loc_db.get_location_offset(mystr) + len(self.MYSTRING)+1) class Test_MOVS(Asm_Test_32): @@ -43,10 +43,10 @@ class Test_MOVS(Asm_Test_32): def check(self): assert(self.myjit.cpu.ECX == 0) - buffer = self.myjit.ir_arch.loc_db.getby_name('buffer') - assert(self.myjit.cpu.EDI == self.myjit.ir_arch.loc_db.loc_key_to_offset(buffer) + len(self.MYSTRING)) - mystr = self.myjit.ir_arch.loc_db.getby_name('mystr') - assert(self.myjit.cpu.ESI == self.myjit.ir_arch.loc_db.loc_key_to_offset(mystr) + len(self.MYSTRING)) + buffer = self.myjit.ir_arch.loc_db.get_name_location('buffer') + assert(self.myjit.cpu.EDI == self.myjit.ir_arch.loc_db.get_location_offset(buffer) + len(self.MYSTRING)) + mystr = self.myjit.ir_arch.loc_db.get_name_location('mystr') + assert(self.myjit.cpu.ESI == self.myjit.ir_arch.loc_db.get_location_offset(mystr) + len(self.MYSTRING)) if __name__ == "__main__": diff --git a/test/core/asmblock.py b/test/core/asmblock.py index 465697f4..cd1d262a 100644 --- a/test/core/asmblock.py +++ b/test/core/asmblock.py @@ -105,7 +105,7 @@ open("graph2.dot", "w").write(asmcfg.dot()) # Test helper methods ## loc_key_to_block should always be updated assert asmcfg.loc_key_to_block(first_block.loc_key) == first_block -testlabel = mdis.loc_db.getby_name_create("testlabel") +testlabel = mdis.loc_db.get_or_create_name_location("testlabel") my_block = AsmBlock(testlabel) asmcfg.add_block(my_block) assert len(asmcfg) == 3 @@ -116,7 +116,7 @@ assert asmcfg.loc_key_to_block(my_block.loc_key) == my_block assert len(list(asmcfg.get_bad_blocks())) == 0 assert len(list(asmcfg.get_bad_blocks_predecessors())) == 0 ### Add a bad block, not linked -testlabel_bad = mdis.loc_db.getby_name_create("testlabel_bad") +testlabel_bad = mdis.loc_db.get_or_create_name_location("testlabel_bad") my_bad_block = AsmBlockBad(testlabel_bad) asmcfg.add_block(my_bad_block) assert list(asmcfg.get_bad_blocks()) == [my_bad_block] @@ -135,7 +135,7 @@ assert len(list(asmcfg.get_bad_blocks_predecessors(strict=True))) == 0 ## Sanity check asmcfg.sanity_check() ### Next on itself -testlabel_nextitself = mdis.loc_db.getby_name_create("testlabel_nextitself") +testlabel_nextitself = mdis.loc_db.get_or_create_name_location("testlabel_nextitself") my_block_ni = AsmBlock(testlabel_nextitself) my_block_ni.bto.add(AsmConstraintNext(my_block_ni.loc_key)) asmcfg.add_block(my_block_ni) @@ -149,11 +149,11 @@ assert error_raised asmcfg.del_block(my_block_ni) asmcfg.sanity_check() ### Multiple next on the same node -testlabel_target = mdis.loc_db.getby_name_create("testlabel_target") +testlabel_target = mdis.loc_db.get_or_create_name_location("testlabel_target") my_block_target = AsmBlock(testlabel_target) asmcfg.add_block(my_block_target) -testlabel_src1 = mdis.loc_db.getby_name_create("testlabel_src1") -testlabel_src2 = mdis.loc_db.getby_name_create("testlabel_src2") +testlabel_src1 = mdis.loc_db.get_or_create_name_location("testlabel_src1") +testlabel_src2 = mdis.loc_db.get_or_create_name_location("testlabel_src2") my_block_src1 = AsmBlock(testlabel_src1) my_block_src2 = AsmBlock(testlabel_src2) my_block_src1.bto.add(AsmConstraintNext(my_block_target.loc_key)) @@ -184,8 +184,8 @@ assert asmcfg.loc_key_to_block(my_block_src1.loc_key).max_size == 0 ## Check pendings ### Create a pending element -testlabel_pend_src = mdis.loc_db.getby_name_create("testlabel_pend_src") -testlabel_pend_dst = mdis.loc_db.getby_name_create("testlabel_pend_dst") +testlabel_pend_src = mdis.loc_db.get_or_create_name_location("testlabel_pend_src") +testlabel_pend_dst = mdis.loc_db.get_or_create_name_location("testlabel_pend_dst") my_block_src = AsmBlock(testlabel_pend_src) my_block_dst = AsmBlock(testlabel_pend_dst) my_block_src.bto.add(AsmConstraintTo(my_block_dst.loc_key)) @@ -247,7 +247,7 @@ assert len(entry_block.lines) == 4 assert map(str, entry_block.lines) == ['XOR EAX, EAX', 'XOR EBX, EBX', 'XOR ECX, ECX', - 'JNZ loc_3'] + 'JNZ loc_key_3'] assert len(asmcfg.successors(entry_block.loc_key)) == 2 assert len(entry_block.bto) == 2 nextb = asmcfg.loc_key_to_block((cons.loc_key for cons in entry_block.bto @@ -258,11 +258,11 @@ assert len(nextb.lines) == 4 assert map(str, nextb.lines) == ['XOR EDX, EDX', 'XOR ESI, ESI', 'XOR EDI, EDI', - 'JMP loc_4'] + 'JMP loc_key_4'] assert asmcfg.successors(nextb.loc_key) == [nextb.loc_key] assert len(tob.lines) == 2 assert map(str, tob.lines) == ['XOR EBP, EBP', - 'JMP loc_3'] + 'JMP loc_key_3'] assert asmcfg.successors(tob.loc_key) == [tob.loc_key] # Check split_block @@ -272,7 +272,7 @@ asmcfg.apply_splitting(mdis.loc_db) assert asmcfg_bef == asmcfg open("graph5.dot", "w").write(asmcfg.dot()) ## Create conditions for a block split -inside_firstbbl = mdis.loc_db.getby_offset(4) +inside_firstbbl = mdis.loc_db.get_offset_location(4) tob.bto.add(AsmConstraintTo(inside_firstbbl)) asmcfg.rebuild_edges() assert len(asmcfg.pendings) == 1 @@ -289,7 +289,7 @@ lbl_newb = asmcfg.successors(entry_block.loc_key)[0] newb = asmcfg.loc_key_to_block(lbl_newb) assert len(newb.lines) == 2 assert map(str, newb.lines) == ['XOR ECX, ECX', - 'JNZ loc_3'] + 'JNZ loc_key_3'] preds = asmcfg.predecessors(lbl_newb) assert len(preds) == 2 assert entry_block.loc_key in preds @@ -322,10 +322,10 @@ solutions = list(matcher.match(asmcfg)) assert len(solutions) == 1 solution = solutions.pop() for jbbl, label in solution.iteritems(): - offset = mdis.loc_db.loc_key_to_offset(label) + offset = mdis.loc_db.get_location_offset(label) assert offset == int(jbbl._name, 16) -loc_key_dum = mdis.loc_db.getby_name_create("dummy_loc") +loc_key_dum = mdis.loc_db.get_or_create_name_location("dummy_loc") asmcfg.add_node(loc_key_dum) error_raised = False try: diff --git a/test/core/parse_asm.py b/test/core/parse_asm.py index e8d5adc5..ddb195d2 100755 --- a/test/core/parse_asm.py +++ b/test/core/parse_asm.py @@ -70,9 +70,9 @@ class TestParseAsm(unittest.TestCase): loc_db) lbls = [] for i in xrange(6): - lbls.append(loc_db.getby_name('lbl%d' % i)) + lbls.append(loc_db.get_name_location('lbl%d' % i)) # align test - offset = loc_db.loc_key_to_offset(lbls[5]) + offset = loc_db.get_location_offset(lbls[5]) assert(offset % 0x10 == 0) lbl2block = {} for block in asmcfg.blocks: @@ -98,7 +98,7 @@ class TestParseAsm(unittest.TestCase): asmcfg, loc_db = parse_txt(mn_x86, 32, ASM0) lbls = [] for i in xrange(2): - lbls.append(loc_db.getby_name('lbl%d' % i)) + lbls.append(loc_db.get_name_location('lbl%d' % i)) lbl2block = {} for block in asmcfg.blocks: lbl2block[block.loc_key] = block |