diff options
| author | Ajax <commial@gmail.com> | 2019-05-09 10:50:32 +0200 |
|---|---|---|
| committer | Ajax <commial@gmail.com> | 2019-05-09 10:52:12 +0200 |
| commit | 178b202120a22b7ca92c137c363ebb15d843a726 (patch) | |
| tree | 32e07d366d08451db96c15b5d5627e3abad92531 /example/loader/build_pe.py | |
| parent | 5c5eb1f9b7a65728b8745f7e07bc1de66d528d3d (diff) | |
| download | miasm-178b202120a22b7ca92c137c363ebb15d843a726.tar.gz miasm-178b202120a22b7ca92c137c363ebb15d843a726.zip | |
Loader example: test_pe: remove useless imports, comment and rename
Diffstat (limited to 'example/loader/build_pe.py')
| -rw-r--r-- | example/loader/build_pe.py | 33 |
1 files changed, 33 insertions, 0 deletions
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)) |