about summary refs log tree commit diff stats
path: root/example
diff options
context:
space:
mode:
authorPierre LALET <pierre.lalet@cea.fr>2019-02-27 20:29:44 +0100
committerFabrice Desclaux <fabrice.desclaux@cea.fr>2019-03-05 16:52:51 +0100
commitd3a42fa5dcdb0c467586eb6b92271fa4dbeb648b (patch)
treeb5ca14f60ad2a10148990ffc30e4bad8f49c9283 /example
parent944806c506446c918eb74c17a605f5f56d4b75e0 (diff)
downloadmiasm-d3a42fa5dcdb0c467586eb6b92271fa4dbeb648b.tar.gz
miasm-d3a42fa5dcdb0c467586eb6b92271fa4dbeb648b.zip
Include elfesteem fork in miasm
Diffstat (limited to 'example')
-rwxr-xr-xexample/asm/shellcode.py4
-rw-r--r--example/elfesteem/minidump_to_pe.py48
-rw-r--r--example/elfesteem/test_pe.py31
-rwxr-xr-xexample/jitter/arm_sc.py2
-rw-r--r--example/jitter/run_with_linuxenv.py2
-rw-r--r--example/jitter/unpack_upx.py2
6 files changed, 84 insertions, 5 deletions
diff --git a/example/asm/shellcode.py b/example/asm/shellcode.py
index ed489bbd..59ea3a94 100755
--- a/example/asm/shellcode.py
+++ b/example/asm/shellcode.py
@@ -4,8 +4,8 @@ from argparse import ArgumentParser
 from pdb import pm
 
 from future.utils import viewitems
-from elfesteem import pe_init
-from elfesteem.strpatchwork import StrPatchwork
+from miasm.elfesteem import pe_init
+from miasm.elfesteem.strpatchwork import StrPatchwork
 
 from miasm.core import parse_asm, asmblock
 from miasm.analysis.machine import Machine
diff --git a/example/elfesteem/minidump_to_pe.py b/example/elfesteem/minidump_to_pe.py
new file mode 100644
index 00000000..8aff3e62
--- /dev/null
+++ b/example/elfesteem/minidump_to_pe.py
@@ -0,0 +1,48 @@
+#! /usr/bin/env python
+"""Minidump to PE example"""
+
+import sys
+
+from future.utils import viewvalues
+
+from miasm.elfesteem.minidump_init import Minidump
+from miasm.elfesteem.pe_init import PE
+
+minidump = Minidump(open(sys.argv[1], 'rb').read())
+
+pe = PE()
+for i, memory in enumerate(sorted(viewvalues(minidump.memory),
+                                  key=lambda x:x.address)):
+    # Get section name
+    name = str(memory.name)
+    if not name:
+        name = "s_%02d" % i
+    else:
+        name = name.split('\\')[-1]
+
+    # Get section protection
+    protect = memory.pretty_protect
+    protect_mask = 0x20
+    if protect == "UNKNOWN":
+        protect_mask |= 0xe0000000
+    else:
+        if "EXECUTE" in protect:
+            protect_mask |= 1 << 29
+        if "READ" in protect:
+            protect_mask |= 1 << 30
+        if "WRITE" in protect:
+            protect_mask |= 1 << 31
+
+    # Add the section
+    pe.SHList.add_section(name=name, addr=memory.address, rawsize=memory.size,
+                          data=memory.content, flags=protect_mask)
+
+# Find entry point
+try:
+    entry_point = minidump.threads.Threads[0].ThreadContext.Eip[0]
+except AttributeError:
+    entry_point = minidump.threads.Threads[0].ThreadContext.Rip[0]
+
+pe.Opthdr.AddressOfEntryPoint = entry_point
+
+open("out_pe.bin", "wb").write(bytes(pe))
diff --git a/example/elfesteem/test_pe.py b/example/elfesteem/test_pe.py
new file mode 100644
index 00000000..e9cff0b4
--- /dev/null
+++ b/example/elfesteem/test_pe.py
@@ -0,0 +1,31 @@
+#! /usr/bin/env python
+
+import miasm.elfesteem.pe as pe
+from miasm.elfesteem.pe_init import PE
+import rlcompleter
+import readline
+import pdb
+import sys
+from pprint import pprint as pp
+readline.parse_and_bind("tab: complete")
+
+
+e_ = PE()
+mysh = b"\xc3"
+s_text = e_.SHList.add_section(
+    name="text", addr=0x1000, rawsize=0x1000, data=mysh)
+e_.Opthdr.AddressOfEntryPoint = s_text.addr
+new_dll = [({"name": "kernel32.dll",
+             "firstthunk": s_text.addr + 0x100},
+            ["CreateFileA", "SetFilePointer", "WriteFile", "CloseHandle"]
+            ),
+           ({"name": "USER32.dll",
+             "firstthunk": None},
+            ["SetDlgItemInt", "GetMenu", "HideCaret"]
+            )
+           ]
+e_.DirImport.add_dlldesc(new_dll)
+
+s_myimp = e_.SHList.add_section(name="myimp", rawsize=0x1000)
+e_.DirImport.set_rva(s_myimp.addr)
+open('uu.bin', 'wb').write(bytes(e_))
diff --git a/example/jitter/arm_sc.py b/example/jitter/arm_sc.py
index 8d5b5677..ddadbf29 100755
--- a/example/jitter/arm_sc.py
+++ b/example/jitter/arm_sc.py
@@ -3,7 +3,7 @@
 from miasm.core.utils import int_to_byte
 from miasm.analysis.sandbox import Sandbox_Linux_armb_str
 from miasm.analysis.sandbox import Sandbox_Linux_arml_str
-from elfesteem.strpatchwork import StrPatchwork
+from miasm.elfesteem.strpatchwork import StrPatchwork
 
 from pdb import pm
 
diff --git a/example/jitter/run_with_linuxenv.py b/example/jitter/run_with_linuxenv.py
index e2869699..0237cc94 100644
--- a/example/jitter/run_with_linuxenv.py
+++ b/example/jitter/run_with_linuxenv.py
@@ -2,7 +2,7 @@ from argparse import ArgumentParser
 import logging
 import re
 
-from elfesteem import elf as elf_csts
+from miasm.elfesteem import elf as elf_csts
 
 from miasm.os_dep.linux import environment, syscall
 from miasm.analysis.machine import Machine
diff --git a/example/jitter/unpack_upx.py b/example/jitter/unpack_upx.py
index 0a41d038..05d28b16 100644
--- a/example/jitter/unpack_upx.py
+++ b/example/jitter/unpack_upx.py
@@ -2,7 +2,7 @@ from __future__ import print_function
 import os
 import logging
 from pdb import pm
-from elfesteem import pe
+from miasm.elfesteem import pe
 from miasm.analysis.sandbox import Sandbox_Win_x86_32
 
 # User defined methods