4e3819cf |
1 | #! /bin/perl |
2 | |
3 | $| = 1; |
4 | sleep 10; |
5 | for (;;) { |
6 | sysread(STDIN, $buf, 65536) or die "read: $!"; |
7 | hexdump($buf); |
8 | } |
9 | |
10 | sub hexdump { |
11 | my $buf = shift; |
12 | my ($off, $i); |
13 | |
14 | while ($off < length($buf)) { |
15 | printf "%08x : ", $off; |
16 | for ($i = $off; $i < $off + 16; $i++) { |
17 | if ($i >= length($buf)) { |
18 | print "** "; |
19 | } else { |
20 | printf "%02x ", ord(substr($buf, $i, 1)); |
21 | } |
22 | } |
23 | print ": "; |
24 | for ($i = $off; $i < $off + 16; $i++) { |
25 | if ($i >= length($buf)) { |
26 | print "*"; |
27 | } else { |
28 | $ch = substr($buf, $i, 1); |
29 | $code = ord($ch); |
30 | if ($code < 32 || $code > 126) { |
31 | print "."; |
32 | } else { |
33 | print $ch; |
34 | } |
35 | } |
36 | } |
37 | print "\n"; |
38 | $off += 16; |
39 | } |
40 | print "\n"; |
41 | } |