diff options
| -rw-r--r-- | example/asm/simple.py | 37 | ||||
| -rw-r--r-- | test/test_all.py | 3 |
2 files changed, 40 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) diff --git a/test/test_all.py b/test/test_all.py index 70ab8e66..5de12bf4 100644 --- a/test/test_all.py +++ b/test/test_all.py @@ -97,6 +97,9 @@ class ExampleAssembler(Example): """ example_dir = "asm" + +testset += ExampleAssembler(["simple.py"]) + class ExampleShellcode(ExampleAssembler): """Specificities: - script: asm/shellcode.py |