Created
June 17, 2014 21:04
-
-
Save anonymous/e0493e823091078b5132 to your computer and use it in GitHub Desktop.
Script for searching matching blocks in a drive
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 | |
# This script searches for matching blocks in a drive | |
# VERSION 1 | |
# License: GNU GPL version 3 or any later version as released by the Free Software Foundation | |
# NO WARRANTY | |
# Author: reddit.com user gnulicious | |
# THIS SCRIPT DOES NOT DO SANITY CHECKING ON ITS ARGUMENTS. Be sure you know what you're doing. | |
[[ $# != 6 ]] && { echo "Expected 6 arguments. See script code." ; exit ; } | |
# ALL UNITS ARE IN SECTORS (512 Bytes) | |
file="$1" | |
size="$2" | |
origin="$3" | |
search_start="$4" | |
search_end="$5" | |
search_increment="$6" | |
#Options | |
end_at_first_match=false | |
# get the md5sum and sha1sum of the origin chunk | |
origin_md5=$(dd bs=512 count="$size" if="$file" skip="$origin" | md5sum -b - ) | |
origin_sha1=$(dd bs=512 count="$size" if="$file" skip="$origin" | sha1sum -b - ) | |
declare -a match_locations | |
search="$search_start" | |
printf "Starting search..." | |
while [[ "$search" -lt "$search_end" && ( ${#match_locations[*]} -lt 1 || "$end_at_first_match" != true ) ]] ; do | |
[[ "$(dd bs=512 count="$size" if="$file" skip="$search" | md5sum -b - )" == "$origin_md5" ]] && | |
[[ "$(dd bs=512 count="$size" if="$file" skip="$search" | sha1sum -b - )" == "$origin_sha1" ]] && | |
{ printf "\nMatch found at location: $search\n" ; match_locations+=("$search") ; } | |
printf "." | |
search=$((search + search_increment)) | |
done | |
if [[ ${#match_locations[@]} -gt 0 ]]; then | |
echo | |
echo "With arguments $@, found matches at the following locations:" | |
for location in "${match_locations[@]}"; do | |
echo "$location" ; | |
done | |
else | |
echo "No matches found." | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment