Fri, 24 Nov 2023 16:15:07 +0100
1 files changed,
9 insertions(+),
4 deletions(-)
jump to
M
src/shell/hexdump.c
→
src/shell/hexdump.c
@@ -15,19 +15,24 @@
uint8_t in_buffer[16]; uint8_t out_buffer[64]; - uint32_t line = 0; while (1) { + int in_offset = ftell(file); + int size = fread(in_buffer, 1, 16, file); if (size == 0) { break; } int out_offset = 0; - - out_offset += sprintf(out_buffer + out_offset, "%x%x ", line++, 0); + out_offset += sprintf(out_buffer + out_offset, "%x%x%x%x ", in_offset >> 24, in_offset >> 16, in_offset >> 8, in_offset); for (int i = 0; i < 16; i++) { - out_offset += sprintf(out_buffer + out_offset, "%x ", in_buffer[i]); + if (i < size) { + out_offset += sprintf(out_buffer + out_offset, "%x ", in_buffer[i]); + } else { + out_offset += sprintf(out_buffer + out_offset, " "); + } } out_offset += sprintf(out_buffer + out_offset, " |"); for (int i = 0; i < 16; i++) { + if (i >= size) { break; } uint8_t c = in_buffer[i]; if (c < 0x20 || c > 0x7F) { c = '.'; } out_offset += sprintf(out_buffer + out_offset, "%c", c);