diff options
| author | Camille Mougey <camille.mougey@cea.fr> | 2015-01-06 17:37:16 +0100 |
|---|---|---|
| committer | Camille Mougey <camille.mougey@cea.fr> | 2015-01-23 17:24:41 +0100 |
| commit | 69ce9d7a43e60d97fb02ccef0a4f8f3aa3d427ee (patch) | |
| tree | 059f2b6f194defa5ea4bd70affd93d345d1e10e3 /example/asm_box_x86_32_mod.py | |
| parent | 8caaa01f9a6f18a127a5825783d53b49c3a5f532 (diff) | |
| download | miasm-69ce9d7a43e60d97fb02ccef0a4f8f3aa3d427ee.tar.gz miasm-69ce9d7a43e60d97fb02ccef0a4f8f3aa3d427ee.zip | |
AsmBox: Extract assembly code from AsmBox examples
Diffstat (limited to 'example/asm_box_x86_32_mod.py')
| -rw-r--r-- | example/asm_box_x86_32_mod.py | 89 |
1 files changed, 0 insertions, 89 deletions
diff --git a/example/asm_box_x86_32_mod.py b/example/asm_box_x86_32_mod.py deleted file mode 100644 index 5f90fe9c..00000000 --- a/example/asm_box_x86_32_mod.py +++ /dev/null @@ -1,89 +0,0 @@ -#! /usr/bin/env python - -from miasm2.core.cpu import parse_ast -from miasm2.arch.x86.arch import mn_x86, base_expr, variable -from miasm2.core.bin_stream import bin_stream -from miasm2.core import parse_asm -from miasm2.expression.expression import * -from elfesteem import * -from pdb import pm -from miasm2.core import asmbloc -import struct - -e = pe_init.PE() -s_text = e.SHList.add_section(name="text", addr=0x1000, rawsize=0x1000) -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) - -reg_and_id = dict(mn_x86.regs.all_regs_ids_byname) - - -def my_ast_int2expr(a): - return ExprInt32(a) - - -def my_ast_id2expr(t): - return reg_and_id.get(t, ExprId(t, size=32)) - -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: - CALL test_automod - CALL test_automod - RET - -test_automod: - PUSH EBP - MOV EBP, ESP - -loop: - MOV EAX, 0 - CMP EAX, 0 - JMP mod_addr -mod_addr: - JNZ end - - PUSH 0 - PUSH title - PUSH msg - PUSH 0 - CALL DWORD PTR [ MessageBoxA ] - - ; automodif code - MOV BYTE PTR [mod_addr], 0xEB - JMP loop -end: - MOV BYTE PTR [mod_addr], 0x75 - MOV ESP, EBP - POP EBP - RET - -title: -.string "Hello!" -msg: -.string "World!" -''') - -# fix shellcode addr -symbol_pool.set_offset(symbol_pool.getby_name("main"), e.rva2virt(s_text.addr)) -symbol_pool.set_offset(symbol_pool.getby_name_create("MessageBoxA"), - e.DirImport.get_funcvirt('MessageBoxA')) -e.Opthdr.AddressOfEntryPoint = s_text.addr - -for b in blocs[0]: - print b - -resolved_b, patches = asmbloc.asm_resolve_final( - mn_x86, blocs[0], symbol_pool) -print patches - -for offset, raw in patches.items(): - e.virt[offset] = raw - -open('box_x86_32_mod.bin', 'wb').write(str(e)) |