diff options
| author | serpilliere <serpilliere@users.noreply.github.com> | 2015-01-26 10:04:24 +0100 |
|---|---|---|
| committer | serpilliere <serpilliere@users.noreply.github.com> | 2015-01-26 10:04:24 +0100 |
| commit | b87f775c1a6a5c78c62beee925eaba6dc337577e (patch) | |
| tree | cf2650f575971bf8a23655a28c944e9e8a9da561 /example/asm/simple.py | |
| parent | c59591a779ac644d1b50a720aea93cd8b36a2ddf (diff) | |
| parent | 7b9bbe4754db4d1f5229cc5cc5769ad6cf2e0a84 (diff) | |
| download | focaccia-miasm-b87f775c1a6a5c78c62beee925eaba6dc337577e.tar.gz focaccia-miasm-b87f775c1a6a5c78c62beee925eaba6dc337577e.zip | |
Merge pull request #45 from commial/refactor-examples
Refactor examples
Diffstat (limited to 'example/asm/simple.py')
| -rw-r--r-- | example/asm/simple.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/example/asm/simple.py b/example/asm/simple.py new file mode 100644 index 00000000..1ae3ae05 --- /dev/null +++ b/example/asm/simple.py @@ -0,0 +1,37 @@ +from pdb import pm +from pprint import pprint + +from miasm2.arch.x86.arch import mn_x86 +from miasm2.core import parse_asm, asmbloc +import miasm2.expression.expression as m2_expr +from miasm2.core import asmbloc + + +# Assemble code +blocs, symbol_pool = parse_asm.parse_txt(mn_x86, 32, ''' +main: + MOV EAX, 1 + MOV EBX, 2 + MOV ECX, 2 + MOV DX, 2 + +loop: + INC EBX + CMOVZ EAX, EBX + ADD EAX, ECX + JZ loop + RET +''') + +# Set 'main' label's offset +symbol_pool.set_offset(symbol_pool.getby_name("main"), 0x0) + +# Spread information and resolve instructions offset +resolved_b, patches = asmbloc.asm_resolve_final(mn_x86, blocs[0], symbol_pool) + +# Show resolved blocs +for bloc, dummy in resolved_b: + print bloc + +# Print offset -> bytes +pprint(patches) |