#!/usr/bin/perl # # Nasty script for finding bits of office documents in a filesystem # image. Assumes that the files are 256k or smaller. Increase $BLKS # for larger files. # # Usage: cd scratchdir; docfind.pl < /dev/diskdev $BSIZE = 8192; $BLKS = 32; while (defined($dp = nextblk())) { next unless (substr($$dp, 0, 4) eq "\xd0\xcf\x11\xe0"); $dat = $$dp; @newblks = (); for (1..($BLKS - 1)) { $dp = nextblk(); last unless defined($dp); push(@newblks, $dp); $dat .= $$dp; } unshift(@blks, @newblks); $n++; print "Writing $n.doc\n"; open(FILE, ">$n.doc") || die "$n.doc: $!\n"; print FILE $dat; close(FILE); } sub nextblk { my $blk = shift(@blks); return $blk if (defined($blk)); my $data, $nread; $nread = read(STDIN, $data, $BSIZE); die "read: $!\n" unless (defined $nread); return undef if ($nread != $BSIZE); return \$data; }