xxd

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 24, 2022 License: BSD-3-Clause Imports: 3 Imported by: 1

README

xxd - a Go package for generating hex dumps

Overview

Under Linux there is a handy stand alone command xxd that can be used to generate HEX dumps of binary data files. This package reproduces one of its output formats: the output of xxd -g1.

With data := []bytes{0x00, 0xf0, 0x07, ... 0x5b, 0x00, 0x20}, of 64 bytes total length, for example, xxd.Print(0, data) will generate the following output:

00000000: 00 f0 07 20 c5 63 00 20 8f 31 00 20 79 31 00 20  ... .c. .1. y1. 
00000010: 95 31 00 20 9b 31 00 20 a1 31 00 20 00 00 00 00  .1. .1. .1. ....
00000020: 00 00 00 00 00 00 00 00 00 00 00 00 31 3a 00 20  ............1:. 
00000030: a7 31 00 20 00 00 00 00 f1 3a 00 20 11 5b 00 20  .1. .....:. .[. 

Each line is aligned to a multiple of 16 bytes, but data is output starting at the offset indicated by the first argument. As such, xxd.Print(5, data) will generate:

00000000:                00 f0 07 20 c5 63 00 20 8f 31 00       ... .c. .1.
00000010: 20 79 31 00 20 95 31 00 20 9b 31 00 20 a1 31 00   y1. .1. .1. .1.
00000020: 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ...............
00000030: 00 31 3a 00 20 a7 31 00 20 00 00 00 00 f1 3a 00  .1:. .1. .....:.
00000040: 20 11 5b 00 20                                    .[. 

Automated documentation for this Go package is available from Go Reference.

License info

The xxd package is distributed with the same BSD 3-clause license as that used by golang itself.

Reporting bugs and feature requests

The xxd package was developed purely out of self-interest to help debug other programs and packages. Should you find a bug or want to suggest a feature addition, please use the bug tracker.

Documentation

Overview

Package xxd generates an ASCII dump of binary data in the format of the `xxd -g1` command line tool.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dump

func Dump(address int, data []byte) (lines []string)

Dump converts a binary blob based at address into an array of separate lines in the format of `xxd -g`.

func Log

func Log(offset int, data []byte)

Log dumps the xxd.Dump() output directly with log.Print().

func Print

func Print(offset int, data []byte)

Print dumps the xxd.Dump() output directly to stdout.

Example
Print(0x4f, []byte{
	1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 32, 33, 126,
})
Output:

00000040:                                              01                 .
00000050: 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 20 21  .............. !
00000060: 7e                                               ~

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL