logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

Test::HexDifferences::HexDump - Format binary to hexadecimal strings

Author

       Steffen Winkler

Bugs And Limitations

       none

Configuration And Environment

       nothing

Dependencies

       Hash::Util

       Sub::Exporter

Description

       This is a formatter for binary data.

Diagnostics

       nothing

Example

       Inside of this Distribution is a directory named example.  Run this *.t files.

Incompatibilities

       none

Name

       Test::HexDifferences::HexDump - Format binary to hexadecimal strings

See Also

       Test::HexDifferences

       Data::Hexdumper inspired by

Subroutines/Methods

subroutinehex_dump
           $string = hex_dump(
               $binary,
               {
                   address => $display_start_address,
                   format  => $format_string,
               }
           );

Synopsis

           use Test::HexDifferences::HexDump;

           $string = hex_dump(
               $binary,
           );

           $string = hex_dump(
               $binary,
               {
                   address => $start_address,
                   format  => "%a : %4C : %d\n",
               }
           );

   Formatelements
       Every format element in the format string is starting with % like sprintf.

       If the given format is shorter defined as needed for the data length the remaining data are displayed in
       default format.  If the given format is longer defined as the data length the output will filled with
       space and it stops before next repetition.

       Dataformat

       It is not very clever to use little-endian formats for tests.  There is a fallback to bytes if multibyte
       formats can not displayed.

        %C  - unsigned char
        %S  - unsigned 16-bit, endian depends on machine
        %S< - unsigned 16-bit, little-endian
        %S> - unsigned 16-bit, big-endian
        %v  - unsigned 16-bit, little-endian
        %n  - unsigned 16-bit, big-endian
        %L  - unsigned 32-bit, endian depends on machine
        %L< - unsigned 32-bit, little-endian
        %L> - unsigned 32-bit, big-endian
        %V  - unsigned 32-bit, little-endian
        %N  - unsigned 32-bit, big-endian
        %Q  - unsigned 64-bit, endian depends on machine
        %Q< - unsigned 64-bit, little-endian
        %Q> - unsigned 64-bit, big-endian

       "pack" and "unpack" before Perl v5.10 do not allow "<" and ">" to mark the byte order.  This is allowed
       here for all Perl versions.

       "pack" and "unpack" on a 32 bit machine do not allow the "Q" formats.  This is allowed here for all
       machines.

       Addressformat

        %a  - 16 bit address
        %4a - 16 bit address
        %8a - 32 bit address

       ASCIIformat

       It can not display all chars.  First it must be a printable ASCII char.  It can not be anything of space,
       q{.}, q{'}, q{"} or q{\}.  Otherwise q{.} will be printed.

        %d - display ASCII

       Repetition

        %*x - repetition endless
        %1x - repetition 1 time
        %2x - repetition 2 times
        ...

       Specialformats

        %\n - ignore \n

   Defaultformat
       The default format is:

        "%a : %4C : %d\n"

       or fully written as

        "%a : %4C : %d\n%*x"

   Complexformats
       The %...x allows to write mixed formats e.g.

        Format:
         %a : %N %4C : %d\n%1x%
         %a : %n %2C : %d\n%*x
        Input:
           \0x01\0x23\0x45\0x67\0x89\0xAB\0xCD\0xEF
           \0x01\0x23\0x45\0x67
           \0x89\0xAB\0xCD\0xEF
        Output:
           0000 : 01234567 89 AB CD EF : .#-Eg...
           0008 : 0123 45 67 : .#-E
           000C : 89AB CD EF : g...

Version

       0.008

See Also