blob: 4b03d85ff338d1350953b97f6dc1f0443d313d2b [file] [log] [blame]
Patrick Georgi55189c92020-05-10 20:09:31 +02001/* SPDX-License-Identifier: BSD-3-Clause or GPL-2.0 */
Stefan Reinauer6540ae52007-07-12 16:35:42 +00002
3#ifndef _HEXDUMP_H
4#define _HEXDUMP_H
5
Stefan Reinauer6540ae52007-07-12 16:35:42 +00006#include <stdint.h>
7#include <sys/types.h>
8#include <stdio.h>
9
Stefan Reinauer6540ae52007-07-12 16:35:42 +000010/*--------------------------------------------------------------------------
11 * hexdump_format_t
12 *
13 * This specifies how the output of the 'hexdump' function should look.
14 *
15 * fields:
16 * bytes_per_line: the number of data bytes to display per line of
17 * output
18 * addrprint_width: Each line of output begins with the address of the
19 * first data byte displayed on that line. This
20 * specifies the number of bytes wide the address
21 * should be displayed as. This value must be from 1
22 * to 8.
23 * indent: This is a string to display at the start of each
24 * output line. Its purpose is to indent the output.
25 * sep1: This is a string to display between the address and
26 * the bytes of data displayed in hex. It serves as a
27 * separator.
28 * sep2: This is a string to display between individual hex
29 * values. It serves as a separator.
30 * sep3: This is a string to display between the bytes of
31 * data in hex and the bytes of data displayed as
32 * characters. It serves as a separator.
33 * nonprintable: This is a substitute character to display in place
34 * of nonprintable characters.
Stefan Reinauer6540ae52007-07-12 16:35:42 +000035 *--------------------------------------------------------------------------*/
Stefan Reinauer90b96b62010-01-13 21:00:23 +000036typedef struct {
37 int bytes_per_line;
38 int addrprint_width;
39 const char *indent;
40 const char *sep1;
41 const char *sep2;
42 const char *sep3;
43 unsigned char nonprintable;
Stefan Reinauer90b96b62010-01-13 21:00:23 +000044} hexdump_format_t;
Stefan Reinauer6540ae52007-07-12 16:35:42 +000045
46/*--------------------------------------------------------------------------
47 * hexdump
48 *
49 * Write a hex dump of 'mem' to 'outfile'.
50 *
51 * parameters:
52 * mem: a pointer to the memory to display
53 * bytes: the number of bytes of data to display
54 * addrprint_start: The address to associate with the first byte of
55 * data. For instance, a value of 0 indicates that the
56 * first byte displayed should be labeled as byte 0.
57 * outfile: The place where the hex dump should be written.
58 * For instance, stdout or stderr may be passed here.
59 * format: A structure specifying how the hex dump should be
60 * formatted.
61 *--------------------------------------------------------------------------*/
Stefan Reinauer90b96b62010-01-13 21:00:23 +000062void hexdump(const void *mem, int bytes, uint64_t addrprint_start,
63 FILE * outfile, const hexdump_format_t * format);
Stefan Reinauer6540ae52007-07-12 16:35:42 +000064
Stefan Reinauer90b96b62010-01-13 21:00:23 +000065#endif /* _HEXDUMP_H */