use Digest::MD5; use File::Path qw(make_path); open (my $infile, '<', 'file') or die "cannot open file: $!"; binmode ($infile); make_path ('./extracted'); my $curpos = ''; my $fileLocation = ''; my $fileSize = ''; my $fileName = ''; my $file =''; my $chunk = ''; my $exit = ''; #GET File Location, File Size, File Name and write to file seek ($infile, 0x10, 0); until ($exit){ $curpos = tell $infile; seek ($infile, $curpos, 0); read ($infile, $fileLocation, 0x08); $curpos = tell $infile; seek ($infile, $curpos, 0); read ($infile, $fileSize, 0x08); $curpos = tell $infile; seek ($infile, $curpos, 0); read ($infile, $fileName, 0x20); $curpos = tell $infile; if ($fileLocation =~ 'unformatted characters'){ last; } $fileLocation =~ s/(.)/sprintf("%02x",ord($1))/eg; $fileSize =~ s/(.)/sprintf("%02x",ord($1))/eg; $fileName =~ s/\0+$//; if ($fileLocation =~ 'formatted characters'){ last; } #THIS PART ACTUALLY EXTRACTS THE DATA BASED OFF OF OFFSETS open($file, '>', "extracted/$fileName") or die "Cannot open $fileName +$!"; binmode($file); sysseek ($infile, hex($fileLocation), 0); sysread ($infile, $chunk, hex($fileSize)); syswrite ($file, $chunk); $fileLocation = ''; $fileSize = ''; }; #GET MD5 my $dirname = "extracted"; foreach my $file (<$dirname/*>) { next if -d $file; open( my $FILE, $file ); binmode($FILE); open (my $md5, "+>>", "C:/md5") or die "cant open md5.txt: $!"; binmode($md5); $file =~ s{.*/}{}; syswrite $md5, Digest::MD5->new->addfile($FILE)->hexdigest; syswrite $md5, " $file\n"; };
In reply to Re^2: problem with sysseek in loop
by james28909
in thread problem with sysseek in loop
by james28909
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |