Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dantheman213/7744598fda4033f1c4189e22bdb26ad7 to your computer and use it in GitHub Desktop.
Save dantheman213/7744598fda4033f1c4189e22bdb26ad7 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# ex: ./charles_convert_raw_hexdump_to_bin.sh hexdumpraw.txt hexformatted.txt data.bin
# hexdumpraw.txt ex:
## 00000510 0a 6d 6f 64 65 6c 5f 6e 61 6d 65 12 07 4e 65 78 model_name Nex
## 00000520 75 73 20 35 1a 20 0a 11 61 72 63 68 69 74 65 63 us 5 architec
## 00000530 74 75 72 65 5f 6e 61 6d 65 12 0b 61 72 6d 65 61 ture_name armea
## 00000540 62 69 2d 76 37 61 1a 19 0a 0b 64 65 76 69 63 65 bi-v7a device
## 00000550 5f 6e 61 6d 65 12 0a 68 61 6d 6d 65 72 68 65 61 _name hammerhea
## 00000560 64 1a 1a 0a 0c 70 72 6f 64 75 63 74 5f 6e 61 6d d product_nam
## 00000570 65 12 0a 68 61 6d 6d 65 72 68 65 61 64 1a 51 0a e hammerhead Q
## 00000580 0a 62 75 69 6c 64 5f 69 6e 66 6f 12 43 67 6f 6f build_info Cgoo
# hexformatted.txt outputs to:
## 0a 6d 6f 64 65 6c 5f 6e 61 6d 65 12 07 4e 65 78
## 75 73 20 35 1a 20 0a 11 61 72 63 68 69 74 65 63
## 74 75 72 65 5f 6e 61 6d 65 12 0b 61 72 6d 65 61
## ....
# data.bin represents hex above
if [ "$#" -ne 3 ]; then
echo "Incorrect inputs"
echo "./charles_convert_raw_hexdump_to_bin.sh <input hex raw file> <output hex dump formatted> <output binary from formatted hex dump file>"
echo "ex: ./charles_convert_raw_hexdump_to_bin.sh hexdumpraw.txt hexformatted.txt data.bin"
exit 1
fi
echo "" > $2
cat $1 | while read line
do
# extracts 16 byte hex line from larger string
newLine="${line:10:47}"
echo $newLine >> $2
done
# remove blank first line from file
sed -i '1d' $2
# converts text hex values into binary
xxd -r -p $2 $3
echo "COMPLETE!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment