Patrick Georgi | 55189c9 | 2020-05-10 20:09:31 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: BSD-3-Clause or GPL-2.0 */ |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 2 | |
| 3 | #ifndef _HEXDUMP_H |
| 4 | #define _HEXDUMP_H |
| 5 | |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 6 | #include <stdint.h> |
| 7 | #include <sys/types.h> |
| 8 | #include <stdio.h> |
| 9 | |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 10 | /*-------------------------------------------------------------------------- |
| 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 Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 35 | *--------------------------------------------------------------------------*/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 36 | typedef 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 Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 44 | } hexdump_format_t; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 45 | |
| 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 Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 62 | void hexdump(const void *mem, int bytes, uint64_t addrprint_start, |
| 63 | FILE * outfile, const hexdump_format_t * format); |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 64 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 65 | #endif /* _HEXDUMP_H */ |