我不熟悉内存管理。
我要做的是读取内存地址中的数据。研究如何获取进程的内存地址和基址。在获取进程的piddef get_pid(process_name):
for proc in psutil.process_iter():
if process_name in str(proc.name):
print ("target: {}, pid: {}".format(process_name, proc.pid))
return proc.pid
查找进程的基地址process = ctypes.windll.kernel32.OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ, False, pid)
modules = win32process.EnumProcessModules(process)
print(hex(modules))result:
0x140000000 0x7ff972560000 0x7ff96b650000 0x7ff971d90000
0x7ff96eb70000 0x7ff96cb60000 0x7ff950ee0000 0x7ff971e50000
0x7ff971fd0000 0x7ff970f30000 0x7ff9721f0000 0x7ff972500000
0x7ff96f0e0000 0x7ff96f040000 0x7ff96edf0000 0x7ff9718d0000
0x7ff96f020000 0x7ff9724d0000 0x7ff96cb30000 0x7ff96cad0000
0x7ff96e930000 0x7ff96efa0000 0x7ff9723a0000 0x7ff9715a0000
0x7ff9720e0000 0x7ff970ed0000 0x7ff96fa90000 0x7ff96f2e0000
0x7ff96e8f0000 0x7ff96e8d0000 0x7ff96e870000 0x7ff96e8c0000
0x7ff9713e0000 0x7ff971f00000 ...
在这一步,我会得到一个模块的列表,模块的len是137,我假设是动态内存地址,有没有办法证明是动态内存?在读取地址中的数据for module in modules:
print(hexlify(ctypes.string_at(id(addr), sys.getsizeof(addr))))result:
b'0100000000000000902c806c000000000b00000000000000ffffffffffffffffe4323038380000000000000000000000307831343030303030303000'
b'0100000000000000902c806c000000000e00000000000000ffffffffffffffffe4000000000000000000000000000000307837666639373235363030303000'
b'0100000000000000902c806c000000000e00000000000000ffffffffffffffffe4323038380000000000000000000000307837666639366236353030303000'
...
如何获得可读的数据?非常感谢。在