简体   繁体   English

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

[英]How can I read the memory of another process in Python in Windows?

I'm trying to write a Python script that reads a series of memory locations of a particular process.我正在尝试编写一个 Python 脚本来读取特定进程的一系列内存位置。

How can I do this in Python?我怎样才能在 Python 中做到这一点?

I'll be using Windows if it matters.如果重要的话,我会使用 Windows。 I have the processes PID that I'm attempting to read/edit.我有我试图读取/编辑的进程 PID。

Am I going to have to revert to calling ReadProcessMemory() and using ctypes?我将不得不恢复调用 ReadProcessMemory() 并使用 ctypes 吗?

I didn't see anything in the standard python libraries but I found an example using ctypes like you suggested on another site:我在标准 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)

Yes, ctypes (or win32all ) and ReadProcessMemory are exactly the way to go.是的, ctypes (或win32all )和ReadProcessMemory正是要走的路。 Were you looking for something extra/different?你在寻找额外/不同的东西吗? What, in particular?什么,特别是?

See http://www.windowsreference.com/windows-xp/dos-commands-and-equivalent-linux-commands/请参阅http://www.windowsreference.com/windows-xp/dos-commands-and-equivalent-linux-commands/

You can use tasklist.exe to list processes, then scrape the results.您可以使用 tasklist.exe 列出进程,然后抓取结果。 Then use taskkill.exe (or tstskill.exe) to end them.然后使用 taskkill.exe(或 tstskill.exe)来结束它们。

But ctypes and kernal32 is probably safer.但是 ctypes 和 kernal32 可能更安全。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在linux中读取python中进程的内存? - How can I read the memory of a process in python in linux? 如何在 Windows 10 中使用 python3.9 检查文件是否在我的 python 脚本之外的另一个进程中主动打开? - How can I check if a file is actively open in another process outside of my python script with python3.9 in Windows 10? 如何编写Perl,Python或Ruby程序来改变Windows上另一个进程的内存? - How to write a Perl, Python, or Ruby program to change the memory of another process on Windows? Python:如何从另一个进程读取变量? - Python: how to read variables from another process? 如何以其他Windows用户身份运行python进程 - How to run python process as another Windows user 如何在 python 的另一个函数中启动进程? - How can i start process inside another function in python? 如何在 Windows 上用 Python 读取系统信息? - How can I read system information in Python on Windows? 如何使用python读取我的Windows平板电脑中的加速度计? - How can I read the accelerometer in my windows tablet with python? 如何读取和处理 Python 中对于 memory 来说太大的文件? - How to read and process a file in Python that is too big for memory? 如何在 C++ 进程中将数据从 CPU 复制到 GPU,并在指向复制的内存的同时在另一个 python 进程中运行 TF? - How do I copy data from CPU to GPU in a C++ process and run TF in another python process while pointing to the copied memory?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM