# HG changeset patch # User Matti Hamalainen # Date 1582129550 -7200 # Node ID 2fcd8d712b1e49c67eef6b5c0ec2850e40798c0f # Parent 758223ba6551fb774907f5d645ab67fd35c5e5c0 More improvements to the grep mode. diff -r 758223ba6551 -r 2fcd8d712b1e tools/fanalyze.c --- a/tools/fanalyze.c Wed Feb 19 18:00:49 2020 +0200 +++ b/tools/fanalyze.c Wed Feb 19 18:25:50 2020 +0200 @@ -107,6 +107,7 @@ typedef struct { char *name; + char *desc; Uint32 nmax; unsigned int bsize; } DMGrepType; @@ -114,11 +115,11 @@ static const DMGrepType dmGrepTypes[DMGV_last] = { - { "8bit (byte)" , (1ULL << 8) - 1, 1 }, - { "16bit (word) LE" , (1ULL << 16) - 1, 2 }, - { "16bit (word) BE" , (1ULL << 16) - 1, 2 }, - { "32bit (word) LE" , (1ULL << 32) - 1, 4 }, - { "32bit (word) BE" , (1ULL << 32) - 1, 4 }, + { "8" , "8bit (byte)" , (1ULL << 8) - 1, 1 }, + { "le16" , "16bit (word) LE" , (1ULL << 16) - 1, 2 }, + { "be16" , "16bit (word) BE" , (1ULL << 16) - 1, 2 }, + { "le32" , "32bit (word) LE" , (1ULL << 32) - 1, 4 }, + { "be32" , "32bit (word) BE" , (1ULL << 32) - 1, 4 }, }; @@ -155,6 +156,7 @@ int nsetGrepValues = 0; DMGrepValue setGrepValues[SET_MAX_GREP_VALUES]; size_t optMinMatchLen = 8; +BOOL optOffsetMode = FALSE; DMMatchSeq dmSequences[SET_MAX_SEQUENCES]; int ndmSequences = 0; @@ -172,6 +174,8 @@ { 12, 'o', "offset" , "Show data in offset [,...][:[8|16|32][d|x]]", OPT_ARGREQ }, { 14, 'm', "match" , "Find matching sequences minimum of bytes long", OPT_NONE }, { 16, 'n', "minmatch" , "Minimum match sequence length", OPT_ARGREQ }, + + { 18, 'O', "offset-mode" , "Output -o offset list when in grep mode (-g)", OPT_NONE }, }; static const int optListN = sizeof(optList) / sizeof(optList[0]); @@ -445,7 +449,7 @@ ret = dmError(DMERR_INVALID_ARGS, "Integer value %d <= %d <= %d out of range for type %s.\n", val.values[n], 0, dmGrepTypes[val.type].nmax, - dmGrepTypes[val.type].name); + dmGrepTypes[val.type].desc); goto out; } @@ -465,7 +469,7 @@ if (mode == FA_GREP) { printf("Grep %s: ", - dmGrepTypes[val.type].name); + dmGrepTypes[val.type].desc); dmPrintGrepValueList(stdout, node, FALSE, NULL, 0); printf("\n"); @@ -523,6 +527,10 @@ } return TRUE; + case 18: + optOffsetMode = TRUE; + break; + default: dmErrorMsg("Unknown argument '%s'.\n", currArg); return FALSE; @@ -719,6 +727,10 @@ { DMGrepValue *node = &setGrepValues[n]; const DMGrepType *def = &dmGrepTypes[node->type]; + BOOL sep = FALSE; + + if (optOffsetMode) + printf("-o "); for (size_t offs = 0; offs + (def->bsize * node->nvalues) < file->size; offs++) { @@ -738,15 +750,28 @@ if (match) { - printf("%08" DM_PRIx_SIZE_T, offs); - if (dmVerbosity >= 1) + if (optOffsetMode) { - printf(" : "); - dmPrintGrepValueList(stdout, node, TRUE, file, offs); + printf("%s0x%" DM_PRIx_SIZE_T, sep ? "," : "", offs); + sep = TRUE; } - printf("\n"); + else + printf("%08" DM_PRIx_SIZE_T, offs); + + if (!optOffsetMode) + { + if (dmVerbosity >= 1) + { + printf(" : "); + dmPrintGrepValueList(stdout, node, TRUE, file, offs); + } + printf("\n"); + } } } + + if (optOffsetMode) + printf(":%s\n", def->name); } } }