about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorserpilliere <devnull@localhost>2012-03-20 10:42:05 +0100
committerserpilliere <devnull@localhost>2012-03-20 10:42:05 +0100
commitb410b90f5a6192da950746357ac7693780fe73cd (patch)
tree4ecdc93fe84389cc58fd9e0da5ca6a8488a31eb3
parent7601496221d54e2c67d3138675ffa7dab91eff36 (diff)
downloadmiasm-b410b90f5a6192da950746357ac7693780fe73cd.tar.gz
miasm-b410b90f5a6192da950746357ac7693780fe73cd.zip
example: add asm box
-rw-r--r--example/asm_box.py36
-rwxr-xr-xexample/asm_x86.py7
2 files changed, 41 insertions, 2 deletions
diff --git a/example/asm_box.py b/example/asm_box.py
new file mode 100644
index 00000000..a00fe703
--- /dev/null
+++ b/example/asm_box.py
@@ -0,0 +1,36 @@
+#! /usr/bin/env python
+
+from miasm.core import parse_asm
+from miasm.core import asmbloc
+from miasm.arch.ia32_arch import *
+from elfesteem import *
+e = pe_init.PE()
+s_text = e.SHList.add_section(name = "text ", addr = 0x1000, rawsize = 0x100)
+s_iat = e.SHList.add_section(name = "iat" , rawsize = 0x100)
+new_dll = [({ "name" : "USER32.dll",
+              "firstthunk" : s_iat.addr},
+            ["MessageBoxA"])]
+e.DirImport.add_dlldesc(new_dll)
+s_myimp = e.SHList.add_section(name = "myimp",rawsize = len(e.DirImport))
+e.DirImport.set_rva(s_myimp.addr)
+all_bloc, symbol_pool = parse_asm.parse_txt(x86_mn, r'''
+main:
+    push 0
+    push title
+    push msg
+    push 0
+    call [ MessageBoxA ]
+    ret
+title:
+.string "Hello!"
+msg:
+.string "Word!"
+''')
+symbol_pool.add(asmbloc.asm_label('base_address', 0))
+symbol_pool.getby_name("MessageBoxA").offset = e.DirImport.get_funcvirt('MessageBoxA')
+symbol_pool.getby_name("main").offset = e.rva2virt(s_text.addr)
+resolved_b, patches = asmbloc.asm_resolve_final(x86_mn, all_bloc[0], symbol_pool)
+for p in patches:
+    e.virt[p] = patches[p]
+e.Opthdr.AddressOfEntryPoint = e.virt2rva(symbol_pool.getby_name("main").offset)
+open('msg.exe', 'wb').write(str(e))
diff --git a/example/asm_x86.py b/example/asm_x86.py
index 79b61886..bbccf25e 100755
--- a/example/asm_x86.py
+++ b/example/asm_x86.py
@@ -10,7 +10,9 @@ import struct
 
 my_mn = x86_mn
 
-
+"""
+asm a linux shell code in a windows PE
+"""
 
 
 my_mn = x86_mn
@@ -67,7 +69,8 @@ open("graph.txt" , "w").write(g)
 print "symbols"
 print symbol_pool
 #dont erase from start to shell code padading
-resolved_b, patches = asmbloc.asm_resolve_final(my_mn, all_bloc[0], symbol_pool)
+resolved_b, patches = asmbloc.asm_resolve_final(my_mn, all_bloc[0], symbol_pool,
+                                                constrain_pos=True)
 print patches
 
 for offset, raw in patches.items():