2022-02-23 20:10:45 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
if [ -z ${1+x} ]; then
|
2022-09-25 11:19:41 +00:00
|
|
|
printf "\e[31m%s\e[30m\n" "Did not pass executable file (full path)"
|
|
|
|
printf "\e[31m%s\e[30m\n" "Usage: $0 <executable> <crash_log>"
|
|
|
|
echo -en "\e[0m"
|
|
|
|
exit 1
|
2022-02-23 20:10:45 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z ${2+x} ]; then
|
2022-09-25 11:19:41 +00:00
|
|
|
printf "\e[31m%s\e[30m\n" "Did not pass crash log file (full path)"
|
|
|
|
printf "\e[31m%s\e[30m\n" "Usage: $0 <executable> <crash_log>"
|
|
|
|
echo -en "\e[0m"
|
|
|
|
exit 1
|
2022-02-23 20:10:45 +00:00
|
|
|
fi
|
|
|
|
|
2023-03-12 15:48:45 +00:00
|
|
|
TMP_OFFSET=$(grep -E -o "\(with offset [0-9A-Fa-f]+\)" "$2" | grep -E -o "[0-9A-Fa-f]*")
|
2022-09-25 11:19:41 +00:00
|
|
|
if [ -z "$TMP_OFFSET" ]; then
|
2023-03-12 15:48:45 +00:00
|
|
|
TMP_OFFSET=$(grep -E -o "^[0-9A-Fa-f]+-[0-9A-Fa-f]+ \S+\.exe" "$2" | grep -E -o "^[0-9A-Fa-f]+")
|
2022-09-25 11:19:41 +00:00
|
|
|
if [ -z "$TMP_OFFSET" ]; then
|
2023-03-12 15:48:45 +00:00
|
|
|
TMP_OFFSET="0"
|
|
|
|
if ! grep -q -E -o "\s\S+\.exe!" "$2"; then
|
|
|
|
printf "\e[31m%s\e[30m\n" "Module offset not found; addresses will be absolute"
|
|
|
|
echo -en "\e[0m"
|
|
|
|
fi
|
2022-09-25 11:19:41 +00:00
|
|
|
fi
|
|
|
|
fi
|
2022-02-23 20:10:45 +00:00
|
|
|
|
2023-03-12 15:48:45 +00:00
|
|
|
if [ "$TMP_OFFSET" != "0" ]; then
|
|
|
|
echo "Module offset: 0x$TMP_OFFSET"
|
|
|
|
fi
|
|
|
|
|
2024-03-29 09:48:59 +00:00
|
|
|
ADDR_BASE=0x$(objdump -x "$1" | grep -E -o "^ImageBase\s+[0-9A-Fa-f]+$" | grep -E -o "[0-9A-Fa-f]+$")
|
2023-03-12 15:48:45 +00:00
|
|
|
echo "Image base: $ADDR_BASE"
|
|
|
|
|
|
|
|
ADDR_PC_REGEX='[0-9A-Fa-f]+ [0-9A-Fa-f]+ [0-9A-Fa-f]+ [0-9A-Fa-f]+'
|
2022-02-23 20:10:45 +00:00
|
|
|
while read -r line
|
|
|
|
do
|
2022-09-25 11:19:41 +00:00
|
|
|
if [[ $line =~ $ADDR_PC_REGEX ]]
|
|
|
|
then
|
2023-03-12 15:48:45 +00:00
|
|
|
RELATIVE_ADDR=$(echo "$line" | grep -E -o -m 1 "\s\S+\.exe!.*0x([0-9A-Fa-f]+)" | grep -E -o "0x[0-9A-Fa-f]+" | head -1)
|
|
|
|
if [ -z "$RELATIVE_ADDR" ]; then
|
|
|
|
TMP_ADDR=$(echo "$line" | grep -E -o -m 1 "[0-9A-Fa-f]+ " | head -1)
|
|
|
|
REAL_ADDR=$(printf '0x%X\n' "$(((0x$TMP_ADDR-0x$TMP_OFFSET)+ADDR_BASE))")
|
|
|
|
else
|
|
|
|
REAL_ADDR=$(printf '0x%X\n' "$((RELATIVE_ADDR+ADDR_BASE))")
|
|
|
|
fi
|
|
|
|
addr2line -e "$1" -a -p -f -C -i "$REAL_ADDR" | sed 's/ [^ ]*\/src\// src\//g'
|
2022-09-25 11:19:41 +00:00
|
|
|
fi
|
2022-02-23 20:10:45 +00:00
|
|
|
done < "$2"
|