diff options
| author | Camille Mougey <camille.mougey@cea.fr> | 2015-01-26 09:53:30 +0100 |
|---|---|---|
| committer | Camille Mougey <camille.mougey@cea.fr> | 2015-01-26 09:53:30 +0100 |
| commit | 7b9bbe4754db4d1f5229cc5cc5769ad6cf2e0a84 (patch) | |
| tree | 32ee3dbcbfa9d74df96a9bd1bfece6591a145bd1 /example/asm/simple.py | |
| parent | 4ed9736a17347662a89997f6e2afa1d09af7d3ab (diff) | |
| download | miasm-7b9bbe4754db4d1f5229cc5cc5769ad6cf2e0a84.tar.gz miasm-7b9bbe4754db4d1f5229cc5cc5769ad6cf2e0a84.zip | |
Example/ASM: Add a minimalist example
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) |