I am trying to make Python get the value/data from an address such as 0x101BFFDC, which I found by using a cheat engine for a game. I've done much research and believe that I need to use ReadProcessMemory
. However, I have tried several examples without success.
For example, I found the following code:
from ctypes import *
from ctypes.wintypes import *
import struct
OpenProcess = windll.kernel32.OpenProcess
ReadProcessMemory = windll.kernel32.ReadProcessMemory
CloseHandle = windll.kernel32.CloseHandle
PROCESS_ALL_ACCESS = 0x1F0FFF
pid = 10684 # pid of the game
address = 0x101BFFDC # I put the address here
buffer = c_char_p(b"The data goes here")
val = c_int()
bufferSize = len(buffer.value)
bytesRead = c_ulong(0)
processHandle = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
if ReadProcessMemory(processHandle, address, buffer, bufferSize, byref(bytesRead)):
memmove(ctypes.byref(val), buffer, ctypes.sizeof(val))
print("Success:" + str(val.value))
else:
print("Failed.")
CloseHandle(processHandle)
I expect it to give me the value 56, which is what I get from the cheat engine. However, it just prints "Failed." every time.
How can I get the value right?