rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions
hexdump.h File Reference

Functions

void hexdump (void *mem, size_t len, unsigned int prefix=0, bool printChar=false)
 

Function Documentation

◆ hexdump()

void hexdump ( void *  mem,
size_t  len,
unsigned int  prefix = 0,
bool  printChar = false 
)

Definition at line 12 of file hexdump.cpp.

12 {
13 char buffer[128];
14 size_t offset = 0;
15
16 for (unsigned i = 0; i < len + ((len % HEXDUMP_COLS) ? (HEXDUMP_COLS - len % HEXDUMP_COLS) : 0); i++) {
17 /* print offset */
18 if (i % HEXDUMP_COLS == 0) {
19 offset += sprintf(buffer + offset, "%08x: ", prefix + i);
20 } else if ((i + HEXDUMP_COLS / 2) % HEXDUMP_COLS == 0) {
21 offset += sprintf(buffer + offset, " ");
22 }
23
24 /* print hex data */
25 if (i < len) {
26 offset += sprintf(buffer + offset, "%02x ", 0xFF & ((unsigned char *)mem)[i]);
27 } else if (printChar) {
28 /* end of block, just aligning for ASCII dump */
29 offset += sprintf(buffer + offset, " ");
30 }
31
32 if (i % HEXDUMP_COLS == (HEXDUMP_COLS - 1)) {
33 if (printChar) {
34 /* print ASCII dump */
35 offset += sprintf(buffer + offset, "|");
36 for (unsigned j = i - (HEXDUMP_COLS - 1); j <= i; j++)
37 {
38 if (j >= len) {
39 /* end of block, not really printing */
40 offset += sprintf(buffer + offset, " ");
41 } else if (isprint(((unsigned char *)mem)[j])) {
42 /* printable char */
43 offset += sprintf(buffer + offset, "%c", 0xFF & ((char *)mem)[j]);
44 } else {
45 /* other char */
46 offset += sprintf(buffer + offset, ".");
47 }
48 }
49 }
50
51 offset += sprintf(buffer + offset, "|");
52 buffer[offset] = '\0';
53 efiPrintf("%s", buffer);
54 offset = 0;
55 }
56 }
57}
static BigBufferHandle buffer
uint16_t offset
Definition tunerstudio.h:0

Go to the source code of this file.