use diagnostics; use warnings; use Wx; use Wx::Event qw(EVT_BUTTON); use Wx::Event qw(EVT_DROP_FILES); use File::Slurp; use Digest::MD5; use File::Path; ############################################################################### my $app = Wx::SimpleApp->new; my $frame = Wx::Frame->new( undef, -1, 'test tool', wxDefaultPosition, Wx::Size->new(700,400), wxDEFAULT_DIALOG_STYLE|wxSTAY_ON_TOP ); $frame->DragAcceptFiles(1); EVT_DROP_FILES( $frame, \&extract ); ############################################################################### my $noteBook = Wx::Notebook->new($frame, -1, wxDefaultPosition, wxDefaultSize); my $window1 = Wx::Panel->new($noteBook, wxID_ANY); my $window2 = Wx::Panel->new($noteBook, wxID_ANY); my $window3 = Wx::Panel->new($noteBook, wxID_ANY); $noteBook->AddPage($window1, "First", 1, 0); $noteBook->AddPage($window2, "Second", 0, 1); $noteBook->AddPage($window3, "Third", 0, 2); $frame->Show(1); $app->SetTopWindow($frame); $app->MainLoop; ############################################################################### sub extract { $_= shift; print "@_\n"; #<------- prints: "Wx::DropFilesEvent=SCALAR(0x3131024)" #please read below the code for the question pertaining to this. open (my $data, '<', "@_") or die "cannot open $data $!"; my $fileLocation = ''; my $fileSize = ''; my $fileName = ''; my $chunk = ''; seek ( $data, 0x04, 0 ); read ( $data, my $count, 0x04 ); $count =~ s/(.)/sprintf("%02x",ord($1))/egs; my $entryCount = hex($count); print "\nEntry count in file is: $entryCount\n\n"; seek ( $data, 0x00, 0 ); seek( $data, 0x10, 0 ) or die "cannot seek $data $!"; for (my $i=1; $i <= $entryCount; $i++) { read( $data, $fileLocation, 0x08 ); read( $data, $fileSize, 0x08 ); read( $data, $fileName, 0x20 ); $fileLocation =~ s/(.)/sprintf("%02x",ord($1))/egs; $fileSize =~ s/(.)/sprintf("%02x",ord($1))/egs; $fileName =~ s/\0+$//; open( my $extractedData, '>', "extracted/$fileName" ) or die "Cannot open $fileName $!"; sysseek( $data, hex($fileLocation), 0 ); sysread( $data, $chunk, hex($fileSize) ); syswrite( $extractedData, $chunk ); close( $extractedData ); } my $dirname = "extracted/"; my @md5s = read_file("md5"); my $md5s = join( '', @md5s ); my $filesize = ''; open( my $buf, '<', "extracted/sdk_version" ) or die "cannot open $buf $!"; 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{.*/}{}; my $md5 = Digest::MD5->new->addfile($FILE)->hexdigest; if ( $md5s =~ $md5 ) { print "$md5 Match! $sdk $file $filesize\n"; } else { print "WARNING !\n"; } } }