是否有Python中内置的用于编辑内存的好用且易用的模块?或者说,是否存在这样的模块?
我正在寻找一种连接到进程并从中读取/写入的方法。就像Cheat Engine一样的工作方式。 这里是C++中它如何工作的示例。
是否有Python中内置的用于编辑内存的好用且易用的模块?或者说,是否存在这样的模块?
我正在寻找一种连接到进程并从中读取/写入的方法。就像Cheat Engine一样的工作方式。 这里是C++中它如何工作的示例。
from ctypes import *
from ctypes.wintypes import *
pid = 0 #the pid of the process, aquired earlier by hand
address = 0x0000 #where to read from while in the memory
OpenProcess = windll.kernel32.OpenProcess
ReadProcessMemory = windll.kernel32.ReadProcessMemory
CloseHandle = windll.kernel32.CloseHandle
PROCESS_ALL_ACCESS = 0x1F0FFF
datadummy = b'.'*200
buffer = c_char_p(datadummy)
bufferSize = len(buffer.value)
bytesRead = c_ulong(0)
processHandle = OpenProcess(PROCESS_ALL_ACCESS, False, int(PID))
ReadProcessMemory(processHandle, address, buffer, bufferSize, byref(bytesRead))
CloseHandle(processHandle)
为了写入内存,我只需要添加WriteProcessMemory = windll.kernel32.WriteProcessMemory
,然后调用它即可。
ctypes
模块来实现。具体地说,需要用到ctypes.from_address()
函数。 - martineau