2024-05-20 14:09:35 发布
网友
我正在尝试编写一个Python脚本,用于读取特定进程的一系列内存位置
如何在Python中实现这一点
如果有必要的话,我会使用Windows。我有我正在尝试读取/编辑的进程PID
我是否必须恢复调用ReadProcessMemory()并使用ctypes
见http://www.windowsreference.com/windows-xp/dos-commands-and-equivalent-linux-commands/
您可以使用tasklist.exe列出进程,然后刮取结果。然后使用taskkill.exe(或tstskill.exe)结束它们
但是ctypes和kernal32可能更安全
我在标准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)
是的,ctypes(或^{})和ReadProcessMemory正是要走的路。你是在寻找额外的/与众不同的东西吗?特别是什么
ctypes
ReadProcessMemory
见http://www.windowsreference.com/windows-xp/dos-commands-and-equivalent-linux-commands/
您可以使用tasklist.exe列出进程,然后刮取结果。然后使用taskkill.exe(或tstskill.exe)结束它们
但是ctypes和kernal32可能更安全
我在标准python库中没有看到任何内容,但我发现了一个使用ctypes的示例,就像您在另一个站点上建议的那样:
是的,} )和
ctypes
(或^{ReadProcessMemory
正是要走的路。你是在寻找额外的/与众不同的东西吗?特别是什么相关问题 更多 >
编程相关推荐