Template Struct hexdump

Struct Documentation

template<size_t OFFSET_SIZE = sizeof(intptr_t), size_t BYTES_PER_LINE = 16, size_t BYTES_PER_COLUMN = 1, size_t GROUPS = 2, size_t COLUMN_PAD = 1, size_t GROUP_PAD = 2, char FRAME = '|', char PLACEHOLDER = '\0'>
struct hexdump

Encode an entire memory region in a hexdump style format.

The usage is as follows: instantiate a hexdumper struct that is parametrized with some format flags. Then pass a pointer and size to the dumper’s () operator. This allows the hexdump to be integrated into any kind of output stream, e.g.:

canonical_hexdump hd;
std::cerr << "Something weird in this memory region: "
   << hd(buf, bufsize) << std::endl;

Public Functions

template<typename T>
inline std::string operator()(T const *input, size_t input_size, bool from_zero = true) const

Take an input pointer and input size in Bytes. Optionally take a flag that determines whether the printed offsets should start from zero or from the input pointer.

The result is a string containing the hexump.

There is an overload for std::string for convenience.

Parameters
  • input[in] The input string to format.

  • input_size[in] The sie of the input buffer.

  • from_zero[in] Set if addresses should start from zero, or from the actual address input points to. Defaults to starting from zero.

Returns

The formatted output.

inline std::string operator()(std::string const &str, bool from_zero = true) const

Same as operator(), but for std::string inputs.

Public Static Functions

static inline constexpr size_t _frame_size()
Returns

size of the frame

Public Static Attributes

static constexpr size_t COLUMNS = BYTES_PER_LINE / BYTES_PER_COLUMN

Number of columns in total.

static constexpr size_t COLUMNS_PER_GROUP = COLUMNS / GROUPS

Number of columns per group.

static constexpr size_t BYTES_PER_GROUP = COLUMNS_PER_GROUP * BYTES_PER_COLUMN

Number of bytes per group.

static constexpr size_t O_OFFSET_WIDTH_UNPADDED = (OFFSET_SIZE * 2)

Output width without trailing/end padding.

static constexpr size_t O_OFFSET_WIDTH = O_OFFSET_WIDTH_UNPADDED + GROUP_PAD

Output width with trailing/end padding.

static constexpr size_t O_COLUMN_WIDTH_UNPADDED = (BYTES_PER_COLUMN * 2)

Column width without trailing/end padding.

static constexpr size_t O_COLUMN_WIDTH = O_COLUMN_WIDTH_UNPADDED + COLUMN_PAD

Column width with trailing/end padding.

static constexpr size_t O_GROUP_WIDTH_UNPADDED = (((COLUMNS_PER_GROUP - 1) * O_COLUMN_WIDTH) + O_COLUMN_WIDTH_UNPADDED)

Group width without trailing/end padding.

static constexpr size_t O_GROUP_WIDTH = O_GROUP_WIDTH_UNPADDED + GROUP_PAD

Group width with trailing/end padding.

static constexpr size_t O_PLAIN_WIDTH = (_frame_size() + BYTES_PER_LINE)

Width of the plain text section.

static constexpr size_t O_LINE_WIDTH = (O_OFFSET_WIDTH + (GROUPS * O_GROUP_WIDTH) + O_PLAIN_WIDTH)

Line width.