about summary refs log tree commit diff stats
path: root/example/asm_box_x86_32.py
diff options
context:
space:
mode:
authorCamille Mougey <camille.mougey@cea.fr>2015-01-06 17:35:50 +0100
committerCamille Mougey <camille.mougey@cea.fr>2015-01-23 17:24:41 +0100
commit8caaa01f9a6f18a127a5825783d53b49c3a5f532 (patch)
tree6ffeda2f2d5427656eb76dc30c2508112be488eb /example/asm_box_x86_32.py
parentaa6165b051e9bd6363b759a04babfc558099fed8 (diff)
downloadmiasm-8caaa01f9a6f18a127a5825783d53b49c3a5f532.tar.gz
miasm-8caaa01f9a6f18a127a5825783d53b49c3a5f532.zip
AsmBox: Now, the example take the assembly file in input
Diffstat (limited to 'example/asm_box_x86_32.py')
-rw-r--r--example/asm_box_x86_32.py26
1 files changed, 11 insertions, 15 deletions
diff --git a/example/asm_box_x86_32.py b/example/asm_box_x86_32.py
index 85c998a5..8664671d 100644
--- a/example/asm_box_x86_32.py
+++ b/example/asm_box_x86_32.py
@@ -1,4 +1,5 @@
 #! /usr/bin/env python
+from argparse import ArgumentParser
 from pdb import pm
 
 from elfesteem import pe_init
@@ -9,6 +10,10 @@ from miasm2.core import parse_asm
 from miasm2.expression.expression import *
 from miasm2.core import asmbloc
 
+parser = ArgumentParser("x86 32bits assembler")
+parser.add_argument("source", help="Source to assemble")
+args = parser.parse_args()
+
 pe = pe_init.PE()
 s_text = pe.SHList.add_section(name="text", addr=0x1000, rawsize=0x1000)
 s_iat = pe.SHList.add_section(name="iat", rawsize=0x100)
@@ -31,20 +36,10 @@ def my_ast_id2expr(t):
 my_var_parser = parse_ast(my_ast_id2expr, my_ast_int2expr)
 base_expr.setParseAction(my_var_parser)
 
-blocs, symbol_pool = parse_asm.parse_txt(mn_x86, 32, '''
-main:
-    PUSH 0
-    PUSH title
-    PUSH msg
-    PUSH 0
-    CALL DWORD PTR [ MessageBoxA ]
-    RET
-
-title:
-.string "Hello!"
-msg:
-.string "World!"
-''')
+with open(args.source) as fstream:
+    source = fstream.read()
+
+blocs, symbol_pool = parse_asm.parse_txt(mn_x86, 32, source)
 
 # fix shellcode addr
 symbol_pool.set_offset(symbol_pool.getby_name("main"), pe.rva2virt(s_text.addr))
@@ -62,4 +57,5 @@ print patches
 for offset, raw in patches.items():
     pe.virt[offset] = raw
 
-open('box_x86_32.bin', 'wb').write(str(pe))
+output = args.source.replace(".S", ".bin")
+open(output, 'wb').write(str(pe))