#!/usr/bin/perl ## flashrecover -- copyright (c) 2005 by Jay Savage, ## ## flashrecover scans through a disk image looking for JPEG headers, copying them files. ## ## NOTE! USE THIS PROGRAM AT YOUR OWN RISK; THIS PROGRAM COMES WITH ## NO WARRANTY WHATSOEVER. ## ## Current version: ## $Id: flashrecover,v 1.2 2005/09/09 16:08:20 jay Exp $ ## ## Permission to use, copy, modify, and distribute this software for any ## purpose with or without fee is hereby granted, provided that the above ## copyright notice and this permission notice appear in all copies. use warnings; use strict; my $image = shift @ARGV; my $file = 0; my $dir = "lost+found"; my $name = $dir . "/flash_000.jpg"; my $sector; my $seclen = 512; my $magic = qr/^\xff\xd8\xff(?:\xe1|\xe0)/; mkdir $dir or die "$!" unless -d $dir; open(IMG, "< :raw", $image) or die "Couldn't open $image for reading: $!\n"; seek(IMG, 0, 0); while (!eof) { read(IMG, $sector, $seclen) or die "Couldn't read from $name: $!\n"; next if $file == 0 and $sector !~ $magic; if ($sector =~ $magic) { close(SAVE); print "Recoverd image to $name\n" if $file != 0; $name = sprintf("%s/flash_%3.3d.jpg", $dir, ++$file); open(SAVE, "> :raw", $name) or die "Couldn't open $name for writing: $!\n"; } print SAVE $sector or die "Couldn't write to $name:$!\n"; } close(SAVE); print "Recoverd image to $name\n"; print "\nRecovered $file files to $dir\n\n";