diff options
| author | Ajax <commial@gmail.com> | 2015-11-09 14:34:15 +0100 |
|---|---|---|
| committer | Ajax <commial@gmail.com> | 2015-11-09 14:34:15 +0100 |
| commit | 26ec3c0b272038e0130b8fc7c9c322b5ab20f2be (patch) | |
| tree | 024453cdd6aabef43451a1149ef85f88c18c87d5 /example/disasm/callback.py | |
| parent | 544273b1d41bccb95c882acb52b198c33d8c3ab1 (diff) | |
| download | miasm-26ec3c0b272038e0130b8fc7c9c322b5ab20f2be.tar.gz miasm-26ec3c0b272038e0130b8fc7c9c322b5ab20f2be.zip | |
Example/Disasm/Callback: comment and update with new API
Diffstat (limited to 'example/disasm/callback.py')
| -rw-r--r-- | example/disasm/callback.py | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/example/disasm/callback.py b/example/disasm/callback.py index 9c443e17..6c77023e 100644 --- a/example/disasm/callback.py +++ b/example/disasm/callback.py @@ -1,6 +1,5 @@ from miasm2.core.bin_stream import bin_stream_str -from miasm2.core.asmbloc import asm_constraint, asm_label -from miasm2.expression.expression import ExprId +from miasm2.core.asmbloc import asm_label, asm_constraint, expr_is_label from miasm2.arch.x86.disasm import dis_x86_32, cb_x86_funcs @@ -15,17 +14,25 @@ def cb_x86_callpop(cur_bloc, symbol_pool, *args, **kwargs): 1005: pop """ + # Pattern matching if len(cur_bloc.lines) < 1: return - l = cur_bloc.lines[-1] - if l.name != 'CALL': + ## We want to match a CALL, always the last line of a basic block + last_instr = cur_bloc.lines[-1] + if last_instr.name != 'CALL': return - dst = l.args[0] - if not (isinstance(dst, ExprId) and isinstance(dst.name, asm_label)): + ## The destination must be a label + dst = last_instr.args[0] + if not expr_is_label(dst): return - if dst.name.offset != l.offset + l.l: + ## The destination must be the next instruction + if dst.name.offset != last_instr.offset + last_instr.l: return - l.name = 'PUSH' + + # Update instruction instance + last_instr.name = 'PUSH' + + # Update next blocks to process in the disassembly engine cur_bloc.bto.clear() cur_bloc.add_cst(dst.name.offset, asm_constraint.c_next, symbol_pool) |