Some time ago I accidentally erased a Compact Flash card with digicam images, before I copied them to another medium. Stupid...
Luckily I realised that those Flash Cards have some basic file system layout, very similar to ye olde FAT-16. This means that erasing a file just sets a bit in the allocation table instead of physically removing the data from the actual file blocks. Also, I was pretty sure that I didn't erase single images in between, so the actual image data would likely be aligned in consecutive file blocks.
I mounted the CF card on my Mac (using a PCMCIA adapter) and copied the file system to a disk image. After some tinkering with JPEG and EXIF file format specifications I was able to recover the images.
Now this is a real kludge, with the following limitations (at least):
#!/usr/bin/perl -w use strict; # # Quick kludge to extract Digicam images from a file # e.g. a disk image from an accidentally erased CF card # # Scan string for the folowing markers: # SOI - Start of Image = \xff\xd8 # APP1 header for Exif = \xff\xe1 # EOI - End of Image = \xff\xd9 # # Note that the whole blob is read in memory - YYMV! # die "$0 <file> with embedded EXIF images\n" unless (-f $ARGV[0]); my @IMGS; { open(FH, $ARGV[0]) or die $!; local $/ = undef; # Hmm... this breaks on embedded (EXIF) thumbnails... # @IMGS = split(/\xff\xd8/, <FH>); # For EXIF only: @IMGS = split(/\xff\xd8\xff\xe1/, <FH>); } # 1st array element contains leading crap for my $idx (1..@IMGS-1) { open(FH, sprintf("> img%02d.jpg", $idx)) or die $!; # cut crap after EOI marker print FH "\xff\xd8\xff\xe1", split(/\xff\xd9/, $IMGS[$idx], 1), "\xf +f\xd9"; close FH; }
--
Cheers, Joe
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Extract Digicam images from raw file
by Anonymous Monk on Jan 09, 2003 at 19:19 UTC |