LumaOS  v0.1.116
An experimental x86-64 OS
Loading...
Searching...
No Matches
hexdump.c
Go to the documentation of this file.
1
15
16#include <kernel/hexdump.h>
17#include <stddef.h>
18#include <kernel/kprintf.h>
19
20
21void hexdump(const void* data, const size_t size) {
22 //TODO: Comment this function
23 char ascii[17];
24
25 ascii[16] = '\0';
26
27 for (size_t i = 0; i < size; ++i) {
28 kprintf("%02X ", ((unsigned char*)data)[i]);
29
30 if (((unsigned char*)data)[i] >= ' ' && ((unsigned char*)data)[i] <= '~')
31 ascii[i % 16] = ((unsigned char*)data)[i];
32 else
33 ascii[i % 16] = '.';
34
35 if ((i+1) % 8 == 0 || i+1 == size) {
36 kprintf(" ");
37
38 if ((i+1) % 16 == 0) {
39 kprintf("| %s \n", ascii);
40 } else if (i+1 == size) {
41 ascii[(i+1) % 16] = '\0';
42
43 if ((i+1) % 16 <= 8)
44 kprintf(" ");
45
46 for (size_t j = (i + 1) % 16; j < 16; ++j)
47 kprintf(" ");
48
49 kprintf("| %s \n", ascii);
50 }
51 }
52 }
53}
54
void hexdump(const void *data, const size_t size)
Prints each byte as a hex number from a buffer of bytes.
Definition hexdump.c:21
Hexdump utility for displaying memory contents in hexadecimal.
Tools for printing to the console and serial output.
void kprintf(const char *fmt,...) __attribute__((format(printf
Wrapper for a standard print.