WUMSLoader/source/utils/utils.c

39 lines
1.2 KiB
C
Raw Normal View History

2022-02-04 21:44:03 +01:00
#include "utils/logger.h"
2020-04-28 14:43:07 +02:00
#include <stddef.h>
2022-02-04 21:44:03 +01:00
#include <string.h>
2021-09-17 16:22:54 +02:00
#include <whb/log.h>
2020-04-28 14:43:07 +02:00
// https://gist.github.com/ccbrown/9722406
2020-05-17 19:05:51 +02:00
void dumpHex(const void *data, size_t size) {
2020-04-28 14:43:07 +02:00
char ascii[17];
size_t i, j;
ascii[16] = '\0';
2021-09-17 16:22:54 +02:00
DEBUG_FUNCTION_LINE_WRITE("0x%08X (0x0000): ", data);
2020-04-28 14:43:07 +02:00
for (i = 0; i < size; ++i) {
2021-09-17 16:22:54 +02:00
WHBLogWritef("%02X ", ((unsigned char *) data)[i]);
2020-05-17 19:05:51 +02:00
if (((unsigned char *) data)[i] >= ' ' && ((unsigned char *) data)[i] <= '~') {
ascii[i % 16] = ((unsigned char *) data)[i];
2020-04-28 14:43:07 +02:00
} else {
ascii[i % 16] = '.';
}
2020-05-17 19:05:51 +02:00
if ((i + 1) % 8 == 0 || i + 1 == size) {
2021-09-17 16:22:54 +02:00
WHBLogWritef(" ");
2020-05-17 19:05:51 +02:00
if ((i + 1) % 16 == 0) {
2021-09-17 16:22:54 +02:00
WHBLogPrintf("| %s ", ascii);
2020-05-17 19:05:51 +02:00
if (i + 1 < size) {
2021-09-17 16:22:54 +02:00
DEBUG_FUNCTION_LINE_WRITE("0x%08X (0x%04X); ", data + i + 1, i + 1);
2020-04-28 14:43:07 +02:00
}
2020-05-17 19:05:51 +02:00
} else if (i + 1 == size) {
ascii[(i + 1) % 16] = '\0';
if ((i + 1) % 16 <= 8) {
2021-09-17 16:22:54 +02:00
WHBLogWritef(" ");
2020-04-28 14:43:07 +02:00
}
2020-05-17 19:05:51 +02:00
for (j = (i + 1) % 16; j < 16; ++j) {
2021-09-17 16:22:54 +02:00
WHBLogWritef(" ");
2020-04-28 14:43:07 +02:00
}
2021-09-17 16:22:54 +02:00
WHBLogPrintf("| %s ", ascii);
2020-04-28 14:43:07 +02:00
}
}
}
}