Last active
April 13, 2022 13:28
-
-
Save raphaelsc/ca5060f1cc754cbd81da9f2e12ad1e7c 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 | |
input=$1 | |
hole_size=$2 | |
hole_found=false | |
old_line= | |
sample= | |
previous_offset= | |
if [ "$hole_size" = "" ]; then | |
hole_size="1024" | |
fi | |
FILESIZE=$(stat -c%s "$1") | |
echo "Size of $1 = $FILESIZE bytes." | |
hexdump $input | while IFS= read -r line | |
do | |
if [ "$hole_found" = true ]; then | |
offset=$(echo "$line" | awk '{ print toupper($1) }') | |
count=$(echo "ibase=16; $offset - $previous_offset" | bc) | |
cond=$(echo "$count >= $hole_size" | bc) | |
if [ "$cond" = "1" ]; then | |
echo "Found hole of size "$count" at 0x"$previous_offset", sample: "$sample"" | |
fi | |
hole_found=false | |
fi | |
if [ "$line" == "*" ]; then | |
previous_offset=$(echo "$old_line" | awk '{ print toupper($1) }') | |
hole_found=true | |
sample=$old_line | |
fi | |
old_line=$line | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment