【发布时间】:2019-04-19 02:27:47
【问题描述】:
我正在尝试从游戏进程中读取内存(就像 Cheat Engine 所做的那样)。我研究过不同的帖子,例如:
- Get HWND of each Window?
- How can I read the memory of another process in Python in Windows?
- WriteProcessMemory and ReadProcessMemory
然后,我可以拼出我的第一个记忆阅读脚本。基本上,它有两个步骤。获取进程句柄,然后从句柄中读取内存地址。
但我得到的价值是错误的。
我的代码
import win32gui,win32com.client
import win32api
import ctypes
import win32ui
import win32process
from ctypes import wintypes
### Initializing functions and permissions ###
OpenProcess = ctypes.windll.kernel32.OpenProcess
ReadProcessMemory = ctypes.windll.kernel32.ReadProcessMemory # Method 1
PROCESS_ALL_ACCESS = 0x1F0FFF
PROCESS_QUERY_INFORMATION = 0x0400
PROCESS_VM_OPERATION = 0x0008
PROCESS_VM_READ = 0x0010
PROCESS_VM_WRITE = 0x0020
### End of Initializing session
### Getting process handle ###
HWND = win32ui.FindWindow(None,'My Game').GetSafeHwnd()
PID = win32process.GetWindowThreadProcessId(HWND)[1]
processHandle = OpenProcess(PROCESS_ALL_ACCESS, False, PID) # Why is it zero
### End of Getting process handle ###
### Reading value of a Memory Address ###
ADDRESS = 0x0111FF62
buffer = ctypes.c_char_p("Hello, World".encode('utf-8'))
bufferSize = len(buffer.value)
bytesRead = ctypes.c_ulong(0)
memory_value = ReadProcessMemory(processHandle, ADDRESS, buffer, bufferSize, ctypes.byref(bytesRead)) # Why is it zero
print('Memory Value = ', memory_value)
内存值 = 0
我从内存扫描软件中得到的真实价值
我使用函数win32gui.SetForegroundWindow(HWND ) 仔细检查了我的 HWND 值是否正确。它确实将窗户带到了前景。所以我很确定我的程序在 HWND 行之前是错误的。
【问题讨论】: