forked from pywinauto/injected
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcfuncs.py
75 lines (61 loc) · 2.67 KB
/
cfuncs.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
"""Some functions already exists in pywinauto, but for correctly
injector work needs full redefinition with ctypes compatible
"""
import win32con
from ctypes import Structure, sizeof, alignment
from ctypes import c_char_p, c_wchar_p
from ctypes import POINTER
from ctypes import windll
from ctypes.wintypes import BOOL, DWORD, HANDLE, LPVOID, LPCVOID
# C:/PROGRA~1/MICROS~4/VC98/Include/winbase.h 223
class SECURITY_ATTRIBUTES(Structure):
_fields_ = [
# C:/PROGRA~1/MICROS~4/VC98/Include/winbase.h 223
('nLength', DWORD),
('lpSecurityDescriptor', LPVOID),
('bInheritHandle', BOOL),
]
assert sizeof(SECURITY_ATTRIBUTES) == 12 or sizeof(SECURITY_ATTRIBUTES) == 24, sizeof(SECURITY_ATTRIBUTES)
assert alignment(SECURITY_ATTRIBUTES) == 4 or alignment(SECURITY_ATTRIBUTES) == 8, alignment(SECURITY_ATTRIBUTES)
PAGE_READWRITE = win32con.PAGE_READWRITE
WAIT_TIMEOUT = win32con.WAIT_TIMEOUT
PROCESS_ALL_ACCESS = win32con.PROCESS_ALL_ACCESS
VIRTUAL_MEM = ( win32con.MEM_RESERVE | win32con.MEM_COMMIT )
LPCSTR = LPCTSTR = c_char_p
LPWTSTR = c_wchar_p
LPDWORD = PDWORD = POINTER(DWORD)
LPTHREAD_START_ROUTINE = LPVOID
LPSECURITY_ATTRIBUTES = POINTER(SECURITY_ATTRIBUTES)
OpenProcess = windll.kernel32.OpenProcess
OpenProcess.restype = HANDLE
OpenProcess.argtypes = (DWORD, BOOL, DWORD)
VirtualAllocEx = windll.kernel32.VirtualAllocEx
VirtualAllocEx.restype = LPVOID
VirtualAllocEx.argtypes = (HANDLE, LPVOID, DWORD, DWORD, DWORD)
ReadProcessMemory = windll.kernel32.ReadProcessMemory
ReadProcessMemory.restype = BOOL
ReadProcessMemory.argtypes = (HANDLE, LPCVOID, LPVOID, DWORD, DWORD)
WriteProcessMemory = windll.kernel32.WriteProcessMemory
WriteProcessMemory.restype = BOOL
WriteProcessMemory.argtypes = (HANDLE, LPVOID, LPCVOID, DWORD, DWORD)
CreateRemoteThread = windll.kernel32.CreateRemoteThread
CreateRemoteThread.restype = HANDLE
CreateRemoteThread.argtypes = (HANDLE, LPSECURITY_ATTRIBUTES, DWORD, LPTHREAD_START_ROUTINE, LPVOID, DWORD, LPDWORD)
GetModuleHandleA = windll.kernel32.GetModuleHandleA
GetModuleHandleA.restype = HANDLE
GetModuleHandleA.argtypes = (LPCTSTR,)
LoadLibraryA = windll.kernel32.LoadLibraryA
LoadLibraryA.restype = HANDLE
LoadLibraryA.argtypes = (LPCTSTR,)
GetModuleHandleW = windll.kernel32.GetModuleHandleW
GetModuleHandleW.restype = HANDLE
GetModuleHandleW.argtypes = (LPWTSTR,)
LoadLibraryW = windll.kernel32.LoadLibraryW
LoadLibraryW.restype = HANDLE
LoadLibraryW.argtypes = (LPWTSTR,)
GetProcAddress = windll.kernel32.GetProcAddress
GetProcAddress.restype = LPVOID
GetProcAddress.argtypes = (HANDLE, LPCTSTR)
WaitForSingleObject = windll.kernel32.WaitForSingleObject
WaitForSingleObject.restype = DWORD
WaitForSingleObject.argtypes = (HANDLE, DWORD)