-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDump.c
37 lines (29 loc) · 776 Bytes
/
Dump.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "Dump.h"
#include <stdint.h>
#include <stdlib.h>
#define DUMP_LINE_WIDTH 16
void dump(const char* description, const void* data, size_t length)
{
size_t index = 0;
size_t position = 0;
char buffer[DUMP_LINE_WIDTH + 1];
const uint8_t* pointer = (const uint8_t*)data;
printf("%s (%d bytes): ", description, length);
while (index < length)
{
if ((position == 0) && (length > DUMP_LINE_WIDTH))
printf("\n %08x ", index);
printf(" %02x", *pointer);
buffer[position] = (*pointer > ' ') ? *pointer : '.';
index ++;
pointer ++;
position ++;
if ((position == DUMP_LINE_WIDTH) || (index == length))
{
buffer[position] = '\0';
printf(" -- %s", buffer);
position = 0;
}
}
printf("\n");
}