#!/bin/bash

# Something must be hidden in the image file. Look for trailing data
# From Wikipedia, 0xFFD9 marks the end of a JPEG, and 0xFFD8 the start

echo "Something must be hidden in the image file. Look for trailing data"
echo -e "From Wikipedia, 0xFFD9 marks the end of a JPEG, and 0xFFD8 the start\n"

echo "xxd comp3.jpg | grep -A5 "ffd9" --color=always"
xxd comp3.jpg | grep -A5 "ffd9" --color=always

# Looks like another JPEG header starting at 0xCBD4
# So we need to rip the end off the JPEG and save it as a new file.

echo -e "\nLooks like another JPEG header starting at 0xCBD4!\n"
echo -e "So we need to rip the end off the JPEG and save it as a new file.\n"

echo "ls -l comp3.jpg"
ls -l comp3.jpg

# 62468 bytes long, so need to get (62468 - 52180) = 10288 bytes

echo -e "\n62468 bytes long, so need to get (62468 - 52180) = 10288 bytes starting"
echo "at 52180"

echo -e "\ndd -q ibs=1 skip=52180 count=10288 if=comp3.jpg of=comp4.jpg"
dd ibs=1 skip=52180 count=10288 if=comp3.jpg of=comp4.jpg &> /dev/null

xdg-open comp4.jpg
