Once upon a time, a Compact Flash card containing a bunch of pictures (jpeg images) was accidentally formatted. I wanted the pictures back, so I rescued them.
JpegRescue is a small program that I wrote to do this. It searches a filesystem for what appear to be JPEG files, and then it extracts these JPEG files.
The workings of JpegRescue are described in this journal entry.
The basic program is available here: jpegrescue.c
. It has no unusual dependencies, so you should be able to compile it directly: gcc jpegrescue.c -o jpegrescue
.
The program takes one command line argument, which is the name of the file to search for jpeg images. This can be a block device (like /dev/hda1
), or a file that contains an image of a filesystem.
If you have any questions, comments, or suggestions, please leave them here, along with your email address.
The code as given searches for the string "Exif" as a signature of a JPEG file. Not all JPEG files have Exif information, so this is not the most reliable way to search for JPEG data. Actually, if you want to be sure of finding all the JPEG data that exists (at the expense of many false failures — which isn't really an expense), change the search pattern to the following:
/* This pattern will find all JPEG data. */ char pattern[] = { 0xFF, 0xD8}; int pattern_len = 2; int pattern_ofs = 0;
If you're running on a big-endian machine (PowerPC, Sparc, ... — really, anything but x86), then comment out the one line in the body of wordswap
.
If you're looking for something other than JPEG data, try foremost, "a console program to recover files based on their headers and footers" (developed by the Air Force Office of Special Investigations!). JpegRescue is similar in concept to Foremost but is specially adapted to identify and extract JPEG data.
The program should compile fine on Windows. You can use dd for windows to generate a filesystem image for JpegRescue to process.
JpegRescue is listed on FreshMeat.
Copyright © 2004-04-07 by Tobin Fricke