我正在尝试编写一个 Python 脚本来读取特定进程的一系列内存位置。
如何在 Python 中执行此操作?
如果有必要的话我会使用 Windows。我有正在尝试读取/编辑的进程 PID。
我是否必须恢复调用 ReadProcessMemory() 并使用 ctypes?
最佳答案
我在标准 python 库中没有看到任何内容,但我找到了一个使用 ctypes 的示例,就像您在另一个站点上建议的那样:
from ctypes import *
from ctypes.wintypes import *
OpenProcess = windll.kernel32.OpenProcess
ReadProcessMemory = windll.kernel32.ReadProcessMemory
CloseHandle = windll.kernel32.CloseHandle
PROCESS_ALL_ACCESS = 0x1F0FFF
pid = 4044 # I assume you have this from somewhere.
address = 0x1000000 # Likewise; for illustration I'll get the .exe header.
buffer = c_char_p("The data goes here")
bufferSize = len(buffer.value)
bytesRead = c_ulong(0)
processHandle = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
if ReadProcessMemory(processHandle, address, buffer, bufferSize, byref(bytesRead)):
print "Success:", buffer
else:
print "Failed."
CloseHandle(processHandle)
关于python - 如何在 Windows 中使用 Python 读取另一个进程的内存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55345705/