Skip to content

Instantly share code, notes, and snippets.

@coderofsalvation
Last active April 30, 2019 18:00
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 coderofsalvation/fbf03834fc16fa4f13b92513631f969c to your computer and use it in GitHub Desktop.
Save coderofsalvation/fbf03834fc16fa4f13b92513631f969c to your computer and use it in GitHub Desktop.
tool to include binary data (tar/zip archives etc) inside a shellscript
#!/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