diff options
| author | serpilliere <serpilliere@users.noreply.github.com> | 2019-05-10 12:55:21 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-05-10 12:55:21 +0200 |
| commit | c922e7067018a8ec13082fa9a268f70b026b0ad7 (patch) | |
| tree | 32e07d366d08451db96c15b5d5627e3abad92531 | |
| parent | 82ec0ab9b24553c894540bb1f560df2cf062679b (diff) | |
| parent | 178b202120a22b7ca92c137c363ebb15d843a726 (diff) | |
| download | miasm-c922e7067018a8ec13082fa9a268f70b026b0ad7.tar.gz miasm-c922e7067018a8ec13082fa9a268f70b026b0ad7.zip | |
Merge pull request #1036 from commial/refactor/example-loader
Refactor/example loader
| -rw-r--r-- | example/elfesteem/test_pe.py | 31 | ||||
| -rw-r--r-- | example/loader/build_pe.py | 33 | ||||
| -rw-r--r-- | example/loader/minidump_to_pe.py (renamed from example/elfesteem/minidump_to_pe.py) | 0 | ||||
| -rwxr-xr-x | test/test_all.py | 12 |
4 files changed, 45 insertions, 31 deletions
diff --git a/example/elfesteem/test_pe.py b/example/elfesteem/test_pe.py deleted file mode 100644 index 543cbea5..00000000 --- a/example/elfesteem/test_pe.py +++ /dev/null @@ -1,31 +0,0 @@ -#! /usr/bin/env python - -import miasm.loader.pe as pe -from miasm.loader.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/loader/build_pe.py b/example/loader/build_pe.py new file mode 100644 index 00000000..6baeb645 --- /dev/null +++ b/example/loader/build_pe.py @@ -0,0 +1,33 @@ +#! /usr/bin/env python + +from miasm.loader.pe_init import PE + +# Build an empty PE object +pe_object = PE() + +# Add a section with a just a "RET" +payload = b"\xc3" +s_text = pe_object.SHList.add_section( + name="text", addr=0x1000, rawsize=0x1000, data=payload +) + +# Set the entry point on this instruction +pe_object.Opthdr.AddressOfEntryPoint = s_text.addr + +# Add some imports +new_dll = [ + ({"name": "kernel32.dll", + "firstthunk": s_text.addr + 0x100}, + ["CreateFileA", "SetFilePointer", "WriteFile", "CloseHandle"] + ), + ({"name": "USER32.dll", + "firstthunk": None}, + ["SetDlgItemInt", "GetMenu", "HideCaret"] + ) +] +pe_object.DirImport.add_dlldesc(new_dll) +s_myimp = pe_object.SHList.add_section(name="myimp", rawsize=0x1000) +pe_object.DirImport.set_rva(s_myimp.addr) + +# Rebuild the PE and dump it to a file +open('fresh_pe.exe', 'wb').write(bytes(pe_object)) diff --git a/example/elfesteem/minidump_to_pe.py b/example/loader/minidump_to_pe.py index 30a95325..30a95325 100644 --- a/example/elfesteem/minidump_to_pe.py +++ b/example/loader/minidump_to_pe.py diff --git a/test/test_all.py b/test/test_all.py index a8a0d599..1f729a71 100755 --- a/test/test_all.py +++ b/test/test_all.py @@ -696,6 +696,18 @@ for script in [["basic_op.py"], ]: testset += ExampleExpression(script) +## Loader +class ExampleLoader(Example): + """Loader examples specificities: + - script path begins with "loader/" + """ + example_dir = "loader" + + +testset += ExampleLoader(["build_pe.py"], products=["fresh_pe.exe"]) +# A sample is required, so "minidump_to_pe.py" is disabled for now + + ## Symbolic Execution class ExampleSymbolExec(Example): """Symbol Exec examples specificities: |