Last active
April 30, 2019 18:00
-
-
Save coderofsalvation/fbf03834fc16fa4f13b92513631f969c to your computer and use it in GitHub Desktop.
tool to include binary data (tar/zip archives etc) inside a shellscript
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 | |
tmpfile=/tmp/bin2sh | |
code_begin='#!/bin/bash | |
BIN2SH=1 | |
function extract_payload() | |
{ | |
match=$(grep --text --line-number '^PAYLOAD:$' $0 | cut -d ':' -f 1) | |
payload_start=$((match + 1)) | |
tail -n +$payload_start $0 | |
} | |
# the code below was generated by bin2sh: https://gist.github.com/coderofsalvation/fbf03834fc16fa4f13b92513631f969c | |
# do not remove this + the line above | |
' | |
code_end=' | |
exit 0 | |
PAYLOAD:' | |
if [[ ! "$2" ]]; then | |
echo "Usage: $0 PAYLOAD_FILE your.sh > final.sh" | |
echo "" | |
echo "run '[[ -n \$BIN2SH ]] && extract_payload > myfile.bin' in your.sh" | |
exit 0 | |
fi | |
[[ ! -f "$2" ]] && touch "$2" | |
{ | |
echo "$code_begin" | |
cat "$2" | |
echo "$code_end" | |
cat "$1" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment