python - 如何在 Windows 中使用 Python 读取另一个进程的内存?

标签 python

我正在尝试编写一个 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/

相关文章:

python - Pandas 情节时间序列 ['numpy.ndarray' 对象没有属性 'find']

python - Flask 应用程序的功能测试 : Weird Twill Traceback

python - pandas read_csv 忽略分隔符

python - 如何读取 Abaqus .mtx 文件? Scipy.io.mmread 给出 'not enough values to unpack' 错误

python - 使用 Python 在 YAML 中获取重复键

python - 如何分离嵌套列表的每个元素并将列表转换为元组列表?

python - Ubuntu 上的 PyXML

python - pyspark: TypeError: IntegerType 无法接受类型为 <type 'unicode' > 的对象

python - 使用 pyinstaller 文本无法解码

python - Django oscar 添加标准运输方式