gpt4 book ai didi

Python读取Linux进程内存并转储到文件

转载 作者:太空宇宙 更新时间:2023-11-03 19:01:05 24 4
gpt4 key购买 nike

我有以下脚本:

import sys, os

pid = sys.argv[1]
maps_file = open("/proc/%s/maps" % pid, 'r')
mem_file = open("/proc/%s/mem" % pid, 'r')
for line in maps_file.readlines(): # for each mapped region
m = re.match(r'([0-9A-Fa-f]+)-([0-9A-Fa-f]+) ([-r])', line)
if m.group(3) == 'r': # if this is a readable region
start = int(m.group(1), 16)
end = int(m.group(2), 16)
mem_file.seek(start) # seek to region start
chunk = mem_file.read(end - start) # read region contents
#print chunk, # dump contents to standard output
mem_dump = open(pid+".bin", "wb")
mem_dump.write(str(chunk,))
mem_dump.close()
maps_file.close()
mem_file.close()

到目前为止,一切正常(转储进程的内存),但我无法将数据保存到文件中。我做错了什么?

最佳答案

文件是否会被写入到您不希望的某个位置(看起来它们将被写入当前目录)?

关于Python读取Linux进程内存并转储到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16060237/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com