Figured out a better way. Now it also prints out MD5, Match!, filename and filesize. If it doesnt match, it just prints "Warning" and nothing else

Here is the final working code:

use File::Path qw(make_path rmtree); use Digest::MD5; use File::Slurp; rmtree 'extracted'; open( my $infile, '<', $ARGV[0] ) or die "cannot open file: $!"; binmode($infile); make_path('./extracted'); #or die "Failed to create Direcotry: $!"; 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) { read( $infile, $fileLocation, 0x08 ); read( $infile, $fileSize, 0x08 ); read( $infile, $fileName, 0x20 ); if ( $fileLocation =~ 'SCE' ) { last; } $fileLocation =~ s/(.)/sprintf("%02x",ord($1))/eg; $fileSize =~ s/(.)/sprintf("%02x",ord($1))/eg; $fileName =~ s/\0+$//; if ( $fileLocation =~ 'ffffffffffffffff' ) { last; } open( $file, '>', "extracted/$fileName" ) or die "Cannot open $fil +eName $!"; binmode($file); sysseek( $infile, hex($fileLocation), 0 ); sysread( $infile, $chunk, hex($fileSize) ); syswrite( $file, $chunk ); $fileLocation = ''; $fileSize = ''; } #Get md5 of each file extracted and compare against array my $dirname = "extracted"; my @md5s = read_file "C:/md5"; my $scal = join( '', @md5s ); my $filesize = ''; open( my $buf, '<', "extracted/sdk_version" ) or die "cannot open sdk_version: $!"; seek( $buf, 0x00, 0 ); read( $buf, my $sdk, 0x03 ); foreach my $file (<$dirname/*>) { next if -d $file; open( my $FILE, $file ); binmode($FILE); $filesize = -s $FILE; $file =~ s{.*/}{}; $md5 = Digest::MD5->new->addfile($FILE)->hexdigest; if ( $scal =~ $md5 ) { print "$md5 Match! $sdk $file $filesize\n"; } else { print "WARNING !\n"; } }

In reply to Re^6: problem with sysseek in loop by james28909
in thread problem with sysseek in loop by james28909

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.