This repository has been archived by the owner on Sep 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test2.py
72 lines (49 loc) · 2.22 KB
/
test2.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
# encoding: utf-8
import ctypes
import struct
# import numpy
def errcheck(result, func, args):
if not result:
raise ctypes.WinError(ctypes.get_last_error())
def get_memory(handle, address, size):
buffer = ctypes.create_string_buffer(size)
#bytesRead = ctypes.c_ulong(0)
bytesRead = ctypes.c_size_t(0)
return_code = ReadProcessMemory(handle, address, buffer, size, ctypes.byref(bytesRead))
assert bytesRead.value == size
return buffer.raw, return_code
def write_memory(handle, address, value):
bytesWrote = ctypes.c_size_t(0)
return_code = WriteProcessMemory(handle, address, ctypes.byref(ctypes.c_long(value)), 4, ctypes.byref(bytesWrote))
return bytesWrote.value, return_code
def looks_like_a_pointer(addr):
if (addr % 4 == 0) and (0x29B000 <= addr < 0x2884000):
return True
return False
def is_nearby_address(addr1, addr2):
return abs(addr1 - addr2) <= 0x1000
def get_value(ints, address):
index = (address - 0x29B000) / 4
if index < 0:
raise IndexError(index)
return ints[index]
def chunks(l, n):
"""Yield successive n-sized chunks from l."""
for i in xrange(0, len(l), n):
yield l[i:i+n]
OpenProcess = ctypes.windll.kernel32.OpenProcess
CloseHandle = ctypes.windll.kernel32.CloseHandle
#ReadProcessMemory = ctypes.windll.kernel32.ReadProcessMemory
ReadProcessMemory = ctypes.WinDLL('kernel32', use_last_error=True).ReadProcessMemory
ReadProcessMemory.errcheck = errcheck
ReadProcessMemory.argtypes = [ctypes.wintypes.HANDLE, ctypes.wintypes.LPCVOID, ctypes.wintypes.LPVOID, ctypes.c_size_t, ctypes.POINTER(ctypes.c_size_t)]
ReadProcessMemory.restype = ctypes.wintypes.BOOL
WriteProcessMemory = ctypes.WinDLL('kernel32', use_last_error=True).WriteProcessMemory
WriteProcessMemory.argtypes = [ctypes.wintypes.HANDLE, ctypes.wintypes.LPVOID, ctypes.wintypes.LPCVOID, ctypes.c_size_t, ctypes.POINTER(ctypes.c_size_t)]
WriteProcessMemory.restype = ctypes.wintypes.BOOL
WriteProcessMemory.errcheck = errcheck
PROCESS_ALL_ACCESS = 0x1F0FFF
PID = 3760
MEMORY_BLOCK_ADDRESS = 0x2029B000
MEMORY_BLOCK_SIZE = 0x25E9000
processHandle = OpenProcess(PROCESS_ALL_ACCESS, False, PID)