1 /*****************************************************************************\
4 \*****************************************************************************/
12 * David S. Peterson. All rights reserved.
14 * Author: David S. Peterson <dave_peterson@pobox.com>
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions are
19 * 1. Redistributions of source code must retain the above copyright notice,
20 * this list of conditions, and the entire permission notice, including
21 * the following disclaimer of warranties.
22 * 2. Redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions, and the entire permission notice,
24 * including the following disclaimer in the documentation and/or other
25 * materials provided with the distribution.
26 * 3. The name(s) of the author(s) may not be used to endorse or promote
27 * products derived from this software without specific prior written
30 * ALTERNATIVELY, this product may be distributed under the terms of the GNU
31 * General Public License, in which case the provisions of the GPL are
32 * required INSTEAD OF the above restrictions. (This clause is necessary due
33 * to a potential bad interaction between the GPL and the restrictions
34 * contained in a BSD-style copyright.)
36 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
37 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED.
39 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
40 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
42 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
43 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
45 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
49 #include <sys/types.h>
52 typedef int (*is_printable_fn_t) (unsigned char c);
54 /*--------------------------------------------------------------------------
57 * This specifies how the output of the 'hexdump' function should look.
60 * bytes_per_line: the number of data bytes to display per line of
62 * addrprint_width: Each line of output begins with the address of the
63 * first data byte displayed on that line. This
64 * specifies the number of bytes wide the address
65 * should be displayed as. This value must be from 1
67 * indent: This is a string to display at the start of each
68 * output line. Its purpose is to indent the output.
69 * sep1: This is a string to display between the address and
70 * the bytes of data displayed in hex. It serves as a
72 * sep2: This is a string to display between individual hex
73 * values. It serves as a separator.
74 * sep3: This is a string to display between the bytes of
75 * data in hex and the bytes of data displayed as
76 * characters. It serves as a separator.
77 * nonprintable: This is a substitute character to display in place
78 * of nonprintable characters.
79 * is_printable_fn: This is a user-supplied function that takes a byte
80 * value as input and returns a boolean value
81 * indicating whether the corresponding character is
82 * printable. A value of NULL will cause
83 * default_is_printable_fn to be used.
84 *--------------------------------------------------------------------------*/
92 unsigned char nonprintable;
93 is_printable_fn_t is_printable_fn;
97 /*--------------------------------------------------------------------------
100 * Write a hex dump of 'mem' to 'outfile'.
103 * mem: a pointer to the memory to display
104 * bytes: the number of bytes of data to display
105 * addrprint_start: The address to associate with the first byte of
106 * data. For instance, a value of 0 indicates that the
107 * first byte displayed should be labeled as byte 0.
108 * outfile: The place where the hex dump should be written.
109 * For instance, stdout or stderr may be passed here.
110 * format: A structure specifying how the hex dump should be
112 *--------------------------------------------------------------------------*/
113 void hexdump (const void *mem, int bytes, uint64_t addrprint_start,
114 FILE *outfile, const hexdump_format_t *format);
116 /*--------------------------------------------------------------------------
117 * default_is_printable_fn
119 * Determine whether the input character is printable. The proper behavior
120 * for this type of function may be system-dependent. This function appears
121 * to work well on a Linux system. However, if it is not adequate for your
122 * purposes, you can write your own.
125 * c: the input character
128 * Return 1 if the input character is printable. Otherwise return 0.
129 *--------------------------------------------------------------------------*/
130 int default_is_printable_fn (unsigned char c);
132 #endif /* _HEXDUMP_H */