forked from code-gopher/DnfHelper-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkernel32.py
More file actions
29 lines (20 loc) · 662 Bytes
/
kernel32.py
File metadata and controls
29 lines (20 loc) · 662 Bytes
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
import win32api
import win32process
def open_process(pid: int) -> int:
handle = win32api.OpenProcess(2097151, False, pid)
return handle
def close_process(handle: int) -> int:
return win32api.CloseHandle(handle)
def write_byte_arr(addr: int, data: bytes) -> bool:
handle = open_process(1)
win32process.WriteProcessMemory(handle, addr, data, len(data))
return True
def read_byte_arr(addr: int, data: bytes) -> bool:
handle = open_process(1)
try:
win32process.ReadProcessMemory(handle, addr, data, len(data))
except Exception as msg:
print(msg)
finally:
close_process(handle)
return True