Data-HexDump-0.02/0042755000175000017500000000000006764573061012006 5ustar ftaftaData-HexDump-0.02/Makefile.PL0100644000175000017500000000053306744730200013740 0ustar ftafta# -*- mode: Perl -*- use ExtUtils::MakeMaker; WriteMakefile(NAME => "Data::HexDump", VERSION_FROM => "lib/Data/HexDump.pm", dist => { COMPRESS => "gzip", SUFFIX => "gz" }, clean => { FILES => '*.bak *.old mibs/*.dump lib/*/*~' }, EXE_FILES => [ qw(hexdump) ], ); Data-HexDump-0.02/hexdump0100755000175000017500000000112406745132333013367 0ustar ftafta#!/usr/bin/perl -w use lib "lib"; use strict; use Data::HexDump; use FileHandle; my $prgname = "hexdump"; my $file = shift; my $fh; if ($file) { die "$prgname: $file: Is a directory\n" if -d $file; $fh = new FileHandle $file; die "$prgname: $file: $!\n" unless defined $fh; my $f = new Data::HexDump; $f->fh($fh); $f->block_size(1024); print while $_ = $f->dump; close $fh; } else { # read STDIN } sub Usage { die "Usage: $prgname [FILE]\n" . "Dump FILE, or standard input, to standard output.\n\n" . "With no FILE, or when FILE is -, read standard input.\n"; } Data-HexDump-0.02/t/0042755000175000017500000000000006764573061012251 5ustar ftaftaData-HexDump-0.02/t/compare.t0100644000175000017500000000130406745156545014060 0ustar ftafta# -*- Mode: Perl -*- BEGIN { unshift @INC, "lib", "../lib" } use strict; use Data::HexDump; local $^W = 1; my $t = 1; print "1..2\n"; # data my $org = ""; for (my $i = 0; $i <= 255; $i++) { $org .= pack 'c', $i; } $org = $org x 17 . "more data"; # non-oo print &undump(HexDump $org) eq $org ? "" : "not ", "ok $t\n"; $t++; # data my $f = new Data::HexDump; $f->data($org); print &undump($f->dump) eq $org ? "" : "not ", "ok $t\n"; # filehandle # todo # file # todo sub undump { my $res = shift; my @t = split /\n/, $res; $res = ''; splice @t, 0, 2; for my $line (@t) { $line = substr $line, 10, 49; my @n = split / +(?:\- )?/, $line; map { $res .= chr hex } @n; } $res; } Data-HexDump-0.02/t/data.t0100644000175000017500000000545606743456501013350 0ustar ftafta# -*- Mode: Perl -*- BEGIN { unshift @INC, "lib", "../lib" } use strict; use Data::HexDump; local $^W = 1; print "1..10\n"; my $t = 1; my $v = "f"; &Check ($t++, HexDump $v x 7, " 00 01 02 03 04 05 06 07 - " . "08 09 0A 0B 0C 0D 0E 0F 0123456789ABCDEF\n\n" . "00000000 66 66 66 66 66 66 66 " . " fffffff\n"); &Check ($t++, HexDump $v x 8, " 00 01 02 03 04 05 06 07 - " . "08 09 0A 0B 0C 0D 0E 0F 0123456789ABCDEF\n\n" . "00000000 66 66 66 66 66 66 66 66 " . " ffffffff\n"); &Check ($t++, HexDump $v x 9, " 00 01 02 03 04 05 06 07 - " . "08 09 0A 0B 0C 0D 0E 0F 0123456789ABCDEF\n\n" . "00000000 66 66 66 66 66 66 66 66 - " . "66 fffffffff\n"); &Check ($t++, HexDump $v x 15, " 00 01 02 03 04 05 06 07 - " . "08 09 0A 0B 0C 0D 0E 0F 0123456789ABCDEF\n\n" . "00000000 66 66 66 66 66 66 66 66 - " . "66 66 66 66 66 66 66 fffffffffffffff\n"); &Check ($t++, HexDump $v x 16, " 00 01 02 03 04 05 06 07 - " . "08 09 0A 0B 0C 0D 0E 0F 0123456789ABCDEF\n\n" . "00000000 66 66 66 66 66 66 66 66 - " . "66 66 66 66 66 66 66 66 ffffffffffffffff\n"); &Check ($t++, HexDump $v x 23, " 00 01 02 03 04 05 06 07 - " . "08 09 0A 0B 0C 0D 0E 0F 0123456789ABCDEF\n\n" . "00000000 66 66 66 66 66 66 66 66 - " . "66 66 66 66 66 66 66 66 ffffffffffffffff\n" . "00000010 66 66 66 66 66 66 66 " . " fffffff\n"); &Check ($t++, HexDump $v x 24, " 00 01 02 03 04 05 06 07 - " . "08 09 0A 0B 0C 0D 0E 0F 0123456789ABCDEF\n\n" . "00000000 66 66 66 66 66 66 66 66 - " . "66 66 66 66 66 66 66 66 ffffffffffffffff\n" . "00000010 66 66 66 66 66 66 66 66 " . " ffffffff\n"); &Check ($t++, HexDump $v x 25, " 00 01 02 03 04 05 06 07 - " . "08 09 0A 0B 0C 0D 0E 0F 0123456789ABCDEF\n\n" . "00000000 66 66 66 66 66 66 66 66 - " . "66 66 66 66 66 66 66 66 ffffffffffffffff\n" . "00000010 66 66 66 66 66 66 66 66 - " . "66 fffffffff\n"); &Check ($t++, HexDump $v x 31, " 00 01 02 03 04 05 06 07 - " . "08 09 0A 0B 0C 0D 0E 0F 0123456789ABCDEF\n\n" . "00000000 66 66 66 66 66 66 66 66 - " . "66 66 66 66 66 66 66 66 ffffffffffffffff\n" . "00000010 66 66 66 66 66 66 66 66 - " . "66 66 66 66 66 66 66 fffffffffffffff\n"); &Check ($t++, HexDump $v x 32, " 00 01 02 03 04 05 06 07 - " . "08 09 0A 0B 0C 0D 0E 0F 0123456789ABCDEF\n\n" . "00000000 66 66 66 66 66 66 66 66 - " . "66 66 66 66 66 66 66 66 ffffffffffffffff\n" . "00000010 66 66 66 66 66 66 66 66 - " . "66 66 66 66 66 66 66 66 ffffffffffffffff\n"); sub Check { my $num = shift; my $v1 = shift; my $v2 = shift; print "" . ($v1 eq $v2 ? "" : "not ") . "ok $num\n"; print $v1 unless $v1 eq $v2; } Data-HexDump-0.02/MANIFEST.SKIP0100644000175000017500000000012106736757130013671 0ustar ftafta^Makefile(\.old)?$ ^MANIFEST\.bak$ .*~$ (^|/)TAGS$ .*\.tar\.gz$ blib/ pm_to_blib Data-HexDump-0.02/lib/0042755000175000017500000000000006764573061012554 5ustar ftaftaData-HexDump-0.02/lib/Data/0042755000175000017500000000000006764573061013425 5ustar ftaftaData-HexDump-0.02/lib/Data/HexDump.pm0100644000175000017500000001165406764572777015354 0ustar ftafta# -*- mode: Perl -*- ########################################################################## # # HexDump.pm - Hexadecial Dumper # # version : 0.02 # Copyright (c) 1998, 1999, Fabien Tassin ########################################################################## # ABSOLUTELY NO WARRANTY WITH THIS PACKAGE. USE IT AT YOUR OWN RISKS. ########################################################################## package Data::HexDump; use strict; use vars qw(@ISA $VERSION @EXPORT); use Exporter; use Carp; use FileHandle; @ISA = ('Exporter'); $VERSION = 0.02; @EXPORT = qw(HexDump); sub new { my $this = shift; my $class = ref($this) || $this; my $self = {}; bless $self, $class; $self->{'readsize'} = 128; return $self; } sub DESTROY { my $self = shift; $self->{'fh'}->close if defined $self->{'file'}; } sub file { my $self = shift; my $file = shift; $self->{'file'} = $file if defined $file; $self->{'file'}; } sub fh { my $self = shift; my $fh = shift; $self->{'fh'} = $fh if defined $fh; $self->{'fh'}; } sub data { my $self = shift; my $data = shift; $self->{'data'} = $data if defined $data; $self->{'data'}; } sub block_size { my $self = shift; my $bs = shift; $self->{'blocksize'} = $bs if defined $bs; $self->{'blocksize'}; } sub dump { my $self = shift; my $out; my $l; $self->{'i'} = 0 unless defined $self->{'i'}; $self->{'j'} = 0 unless defined $self->{'j'}; my $i = $self->{'i'}; my $j = $self->{'j'}; unless ($i || $j) { $out = " "; $l = ""; for (my $i = 0; $i < 16; $i++) { $out .= sprintf "%02X", $i; $out .= " " if $i < 15; $out .= "- " if $i == 7; $l .= sprintf "%X", $i; } $i = $j = 0; $out .= " $l\n\n"; } return undef if $self->{'eod'}; $out .= sprintf "%08X ", $j * 16; $l = ""; my $val; while ($val = $self->get) { while (length $val && defined (my $v = substr $val, 0, 1, '')) { $out .= sprintf "%02X", ord $v; $out .= " " if $i < 15; $out .= "- " if $i == 7 && (length $val || !($self->{'eod'} || length $val)); $i++; $l .= ord($v) >= 0x20 && ord($v) <= 0x7E ? $v : "."; if ($i == 16) { $i = 0; $j++; $out .= " " . $l; $l = ""; $out .= "\n"; if (defined $self->{'blocksize'} && $self->{'blocksize'} && ($j - $self->{'j'}) > $self->{'blocksize'} / 16) { $self->{'i'} = $i; $self->{'j'} = $j; $self->{'val'} = $val; return $out; } $out .= sprintf "%08X ", $j * 16 if length $val || !length $val && !$self->{'eod'}; } } } if ($i || (!$i && !$j)) { $out .= " " x (3 * (17 - $i) - 2 * ($i > 8)); $out .= "$l\n"; } $self->{'i'} = $i; $self->{'j'} = $j; $self->{'val'} = $val; return $out; } # get data from different sources (scalar, filehandle, file..) sub get { my $self = shift; my $buf; my $length = $self->{'readsize'}; undef $self->{'val'} if defined $self->{'val'} && ! length $self->{'val'}; if (defined $self->{'val'}) { $buf = $self->{'val'}; undef $self->{'val'}; } elsif (defined $self->{'data'}) { $self->{'data_offs'} = 0 unless defined $self->{'data_offs'}; my $offset = $self->{'data_offs'}; $buf = substr $self->{'data'}, $offset, $length; $self->{'data_offs'} += length $buf; $self->{'eod'} = 1 if $self->{'data_offs'} == length $self->{'data'}; } elsif (defined $self->{'fh'}) { read $self->{'fh'}, $buf, $length; $self->{'eod'} = eof $self->{'fh'}; } elsif (defined $self->{'file'}) { $self->{'fh'} = new FileHandle $self->{'file'}; read $self->{'fh'}, $buf, $length; $self->{'eod'} = eof $self->{'fh'}; } else { print "Not yet implemented\n"; } $buf; } sub HexDump ($) { my $val = shift; my $f = new Data::HexDump; $f->data($val); $f->dump; } 1; =head1 NAME Data::HexDump - Hexadecial Dumper =head1 SYNOPSIS use Data::HexDump; my $buf = "foo\0bar"; print HexDump $buf; or my $f = new Data::HexDump; $f->data($buf); print $f->dump; or my $fh = new FileHandle $file2dump; my $f = new Data::HexDump; $f->fh($fh); $f->block_size(1024); print while $_ = $f->dump; close $fh; or my $f = new Data::HexDump; $f->file($file2dump); $f->block_size(1024); print while $_ = $f->dump; =head1 DESCRIPTION Dump in hexadecimal the content of a scalar. The result is returned in a string. Each line of the result consists of the offset in the source in the leftmost column of each line, followed by one or more columns of data from the source in hexadecimal. The rightmost column of each line shows the printable characters (all others are shown as single dots). =head1 COPYRIGHT Copyright (c) 1998-1999 Fabien Tassin. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 AUTHOR Fabien Tassin Efta@oleane.netE =head1 VERSION 0.02 - Second release (September 1999) =head1 SEE ALSO perl(1) =cut Data-HexDump-0.02/README0100644000175000017500000000203306743462777012667 0ustar ftaftaNAME Data::HexDump - A Simple Hexadecial Dumper DESCRIPTION Dump in hexadecimal the content of a scalar. The result is returned in a string. Each line of the result consists of the offset in the source in the leftmost column of each line, followed by one or more columns of data from the source in hexadecimal. The rightmost column of each line shows the printable characters (all others are shown as single dots) INSTALLATION To install, cd to the directory containing the unpacked distribution and do one of the following: a. Create a makefile by running Makefile.PL using the perl program into whose library you want to install and then run make three times: perl Makefile.PL make make test make install b. To install into a private library, for example your home directory: perl Makefile.PL INSTALLSITELIB=$HOME/lib INSTALLMAN3DIR=$HOME/man make make test make pure_install AUTHOR Fabien Tassin Data-HexDump-0.02/MANIFEST0100644000175000017500000000013306747005310013113 0ustar ftaftaMANIFEST MANIFEST.SKIP Makefile.PL README hexdump lib/Data/HexDump.pm t/compare.t t/data.t