多平台内存编辑库
mem-edit的Python项目详细描述
内存编辑
mem_edit是一个用python编写的多平台内存编辑库。
主页:https://mpxd.net/code/jan/mem_edit
功能:
- 扫描进程使用的所有可读内存。
- (可选)将搜索限制为具有读写权限的区域。
- 地址空间分配报告
- 使用cTypes对象读/写
- 基本类型,例如
ctypes.c_ulong()
- 数组,例如
(ctypes.c_byte * 4)()
ctypes.Structure or ctypes.Union
和子类的实例。
- 基本类型,例如
- 在Windows和Linux上运行
安装
依赖项:
- python 3(用3.7编写和测试)
- C类型
- 键入(用于类型批注)
从pypi安装pip(首选):
pip3 install mem_edit
使用git存储库中的pip进行安装
pip3 install git+https://mpxd.net/code/jan/mem_edit.git@release
文档
大多数函数和类都是内联的。 要阅读联机帮助,
importmem_edithelp(mem_edit.Process)
示例
增加“magic.exe”中的幻数(无符号长1234567890):
importctypesfrommem_editimportProcessmagic_number=ctypes.ulong(1234567890)pid=Process.get_pid_by_name('magic.exe')withProcess.open_process(pid)asp:addrs=p.search_all_memory(magic_number)# We don't want to edit if there's more than one result...assert(len(addrs)==1)# We don't actually have to read the value here, but let's do so anyways...num_ulong=p.read_memory(addrs[0],ctypes.c_ulong())num=num_ulong.valuep.write_memory(addrs[0],ctypes.c_ulong(num+1))
值更改后缩小搜索范围:
importctypesfrommem_editimportProcessinitial_value=40final_value=55pid=Process.get_pid_by_name('monitor_me.exe')withProcess.open_process(pid)asp:addrs=p.search_all_memory(ctypes.c_int(initial_value))input('Press enter when value has changed to '+str(final_value))filtered_addrs=p.search_addresses(addrs,ctypes.c_int(final_value))print('Found addresses:')foraddrinfiltered_addrs:print(hex(addr))
阅读并更改结构:
importctypesfrommem_editimportProcessclassMyStruct(ctypes.Structure):_fields_=[('first_member',ctypes.c_ulong),('second_member',ctypes.c_void_p),]pid=Process.get_pid_by_name('something.exe')withProcess.open_process(pid)asp:s=MyStruct()s.first_member=1234567890s.second_member=0x1234addrs=p.search_all_memory(s)print(addrs)p.write_memory(0xafbfe0,s)