.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Data::Hexdumper 3pm" .TH Data::Hexdumper 3pm "2021-01-05" "perl v5.32.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Data::Hexdumper \- Make binary data human\-readable .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 12 \& use Data::Hexdumper qw(hexdump); \& print hexdump( \& data => $data, # what to dump \& # NB number_format is deprecated \& number_format => \*(AqS\*(Aq, # display as unsigned \*(Aqshorts\*(Aq \& start_position => 100, # start at this offset ... \& end_position => 148 # ... and end at this offset \& ); \& print hexdump( \& "abcdefg", \& { output_format => \*(Aq%4a : %C %S< %L> : %d\*(Aq } \& ); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" \&\f(CW\*(C`Data::Hexdumper\*(C'\fR provides a simple way to format arbitrary binary data into a nice human-readable format, somewhat similar to the Unix 'hexdump' utility. .PP 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. .SH "SUBROUTINES" .IX Header "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. .PP 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. .SS "hexdump" .IX Subsection "hexdump" Does everything. Takes a hash of parameters, one of which is mandatory, the rest having sensible defaults if not specified. Available parameters are: .IP "data" 4 .IX Item "data" A scalar containing the binary data we're interested in. This is mandatory. .IP "start_position" 4 .IX Item "start_position" An integer telling us where in \f(CW\*(C`data\*(C'\fR to start dumping. Defaults to the beginning of \f(CW\*(C`data\*(C'\fR. .IP "end_position" 4 .IX Item "end_position" An integer telling us where in \f(CW\*(C`data\*(C'\fR to stop dumping. Defaults to the end of \f(CW\*(C`data\*(C'\fR. .IP "number_format" 4 .IX Item "number_format" This is deprecated. See '\s-1INCOMPATIBLE CHANGES\s0' below. If you use this your data will be padded with NULLs to be an integer multiple of 16 bytes. You can expect number_format to be removed at some point in 2014 or later. .Sp 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 \f(CW\*(C`pack\*(C'\fR function: .RS 4 .IP "C \- unsigned char" 4 .IX Item "C - unsigned char" .PD 0 .IP "S \- unsigned 16\-bit, native endianness" 4 .IX Item "S - unsigned 16-bit, native endianness" .IP "v or S< \- unsigned 16\-bit, little-endian" 4 .IX Item "v or S< - unsigned 16-bit, little-endian" .IP "n or S> \- unsigned 16\-bit, big-endian" 4 .IX Item "n or S> - unsigned 16-bit, big-endian" .IP "L \- unsigned 32\-bit, native endianness" 4 .IX Item "L - unsigned 32-bit, native endianness" .IP "V or L< \- unsigned 32\-bit, little-endian" 4 .IX Item "V or L< - unsigned 32-bit, little-endian" .IP "N or L> \- unsigned 32\-bit, big-endian" 4 .IX Item "N or L> - unsigned 32-bit, big-endian" .IP "Q \- unsigned 64\-bit, native endianness" 4 .IX Item "Q - unsigned 64-bit, native endianness" .IP "Q< \- unsigned 64\-bit, little-endian" 4 .IX Item "Q< - unsigned 64-bit, little-endian" .IP "Q> \- unsigned 64\-bit, big-endian" 4 .IX Item "Q> - unsigned 64-bit, big-endian" .RE .RS 4 .PD .Sp 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 \f(CW\*(C`pack()\*(C'\fR. .RE .IP "output_format" 4 .IX Item "output_format" This is an alternative and much more flexible (but more complex) method of specifying the output format. Instead of specifying a single format for all your output, you can specify formats like: .Sp .Vb 1 \& %4a : %C %S %L> %Q : %d .Ve .Sp which will, on each line, display first the address (consisting of '0x' and 4 hexadecimal digits, zero-padded if necessary), then a space, then a colon, then a single byte of data, then a space, then an unsigned 16\-bit value in native endianness, then a space, then an unsigned 32\-bit big-endian value, ... then a colon, a space, then the characters representing your 15 byte record. .Sp You can use exactly the same characters and character sequences as are specified above for number_format, plus 'a' for the address, and 'd' for the data. To output a literal % character, use %% as is normal with formats \- see sprintf for details. To output a literal < or > character where it may be confused with any of the {S,L,Q}{<,>} sequences, use %< or %>. So, for example, to output a 16\-bit value in native endianness followed by <, use \f(CW%S\fR%<. .Sp \&\f(CW%a\fR takes an optional base-ten number between the % and the a signifying the number of hexadecimal digits. This defaults to 4. .Sp %{C,S,L,Q} also take an optional base-ten number between the % and the letter, signifying the number of repeats. These will be separated by spaces in the output. So '%4C' is equivalent to '%C \f(CW%C\fR \f(CW%C\fR \f(CW%C\fR'. .Sp Anything else will get printed literally. This format will be repeated for as many lines as necessary. If the amount of data isn't enough to completely fill the last line, it will be padded with \&\s-1NULL\s0 bytes. .Sp To specify both number_format and output_format is a fatal error. .Sp If neither are given, output_format defaults to: .Sp .Vb 1 \& \*(Aq %4a : %16C : %d\*(Aq .Ve .Sp which is equivalent to the old-style: .Sp .Vb 1 \& number_format => \*(AqC\*(Aq .Ve .IP "suppress_warnings" 4 .IX Item "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. .IP "space_as_space" 4 .IX Item "space_as_space" Make this true if you want spaces (\s-1ASCII\s0 character 0x20) to be printed as spaces Otherwise, spaces will be printed as full stops / periods (\s-1ASCII\s0 0x2E). .PP Alternatively, you can supply the parameters as a scalar chunk of data followed by an optional hashref of the other options: .PP .Vb 5 \& $results = hexdump($string); \& $results = hexdump( \& $string, \& { start_position => 100, end_position => 148 } \& ); .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" Data::Dumper .PP Data::HexDump if your needs are simple .PP perldoc \-f unpack .PP perldoc \-f pack .SH "INCOMPATIBLE CHANGES" .IX Header "INCOMPATIBLE CHANGES" \&'number_format' is now implemented in terms of 'output_format'. Your data will be padded to a multiple of 16 bytes. Previously-silent code may now emit warnings. .PP The mappings are: .PP .Vb 10 \& \*(AqC\*(Aq => \*(Aq %4a : %C %C %C %C %C %C %C %C %C %C %C %C %C %C %C %C : %d\*(Aq \& \*(AqS\*(Aq => \*(Aq %4a : %S %S %S %S %S %S %S %S : %d\*(Aq \& \*(AqS<\*(Aq => \*(Aq %4a : %S< %S< %S< %S< %S< %S< %S< %S< : %d\*(Aq \& \*(AqS>\*(Aq => \*(Aq %4a : %S> %S> %S> %S> %S> %S> %S> %S> : %d\*(Aq \& \*(AqL\*(Aq => \*(Aq %4a : %L %L %L %L : %d\*(Aq \& \*(AqL<\*(Aq => \*(Aq %4a : %L< %L< %L< %L< : %d\*(Aq \& \*(AqL>\*(Aq => \*(Aq %4a : %L> %L> %L> %L> : %d\*(Aq \& \*(AqQ\*(Aq => \*(Aq %4a : %Q %Q : %d\*(Aq \& \*(AqQ<\*(Aq => \*(Aq %4a : %Q< %Q< : %d\*(Aq \& \*(AqQ>\*(Aq => \*(Aq %4a : %Q> %Q> : %d\*(Aq .Ve .PP and of course: .PP .Vb 4 \& \*(AqV\*(Aq => \*(AqL<\*(Aq \& \*(AqN\*(Aq => \*(AqL>\*(Aq \& \*(Aqv\*(Aq => \*(AqS<\*(Aq \& \*(Aqn\*(Aq => \*(AqS>\*(Aq .Ve .SH "BUGS/LIMITATIONS" .IX Header "BUGS/LIMITATIONS" Behaviour of \f(CW%a\fR is not defined if your file is too big. .PP Behaviour of \f(CW%NNa\fR is not defined if \s-1NN\s0 is too big for your sprintf implementation to handle 0x%0${\s-1NN\s0}X. .SH "FEEDBACK" .IX Header "FEEDBACK" I welcome constructive criticism and bug reports. Please report bugs either by email or via \s-1RT:\s0 .PP The best bug reports contain a test file that fails with the current code, and will pass once it has been fixed. The code repository is on Github: .SH "AUTHOR, COPYRIGHT and LICENCE" .IX Header "AUTHOR, COPYRIGHT and LICENCE" Copyright 2001 \- 2012 David Cantrell <\fIdavid@cantrell.org.uk\fR> .PP This software is free-as-in-speech software, and may be used, distributed, and modified under the terms of either the \s-1GNU\s0 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 \s-1GPL2\s0.txt and \s-1ARTISTIC\s0.txt, respectively. .SH "CONSPIRACY" .IX Header "CONSPIRACY" This module is also free-as-in-mason software. .SH "THANKS TO ..." .IX Header "THANKS TO ..." \&\s-1MHX,\s0 for reporting a bug when dumping a single byte of data .PP Stefan Siegl, for reporting a bug when dumping an \s-1ASCII 0\s0 .PP Steffen Winkler, for inspiring me to use proper output formats