Created
April 24, 2020 00:33
-
-
Save ioquatix/fa726f78bb950b0fffa36a6620c1ef93 to your computer and use it in GitHub Desktop.
Linux Memory Dump
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# This script reads a list of PIDs from the command line and dumps all readable memory regions. | |
REGION_PATTERN = /(\h+)-(\h+) (r)/ | |
ARGV.each do |pid| | |
maps = File.open("/proc/#{pid}/maps") | |
mem = File.open("/proc/#{pid}/mem") | |
maps.each_line do |line| | |
if match = line.match(REGION_PATTERN) | |
offset = Integer(match[1], 16) | |
size = Integer(match[2], 16) - offset | |
begin | |
$stderr.puts "Reading from #{offset} +#{size}..." | |
$stdout.write mem.pread(size, offset) | |
rescue Errno::EIO => error | |
$stderr.puts error | |
end | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment