Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Extract Digicam images from raw file

by joe++ (Friar)
on Jan 09, 2003 at 10:53 UTC ( [id://225501]=CUFP: print w/replies, xml ) Need Help??

Monks,

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):

  • The whole disk image is read into memory (my CF card was only 8 MB - YMMV!)
  • This only works if disk blocks are aligned, in other words, the disk image may not be fragmented
  • You need to be able to dump the CF contents to a file; on Mac use Disc Copy (uncompressed!), on Un*x/Linux try something with dd(1)
Hopefully no-one will ever need this ;-)
#!/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
    And to think I paid $30 for a program to do this for me!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://225501]
Approved by rob_au
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (3)
As of 2024-03-29 06:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found