diff options
| author | Pierre LALET <pierre.lalet@cea.fr> | 2019-02-27 20:29:44 +0100 |
|---|---|---|
| committer | Fabrice Desclaux <fabrice.desclaux@cea.fr> | 2019-03-05 16:52:51 +0100 |
| commit | d3a42fa5dcdb0c467586eb6b92271fa4dbeb648b (patch) | |
| tree | b5ca14f60ad2a10148990ffc30e4bad8f49c9283 /example/elfesteem/minidump_to_pe.py | |
| parent | 944806c506446c918eb74c17a605f5f56d4b75e0 (diff) | |
| download | miasm-d3a42fa5dcdb0c467586eb6b92271fa4dbeb648b.tar.gz miasm-d3a42fa5dcdb0c467586eb6b92271fa4dbeb648b.zip | |
Include elfesteem fork in miasm
Diffstat (limited to 'example/elfesteem/minidump_to_pe.py')
| -rw-r--r-- | example/elfesteem/minidump_to_pe.py | 48 |
1 files changed, 48 insertions, 0 deletions
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)) |