hecky

cmp_bytes.sh

Mar 16th, 2013
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.90 KB | None | 0 0
  1. #!/bin/bash
  2. #./cmp_bytes PoC
  3. #Author:    hecky
  4. #Web:       Neobits.org
  5. #Twitter:   @hecky
  6. #Mail:      [email protected]
  7.  
  8. file1=$1
  9. file2=$2
  10.  
  11. if [ $(echo $#) -ne 2 ]; then echo -e "./cmp_bytes.sh file1 file2\n\n\t<<< \e[1;31m@hecky\e[m from \e[1;36mNeobits.org\e[m >>>" ; exit ;fi
  12.  
  13. declare -a bytes1=( $(xxd -p "$file1" | fold -2 ) )
  14. declare -a bytes2=( $(xxd -p "$file2" | fold -2 ) )
  15.  
  16. let size1=$(du -b "$file1" | cut -f1)
  17. let size2=$(du -b "$file2" | cut -f1)
  18.  
  19. if [ $size1 -ne $size2 ]; then
  20.     alert="different"
  21.     if [ $size1 -gt $size2 ]; then
  22.         let size=$size1
  23.     else
  24.         let size=$size2
  25.     fi
  26. else
  27.     #Just for fun :P
  28.     let size=$((($size1+$size2)/2))
  29. fi
  30.  
  31. if [[ -a $file1".hex" && -a $file2".hex" ]]; then rm -rf $file1".hex" $file2".hex" ;fi
  32.  
  33. let count=0
  34.  
  35. if [[ $alert != "different" ]];then
  36.     for ((i=0;i<$size;i++));do
  37.         if [ "${bytes1[$i]}" != "${bytes2[$i]}" ]; then
  38.             let $((count++))
  39.             echo -e "Byte  \e[1;36m"$(($i+1))"\e[m:\t"${bytes1[$i]}" - "${bytes2[$i]}
  40.             (printf $(echo -n "\x"${bytes1[$i]}) >> $file1".hex") &> /dev/null
  41.             (printf $(echo -n "\x"${bytes2[$i]}) >> $file2".hex") &> /dev/null
  42.         fi
  43.     done
  44. else
  45.         for ((i=0;i<$size;i++));do
  46.         if [ "${bytes1[$i]}" != "${bytes2[$i]}" ]; then
  47.             let $((count++))
  48.             echo -e "Byte  \e[1;36m"$(($i+1))"\e[m:\t"${bytes1[$i]}" - "${bytes2[$i]}
  49.             if [[ ${bytes1[$i]} == "" ]];then
  50.                 (printf $(echo -n "\x"${bytes2[$i]}) >> $file2".hex") &> /dev/null             
  51.             elif [[ ${bytes2[$i]} == "" ]];then
  52.                 (printf $(echo -n "\x"${bytes1[$i]}) >> $file2".hex") &> /dev/null
  53.             else
  54.                 (printf $(echo -n "\x"${bytes1[$i]}) >> $file1".hex") &> /dev/null
  55.                 (printf $(echo -n "\x"${bytes2[$i]}) >> $file2".hex") &> /dev/null
  56.             fi
  57.         fi
  58.     done
  59. fi
  60.  
  61. echo -e "\n\e[1;4;31m$count\e[m bytes diferentes"
  62. echo -e "\nSe han guardado los bytes diferentes en \e[1;33m$file1.hex\e[m y \e[1;33m$file2.hex\e[m\n\n\t<<< \e[1;31m@hecky\e[m from \e[1;36mNeobits.org\e[m >>>"
Advertisement
Add Comment
Please, Sign In to add comment