From 27f4c2a796755caff6134dd554d89373abbd148f Mon Sep 17 00:00:00 2001 From: Jason Summers Date: Mon, 22 Mar 2021 14:13:07 -0400 Subject: [PATCH] fat: Improved debug info --- modules/fat.c | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/modules/fat.c b/modules/fat.c index 01e9d63d..35748a6d 100644 --- a/modules/fat.c +++ b/modules/fat.c @@ -76,6 +76,39 @@ typedef struct localctx_struct { u8 *cluster_used_flags; // array[num_fat_entries] } lctx; +static void ucstring_append_hexbytes(de_ucstring *s, const u8 *buf, i64 buflen) +{ + i64 i; + + for(i = 0; i0) ucstring_append_char(s, ' '); + ucstring_append_char(s, (de_rune)de_get_hexchar((int)(buf[i]/16))); + ucstring_append_char(s, (de_rune)de_get_hexchar((int)(buf[i]%16))); + } +} + +static void dbg_hexbytes_oneline_mem(deark *c, const u8 *buf, i64 buflen, const char *label) +{ + de_ucstring *s = NULL; + + if(buflen<0) buflen = 0; + if(buflen>64) buflen = 64; + s = ucstring_create(c); + ucstring_append_hexbytes(s, buf, buflen); + de_dbg(c, "%s: %s", label, ucstring_getpsz_d(s)); + ucstring_destroy(s); +} + +static void dbg_hexbytes_oneline(deark *c, dbuf *f, i64 pos, i64 len, const char *label) +{ + u8 buf[64]; + + if(len<0) len = 0; + if(len>(i64)sizeof(buf)) len = (i64)sizeof(buf); + dbuf_read(f, buf, pos, len); + dbg_hexbytes_oneline_mem(c, buf, len, label); +} + static i64 sectornum_to_offset(deark *c, lctx *d, i64 secnum) { return secnum * d->bytes_per_sector; @@ -650,11 +683,11 @@ static int do_boot_sector(deark *c, lctx *d, i64 pos1) // BIOS parameter block jmpinstrlen = (d->subfmt==FAT_SUBFMT_ATARIST)?2:3; - de_dbg_hexdump(c, c->infile, pos1, jmpinstrlen, jmpinstrlen, "jump instr", 0); + dbg_hexbytes_oneline(c, c->infile, pos1, jmpinstrlen, "jump instr"); if(d->subfmt==FAT_SUBFMT_ATARIST) { do_oem_name(c, d, pos1+2, 6); - de_dbg_hexdump(c, c->infile, pos1+8, 3, 3, "serial num", 0); + dbg_hexbytes_oneline(c, c->infile, pos1+8, 3, "serial num"); } else { do_oem_name(c, d, pos1+3, 8); @@ -694,7 +727,7 @@ static int do_boot_sector(deark *c, lctx *d, i64 pos1) pos = pos1+0x1fe; de_read(cksum_sig, pos, 2); - de_dbg(c, "boot sector signature: 0x%02x 0x%02x", (UI)cksum_sig[0], (UI)cksum_sig[1]); + dbg_hexbytes_oneline_mem(c, cksum_sig, 2, "boot sector signature"); do_atarist_boot_checksum(c, d, pos1); if(d->has_atarist_checksum) { -- 2.11.4.GIT