From b4f573d849e8469a40e0161097151b2b3d5249b4 Mon Sep 17 00:00:00 2001 From: William Bruneau Date: Mon, 2 Dec 2019 10:54:02 +0100 Subject: [PATCH 1/2] Example: add sc2pe.py --- example/loader/sc2pe.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 example/loader/sc2pe.py diff --git a/example/loader/sc2pe.py b/example/loader/sc2pe.py new file mode 100644 index 000000000..953594190 --- /dev/null +++ b/example/loader/sc2pe.py @@ -0,0 +1,25 @@ +import sys + +from argparse import ArgumentParser +from miasm.loader import pe_init + + +parser = ArgumentParser(description="Create a PE from a shellcode") +parser.add_argument("filename", + help="x86 shellcode filename") +parser.add_argument("-p", "--pename", + help="new PE filename (default is 'sc_pe.exe')", + default="sc_pe.exe") +parser.add_argument("-w", "--word-size", + help="word size (default is 32 bits)", + choices=[32, 64], + type=int, + default=32) +args = parser.parse_args() + + +data = open(args.filename, 'rb').read() +pe = pe_init.PE(wsize=args.word_size) +s_text = pe.SHList.add_section(name="text", addr=0x1000, data=data) +pe.Opthdr.AddressOfEntryPoint = s_text.addr +open(args.pename, 'wb').write(bytes(pe)) From 2cf53c576fae38f7882f4b86909bf2e0f076d6b1 Mon Sep 17 00:00:00 2001 From: William Bruneau Date: Mon, 2 Dec 2019 11:07:06 +0100 Subject: [PATCH 2/2] Example: add get_exports.dll --- example/loader/get_exports.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 example/loader/get_exports.py diff --git a/example/loader/get_exports.py b/example/loader/get_exports.py new file mode 100644 index 000000000..19caba42b --- /dev/null +++ b/example/loader/get_exports.py @@ -0,0 +1,18 @@ +from argparse import ArgumentParser +from miasm.jitter.loader.pe import get_export_name_addr_list +from miasm.analysis.binary import Container + + +parser = ArgumentParser(description="Retrieve exported functions of a DLL") +parser.add_argument("filename", + help="DLL filename") +args = parser.parse_args() + + +fdesc = open(args.filename, 'rb') +cont = Container.from_stream(fdesc) + +exported_funcs = get_export_name_addr_list(cont.executable) + +for name_or_ordinal, address in exported_funcs: + print(name_or_ordinal, hex(address))