use strict; use warnings; use IO::File; sub readbin { my $fn= shift; my $fh= IO::File->new($fn, "r") or die "$fn: $!\n"; binmode $fh; my $data; $fh->read($data, -s $fn); $fh->close(); return $data; } if (@ARGV!=2) { die "Usage: cmpbin file1 file2\n"; } my $f1= readbin(shift); my $f2= readbin(shift); for (my $ofs= 0 ; $ofs < length($f1) && $ofs < length($f2) ; $ofs+=4) { if (substr($f1,$ofs,4) ne substr($f2,$ofs,4)) { my ($l,$r)= unpack("VV", substr($f1,$ofs,4).substr($f2,$ofs,4)); printf("%08lx: %08lx %08lx xor=%08x sub=%08x %s %s\n", $ofs, $l, $r, $l^$r, ($l-$r)&0xFFFFFFFF, disp(substr($f1,$ofs,4)), disp(substr($f2,$ofs,4))); } } sub disp { my $x= shift; $x =~ s/[\x00-\x1f\x80-\x9f]/./g; return $x; }