655
|
1 |
#
|
|
2 |
# Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
# All rights reserved.
|
|
4 |
# This component and the accompanying materials are made available
|
|
5 |
# under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
# which accompanies this distribution, and is available
|
|
7 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
#
|
|
9 |
# Initial Contributors:
|
|
10 |
# Nokia Corporation - initial contribution.
|
|
11 |
#
|
|
12 |
# Contributors:
|
|
13 |
#
|
|
14 |
# Description:
|
|
15 |
#
|
|
16 |
|
|
17 |
package EvalidCompare;
|
|
18 |
|
|
19 |
use strict;
|
|
20 |
our $VERSION = '1.00';
|
|
21 |
use IO::Handle;
|
|
22 |
use IO::File;
|
|
23 |
use Cwd;
|
|
24 |
|
|
25 |
use File::Temp qw/ tempfile tempdir /;
|
|
26 |
use File::Find;
|
|
27 |
use File::Path;
|
|
28 |
use File::Basename;
|
|
29 |
use File::Copy;
|
|
30 |
|
|
31 |
#
|
|
32 |
# Constants.
|
|
33 |
#
|
|
34 |
|
|
35 |
my %typeLookup = (
|
|
36 |
'ARM PE-COFF executable' => 'ignore',
|
|
37 |
'E32 EXE' => 'e32',
|
|
38 |
'E32 DLL' => 'e32',
|
|
39 |
'Uncompressed E32 EXE' => 'e32',
|
|
40 |
'Uncompressed E32 DLL' => 'e32',
|
|
41 |
'Compressed E32 EXE' => 'e32',
|
|
42 |
'Compressed E32 DLL' => 'e32',
|
|
43 |
'Intel DLL' => 'intel_pe',
|
|
44 |
'Intel EXE' => 'intel_pe',
|
|
45 |
'MSDOS EXE' => 'intel_pe',
|
|
46 |
'Intel object' => 'intel',
|
|
47 |
'Intel library' => 'intel',
|
|
48 |
'ELF library' => 'elf',
|
|
49 |
'ARM object' => 'arm',
|
|
50 |
'ARM library' => 'arm',
|
|
51 |
'unknown format' => 'identical',
|
|
52 |
'Java class' => 'identical',
|
|
53 |
'ZIP file' => 'zip',
|
|
54 |
'Permanent File Store' => 'permanent_file_store',
|
|
55 |
'SIS file' => 'identical',
|
|
56 |
'MSVC database' => 'ignore',
|
|
57 |
'MAP file' => 'map',
|
|
58 |
'SGML file' => 'sgml',
|
|
59 |
'Preprocessed text' => 'preprocessed_text',
|
|
60 |
'ELF file' => 'elf',
|
|
61 |
'Unknown COFF object' => 'identical',
|
|
62 |
'Unknown library' => 'identical',
|
|
63 |
'chm file' => 'chm_file',
|
|
64 |
'Header file' => 'header',
|
676
|
65 |
'Distribution Policy' => 'distpol',
|
|
66 |
'Rofs image' => 'img'
|
655
|
67 |
);
|
|
68 |
|
|
69 |
|
|
70 |
# %TEMPDIR% and %FILE% are magic words for the expandor
|
|
71 |
# they will be replaced with suitable values when used
|
|
72 |
# they also enabled an order of expandor arguments where the filename is not last
|
|
73 |
my %typeHandler = (
|
|
74 |
e32 => {reader => 'elf2e32 --dump --e32input=', filter => \&Elf2E32Filter},
|
|
75 |
arm => {reader => 'nm --no-sort', filter => \&NmFilter, retry => 1, relative_paths => 1},
|
|
76 |
elf => {reader => 'elfdump -i', filter => \&ElfDumpFilter, rawretry => 1},
|
|
77 |
intel => {reader => '%EPOCROOT%epoc32\gcc_mingw\bin\nm --no-sort', filter => \&NmFilter, rawretry => 1, relative_paths => 1, skipstderr => 1},
|
|
78 |
intel_pe => {reader => 'pe_dump', filter => \&FilterNone, rawretry => 1},
|
|
79 |
zip => {reader => '"'.$FindBin::Bin.'/unzip" -l -v', filter => \&UnzipFilter, rawretry => 1},
|
|
80 |
map => {filter => \&MapFilter, skipblanks => 1},
|
|
81 |
sgml => {filter => \&SgmlFilter},
|
|
82 |
preprocessed_text => {filter => \&PreprocessedTextFilter},
|
|
83 |
permanent_file_store => {reader => 'pfsdump -c -v', filter => \&PermanentFileStoreFilter, rawretry => 1, relative_paths => 1},
|
|
84 |
ignore => {filter => \&FilterAll},
|
|
85 |
chm_file => {expandor => 'hh -decompile %TEMPDIR% %FILE%', rawretry => 1},
|
|
86 |
header => {filter => \&FilterCVSTags},
|
676
|
87 |
distpol => {filter => \&DistributionPolicyFilter},
|
|
88 |
img => {expandor => 'readimage -z %TEMPDIR% %FILE%', rawretry => 1}
|
655
|
89 |
);
|
|
90 |
|
|
91 |
|
|
92 |
#
|
|
93 |
# Globals.
|
|
94 |
#
|
|
95 |
|
|
96 |
my $log;
|
|
97 |
my $verbose;
|
676
|
98 |
my $keepgoing;
|
655
|
99 |
my $toRoot;
|
|
100 |
my $dumpDir;
|
|
101 |
|
|
102 |
undef $dumpDir;
|
|
103 |
|
|
104 |
|
|
105 |
#
|
|
106 |
# Public.
|
|
107 |
#
|
|
108 |
|
|
109 |
sub CompareFiles {
|
|
110 |
my $file1 = shift;
|
|
111 |
my $file2 = shift;
|
|
112 |
$verbose = defined($_[0]) ? shift : 0;
|
|
113 |
$log = defined($_[0]) ? shift : *STDOUT;
|
676
|
114 |
$keepgoing = defined($_[0]) ? shift : 0;
|
|
115 |
|
655
|
116 |
# Try binary compare first (to keep semantics the same as evalid)...
|
|
117 |
if (DoCompareFiles($file1, $file2, 'unknown format')) {
|
|
118 |
return 1,'identical';
|
|
119 |
}
|
|
120 |
my $type = IdentifyFileType($file1);
|
|
121 |
if ($typeLookup{$type} eq 'identical') {
|
|
122 |
return 0,$type; # We already know a binary compare is going to return false.
|
|
123 |
}
|
|
124 |
return DoCompareFiles($file1, $file2, $type),$type;
|
|
125 |
}
|
|
126 |
|
|
127 |
sub GenerateSignature {
|
|
128 |
my $file = shift;
|
|
129 |
$dumpDir = shift;
|
|
130 |
$verbose = defined($_[0]) ? shift : 0;
|
|
131 |
$log = defined($_[0]) ? shift : *STDOUT;
|
|
132 |
my $md5;
|
|
133 |
|
|
134 |
if (eval "require Digest::MD5") { # Prefer Digest::MD5, if available.
|
|
135 |
$md5 = Digest::MD5->new();
|
|
136 |
} elsif (eval "require MD5") { # Try old version of MD5, if available.
|
|
137 |
$md5 = new MD5;
|
|
138 |
} elsif (eval "require Digest::Perl::MD5") { # Try Perl (Slow) version of MD5, if available.
|
|
139 |
$md5 = Digest::Perl::MD5->new();
|
|
140 |
} else {
|
|
141 |
die "Error: Cannot load any MD5 Modules";
|
|
142 |
}
|
|
143 |
|
|
144 |
my $type = IdentifyFileType($file);
|
|
145 |
WriteFilteredData($file, $type, $md5);
|
|
146 |
return $md5->hexdigest(), $type;
|
|
147 |
}
|
|
148 |
|
|
149 |
|
|
150 |
#
|
|
151 |
# Private.
|
|
152 |
#
|
|
153 |
|
|
154 |
sub IdentifyFileType {
|
|
155 |
my $file = shift;
|
|
156 |
open (FILE, $file) or die "Error: Couldn't open \"$file\" for reading: $!\n";
|
|
157 |
binmode (FILE);
|
|
158 |
my $typeBuf;
|
|
159 |
read (FILE, $typeBuf, 512);
|
|
160 |
close (FILE);
|
|
161 |
my ($uid1, $uid2, $uid3, $checksum) = unpack "V4", $typeBuf;
|
|
162 |
|
|
163 |
# NB. Need to use the s modifier so that '.' will match \x0A
|
|
164 |
|
|
165 |
if ($typeBuf =~ /^.\x00\x00\x10.{12}EPOC.{8}(....).{12}(.)..(.)/s) {
|
|
166 |
# E32 Image file with a 0x100000?? UID1
|
|
167 |
# $2 is the flag field indicating an EXE or a DLL
|
|
168 |
# $3 is the flag byte indicating compressable executables
|
|
169 |
# $1 is the format field indicating compression type
|
|
170 |
# See e32tools\inc\e32image.h
|
|
171 |
#
|
|
172 |
my $typename = "E32 EXE";
|
|
173 |
if ((ord $2) & 0x1) {
|
|
174 |
$typename = "E32 DLL";
|
|
175 |
}
|
|
176 |
if ((ord $3) >= 0x1) {
|
|
177 |
if ((ord $1) != 0) {
|
|
178 |
$typename = "Compressed $typename";
|
|
179 |
}
|
|
180 |
else {
|
|
181 |
$typename = "Uncompressed $typename";
|
|
182 |
}
|
|
183 |
}
|
|
184 |
return $typename;
|
|
185 |
}
|
|
186 |
|
|
187 |
if ($typeBuf =~ /^\x4D\x5A.{38}\x00{20}(....)/s) {
|
|
188 |
# A standard 64-byte MS-DOS header with e_magic == IMAGE_DOS_SIGNATURE
|
|
189 |
# $1 is e_lfanew, which we expect to point to a COFF header
|
|
190 |
|
|
191 |
my $offset = unpack "V",$1;
|
|
192 |
if ($offset + 24 <= length $typeBuf) {
|
|
193 |
$typeBuf = substr $typeBuf, $offset;
|
|
194 |
}
|
|
195 |
else {
|
|
196 |
open FILE, $file or die "Error: Couldn't open \"$file\" for reading: $!\n";
|
|
197 |
binmode FILE;
|
|
198 |
seek FILE, $offset, 0;
|
|
199 |
read FILE, $typeBuf, 512;
|
|
200 |
close FILE;
|
|
201 |
}
|
|
202 |
|
|
203 |
if ($typeBuf =~ /^PE\0\0\x4c\x01.{16}(..)/s) {
|
|
204 |
# A PE signature "PE\0\0" followed by a COFF header with
|
|
205 |
# machine type IMAGE_FILE_MACHINE_I386
|
|
206 |
# $1 is the characteristics field
|
|
207 |
#
|
|
208 |
if ((unpack "v",$1) & 0x2000) {
|
|
209 |
return "Intel DLL";
|
|
210 |
}
|
|
211 |
else {
|
|
212 |
return "Intel EXE";
|
|
213 |
}
|
|
214 |
}
|
|
215 |
elsif($typeBuf =~ /^PE\0\0\0\x0a/) {
|
|
216 |
# A PE signature "PE\0\0" followed by ARM COFF file magic value 0xA00
|
|
217 |
return "ARM PE-COFF executable";
|
|
218 |
}
|
|
219 |
else {
|
|
220 |
return "MSDOS EXE";
|
|
221 |
}
|
|
222 |
}
|
|
223 |
|
|
224 |
if ($typeBuf =~ /^(\x4c\x01|\x00\x0A).(\x00|\x01).{4}...\x00/s) {
|
|
225 |
# COFF header with less than 512 sections and a symbol table
|
|
226 |
# at an offset no greater than 0x00ffffff
|
|
227 |
|
|
228 |
if ($1 eq "\x4c\x01") {
|
|
229 |
return "Intel object";
|
|
230 |
}
|
|
231 |
elsif ($1 eq "\x00\x0A") {
|
|
232 |
return "ARM object";
|
|
233 |
}
|
|
234 |
else {
|
|
235 |
return "Unknown COFF object";
|
|
236 |
}
|
|
237 |
}
|
|
238 |
|
|
239 |
if ($typeBuf =~ /^!<arch>\x0A(.{48}([0-9 ]{9})\x60\x0A(......))/s) {
|
|
240 |
# library - could be MARM or WINS
|
|
241 |
|
|
242 |
$typeBuf = $1;
|
|
243 |
my $member_start = 8;
|
|
244 |
|
|
245 |
open (FILE, $file) or die "Error: Couldn't open \"$file\" for reading: $!\n";
|
|
246 |
binmode (FILE);
|
|
247 |
|
676
|
248 |
while ($typeBuf =~ /^.{48}([0-9 ]{9}).\x60\x0A(......)/s) {
|
655
|
249 |
# $1 is the size of the archive member, $2 is first 6 bytes of the file
|
|
250 |
# There may be several different sorts of file in the archive, and we
|
|
251 |
# need to scan through until we find a type we recognize:
|
|
252 |
# $2 == 0x0A00 would be ARM COFF, 0x014C would be Intel COFF
|
|
253 |
if ($2 =~ /^\x00\x0A/) {
|
|
254 |
close FILE;
|
|
255 |
return "ARM library";
|
|
256 |
}
|
|
257 |
if ($2 =~ /^\x4C\x01/) {
|
|
258 |
close FILE;
|
|
259 |
return "Intel library";
|
|
260 |
}
|
|
261 |
my $elfBuf = $2;
|
|
262 |
if ($2 =~ /^\x7F\x45\x4C\x46/) {
|
|
263 |
close FILE;
|
|
264 |
my $dataEncodingLib = substr($elfBuf, 5, 6);
|
|
265 |
if ( $dataEncodingLib =~ /^\x02/) {
|
|
266 |
# e_ident[EI_DATA] == 2 (Data Encoding ELFDATA2MSB - big endian)
|
|
267 |
# this is not supported by Elfdump hence it is treated as 'unknown format'
|
|
268 |
return 'unknown library';
|
|
269 |
}
|
|
270 |
else {
|
|
271 |
return "ELF library";
|
|
272 |
}
|
|
273 |
}
|
|
274 |
|
|
275 |
$member_start += 60 + $1;
|
|
276 |
if ($member_start & 0x1) {
|
|
277 |
$member_start += 1; # align to multiple of 2 bytes
|
|
278 |
}
|
|
279 |
seek FILE, $member_start, 0;
|
|
280 |
read FILE, $typeBuf, 512;
|
|
281 |
}
|
|
282 |
close FILE;
|
|
283 |
return "Unknown library";
|
|
284 |
}
|
|
285 |
|
|
286 |
if ($typeBuf =~ /^\xCA\xFE\xBA\xBE/) {
|
|
287 |
# Java class file - should have match as a straight binary comparison
|
|
288 |
return "Java class";
|
|
289 |
}
|
|
290 |
|
|
291 |
if ($typeBuf =~ /^PK\x03\x04/) {
|
|
292 |
# ZIP file
|
|
293 |
return "ZIP file";
|
|
294 |
}
|
|
295 |
|
|
296 |
if ($uid1 && $uid1==0x10000050) {
|
|
297 |
# Permanent File Store
|
|
298 |
return "Permanent File Store";
|
|
299 |
}
|
|
300 |
|
|
301 |
if ($uid1 && $uid2 && $uid3 && $checksum && $uid3==0x10000419) {
|
|
302 |
if (($uid1==0x100002c3 && $uid2==0x1000006d && $checksum==0x128ca96f) # narrow
|
|
303 |
|| ($uid1==0x10003b0b && $uid2==0x1000006d && $checksum==0x75e21a1d) # unicode
|
|
304 |
|| ($uid1==0x10009205 && $uid2==0x10003a12 && $checksum==0x986a0c25)) # new format
|
|
305 |
{
|
|
306 |
# SIS file
|
|
307 |
return "SIS file";
|
|
308 |
}
|
|
309 |
}
|
|
310 |
|
|
311 |
if ($typeBuf =~ /^Microsoft [^\x0A]+ [Dd]atabase/s) {
|
|
312 |
return "MSVC database";
|
|
313 |
}
|
|
314 |
|
|
315 |
if ($typeBuf =~ /^\S.+ needed due to / || $typeBuf =~ /^Archive member included.*because of file/) {
|
|
316 |
# GCC MAP file
|
|
317 |
return "MAP file";
|
|
318 |
}
|
|
319 |
|
|
320 |
if ($typeBuf =~ /Preferred load address is/) {
|
|
321 |
# Developer Studio MAP file
|
|
322 |
return "MAP file";
|
|
323 |
}
|
|
324 |
|
|
325 |
if ($typeBuf =~ /^Address\s+Size\s+Name\s+Subname\s+Module/) {
|
|
326 |
# CodeWarrior MAP file
|
|
327 |
return "MAP file";
|
|
328 |
}
|
|
329 |
|
|
330 |
if ($typeBuf =~ /^ARM Linker,/) {
|
|
331 |
# RVCT MAP file
|
|
332 |
return "MAP file";
|
|
333 |
}
|
|
334 |
|
|
335 |
if ($typeBuf =~ /<!DOCTYPE/i) {
|
|
336 |
# XML or HTML file - need to ignore javadoc generation dates
|
|
337 |
return "SGML file";
|
|
338 |
}
|
|
339 |
|
|
340 |
if ($typeBuf =~ /^# 1 ".*"(\x0D|\x0A)/s) {
|
|
341 |
# Output of CPP
|
|
342 |
return "Preprocessed text";
|
|
343 |
}
|
|
344 |
|
|
345 |
if ($typeBuf =~ /^\x7F\x45\x4C\x46/) {
|
|
346 |
my $dataEncoding = substr($typeBuf, 5, 6);
|
|
347 |
if ( $dataEncoding =~ /^\x02/) {
|
|
348 |
# e_ident[EI_DATA] == 2 (Data Encoding ELFDATA2MSB - big endian)
|
|
349 |
# this is not supported by Elfdump hence it is treated as 'unknown format'
|
|
350 |
return 'unknown format';
|
|
351 |
}
|
|
352 |
else {
|
|
353 |
return "ELF file";;
|
|
354 |
}
|
|
355 |
}
|
|
356 |
|
|
357 |
if ($typeBuf =~/^ITSF/) {
|
|
358 |
# chm file
|
|
359 |
return "chm file";
|
|
360 |
}
|
|
361 |
|
676
|
362 |
if ($typeBuf =~/^(ROFS|ROFx)/) {
|
|
363 |
# img file
|
|
364 |
return "Rofs image";
|
|
365 |
}
|
|
366 |
|
655
|
367 |
if ($file =~ m/\.(iby|h|hby|hrh|oby|rsg|cpp)$/i) {
|
|
368 |
return "Header file";
|
|
369 |
}
|
|
370 |
|
|
371 |
if ($file =~ /distribution\.policy$/i) {
|
|
372 |
return "Distribution Policy"
|
|
373 |
}
|
|
374 |
|
|
375 |
return 'unknown format';
|
|
376 |
}
|
|
377 |
|
|
378 |
sub WriteFilteredData {
|
|
379 |
my $file = shift;
|
|
380 |
my $type = shift;
|
|
381 |
my $md5 = shift;
|
|
382 |
my $dumpDirExpandedFile = shift;
|
|
383 |
|
|
384 |
my (@dumpDirBuffer);
|
|
385 |
|
|
386 |
unless (exists $typeLookup{$type}) {
|
|
387 |
die "Invalid file type \"$type\"";
|
|
388 |
}
|
|
389 |
$type = $typeLookup{$type};
|
|
390 |
|
|
391 |
# Check to see if this file type requires expanding first
|
|
392 |
if (exists $typeHandler{$type}->{expandor})
|
|
393 |
{
|
|
394 |
my $expandor = $typeHandler{$type}->{expandor};
|
|
395 |
# Create two temporary directories
|
|
396 |
my $tempdir = tempdir ( "EvalidExpand_XXXXXX", DIR => File::Spec->tmpdir, CLEANUP => 1);
|
|
397 |
|
|
398 |
# Build the Expandor commandline
|
|
399 |
$expandor =~ s/%TEMPDIR%/$tempdir/g;
|
|
400 |
$expandor =~ s/%FILE%/$file/g;
|
|
401 |
|
|
402 |
# Expand files
|
|
403 |
my $output = `$expandor 2>&1`;
|
|
404 |
print($log "Expanding using $expandor output was:-\n$output") if ($verbose);
|
|
405 |
if ($? > 0)
|
|
406 |
{
|
|
407 |
print ($log "$expandor exited with $?") if ($verbose);
|
|
408 |
# set type to be identical for retry if raw
|
|
409 |
if ($typeHandler{$type}->{rawretry} == 1)
|
|
410 |
{
|
|
411 |
$type = 'identical';
|
|
412 |
} else {
|
|
413 |
print "ERROR: failed to start $expandor (" .($?). ") - reporting failure\n";
|
|
414 |
}
|
|
415 |
} else {
|
|
416 |
# Process all files in $tempdir
|
|
417 |
my @FileList;
|
|
418 |
find(sub { push @FileList, $File::Find::name if (! -d);}, $tempdir);
|
|
419 |
foreach my $expandfile (@FileList)
|
|
420 |
{
|
|
421 |
my $dumpDirExpandedFilename = "";
|
|
422 |
|
|
423 |
if ($dumpDir)
|
|
424 |
{
|
|
425 |
$dumpDirExpandedFilename = $expandfile;
|
|
426 |
$dumpDirExpandedFilename =~ s/^.*EvalidExpand_\w+//;
|
|
427 |
$dumpDirExpandedFilename = $file.$dumpDirExpandedFilename;
|
|
428 |
}
|
|
429 |
|
|
430 |
my $type = IdentifyFileType($expandfile);
|
|
431 |
|
|
432 |
&WriteFilteredData($expandfile, $type, $md5, $dumpDirExpandedFilename);
|
|
433 |
}
|
|
434 |
}
|
|
435 |
} elsif ($type ne 'identical') {
|
|
436 |
unless (exists $typeHandler{$type}) {
|
|
437 |
die "Invalid comparison type \"$type\"";
|
|
438 |
}
|
|
439 |
my $reader = $typeHandler{$type}->{reader};
|
|
440 |
my $filter = $typeHandler{$type}->{filter};
|
|
441 |
my $retry = $typeHandler{$type}->{retry} || 0;
|
|
442 |
my $rawretry = $typeHandler{$type}->{rawretry} || 0;
|
|
443 |
my $skipblanks = $typeHandler{$type}->{skipblanks} || 0;
|
|
444 |
my $relativePaths = $typeHandler{$type}->{relative_paths} || 0;
|
|
445 |
my $dosPaths = $typeHandler{$type}->{dos_paths} || 0;
|
|
446 |
|
|
447 |
my $skipstderr = $typeHandler{$type}->{skipstderr} || 0;
|
|
448 |
my $redirectstd = "2>&1";
|
|
449 |
|
|
450 |
if ($skipstderr) {
|
|
451 |
$redirectstd = "2>NUL";
|
|
452 |
}
|
|
453 |
|
|
454 |
if ($relativePaths) {
|
|
455 |
$file = RelativePath($file);
|
|
456 |
}
|
|
457 |
if ($dosPaths) {
|
|
458 |
$file =~ s/\//\\/g; # convert to DOS-style backslash separators
|
|
459 |
}
|
|
460 |
|
|
461 |
my $raw;
|
|
462 |
if ($reader) {
|
|
463 |
$raw = IO::File->new("$reader \"$file\" $redirectstd |") or die "Error: Couldn't run \"$reader $file\": $!\n";
|
|
464 |
}
|
|
465 |
else {
|
|
466 |
$raw = IO::File->new("$file") or die "Error: Couldn't open \"$file\": $!\n";
|
|
467 |
}
|
|
468 |
while (my $line = <$raw>) {
|
|
469 |
&$filter(\$line);
|
|
470 |
next if $skipblanks and $line =~ /^\s*$/;
|
|
471 |
$md5->add($line);
|
|
472 |
push @dumpDirBuffer, $line if ($dumpDir);
|
|
473 |
}
|
|
474 |
Drain($raw);
|
|
475 |
$raw->close();
|
|
476 |
|
|
477 |
# Retry once if reader failed and reader has retry specified
|
|
478 |
if ((($?>>8) != 0) && ($retry == 1))
|
|
479 |
{
|
|
480 |
print "Warning: $reader failed (" .($?>>8). ") on $file - retrying\n";
|
|
481 |
# Reset MD5
|
|
482 |
$md5->reset;
|
|
483 |
undef @dumpDirBuffer if ($dumpDir);
|
|
484 |
$raw = IO::File->new("$reader \"$file\" $redirectstd |") or die "Error: Couldn't run \"$reader $file\": $!\n";
|
|
485 |
while (my $line = <$raw>)
|
|
486 |
{
|
|
487 |
&$filter(\$line);
|
|
488 |
next if $skipblanks and $line =~ /^\s*$/;
|
|
489 |
$md5->add($line);
|
|
490 |
push @dumpDirBuffer, $line if ($dumpDir);
|
|
491 |
}
|
|
492 |
Drain($raw);
|
|
493 |
$raw->close();
|
|
494 |
if (($?>>8) != 0)
|
|
495 |
{
|
|
496 |
print "Error: $reader failed again (" .($?>>8) .") on $file - reporting failure\n";
|
|
497 |
}
|
|
498 |
}
|
|
499 |
|
|
500 |
# Retry as raw if specified
|
|
501 |
if (($?>>8) != 0) {
|
|
502 |
if ($rawretry)
|
|
503 |
{
|
|
504 |
if ($reader =~ /^pfsdump/) {
|
|
505 |
print "Warning: $reader failed (". ($?>>8) .") on file $file - retrying as raw binary\n";
|
|
506 |
}
|
|
507 |
else {
|
|
508 |
print "Info: something wrong to execute $reader (". ($?>>8) .") on file $file - retrying as raw binary\n";
|
|
509 |
}
|
|
510 |
# Set type to be identical so it will try it as a raw binary stream
|
|
511 |
$type = 'identical';
|
|
512 |
} else {
|
|
513 |
print "Error: $reader failed (". ($?>>8) .") on file $file - not retrying as raw binary\n";
|
|
514 |
}
|
|
515 |
}
|
|
516 |
}
|
|
517 |
if ($type eq 'identical') {
|
|
518 |
# Reset md5 as it might have been used in reader section
|
|
519 |
$md5->reset;
|
|
520 |
undef @dumpDirBuffer if ($dumpDir);
|
|
521 |
# Treat 'identical' as a special case - no filtering, just write raw binary stream.
|
|
522 |
my $raw = IO::File->new($file) or die "Error: Couldn't open \"$file\" for reading: $!\n";
|
|
523 |
binmode($raw);
|
|
524 |
my $buf;
|
|
525 |
while ($raw->read($buf, 4096)) {
|
|
526 |
$md5->add($buf);
|
|
527 |
}
|
|
528 |
$raw->close();
|
|
529 |
}
|
|
530 |
|
|
531 |
my $dumpDirFilename = $file;
|
|
532 |
$dumpDirFilename = $dumpDirExpandedFile if ($dumpDirExpandedFile);
|
|
533 |
dumpDescriptiveOutput ($file, $dumpDirFilename, @dumpDirBuffer) if ($dumpDir);
|
|
534 |
|
|
535 |
# Make sure the $? is reset for the next file otherwise it will report errors
|
|
536 |
$? = 0;
|
|
537 |
}
|
|
538 |
|
|
539 |
sub DoCompareFiles {
|
|
540 |
my $file1 = shift;
|
|
541 |
my $file2 = shift;
|
|
542 |
my $type = shift;
|
|
543 |
my $same = 0;
|
|
544 |
unless (exists $typeLookup{$type}) {
|
|
545 |
die "Invalid file type \"$type\"";
|
|
546 |
}
|
|
547 |
|
|
548 |
$type = $typeLookup{$type};
|
|
549 |
|
|
550 |
# Check to see if this file type requires expanding first
|
|
551 |
if (exists $typeHandler{$type}->{expandor})
|
|
552 |
{
|
|
553 |
$same = &ExpandAndCompareFiles($file1, $file2, $typeHandler{$type}->{expandor});
|
|
554 |
# Check for Expanding error
|
|
555 |
if ($same == -1)
|
|
556 |
{
|
|
557 |
if ($typeHandler{$type}->{rawretry} == 1)
|
|
558 |
{
|
|
559 |
# Set type to be identical if rawrety is set
|
|
560 |
$type = 'identical';
|
|
561 |
print($log "Warning: Expandor $typeHandler{$type}->{expandor} failed for $file1 or $file2 : retrying as raw\n") if ($verbose);
|
|
562 |
} else {
|
|
563 |
die "Error: Expandor $typeHandler{$type}->{expandor} failed for $file1 or $file2\n";
|
|
564 |
}
|
|
565 |
} else {
|
|
566 |
return $same;
|
|
567 |
}
|
|
568 |
}
|
|
569 |
|
|
570 |
if ($type ne 'identical')
|
|
571 |
{
|
|
572 |
unless (exists $typeHandler{$type}) {
|
|
573 |
die "Invalid comparison type \"$type\"";
|
|
574 |
}
|
|
575 |
|
|
576 |
my $reader = $typeHandler{$type}->{reader};
|
|
577 |
my $filter = $typeHandler{$type}->{filter};
|
|
578 |
my $retry = $typeHandler{$type}->{retry} || 0;
|
|
579 |
my $skipblanks= $typeHandler{$type}->{skipblanks} || 0;
|
|
580 |
my $rawretry = $typeHandler{$type}->{rawretry} || 0;
|
|
581 |
my $relativePaths = $typeHandler{$type}->{relative_paths} || 0;
|
|
582 |
my $skipstderr = $typeHandler{$type}->{skipstderr} || 0;
|
|
583 |
my $redirectstd = "2>&1";
|
|
584 |
|
|
585 |
if ($skipstderr) {
|
|
586 |
$redirectstd = "2>NUL";
|
|
587 |
}
|
|
588 |
|
|
589 |
if ($relativePaths) {
|
|
590 |
$file1 = RelativePath($file1);
|
|
591 |
$file2 = RelativePath($file2);
|
|
592 |
}
|
|
593 |
my $fileHandle1;
|
|
594 |
my $fileHandle2;
|
|
595 |
if ($reader) {
|
|
596 |
$fileHandle1 = IO::File->new("$reader \"$file1\" $redirectstd |") or die "Error: Couldn't run \"$reader $file1\": $!\n";
|
|
597 |
$fileHandle2 = IO::File->new("$reader \"$file2\" $redirectstd |") or die "Error: Couldn't run \"$reader $file2\": $!\n";
|
|
598 |
}
|
|
599 |
else {
|
|
600 |
$fileHandle1 = IO::File->new("$file1") or die "Error: Couldn't open \"$file1\": $!\n";
|
|
601 |
$fileHandle2 = IO::File->new("$file2") or die "Error: Couldn't open \"$file2\": $!\n";
|
|
602 |
}
|
|
603 |
$same = CompareTexts($fileHandle1, $fileHandle2, $filter, $file1, $skipblanks);
|
|
604 |
Drain($fileHandle1, $fileHandle2);
|
|
605 |
|
|
606 |
$fileHandle1->close();
|
|
607 |
my $status1 = $?>>8;
|
|
608 |
$fileHandle2->close();
|
|
609 |
my $status2 = $?>>8;
|
|
610 |
if (($retry) && ($status1 != 0 or $status2 != 0))
|
|
611 |
{
|
|
612 |
print ($log "Warning: $reader failed ($status1, $status2) - retrying\n");
|
|
613 |
|
|
614 |
# Repeat previous code by hand, rather than calling DoCompareFiles
|
|
615 |
# again: if it's a systematic failure that would be a never ending loop...
|
|
616 |
|
|
617 |
$fileHandle1 = IO::File->new("$reader \"$file1\" $redirectstd |") or die "Error: Couldn't run \"$reader $file1\": $!\n";
|
|
618 |
$fileHandle2 = IO::File->new("$reader \"$file2\" $redirectstd |") or die "Error: Couldn't run \"$reader $file2\": $!\n";
|
|
619 |
$same = CompareTexts($fileHandle1, $fileHandle2, $filter, $file1, $skipblanks);
|
|
620 |
Drain($fileHandle1, $fileHandle2);
|
|
621 |
$fileHandle1->close();
|
|
622 |
$status1 = $?>>8;
|
|
623 |
$fileHandle2->close();
|
|
624 |
$status2 = $?>>8;
|
|
625 |
if ($status1 != 0 or $status2 != 0)
|
|
626 |
{
|
|
627 |
print ($log "Warning: $reader failed again ($status1, $status2) - reporting failure\n");
|
|
628 |
$same = 0;
|
|
629 |
}
|
|
630 |
}
|
|
631 |
|
|
632 |
# Retry as raw if specified
|
|
633 |
if (($rawretry)&& ($status1 != 0 or $status2 != 0))
|
|
634 |
{
|
|
635 |
if ($rawretry)
|
|
636 |
{
|
|
637 |
print ($log "Warning: $reader failed (" .($?>>8). ") on a file retrying as raw binary\n");
|
|
638 |
# Set type to be identical so it will try it as a raw binary stream
|
|
639 |
$type = 'identical';
|
|
640 |
} else {
|
|
641 |
print ($log "Error: $reader failed (" .($?>>8). ") on a file not retrying as raw binary\n");
|
|
642 |
}
|
|
643 |
}
|
|
644 |
|
|
645 |
}
|
|
646 |
|
|
647 |
if ($type eq 'identical') {
|
|
648 |
# Treat 'identical' as a special case - no filtering, just do raw binary stream comparison.
|
|
649 |
my $fileHandle1 = IO::File->new($file1) or die "Error: Couldn't open \"$file1\" for reading: $!\n";
|
|
650 |
my $fileHandle2 = IO::File->new($file2) or die "Error: Couldn't open \"$file2\" for reading: $!\n";
|
|
651 |
binmode($fileHandle1);
|
|
652 |
binmode($fileHandle2);
|
|
653 |
$same = CompareStreams($fileHandle1, $fileHandle2, $file1);
|
|
654 |
}
|
|
655 |
|
|
656 |
# Make sure the $? is reset for the next file otherwise it will report errors
|
|
657 |
$? = 0;
|
|
658 |
|
|
659 |
return $same;
|
|
660 |
}
|
|
661 |
|
|
662 |
sub CompareStreams {
|
|
663 |
my $fileHandle1 = shift;
|
|
664 |
my $fileHandle2 = shift;
|
|
665 |
my $filename = shift;
|
|
666 |
my $same = 1;
|
|
667 |
my $offset = -4096;
|
|
668 |
my $buf1;
|
|
669 |
my $buf2;
|
|
670 |
while ($same) {
|
|
671 |
my $len1 = $fileHandle1->read($buf1, 4096);
|
|
672 |
my $len2 = $fileHandle2->read($buf2, 4096);
|
|
673 |
if ($len1 == 0 and $len2 == 0) {
|
|
674 |
return 1;
|
|
675 |
}
|
|
676 |
$same = $buf1 eq $buf2;
|
|
677 |
$offset += 4096;
|
|
678 |
}
|
|
679 |
if ($verbose) {
|
|
680 |
my @bytes1 = unpack "C*", $buf1;
|
|
681 |
my @bytes2 = unpack "C*", $buf2;
|
|
682 |
foreach my $thisByte (@bytes1) {
|
|
683 |
if ($thisByte != $bytes2[0]) {
|
|
684 |
printf $log "Binary comparison: %s failed at byte %d: %02x != %02x\n", $filename, $offset, $thisByte, $bytes2[0];
|
|
685 |
last;
|
|
686 |
}
|
|
687 |
shift @bytes2;
|
|
688 |
$offset+=1;
|
|
689 |
}
|
|
690 |
}
|
|
691 |
return 0;
|
|
692 |
}
|
|
693 |
|
|
694 |
sub NextSignificantLine {
|
|
695 |
my $filehandle = shift;
|
|
696 |
my $linenumber = shift;
|
|
697 |
my $cleanersub = shift;
|
|
698 |
my $skipblanks = shift;
|
|
699 |
|
|
700 |
while (!eof($filehandle)) {
|
|
701 |
my $line = <$filehandle>;
|
|
702 |
$$linenumber++;
|
|
703 |
$cleanersub->(\$line);
|
|
704 |
return $line if !$skipblanks or $line !~ /^\s*$/;
|
|
705 |
}
|
|
706 |
return undef; # on eof
|
|
707 |
}
|
|
708 |
|
|
709 |
sub CompareTexts {
|
|
710 |
my $filehandle1 = shift;
|
|
711 |
my $filehandle2 = shift;
|
|
712 |
my $cleaner = shift;
|
|
713 |
my $filename = shift;
|
|
714 |
my $skipblanks = shift;
|
|
715 |
my $lineNum1 = 0;
|
|
716 |
my $lineNum2 = 0;
|
|
717 |
|
|
718 |
while (1) {
|
|
719 |
my $line1 = NextSignificantLine($filehandle1, \$lineNum1, $cleaner, $skipblanks);
|
|
720 |
my $line2 = NextSignificantLine($filehandle2, \$lineNum2, $cleaner, $skipblanks);
|
|
721 |
|
|
722 |
return 0 if defined($line1) != defined($line2); # eof vs. significant content
|
|
723 |
return 1 if !defined($line1) and !defined($line2); # eof on both files
|
|
724 |
|
|
725 |
if ($line1 ne $line2) {
|
|
726 |
printf($log "Text comparison: %s failed at lines %d/%d\n< %s> %s\n",
|
|
727 |
$filename, $lineNum1, $lineNum2, $line1, $line2) if $verbose;
|
|
728 |
return 0;
|
|
729 |
}
|
|
730 |
}
|
|
731 |
}
|
|
732 |
|
|
733 |
sub Drain {
|
|
734 |
foreach my $handle (@_) {
|
|
735 |
while (my $line = <$handle>) {
|
|
736 |
}
|
|
737 |
}
|
|
738 |
}
|
|
739 |
|
|
740 |
sub RelativePath {
|
|
741 |
my $name = shift;
|
|
742 |
if (($name =~ /^\\[^\\]/) || ($name =~ /^\//)) { # abs path (unix or windows), not UNC
|
|
743 |
unless ($toRoot) {
|
|
744 |
$toRoot = getcwd();
|
|
745 |
$toRoot =~ s/\//\\/g;
|
|
746 |
$toRoot =~ s/^[a-zA-Z]:\\(.*)$/$1/;
|
|
747 |
$toRoot =~ s/[^\\]+/../g;
|
|
748 |
if ($toRoot =~ /^$/) {
|
|
749 |
$toRoot = '.'; # because we are starting in the root
|
|
750 |
}
|
|
751 |
}
|
|
752 |
return $toRoot.$name;
|
|
753 |
}
|
|
754 |
return $name;
|
|
755 |
}
|
|
756 |
|
|
757 |
# Function to expand compressed formats and recompare expanded files
|
|
758 |
# This is the file against file implementation
|
|
759 |
# It returns one identical / non indentical result based on all files in the
|
|
760 |
# expanded content. i.e one non identical expanded file will cause the non
|
|
761 |
# expanded file to be reported as non identical.
|
|
762 |
sub ExpandAndCompareFiles
|
|
763 |
{
|
|
764 |
my $file1 = shift;
|
|
765 |
my $file2 = shift;
|
|
766 |
my $expandor = shift;
|
|
767 |
|
|
768 |
# Create two temporary directories
|
|
769 |
my $tempdir1 = tempdir ( "EvalidExpand_XXXXXX", DIR => File::Spec->tmpdir, CLEANUP => 1);
|
|
770 |
my $tempdir2 = tempdir ( "EvalidExpand_XXXXXX", DIR => File::Spec->tmpdir, CLEANUP => 1);
|
|
771 |
|
|
772 |
# Build the Expandor commandline
|
|
773 |
my $cmd1 = $expandor;
|
|
774 |
$cmd1 =~ s/%TEMPDIR%/$tempdir1/g;
|
|
775 |
$cmd1 =~ s/%FILE%/$file1/g;
|
|
776 |
|
|
777 |
my $cmd2 = $expandor;
|
|
778 |
$cmd2 =~ s/%TEMPDIR%/$tempdir2/g;
|
|
779 |
$cmd2 =~ s/%FILE%/$file2/g;
|
|
780 |
|
|
781 |
# Expand files
|
|
782 |
my $output = `$cmd1 2>&1`;
|
|
783 |
print($log "Expanding using $cmd1 output was:-\n$output") if ($verbose);
|
|
784 |
if ($? > 0)
|
|
785 |
{
|
|
786 |
print ($log "$cmd1 exited with $?") if ($verbose);
|
|
787 |
return -1;
|
|
788 |
}
|
|
789 |
|
|
790 |
$output = `$cmd2 2>&1`;
|
|
791 |
print($log "Expanding using $cmd2 output was:-\n$output") if ($verbose);
|
|
792 |
if ($? > 0)
|
|
793 |
{
|
|
794 |
print ($log "$cmd2 exited with $?") if ($verbose);
|
|
795 |
return -1;
|
|
796 |
}
|
|
797 |
|
|
798 |
# Produce full filelist of expanded files without directory names
|
|
799 |
my %iFileList1;
|
|
800 |
$tempdir1 =~ s#\\#/#g; # Make sure the dir seperators are / for consistent and easier matching.
|
|
801 |
find sub {
|
|
802 |
if (!-d)
|
|
803 |
{
|
|
804 |
my ($fixedpath) = $File::Find::name;
|
|
805 |
$fixedpath =~ s#\\#/#g;
|
|
806 |
my ($relpath) = $File::Find::name =~ /$tempdir1(.*)/i;
|
|
807 |
$iFileList1{$relpath} = "left";
|
|
808 |
}
|
|
809 |
}, $tempdir1;
|
|
810 |
|
|
811 |
my %iFileList2;
|
|
812 |
$tempdir2 =~ s#\\#/#g; # Make sure the dir seperators are / for consistent and easier matching.
|
|
813 |
find sub {
|
|
814 |
if (!-d)
|
|
815 |
{
|
|
816 |
my ($fixedpath) = $File::Find::name;
|
|
817 |
$fixedpath =~ s#\\#/#g;
|
|
818 |
my ($relpath) = $File::Find::name =~ /$tempdir2(.*)/i;
|
|
819 |
$iFileList2{$relpath} = "right";
|
|
820 |
}
|
|
821 |
}, $tempdir2;
|
|
822 |
|
|
823 |
#Work out the if the two file lists are different
|
676
|
824 |
my @tmpfiles;
|
655
|
825 |
foreach my $file (sort keys %iFileList1)
|
|
826 |
{
|
|
827 |
if (! defined $iFileList2{$file})
|
|
828 |
{
|
|
829 |
# If the filename does not exist in the second filelist the compressed files cannot be the same.
|
|
830 |
print ($log "Did not find $file in $file2\n") if ($verbose);
|
676
|
831 |
if(!$keepgoing){
|
|
832 |
return 0;
|
|
833 |
}else{
|
|
834 |
push @tmpfiles, $file;
|
|
835 |
}
|
655
|
836 |
} else {
|
|
837 |
delete $iFileList2{$file}
|
|
838 |
}
|
|
839 |
}
|
676
|
840 |
foreach my $file (@tmpfiles)
|
|
841 |
{
|
|
842 |
delete $iFileList1{$file};
|
|
843 |
}
|
655
|
844 |
|
|
845 |
# There are extra files in the second compressed file therefore the compressed files cannot be the same.
|
|
846 |
if (scalar(keys %iFileList2) > 0)
|
|
847 |
{
|
|
848 |
print ($log "$file2 contained more files than $file1\n") if ($verbose);
|
676
|
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 |
}
|
655
|
856 |
}
|
|
857 |
|
|
858 |
print($log "Comparing content\n") if ($verbose);
|
|
859 |
#filelist1 and filelist2 contain all the same filenames, now compare the contents of each file
|
676
|
860 |
my $same = 1; # Variable to store collated result of comparison, assume an error
|
655
|
861 |
foreach my $file (keys %iFileList1)
|
|
862 |
{
|
676
|
863 |
my $tmpsame;
|
|
864 |
my $type;
|
|
865 |
($tmpsame, $type) = CompareFiles($tempdir1.$file,$tempdir2.$file, $verbose, $log, $keepgoing);
|
|
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 |
}
|
655
|
880 |
}
|
|
881 |
|
|
882 |
#Cleanup the temporary directories
|
|
883 |
rmtree([$tempdir1,$tempdir2]);
|
|
884 |
|
|
885 |
return $same;
|
|
886 |
}
|
|
887 |
|
|
888 |
# Create descriptive versions of input files in response to the -d option to MD5 generation
|
|
889 |
sub dumpDescriptiveOutput ($$@)
|
|
890 |
{
|
|
891 |
my ($originalFile, $dumpDirFile, @content) = @_;
|
|
892 |
|
|
893 |
my $currentDir = cwd;
|
|
894 |
my $drive = "";
|
|
895 |
$dumpDirFile =~ s/^.://; # Remove drive letter
|
|
896 |
|
|
897 |
$drive = $1 if ($currentDir =~ /^(\w{1}:)\//);
|
|
898 |
|
|
899 |
my $DUMPFILE = $dumpDir;
|
|
900 |
$DUMPFILE = cwd."\\$dumpDir" if ($dumpDir !~ /^(\\|\/|\w{1}:\\)/);
|
|
901 |
$DUMPFILE = $drive.$dumpDir if ($dumpDir =~ /^\\/);
|
|
902 |
$DUMPFILE .= "\\" if ($DUMPFILE !~ /(\\|\/)$/);
|
|
903 |
$DUMPFILE .= $dumpDirFile;
|
|
904 |
$DUMPFILE =~ s/\//\\/g;
|
|
905 |
|
|
906 |
# This is most likely to come about due to maintaining path structures in expanded archives e.g. .chm files
|
|
907 |
if (length ($DUMPFILE) > 255)
|
|
908 |
{
|
|
909 |
print ("Warning: Not attempting to create \"$DUMPFILE\" as it exceeds Windows MAX_PATH limit.\n");
|
|
910 |
return;
|
|
911 |
}
|
|
912 |
|
|
913 |
mkpath (dirname ($DUMPFILE));
|
|
914 |
|
|
915 |
my $success = 0;
|
|
916 |
|
|
917 |
if (@content)
|
|
918 |
{
|
|
919 |
if (open DUMPFILE, "> $DUMPFILE")
|
|
920 |
{
|
|
921 |
print DUMPFILE $_ foreach (@content);
|
|
922 |
close DUMPFILE;
|
|
923 |
$success = 1;
|
|
924 |
}
|
|
925 |
}
|
|
926 |
else
|
|
927 |
{
|
|
928 |
$success = 1 if (copy ($originalFile, $DUMPFILE));
|
|
929 |
}
|
|
930 |
|
|
931 |
print ("Warning: Cannot create \"$DUMPFILE\".\n") if (!$success);
|
|
932 |
}
|
|
933 |
|
|
934 |
|
|
935 |
#
|
|
936 |
# Filters.
|
|
937 |
#
|
|
938 |
|
|
939 |
sub Elf2E32Filter {
|
|
940 |
my $line = shift;
|
|
941 |
if ($$line =~ /Time Stamp:|E32ImageFile|Header CRC:/) { # Ignore time stamps, file name and Header CRC which uses the timestamp.
|
|
942 |
$$line = '';
|
|
943 |
}
|
|
944 |
if ($$line =~ /imports from /) {
|
|
945 |
$$line = lc $$line; # DLL names are not case-sensitive in the Symbian platform loader
|
|
946 |
}
|
|
947 |
}
|
|
948 |
|
|
949 |
sub ElfDumpFilter {
|
|
950 |
my $line = shift;
|
|
951 |
$$line =~ s/^\tProgram header offset.*$/Program header offset/;
|
|
952 |
$$line =~ s/^\tSection header offset.*$/Section header offset/;
|
|
953 |
$$line =~ s/#<DLL>(\S+\.\S+)#<\\DLL>/#<DLL>\L$1\E#<\\DLL>/; # DLL names are not case-sensitive in the Symbian platform loader
|
|
954 |
if ($$line =~ /^\.(rel\.)?debug_/) {
|
|
955 |
$$line = ''; # additional debug-related information - not considered significant
|
|
956 |
}
|
|
957 |
}
|
|
958 |
|
|
959 |
sub NmFilter {
|
|
960 |
my $line = shift;
|
|
961 |
$$line =~ s/^.*:$//; # ignore the filenames
|
|
962 |
$$line =~ s/\.\.\\[^(]*\\//g;
|
|
963 |
$$line =~ s/\.\.\/[^(]*\///g; # ignore pathnames of object files
|
|
964 |
$$line =~ s/^BFD: (.*)$//; # ignore the Binary File Descriptor(BFD) warning messages
|
|
965 |
if ($$line =~ /^(.+ (_head|_))\w+_(EPOC32_\w+(_LIB|_iname))$/i) {
|
|
966 |
# dlltool uses the "-o" argument string as the basis for a "unique symbol", but
|
|
967 |
# doesn't turn the name into a canonical form first.
|
|
968 |
# dh.o:
|
|
969 |
# U ________EPOC32_RELEASE_ARM4_UREL_EIKCOCTL_LIB_iname
|
|
970 |
# 00000000 ? _head_______EPOC32_RELEASE_ARM4_UREL_EIKCOCTL_LIB
|
|
971 |
$$line = uc "$1_..._$3\n";
|
|
972 |
}
|
|
973 |
}
|
|
974 |
|
|
975 |
|
|
976 |
sub MapFilter {
|
|
977 |
my $line = shift;
|
|
978 |
$$line =~ s/([d-z])\d*s_?\d+\.o/$1s999.o/; # ignore the names of intermediate files in .LIB
|
|
979 |
$$line =~ s/([d-z])\d*([ht])\.o/$1$2.o/; # ignore the names of intermediate files in .LIB
|
|
980 |
$$line =~ s-/-\\-go; # convert / into \
|
|
981 |
$$line =~ s/(\.\.\\|.:\\)[^(]*\\//g; # ignore pathnames of object files
|
|
982 |
$$line =~ s/\.stab.*$//; # ignore .stab and .stabstr lines
|
|
983 |
$$line =~ s/0x.*size before relaxing//; # ignore additional comments about .stab and .stabstr
|
|
984 |
$$line =~ s/(_head|_)\w+_(EPOC32_\w+(_LIB|_iname))/$1_,,,_$3/; # dlltool-generated unique symbols
|
|
985 |
$$line =~ s/Timestamp is .*$//; # ignore timestamps in DevStudio map files
|
|
986 |
if ($$line =~ /^ARM Linker,/) {
|
|
987 |
$$line = '';
|
|
988 |
} # ignore the message that armlink's license will expire. (in RVCT MAP file)
|
|
989 |
if ($$line =~ /^Your license/) {
|
|
990 |
$$line = '';
|
|
991 |
}
|
|
992 |
$$line =~ s/\s__T\d{8}\s/ __Tnnnnnnnn /; # ignore RVCT generated internal symbols
|
|
993 |
if ($$line =~ /0x00000000 Number 0 /) { # ignore filenames in RVCT link maps
|
|
994 |
$$line = '';
|
|
995 |
}
|
|
996 |
|
|
997 |
# Ignore various case differences:
|
|
998 |
|
|
999 |
## RVCT
|
|
1000 |
|
|
1001 |
# source filenames turning up in mangled symbols e.g.:
|
|
1002 |
# __sti___13_BALServer_cpp 0x000087c9 Thumb Code 52 BALServer.o(.text)
|
|
1003 |
$$line =~ s/^(\s+__sti___\d+_)(\w+)(.*\(\.text\))$/$1\L$2\E$3/;
|
|
1004 |
|
|
1005 |
# object filenames e.g.:
|
|
1006 |
# .text 0x0000a01c Section 164 AssertE.o(.text)
|
|
1007 |
$$line =~ s/^(\s+\.text\s+0x[0-9A-Fa-f]{8}\s+Section\s+\d+\s+)(.+)(\(\.text\))$/$1\L$2\E$3/;
|
|
1008 |
|
|
1009 |
## WINSCW
|
|
1010 |
|
|
1011 |
# import/static libraries processed listed in the last section e.g.:
|
|
1012 |
#1 EDLL.LIB
|
|
1013 |
#99 EDLL.LIB (not used)
|
|
1014 |
$$line =~ s/^(\d{1,2} {5,6})(\w+\.lib)( \(not used\)|)$/$1\L$2\E$3/i;
|
|
1015 |
}
|
|
1016 |
|
|
1017 |
sub UnzipFilter {
|
|
1018 |
my $line = shift;
|
|
1019 |
$$line =~ s/^Archive:.*$/Archive/; # ignore the archive names
|
|
1020 |
# Line format of unzip -l -v
|
|
1021 |
# Length Method Size Ratio Date Time CRC-32 Name, Date can be dd-mm-yy or mm/dd/yy
|
|
1022 |
$$line =~ s/ (\d+).*? ..-..-..\s+..:.. / ($1) 99-99-99 99:99 /; # ignore (Method Size Ratio Date Time) on contained files
|
|
1023 |
$$line =~ s^ (\d+).*? ..\/..\/..\s+..:.. ^ ($1) 99-99-99 99:99 ^; # ignore (Method Size Ratio Date Time) on contained files
|
|
1024 |
}
|
|
1025 |
|
|
1026 |
sub SgmlFilter {
|
|
1027 |
my $line = shift;
|
|
1028 |
$$line =~ s/<!--.*-->//; # ignore comments such as "generated by javadoc"
|
|
1029 |
}
|
|
1030 |
|
|
1031 |
sub PreprocessedTextFilter {
|
|
1032 |
my $line = shift;
|
|
1033 |
$$line =~ s/^# \d+ ".*"( \d)?$//; # ignore #include history
|
|
1034 |
}
|
|
1035 |
|
|
1036 |
sub FilterCVSTags {
|
|
1037 |
my $line = shift;
|
|
1038 |
$$line =~ s#//\s+\$(?:Id|Name|Header|Date|DateTime|Change|File|Revision|Author):.*\$$##m;
|
|
1039 |
# Remove tags like:
|
|
1040 |
# // $Id: //my/perforce/here $
|
|
1041 |
# which may be inserted into source code by some licensees
|
|
1042 |
}
|
|
1043 |
|
|
1044 |
sub PermanentFileStoreFilter {
|
|
1045 |
my $line = shift;
|
|
1046 |
$$line =~ s/^Dumping .*$/Dumping (file)/; # ignore the source file names
|
|
1047 |
}
|
|
1048 |
|
|
1049 |
sub DistributionPolicyFilter {
|
|
1050 |
my $line = shift;
|
|
1051 |
$$line =~ s/# DistPolGen.*//;
|
|
1052 |
}
|
|
1053 |
|
|
1054 |
sub FilterAll {
|
|
1055 |
my $line = shift;
|
|
1056 |
$$line = '';
|
|
1057 |
}
|
|
1058 |
|
|
1059 |
sub FilterNone {
|
|
1060 |
}
|
|
1061 |
|
|
1062 |
1;
|
|
1063 |
|
|
1064 |
__END__
|
|
1065 |
|
|
1066 |
=head1 NAME
|
|
1067 |
|
|
1068 |
EvalidCompare.pm - Utilities for comparing the contents of files.
|
|
1069 |
|
|
1070 |
=head1 DESCRIPTION
|
|
1071 |
|
|
1072 |
This package has been largely factored out of the C<e32toolp> tool C<evalid>. The main pieces of borrowed functionality are the ability to identify file types by examining their content, and the ability to filter irrelevant data out of files to allow comparisons to be performed. This refactoring was done in order to allow both direct and indirect comparisons of files to be supported. Direct comparisions are done by reading a pair of files (in the same way the C<evalid> does). Indirect comparisons are done by generating MD5 signatures of the files to be compared. The later method allows comparisons to be performed much more efficiently, because only one file need be present provided the signature of the other is known.
|
|
1073 |
|
|
1074 |
=head1 INTERFACE
|
|
1075 |
|
|
1076 |
=head2 CompareFiles
|
|
1077 |
|
|
1078 |
Expects to be passed a pair of file names. May optionally also be passed a verbosity level (defaults to 0) and a file handle for logging purposes (defaults to *STDIN). Returns 1 if the files match, 0 if not. Firstly does a raw binary compare of the two files. If they match, no further processing is done and 1 is returned. If not, the type of the first file is found and the files are re-compared, this time ignoring data known to be irrelevant for the file type. The result of this compare is then returned.
|
|
1079 |
|
|
1080 |
=head2 GenerateSignature
|
|
1081 |
|
|
1082 |
Expects to be passed a file name. May optionally also be passed a verbosity level (defaults to 0) and a file handle for logging purposes (defaults to *STDIN). Returns an MD5 signature of the specified file contents, having ignored irrelevant data associted with its type. This signature may subsequently be used to verify that the contents of the file has not been altered in a significant way.
|
|
1083 |
|
|
1084 |
=head1 KNOWN BUGS
|
|
1085 |
|
|
1086 |
None.
|
|
1087 |
|
|
1088 |
=head1 COPYRIGHT
|
|
1089 |
|
|
1090 |
Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
1091 |
All rights reserved.
|
|
1092 |
This component and the accompanying materials are made available
|
|
1093 |
under the terms of the License "Eclipse Public License v1.0"
|
|
1094 |
which accompanies this distribution, and is available
|
|
1095 |
at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
1096 |
|
|
1097 |
Initial Contributors:
|
|
1098 |
Nokia Corporation - initial contribution.
|
|
1099 |
|
|
1100 |
Contributors:
|
|
1101 |
|
|
1102 |
Description:
|
|
1103 |
|
|
1104 |
=cut
|
|
1105 |
|
|
1106 |
__END__
|