【发布时间】:2017-07-04 09:17:50
【问题描述】:
我正在尝试让 Python 从地址(例如 0x101BFFDC)获取值/数据,这是我通过使用游戏作弊引擎发现的。我做了很多研究,认为我需要使用ReadProcessMemory。但是,我尝试了几个示例都没有成功。
例如,我找到了以下代码:
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)
我希望它给我 56 的值,这是我从作弊引擎得到的值。但是,它只打印“失败”。每次。
我怎样才能得到正确的值?
【问题讨论】:
-
@sharath 不能用于从另一个进程读取内存,只有 Python 进程。
标签: python windows memory ctypes cheat-engine