diff options
| author | serpilliere <devnull@localhost> | 2012-12-12 16:33:27 +0100 |
|---|---|---|
| committer | serpilliere <devnull@localhost> | 2012-12-12 16:33:27 +0100 |
| commit | c2c6d796c11bddf96d45fac97438b4e2279ac684 (patch) | |
| tree | 1f367f6e3a99794e5c9d79cfa2d5430a37e50bb5 | |
| parent | 73b7b278452798b37524d9f2ca6c4f7d29945e14 (diff) | |
| download | miasm-c2c6d796c11bddf96d45fac97438b4e2279ac684.tar.gz miasm-c2c6d796c11bddf96d45fac97438b4e2279ac684.zip | |
asmbloc: try to keep original mnemonic if disasm/reasm code (louis granboulan)
| -rw-r--r-- | miasm/core/asmbloc.py | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/miasm/core/asmbloc.py b/miasm/core/asmbloc.py index e3110697..31412fb2 100644 --- a/miasm/core/asmbloc.py +++ b/miasm/core/asmbloc.py @@ -830,6 +830,19 @@ def calc_symbol_offset(symbol_pool): s_to_use.add(l) +def conservative_asm(mnemo, instr, symbol_off = []): + candidates = mnemo.asm(str(instr), symbol_off) + if not candidates: + raise ValueError('cannot asm:%s'%str(instr)) + if not hasattr(instr, "b"): + return candidates[0], candidates + if instr.b in candidates: + return instr.b, candidates + for c in candidates: + if len(c) == len(instr.b): + return c, candidates + return candidates[0], candidates + def asmbloc(mnemo, all_blocs): #compute max bloc len for b in all_blocs: @@ -844,18 +857,11 @@ def asmbloc(mnemo, all_blocs): testing_arg = [mnemo.fix_symbol(a) for a in instr.arg] sav_a = instr.arg instr.arg = testing_arg - candidates=mnemo.asm(str(instr)) - if not candidates: - raise ValueError('cannot asm:%s'%str(instr)) + c, candidates = conservative_asm(mnemo, instr) instr.arg = sav_a - - c = candidates[0] blen_max+= len(candidates[-1])-len(candidates[0]) else: - candidates=mnemo.asm(str(instr)) - if not candidates: - raise ValueError('cannot asm:%s'%str(instr)) - c = candidates[0] + c, candidates = conservative_asm(mnemo, instr) log_asmbloc.debug(instr) log_asmbloc.debug(candidates) log_asmbloc.debug(repr(c)) @@ -904,10 +910,7 @@ def asmbloc_final(mnemo, all_blocs, symbol_pool, symb_reloc_off = {}): else: instr.arg = [mnemo.fix_symbol(a, symbol_pool) for a in instr.arg] symbol_reloc_off = [] - candidates=mnemo.asm(str(instr), symbol_reloc_off) - if not candidates: - raise ValueError('cannot asm:%s'%str(instr)) - c = candidates[0] + c, candidates = conservative_asm(mnemo, instr, symbol_reloc_off) instr.arg = sav_a if len(c)>len(instr.data): #good len, bad offset...XXX |