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

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


In reply to Extract Digicam images from raw file by joe++

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.