I wrote a hexdump script once for comparing the data dumps
from character data from the computer game "Diablo II".
Here it is...
# # List all *.d2s files in the cwd. # foreach ( <*.d2s> ) { print "$_\n"; } # # Compare the contents of three files byte by byte. # print "Enter first character file: "; my $file1 = <STDIN> || &synopsis; print "Enter next character file : "; my $file2 = <STDIN> || &synopsis; print "Enter last character file : "; my $file3 = <STDIN> || &synopsis; chomp( $file1 ); chomp( $file2 ); chomp( $file3 ); open( F1, $file1 ); open( F2, $file2 ); open( F3, $file3 ); open( OUT, ">comparison" ); my $offset = 0; my @f1; my @f2; my @f3; my $ok = 1; print OUT "Dots represent identical values across all 3 files.\n\n"; print OUT "Dec| ", sprintf( "%-23s | ", $file1 ), sprintf( "%-23s | ", $file2 ), sprintf( "%-23s", $file3 ), "\n"; my $c12 = 0; my $c13 = 0; my $c23 = 0; while( $ok ) { my $d1; my $d2; my $d3; my $r1 = read F1, $d1, 8; my $r2 = read F2, $d2, 8; my $r3 = read F3, $d3, 8; if ( $r1 + $r2 + $r3 < 24 ) { $ok = 0; } my @dat1 = unpack "CCCCCCCC", $d1; my @dat2 = unpack "CCCCCCCC", $d2; my @dat3 = unpack "CCCCCCCC", $d3; foreach( @dat1, @dat2, @dat3 ) { $_ = sprintf( "%02x", $_ ); } for( $i=0; $i<@dat1; $i++ ) { $c12++ if $dat1[$i] == $dat2[$i]; $c13++ if $dat1[$i] == $dat3[$i]; $c23++ if $dat2[$i] == $dat3[$i]; if ( $dat1[$i] == $dat2[$i] && $dat1[$i] == $dat3[$i] ) { $dat1[$i] = ' .'; $dat2[$i] = ' .'; $dat3[$i] = ' .'; } } $offset++; print OUT sprintf( "%03d| ", ($offset * 8 - 8) % 1000 ), sprintf( "%-23s | ", join( " ", @dat1 ) ), sprintf( "%-23s | ", join( " ", @dat2 ) ), sprintf( "%-23s\n", join( " ", @dat3 ) ); push( @f1, @dat1 ); push( @f2, @dat2 ); push( @f3, @dat3 ); } close F1; close F2; close F3; foreach( @f1, @f2, @f3 ) { $_ = hex $_; #print "$_\n"; } my @c = ( "Amazon", "Unknown", "Necromancer", "Unknown", "Barbarian" ) +; print OUT sprintf( "Level%23d %23d %23d\n", $f1[36], $f2[36], $f3[ +36] ); print OUT sprintf( "Class%23s %23s %23s\n", $c[$f1[34]], $c[$f2[34 +]], $c[$f3[34]] ); my $stats = "Str Eng Dex Vit"; print OUT sprintf( "Stats%23s %23s %23s\n", $stats, $stats, $stats + ); print OUT sprintf( "Stats%5s%6s%6s%6s %6s%6s%6s%6s %6s%6s%6s%6s\n", $f1[565], $f1[569], $f1[573], $f1[577], $f2[565], $f2[569], $f2[573], $f2[577], $f3[565], $f3[569], $f3[573], $f3[577] ); # # These attributes are not at a hard location. # #print OUT sprintf( "Xp: %23d %23d %23d\n", # $f1[618] + $f1[617] * 256 , #+ $f1[620] * 65536 + +$f1[619] * (2**24), # $f2[618] + $f2[617] * 256 , #+ $f2[620] * 65536 + +$f2[619] * (2**24), # $f3[618] + $f3[617] * 256 ); # + $f3[620] * 65536 ++ $f3[619] * (2**24) ); #print OUT sprintf( "Cash:%23d %23d %23d\n", # $f1[622] + $f1[621] * 256 + $f1[624] * 65536 + $f1 +[623] * (2**24), # $f2[622] + $f2[621] * 256 + $f2[624] * 65536 + $f2 +[623] * (2**24), # $f3[622] + $f3[621] * 256 + $f3[624] * 65536 + $f3 +[623] * (2**24) ); $offset *= 8; print OUT "\nFile similarities: \n"; print OUT &compare( "1,2", $c12 ); print OUT &compare( "1,3", $c13 ); print OUT &compare( "2,3", $c23 ); close OUT; sub synopsis { die "SYNOPSIS: $0 file_1 file_2 file_3\n"; } sub compare { my ($desc, $value) = @_; return " c($desc): ", int( $value*100/$offset ), "% ($value/$offs +et)\n"; }

In reply to Re: A simple hex dump by rje
in thread A simple hex dump by converter

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.