Created
December 1, 2018 19:45
-
-
Save pointhi/590ee986d47d483c9c7d35fae472c661 to your computer and use it in GitHub Desktop.
find image files on a busybox machine (without using tools like file, ...)
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/sh | |
if [ $# -eq 0 ] | |
then | |
echo "Usage: $0 <search_root_dir>" | |
exit | |
fi | |
echo "------ start in directory: \"`pwd`/$1\"" | |
find $1 -type f | while read fname; do | |
# match on Magic number of various image files | |
if hexdump -n8 "$fname" | grep -qF "0000000 5089 474e 0a0d 0a1a"; then | |
echo -ne "\nPNG MATCH: \"$fname\"" | |
elif hexdump -n3 "$fname" | grep -qF "0000000 d8ff 00ff"; then | |
echo -ne "\nJPG MATCH: \"$fname\"" | |
elif hexdump -n2 "$fname" | grep -qF "0000000 4d42"; then | |
echo -ne "\nBMP MATCH: \"$fname\"" | |
else | |
echo -n "." | |
fi; | |
done | |
echo -e "\n------ end" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment