Test::...HexDump(3pm)
πΈ Test::HexDifferences::HexDump β the glow-up guide πΈ
okay bestie, come sit with me because we're about to make binary data look cute. this is the perl manual page for Test::HexDifferences::HexDump (you'll also see it filed under the manual name Test::...HexDump(3pm), that's just the same girl in a different outfit π
), and she formats binary into hexadecimal strings. iconic behavior fr fr.
β¨ NAME β¨
Test::HexDifferences::HexDump β Format binary to hexadecimal strings π¦
β¨ VERSION β¨
0.008 β yes ma'am, we're on 0.008, she's vintage, she's timeless π
β¨ SYNOPSIS β¨
okay so here's the vibe. you pull the module in, you hand it some binary, and it gives you back a string:
use Test::HexDifferences::HexDump;
$string = hex_dump(
$binary,
);
and if you want to be extra (we love extra), you pass in a hashref with your own address and format:
$string = hex_dump(
$binary,
{
address => $start_address,
format => "%a : %4C : %d\n",
}
);
π Format elements
every format element in the format string starts with %, just like sprintf. no cap. π
if the format you gave is shorter than what the data length needs, the leftover data gets shown in the default format. if the format you gave is longer than the data length, the output gets filled with space and it stops before the next repetition. periodt. π
π Data format
ngl it is not very clever to use little-endian formats for tests. there's a fallback to bytes if multibyte formats can not be displayed. so like, the safety net is real. π«Ά
%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. here? allowed for all Perl versions. we don't gatekeep. β¨
pack and unpack on a 32 bit machine do not allow the Q formats. here? allowed for all machines. inclusivity queen π
π Address format
%aβ 16 bit address%4aβ 16 bit address%8aβ 32 bit address
π ASCII format
it can not display all chars, sorry babe. first it must be a printable ASCII char. and it can not be anything of space, q{.}, q{'}, q{"} or q{\}. otherwise q{.} will be printed. that's the rule, we live by it. π
%dβ display ASCII
π Repetition
%*xβ repetition endless%1xβ repetition 1 time%2xβ repetition 2 times...
π§ Special formats
%\nβ ignore\n
π Default format
the default format is:
"%a : %4C : %d\n"
or, fully written out, she's serving:
"%a : %4C : %d\n%*x"
π¦ Complex formats
the %...x lets you 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...
look at that output. literally chef's kiss. π₯
β¨ EXAMPLE β¨
inside of this Distribution is a directory named example. run this *.t files. π
β¨ DESCRIPTION β¨
this is a formatter for binary data. that's it, that's the whole vibe. π
β¨ SUBROUTINES/METHODS β¨
πΈ subroutine hex_dump
$string = hex_dump(
$binary,
{
address => $display_start_address,
format => $format_string,
}
);
bestie this is the main character right here. give her binary, get back a string. π
β¨ DIAGNOSTICS β¨
nothing. she's quiet. lowkey mysterious. π
β¨ CONFIGURATION AND ENVIRONMENT β¨
nothing. no env vars, no config files, we keep it minimal. β¨
β¨ DEPENDENCIES β¨
Hash::UtilSub::Exporter
β¨ INCOMPATIBILITIES β¨
none. she gets along with everyone. π«Ά
β¨ BUGS AND LIMITATIONS β¨
none. no bugs, no limitations, she's perfect, and I will not be taking questions. π
β¨ SEE ALSO β¨
Test::HexDifferencesData::Hexdumperinspired by
β¨ AUTHOR β¨
Steffen Winkler π
β¨ LICENSE AND COPYRIGHT β¨
Copyright (c) 2012 - 2014, Steffen Winkler "<steffenw at cpan.org>". All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. π
and that's the whole page, bestie. no notes. go format something pretty. π
mwah π β this was perl v5.30.3, dated 2020-08-04, and yes the manual page is still called Test::...HexDump(3pm) even though the module is Test::HexDifferences::HexDump. she contains multitudes. β¨
π¦ where this page comes from
- debian bookworm: libtest-hexdifferences-perl 1.001-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libtest-hexdifferences-perl 1.001-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu jammy: libtest-hexdifferences-perl 1.001-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libtest-hexdifferences-perl 1.001-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libtest-hexdifferences-perl 1.001-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libtest-hexdifferences-perl 1.001-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms