Data::Hexdumper.3pm

Langue: en

Version: 2009-03-03 (ubuntu - 24/10/10)

Section: 3 (Bibliothèques de fonctions)

NAME

Data::Hexdumper - Make binary data human-readable

SYNOPSIS

     use Data::Hexdumper qw(hexdump);
     $results = hexdump(
         data           => $data, # what to dump
         number_format  => 'S',   # display as unsigned 'shorts'
         start_position => 100,   # start at this offset ...
         end_position   => 148    # ... and end at this offset
     );
     print $results;
 
 

DESCRIPTION

"Data::Hexdumper" provides a simple way to format arbitary binary data into a nice human-readable format, somewhat similar to the Unix 'hexdump' utility.

It gives the programmer a considerable degree of flexibility in how the data is formatted, with sensible defaults. It is envisaged that it will primarily be of use for those wrestling alligators in the swamp of binary file formats, which is why it was written in the first place.

SUBROUTINES

The following subroutines are exported by default, although this is deprecated and will be removed in some future version. Please pretend that you need to ask the module to export them to you.

If you do assume that the module will always export them, then you may also assume that your code will break at some point after 1 Aug 2012.

hexdump

Does everything. Takes a hash of parameters, one of which is mandatory, the rest having sensible defaults if not specified. Available parameters are:
data
A scalar containing the binary data we're interested in. This is mandatory.
start_position
An integer telling us where in "data" to start dumping. Defaults to the beginning of "data".
end_position
An integer telling us where in "data" to stop dumping. Defaults to the end of "data".
number_format
A string specifying how to format the data. It can be any of the following, which you will notice have the same meanings as they do to perl's "pack" function:
C - unsigned char
S - unsigned 16-bit, native endianness
v or S< - unsigned 16-bit, little-endian
n or S> - unsigned 16-bit, big-endian
L - unsigned 32-bit, native endianness
V or L< - unsigned 32-bit, little-endian
N or L> - unsigned 32-bit, big-endian
Q - unsigned 64-bit, native endianness
Q< - unsigned 64-bit, little-endian
Q> - unsigned 64-bit, big-endian

It defaults to 'C'. Note that 64-bit formats are *always* available, even if your perl is only 32-bit. Similarly, using < and > on the S and L formats always works, even if you're using a pre 5.10.0 perl. That's because this code doesn't use "pack()".
suppress_warnings
Make this true if you want to suppress any warnings - such as that your data may have been padded with NULLs if it didn't exactly fit into an integer number of words, or if you do something that is deprecated.
space_as_space
Make this true if you want spaces (ASCII character 0x20) to be printed as spaces Otherwise, spaces will be printed as full stops / periods (ASCII 0x2E).

Alternatively, you can supply the parameters as a scalar chunk of data followed by an optional hashref of the other options:

     $results = hexdump($string);
 
     $results = hexdump(
         $string,
         { start_position => 100, end_position   => 148 }
     );
 
 

SEE ALSO

Data::Dumper

Data::HexDump if your needs are simple

perldoc -f unpack

perldoc -f pack

BUGS/LIMITATIONS

There is no support for syntax like 'S!' like what pack() has, so it's not possible to tell it to use your environment's native word-lengths.

It formats the data for an 80 column screen, perhaps this should be a frobbable parameter.

Formatting may break if the end position has an address greater than 65535.

FEEDBACK

I welcome constructive criticism and bug reports. Please report bugs either by email or via RT:
  <http://rt.cpan.org/Public/Dist/Display.html?Name=Data-Hexdumper>

The best bug reports contain a test file that fails with the code that is currently in CVS, and will pass once it has been fixed. The CVS repository is on Sourceforge and can be viewed in a web browser here:
  <http://drhyde.cvs.sourceforge.net/drhyde/perlmodules/Data-Hexdumper/>

Copyright 2001 - 2009 David Cantrell <david@cantrell.org.uk>

This software is free-as-in-speech software, and may be used, distributed, and modified under the terms of either the GNU General Public Licence version 2 or the Artistic Licence. It's up to you which one you use. The full text of the licences can be found in the files GPL2.txt and ARTISTIC.txt, respectively.

CONSPIRACY

This module is also free-as-in-mason software.

THANKS TO ...

MHX, for reporting a bug when dumping a single byte of data

Stefan Siegl, for reporting a bug when dumping an ASCII 0