From: Justin Mason (jm at domain jmason.org)
Date: Fri 29 Oct 1999 - 16:56:16 IST
Niall O Broin said:
> 00000000: 0005 1607 0001 0000 0000 0000 0000 0000 ................
> 00000010: 0000 0000 0000 0000 0005 0000 0002 0000 ................
> 00000020: 024d 0000 ef15 0000 0003 0000 0056 0000 .M...........V..
> 00000030: 0016 0000 0004 0000 0155 0000 0000 0000 .........U......
I like the one from an edition of the Camel book, short, simple,
and doesn't need to be rebuilt on every platform. Here it is:
#!/usr/bin/perl
# Usage: xdump [file]
open(STDIN,$ARGV[0]) || die "Can't open $ARGV[0]: $!\n"
if $ARGV[0];
# Do it optimally as long as we can read 16 bytes at a time.
while (($len = read(STDIN,$data,16)) == 16) {
at domain array = unpack('N4', $data);
$data =~ tr/\0-\37\177-\377/./;
printf "%8.8lx %8.8lx %8.8lx %8.8lx %8.8lx %s\n",
$offset, at domain array, $data;
$offset += 16;
}
# Now finish up the end a byte at a time.
if ($len) {
at domain array = unpack('C*', $data);
$data =~ y/\0-\37\177-\377/./;
for ( at domain array) {
$_ = sprintf('%2.2x',$_);
}
push( at domain array, ' ') while $len++ < 16;
$data =~ s/[^ -~]/./g;
printf "%8.8lx ", $offset;
printf "%s%s%s%s %s%s%s%s %s%s%s%s %s%s%s%s %s\n",
at domain array, $data;
}
This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:04:48 GMT