bintools/evalid/EvalidCompare.pm.bak
changeset 683 8e0eb519ef53
parent 676 b5e6747818a9
equal deleted inserted replaced
682:2c32f186fa1f 683:8e0eb519ef53
    60       'ELF file' => 'elf',
    60       'ELF file' => 'elf',
    61       'Unknown COFF object' => 'identical',
    61       'Unknown COFF object' => 'identical',
    62       'Unknown library' => 'identical',
    62       'Unknown library' => 'identical',
    63       'chm file' => 'chm_file',
    63       'chm file' => 'chm_file',
    64 	  'Header file' => 'header',
    64 	  'Header file' => 'header',
    65 	  'Distribution Policy' => 'distpol'
    65 	  'Distribution Policy' => 'distpol',
       
    66 	  'Rofs image' => 'img'
    66      );
    67      );
    67 
    68 
    68 
    69 
    69 # %TEMPDIR% and %FILE% are magic words for the expandor
    70 # %TEMPDIR% and %FILE% are magic words for the expandor
    70 # they will be replaced with suitable values when used
    71 # they will be replaced with suitable values when used
    81       preprocessed_text => {filter => \&PreprocessedTextFilter},
    82       preprocessed_text => {filter => \&PreprocessedTextFilter},
    82       permanent_file_store => {reader => 'pfsdump -c -v', filter => \&PermanentFileStoreFilter, rawretry => 1, relative_paths => 1},
    83       permanent_file_store => {reader => 'pfsdump -c -v', filter => \&PermanentFileStoreFilter, rawretry => 1, relative_paths => 1},
    83       ignore => {filter => \&FilterAll},
    84       ignore => {filter => \&FilterAll},
    84       chm_file => {expandor => 'hh -decompile %TEMPDIR% %FILE%', rawretry => 1},
    85       chm_file => {expandor => 'hh -decompile %TEMPDIR% %FILE%', rawretry => 1},
    85 	  header => {filter => \&FilterCVSTags},
    86 	  header => {filter => \&FilterCVSTags},
    86 	  distpol => {filter => \&DistributionPolicyFilter}
    87 	  distpol => {filter => \&DistributionPolicyFilter},
       
    88       img => {expandor => 'readimage -z %TEMPDIR% %FILE%', rawretry => 1}
    87      );
    89      );
    88 
    90 
    89 
    91 
    90 #
    92 #
    91 # Globals.
    93 # Globals.
    92 #
    94 #
    93 
    95 
    94 my $log;
    96 my $log;
    95 my $verbose;
    97 my $verbose;
       
    98 my $keepgoing;
    96 my $toRoot;
    99 my $toRoot;
    97 my $dumpDir;
   100 my $dumpDir;
    98 
   101 
    99 undef $dumpDir;
   102 undef $dumpDir;
   100 
   103 
   106 sub CompareFiles {
   109 sub CompareFiles {
   107   my $file1 = shift;
   110   my $file1 = shift;
   108   my $file2 = shift;
   111   my $file2 = shift;
   109   $verbose = defined($_[0]) ? shift : 0;
   112   $verbose = defined($_[0]) ? shift : 0;
   110   $log = defined($_[0]) ? shift : *STDOUT;
   113   $log = defined($_[0]) ? shift : *STDOUT;
       
   114   $keepgoing = defined($_[0]) ? shift : 0;
       
   115   
   111   # Try binary compare first (to keep semantics the same as evalid)...
   116   # Try binary compare first (to keep semantics the same as evalid)...
   112   if (DoCompareFiles($file1, $file2, 'unknown format')) {
   117   if (DoCompareFiles($file1, $file2, 'unknown format')) {
   113     return 1,'identical';
   118     return 1,'identical';
   114   }
   119   }
   115   my $type = IdentifyFileType($file1);
   120   my $type = IdentifyFileType($file1);
   238     my $member_start = 8;
   243     my $member_start = 8;
   239 
   244 
   240     open (FILE, $file) or die "Error: Couldn't open \"$file\" for reading: $!\n";
   245     open (FILE, $file) or die "Error: Couldn't open \"$file\" for reading: $!\n";
   241     binmode (FILE);
   246     binmode (FILE);
   242     
   247     
   243     while ($typeBuf =~ /^.{48}([0-9 ]{9})\x60\x0A(......)/s) {
   248     while ($typeBuf =~ /^.{48}([0-9 ]{9}).\x60\x0A(......)/s) {
   244       # $1 is the size of the archive member, $2 is first 6 bytes of the file
   249       # $1 is the size of the archive member, $2 is first 6 bytes of the file
   245       # There may be several different sorts of file in the archive, and we
   250       # There may be several different sorts of file in the archive, and we
   246       # need to scan through until we find a type we recognize:
   251       # need to scan through until we find a type we recognize:
   247       # $2 == 0x0A00 would be ARM COFF, 0x014C would be Intel COFF
   252       # $2 == 0x0A00 would be ARM COFF, 0x014C would be Intel COFF
   248       if ($2 =~ /^\x00\x0A/) {
   253       if ($2 =~ /^\x00\x0A/) {
   350    }
   355    }
   351   
   356   
   352   if ($typeBuf =~/^ITSF/) {
   357   if ($typeBuf =~/^ITSF/) {
   353     # chm file
   358     # chm file
   354     return "chm file";
   359     return "chm file";
       
   360   }
       
   361 
       
   362   if ($typeBuf =~/^(ROFS|ROFx)/) {
       
   363     # img file
       
   364     return "Rofs image";
   355   }
   365   }
   356 
   366 
   357   if ($file =~ m/\.(iby|h|hby|hrh|oby|rsg|cpp)$/i) {
   367   if ($file =~ m/\.(iby|h|hby|hrh|oby|rsg|cpp)$/i) {
   358     return "Header file";
   368     return "Header file";
   359   }
   369   }
   809               $iFileList2{$relpath} = "right";
   819               $iFileList2{$relpath} = "right";
   810             }
   820             }
   811           }, $tempdir2;
   821           }, $tempdir2;
   812   
   822   
   813   #Work out the if the two file lists are different
   823   #Work out the if the two file lists are different
       
   824   my @tmpfiles;
   814   foreach my $file (sort keys %iFileList1)
   825   foreach my $file (sort keys %iFileList1)
   815   {
   826   {
   816     if (! defined $iFileList2{$file})
   827     if (! defined $iFileList2{$file})
   817     {
   828     {
   818       # If the filename does not exist in the second filelist the compressed files cannot be the same.
   829       # If the filename does not exist in the second filelist the compressed files cannot be the same.
   819       print ($log "Did not find $file in $file2\n") if ($verbose);
   830       print ($log "Did not find $file in $file2\n") if ($verbose);
   820       return 0;
   831       if(!$keepgoing){
       
   832       	return 0;
       
   833       }else{
       
   834       	push @tmpfiles, $file;
       
   835       }
   821     } else {
   836     } else {
   822       delete $iFileList2{$file}
   837       delete $iFileList2{$file}
   823     }
   838     }
       
   839   }
       
   840   foreach my $file (@tmpfiles)
       
   841   {
       
   842    	delete $iFileList1{$file};
   824   }
   843   }
   825   
   844   
   826   # There are extra files in the second compressed file therefore the compressed files cannot be the same.
   845   # There are extra files in the second compressed file therefore the compressed files cannot be the same.
   827   if (scalar(keys %iFileList2) > 0)
   846   if (scalar(keys %iFileList2) > 0)
   828   {
   847   {
   829     print ($log "$file2 contained more files than $file1\n") if ($verbose);
   848     print ($log "$file2 contained more files than $file1\n") if ($verbose);
   830     return 0;
   849     if (!$keepgoing){
       
   850 	    return 0;
       
   851 	  }else{
       
   852 	  	foreach my $file (sort keys %iFileList2){
       
   853 	  		print ($log "Dig not find $file in $file1\n") if ($verbose);
       
   854 	  	}
       
   855 	  }
   831   }
   856   }
   832   
   857   
   833   print($log "Comparing content\n") if ($verbose);
   858   print($log "Comparing content\n") if ($verbose);
   834   #filelist1 and filelist2 contain all the same filenames, now compare the contents of each file
   859   #filelist1 and filelist2 contain all the same filenames, now compare the contents of each file
   835   my $same = -1; # Variable to store collated result of comparison, assume an error
   860   my $same = 1; # Variable to store collated result of comparison, assume an error
   836   foreach my $file (keys %iFileList1)
   861   foreach my $file (keys %iFileList1)
   837   {
   862   {
   838     my $type; 
   863   	my $tmpsame;
   839     ($same, $type) = CompareFiles($tempdir1.$file,$tempdir2.$file, $verbose, $log);
   864   	my $type;
   840     print ($log "Comparing $tempdir1.$file against $tempdir2.$file\n") if ($verbose);
   865     ($tmpsame, $type) = CompareFiles($tempdir1.$file,$tempdir2.$file, $verbose, $log, $keepgoing);
   841     last if ($same == 0); # do not bother comparing more files if one of the expanded files is different.
   866     print ($log "Comparing $tempdir1.$file against $tempdir2.$file, $tmpsame, $keepgoing\n") if ($verbose);
       
   867     if (!$keepgoing){
       
   868 	    if ($tmpsame == 0){ # do not bother comparing more files if one of the expanded files is different.
       
   869 	    	$same = 0;
       
   870 	    	last;
       
   871 	    }
       
   872 	  }else{
       
   873 	  	if ($tmpsame == 0){
       
   874 	  		print ($log "Failed\n\n") if ($verbose);
       
   875 	  		$same = 0;
       
   876 	  	}else{
       
   877 	  		print ($log "OK\n\n") if ($verbose);
       
   878 	  	}
       
   879 	  }
   842   }
   880   }
   843   
   881   
   844   #Cleanup the temporary directories
   882   #Cleanup the temporary directories
   845   rmtree([$tempdir1,$tempdir2]);
   883   rmtree([$tempdir1,$tempdir2]);
   846   
   884