gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 17:05:11 26 4
gpt4 key购买 nike

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com