# HG changeset patch # User Matti Hamalainen # Date 1560526799 -10800 # Node ID 72e15cc1492727e975af5bc8c039d148a5841176 # Parent 02d17784fdef84b2a90640de742f2475b730e099 Make the offset mode (-o) also support lists of offsets. Also improve the readability of the output. diff -r 02d17784fdef -r 72e15cc14927 tools/fanalyze.c --- a/tools/fanalyze.c Fri Jun 14 18:33:10 2019 +0300 +++ b/tools/fanalyze.c Fri Jun 14 18:39:59 2019 +0300 @@ -100,14 +100,15 @@ typedef struct { char *name; + char *fmtPrefix; char *fmt; } DMGrepDisp; static const DMGrepDisp dmGrepDisp[DMGS_last] = { - { "hex", "x" }, - { "dec", "d" }, + { "hex", "0", "x" }, + { "dec", "" , "d" }, }; enum @@ -135,7 +136,7 @@ { 0, '?', "help", "Show this help", OPT_NONE }, { 1, 'v', "verbose", "Be more verbose", OPT_NONE }, { 2, 'g', "grep", "Binary grep [,...][:[8|16|32]]", OPT_ARGREQ }, - { 3, 'o', "offset", "Show data in offset :[8|16|32][d|x]]", OPT_ARGREQ }, + { 3, 'o', "offset", "Show data in offset [,...][:[8|16|32][d|x]]", OPT_ARGREQ }, }; static const int optListN = sizeof(optList) / sizeof(optList[0]); @@ -197,12 +198,12 @@ void dmPrintGrepValueList(const DMGrepValue *node, const BOOL match, DMSourceFile *file, const size_t offs) { - char vfmt[16]; + char mfmt[16]; - snprintf(vfmt, sizeof(vfmt), "%%%s%d%s%%s", - node->disp == DMGS_HEX ? "0" : "", + snprintf(mfmt, sizeof(mfmt), "%%%s%d%s%%s", + dmGrepDisp[node->disp].fmtPrefix, dmGrepTypes[node->type].bsize * 2, - node->disp == DMGS_HEX ? "x" : "d"); + dmGrepDisp[node->disp].fmt); for (int n = 0; n < node->nvalues; n++) { @@ -212,14 +213,14 @@ { Uint32 mval; dmGetData(node->type, file, offs + n, &mval); - dmPrint(1, vfmt, mval, veol); + dmPrint(1, mfmt, mval, veol); } else { if (node->vwildcards[n]) dmPrint(1, "?%s", veol); else - dmPrint(1, vfmt, node->values[n], veol); + dmPrint(1, mfmt, node->values[n], veol); } } } @@ -417,10 +418,13 @@ DMGrepValue *node = &setGrepValues[nsetGrepValues++]; memcpy(node, &val, sizeof(val)); - dmMsg(1, "Grep %ss : ", - dmGrepTypes[val.type].name); + if (mode == FA_GREP) + { + dmPrint(1, "Grep %s: ", + dmGrepTypes[val.type].name); - dmPrintGrepValueList(node, FALSE, NULL, 0); + dmPrintGrepValueList(node, FALSE, NULL, 0); + } } else { @@ -592,9 +596,7 @@ if (match) { - dmPrint(0, "%08x : %s match ", - offs, def->name); - + dmPrint(0, "%08x : ", offs); dmPrintGrepValueList(node, TRUE, file, offs); } } @@ -624,42 +626,46 @@ { DMGrepValue *node = &setGrepValues[n]; const DMGrepType *def = &dmGrepTypes[node->type]; - printf("%08x : ", node->values[0]); - for (int nfile = 0; nfile < nsrcFiles; nfile++) + for (int nv = 0; nv < node->nvalues; nv++) { - DMSourceFile *file = &srcFiles[nfile]; - Uint32 mval; - char mstr[32]; - int npad, nwidth; + printf("%08x : ", node->values[nv]); - if (dmGetData(node->type, file, node->values[0], &mval)) + for (int nfile = 0; nfile < nsrcFiles; nfile++) { - char mfmt[16]; - nwidth = def->bsize * 2; - snprintf(mfmt, sizeof(mfmt), "%%0%d%s", - nwidth, dmGrepDisp[node->disp].fmt); + DMSourceFile *file = &srcFiles[nfile]; + Uint32 mval; + char mstr[32]; + int npad, nwidth; + + if (dmGetData(node->type, file, node->values[nv], &mval)) + { + char mfmt[16]; + nwidth = def->bsize * 2; + snprintf(mfmt, sizeof(mfmt), "%%0%d%s", + nwidth, dmGrepDisp[node->disp].fmt); - snprintf(mstr, sizeof(mstr), mfmt, mval); - } - else - { - strcpy(mstr, "----"); - nwidth = 4; + snprintf(mstr, sizeof(mstr), mfmt, mval); + } + else + { + strcpy(mstr, "----"); + nwidth = 4; + } + + npad = (10 - nwidth) / 2; + for (int q = 0; q < npad; q++) + fputc(' ', stdout); + + fputs(mstr, stdout); + + for (int q = 0; q < npad; q++) + fputc(' ', stdout); } - npad = (10 - nwidth) / 2; - for (int q = 0; q < npad; q++) - fputc(' ', stdout); - - fputs(mstr, stdout); - - for (int q = 0; q < npad; q++) - fputc(' ', stdout); + printf(" [%s]\n", + dmGrepDisp[node->disp].name); } - - printf(" [%s]\n", - dmGrepDisp[node->disp].name); } } else