A friend and I have been playing around with capturing images from LilacSat-1. Data loss is not unheard of when trying to recieve data from a small box hurtling through space. One of the issues we've run into is missing the first packets that include the JPEG header (for the sake of simplicity, we're going to temporarily redefine "JPEG header" to mean everything prior to the actual image data).
I knew it had to be possible to recover the header from another image (with the same attributes mind you), but I was having trouble finding a resource that I understood to make sense of my test image. Eventually I stumbled across some code that referenced a page that sadly was no longer online. With a little digging, I was able to turn it up on archive.org.
Finally armed with a resource that made sense to me when I looked at my image in a hex editor, I started writing Python. The code I ended up with isn't pretty, but it works. It parses the file, and fails with an error if anything falls outside of its expectations. As it reads in the good image file, it writes out the header to a new file until it encounters the end of the scan markers, at which point it stops writing the header (though it continues to process the image).
My python hackery, the sample header it produced, as well as a plain text version of the JPEG reference I used can be found in this Gist.