Skip to content

Instantly share code, notes, and snippets.

@ioquatix
Created April 24, 2020 00:33
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ioquatix/fa726f78bb950b0fffa36a6620c1ef93 to your computer and use it in GitHub Desktop.
Save ioquatix/fa726f78bb950b0fffa36a6620c1ef93 to your computer and use it in GitHub Desktop.
Linux Memory Dump
#!/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