Last active
November 8, 2023 16:48
-
-
Save gonoph/0ea32c6eb2f4bc16c76962f54d437ae3 to your computer and use it in GitHub Desktop.
Peek.bash - get a hex dump of the memory of a running process
This file contains 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
#!/bin/bash | |
# vim: sw=4 ts=4 expandtab | |
# modifed from https://www.baeldung.com/linux/read-process-memory | |
err() { echo "$@" >&2 ; exit 1; } | |
test -z "$1" && err "Usage: $0 <pid>" | |
test -d "/proc/$1" || err "PID $1 does not exist" | |
while read -r mem_range perms JUNK ; do | |
if [[ "$perms" == "r"* ]]; then | |
IFS="-" read start_addr end_addr JUNK <<< "$mem_range" | |
start_addr="$(( 16#$start_addr ))" end_addr="$(( 16#$end_addr ))" | |
length=$(( $end_addr - $start_addr)) | |
echo "Reading memory range $mem_range" | |
( set -x; hexdump -C -n $length -s $start_addr < /proc/$1/mem) 2>&1 | |
fi | |
done < "/proc/$1/maps" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample output: