-
Notifications
You must be signed in to change notification settings - Fork 3
/
utils.c
41 lines (39 loc) · 1.1 KB
/
utils.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
38
39
40
41
/** Helper functions
*
* Author: Niklas Eiling <[email protected]>
* SPDX-FileCopyrightText: 2023 Niklas Eiling <[email protected]>
* SPDX-License-Identifier: Apache-2.0
*********************************************************************************/
#include <stdio.h>
#include "utils.h"
void hexdump(const uint8_t* data, size_t size)
{
size_t pos = 0;
while (pos < size) {
printf("%#05zx: ", pos);
for (int i = 0; i < 16; i++) {
if (pos + i < size) {
printf("%02x", data[pos + i]);
} else {
printf(" ");
}
if (i % 4 == 3) {
printf(" ");
}
}
printf(" | ");
for (int i = 0; i < 16; i++) {
if (pos + i < size) {
if (data[pos + i] >= 0x20 && data[pos + i] <= 0x7e) {
printf("%c", data[pos + i]);
} else {
printf(".");
}
} else {
printf(" ");
}
}
printf("\n");
pos += 16;
}
}