Created
July 28, 2016 14:04
-
-
Save cyphunk/44d1bb7540596a2b01b9a58c297db8a3 to your computer and use it in GitHub Desktop.
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 | |
# used this once map lines from a bootloader log to files found in a | |
# firmware dump. This is a cheap way to understand stages of the | |
# bootloader. | |
# | |
# A bit more on that. After extracting all of the firmware parts such | |
# as file systems and monolithic code or bootloaders, make a log of | |
# the boot log (if possible, via serial for example) and then feed | |
# that to this script from the root directory of the extracted firmware. | |
# | |
# example: | |
# cd firmware_extract | |
# find_strings.sh seriallog.0 | |
# or to remove the verbose logging | |
# find_strings.sh seriallog.0 2>/dev/null | |
MINLEN=6 | |
MAXFILES=10 | |
if [ $# -lt 1 ]; then | |
echo "provide file with strings as argument (such as a log file)" | |
exit 1 | |
fi | |
cat $1 | head -100 | \ | |
while read line; do | |
echo "$line" | |
left="$line" | |
match="" | |
while [ 1 ]; do | |
[[ $left =~ ([\-_a-zA-Z][\-_\\ a-zA-Z]{$(($MINLEN-2)),}[\-_a-zA-Z])(.*) ]] | |
matchtmp="${BASH_REMATCH[1]}" | |
if [ "x${matchtmp}" = "x" ]; then | |
break; # no match found. done searching | |
fi | |
if [ ${#matchtmp} -gt ${#match} ]; then | |
match="$matchtmp" | |
fi | |
left="${BASH_REMATCH[2]}" | |
done | |
if [ ${#match} -lt $MINLEN ]; then | |
>&2 printf "### %-40s ###\n" "to short. skip line" | |
continue | |
fi | |
>&2 printf "### %-40s ###\n" "logest match: \"$match\"" | |
FILES=$(grep -rl "$match" . ) | |
if [[ "${FILES}" != "" ]]; then | |
IFS=$'\n' | |
i=1 | |
echo "##### match: \"$match\"" | |
for FILE in $FILES; do | |
if [ $i -gt $MAXFILES ]; then | |
echo "##### ..." | |
break | |
fi | |
echo -ne "##### $FILE\n" | |
i=$(($i+1)) | |
done | |
else | |
>&2 printf "### %-40s ###\n" "no matched files" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment