Skip to content

Instantly share code, notes, and snippets.

@silvasur
Created March 26, 2011 20:56
Show Gist options
  • Save silvasur/888630 to your computer and use it in GitHub Desktop.
Save silvasur/888630 to your computer and use it in GitHub Desktop.
Easily inject files into jpeg files (using the comment tag in the EXIF data)
#!/bin/bash
# jpegincector.sh - Easily inject files into jpeg files (using the comment tag in the EXIF data)
# You need this tools / programs to run jpeginjector.sh:
# * uuencode/uudecode (usually found in the sharutils package)
# * exiftool (usually found in the perl-Image-ExifTool package)
# * uuidgen (usually already installed)
#
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
# Version 2, December 2004
#
# Copyright (C) 2004 Sam Hocevar
# 14 rue de Plaisance, 75014 Paris, France
# Everyone is permitted to copy and distribute verbatim or modified
# copies of this license document, and changing it is allowed as long
# as the name is changed.
#
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
#
# 0. You just DO WHAT THE FUCK YOU WANT TO.
do_inject() {
TEMP_UUE_FILE="/tmp/$(uuidgen)"
uuencode -m `basename "$1"` < "$1" > "$TEMP_UUE_FILE"
exiftool -Comment"<=$TEMP_UUE_FILE" "$2"
rm -f "$TEMP_UUE_FILE"
}
do_extract() {
TEMP_UUE_FILE="/tmp/$(uuidgen)"
if ! exiftool -b -Comment $1 > "$TEMP_UUE_FILE" 2> /dev/null; then
echo "Could not extract file. Perhaps no valid JPEG file?" >&2
rm "$TEMP_UUE_FILE"
return 1
fi
uudecode "$TEMP_UUE_FILE"
RETVAL=$?
rm -f "$TEMP_UUE_FILE"
return $RETVAL
}
PRGNAME=`basename "$0"`
case "$1" in
inject)
if [ $# -ne 3 ]; then
echo -e "$PRGNAME: Command \"$1\" needs two parameters.\n$PRGNAME help for more information." >&2
exit 1
else
do_inject "$2" "$3"
fi
;;
extract)
if [ $# -eq 2 ]; then
do_extract "$2"
else
echo -e "$PRGNAME: Command \"$1\" needs one parameter.\n$PRGNAME help for more information." >&2
fi
;;
help)
cat <<-HELPTEXT
Usage: $PRGNAME COMMAND FILE1 [FILE2]
Where COMMAND is one of these:
help
Print this help.
inject FILE JPEG
Injects FILE into JPEG.
extract JPEG
Extracts a file from JPEG.
HELPTEXT
;;
*)
if [ "$1" == "" ]; then
echo -e "$PRGNAME: No command given.\nUsage: $PRGNAME COMMAND [FILE1] [FILE2]\n\"$PRGNAME help\" for more information." >&2
exit 1
else
echo -e "$PRGNAME: Unknown command: \"$1\".\nUsage: $PRGNAME COMMAND [FILE1] [FILE2]\n\"$PRGNAME help\" for more information." >&2
fi
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment