我正在嘗試編寫一個讀取特定進程的一系列內存位置的Python腳本。如何在Windows中讀取Python中另一個進程的內存?
我該如何在Python中做到這一點?
如果有問題,我將使用Windows。我有我正在嘗試讀取/編輯的進程PID。
我將不得不恢復調用ReadProcessMemory()和使用ctypes?
我正在嘗試編寫一個讀取特定進程的一系列內存位置的Python腳本。如何在Windows中讀取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)
是,(或win32all
)和ReadProcessMemory
是完全相同的方式來走。你在尋找額外/不同的東西嗎?什麼,特別是?
見http://www.windowsreference.com/windows-xp/dos-commands-and-equivalent-linux-commands/
您可以使用tasklist.exe列出的過程,然後刮結果。然後使用taskkill.exe(或tstskill.exe)結束它們。
但ctypes和kernal32可能更安全。
可能是他想做ArtMoney克隆:P – YOU 2009-11-25 04:48:42
我想我在尋找Python庫中的某些東西,它本質上是一個包裝,以避免使用ctypes。謝謝(你的)信息! – 2009-11-25 04:49:05