annotate tools/fanalyze.c @ 1996:4a4c3e15b8c2

Add more analyzing.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 02 Jul 2018 02:26:52 +0300
parents ea6337c873c6
children 8e38fa3c4f98
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * Fanalyze - Analyze similarities between multiple files
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * Programmed and designed by Matti 'ccr' Hamalainen
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 * (C) Copyright 2018 Tecnic Software productions (TNSP)
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 *
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 * Please read file 'COPYING' for information on license and distribution.
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 */
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 #include "dmtool.h"
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 #include "dmlib.h"
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 #include "dmargs.h"
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 #include "dmfile.h"
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
13 #define SET_MAX_FILES 16
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
14 #define SET_MAX_ELEMS 256
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 /* Typedefs
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 */
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 typedef struct
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 {
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
21 Uint8 stats[SET_MAX_ELEMS];
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
22 Uint8 variants, data;
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
23 int interest[16];
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
24 int interestF[16];
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
25 } DMCompElem;
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
26
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
27
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
28 typedef struct
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
29 {
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
30 int count;
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
31 Uint8 value;
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
32 } DMStatValue;
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
33
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
34
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
35 typedef struct
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
36 {
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
37 DMStatValue cv[SET_MAX_ELEMS];
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
38 } DMStats;
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
39
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
40
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
41 typedef struct
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
42 {
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 char *filename;
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 Uint8 *data;
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 size_t size; // offset, crop_start, crop_end, doCrop?
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
46 DMStats stats;
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 } DMSourceFile;
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 /* Global variables
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 */
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 int nsrcFiles = 0; // Number of source files
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 DMSourceFile srcFiles[SET_MAX_FILES]; // Source file names
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
54 DMStats totalStats;
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 /* Arguments
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58 */
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59 static const DMOptArg optList[] =
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 {
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 { 0, '?', "help", "Show this help", OPT_NONE },
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 { 1, 'v', "verbose", "Be more verbose", OPT_NONE },
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63 };
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 static const int optListN = sizeof(optList) / sizeof(optList[0]);
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 void argShowHelp()
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69 {
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 dmPrintBanner(stdout, dmProgName, "[options] <input file #1> <input file #2> [...]");
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 dmArgsPrintHelp(stdout, optList, optListN, 0);
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 BOOL argHandleOpt(const int optN, char *optArg, char *currArg)
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 {
1995
ea6337c873c6 Silence an unused function argument warning.
Matti Hamalainen <ccr@tnsp.org>
parents: 1685
diff changeset
77 (void) optArg;
ea6337c873c6 Silence an unused function argument warning.
Matti Hamalainen <ccr@tnsp.org>
parents: 1685
diff changeset
78
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 switch (optN)
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 {
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 case 0:
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 argShowHelp();
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 exit(0);
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 break;
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 case 1:
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 dmVerbosity++;
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 break;
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 default:
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 dmErrorMsg("Unknown argument '%s'.\n", currArg);
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 return FALSE;
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 return TRUE;
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 BOOL argHandleNonOpt(char *currArg)
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 {
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 if (nsrcFiles < SET_MAX_FILES)
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 {
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103 DMSourceFile *file = &srcFiles[nsrcFiles++];
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 file->filename = currArg;
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105 return TRUE;
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107 else
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108 {
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109 dmErrorMsg("Maximum number of input files exceeded (%d).\n",
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110 SET_MAX_FILES);
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
111 return TRUE;
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
112 }
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
113 }
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
114
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
115
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
116 void dmInitStats(DMStats *stats)
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
117 {
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
118 for (size_t n = 0; n < SET_MAX_ELEMS; n++)
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
119 {
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
120 stats->cv[n].count = 0;
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
121 stats->cv[n].value = n;
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
126 int dmCompareStatFunc(const void *va, const void *vb)
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
127 {
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
128 const DMStatValue *pa = va, *pb = vb;
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
129 return pb->count - pa->count;
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
130 }
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
131
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
132
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
133 void dmSortStats(DMStats *stats)
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134 {
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
135 qsort(&stats->cv, sizeof(DMStatValue), SET_MAX_ELEMS, dmCompareStatFunc);
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
136 }
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
137
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
138
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
139 void dmPrintStats(DMStats *stats, const int nmax, const size_t size)
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
140 {
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
141 for (int n = 0; n < nmax; n++)
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
142 {
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
143 printf("$%02x (%1.2f%%), ",
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
144 stats->cv[n].value,
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
145 ((float) stats->cv[n].count * 100.0f) / (float) size);
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
146 }
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
147 printf("\n\n");
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
148 }
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151 int main(int argc, char *argv[])
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152 {
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153 DMCompElem *compBuf = NULL;
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
154 size_t compBufSize = 0, totalSize = 0;
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155 int res;
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157 dmInitProg("fanalyze", "File format analyzer", "0.1", NULL, NULL);
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158 dmVerbosity = 1;
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
160 dmInitStats(&totalStats);
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
161
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162 // Parse arguments
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163 if (!dmArgsProcess(argc, argv, optList, optListN,
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164 argHandleOpt, argHandleNonOpt, OPTH_BAILOUT))
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165 exit(1);
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167 if (nsrcFiles < 1)
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168 {
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169 dmErrorMsg("Nothing to do. (try --help)\n");
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170 goto out;
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173 // Read input files
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174 for (int nfile = 0; nfile < nsrcFiles; nfile++)
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
175 {
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
176 DMSourceFile *file = &srcFiles[nfile];
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177 if ((res = dmReadDataFile(NULL, file->filename, &file->data, &file->size)) != DMERR_OK)
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178 {
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
179 dmErrorMsg("Could not read '%s': %s\n",
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
180 file->filename, dmErrorStr(res));
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
181 goto out;
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
182 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183
1685
904904f145b4 Various fixes in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 1683
diff changeset
184 dmPrint(2, "Input #%d: '%s', %" DM_PRIu_SIZE_T " bytes.\n",
904904f145b4 Various fixes in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 1683
diff changeset
185 nfile + 1, file->filename, file->size);
904904f145b4 Various fixes in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 1683
diff changeset
186
904904f145b4 Various fixes in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 1683
diff changeset
187 if (!compBufSize || file->size < compBufSize)
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
188 compBufSize = file->size;
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
189
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
190 totalSize += file->size;
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
193 // Allocate comparision buffer
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
194 // XXX: integer overflow?
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
195 dmPrint(2, "Allocating %d element (%d bytes) comparision buffer.\n",
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
196 compBufSize, compBufSize * sizeof(DMCompElem));
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
197
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
198 if ((compBuf = dmCalloc(compBufSize, sizeof(DMCompElem))) == NULL)
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
199 {
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
200 dmErrorMsg("Out of memory. Could not allocate comparision buffer!\n");
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
201 goto out;
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
203
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
204 // Begin analyzing ..
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
205 dmPrint(2, "Analyzing ..\n");
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
206 for (int nfile = 0; nfile < nsrcFiles; nfile++)
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
207 {
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
208 DMSourceFile *file = &srcFiles[nfile];
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
209 dmInitStats(&file->stats);
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
210
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
211 for (size_t offs = 0; offs < file->size; offs++)
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
212 {
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
213 Uint8 bv = file->data[offs];
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
214 totalStats.cv[bv].count++;
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
215 file->stats.cv[bv].count++;
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
216 }
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
217
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
218 for (size_t offs = 0; offs < compBufSize; offs++)
1685
904904f145b4 Various fixes in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 1683
diff changeset
219 {
904904f145b4 Various fixes in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 1683
diff changeset
220 Uint8 data = offs < file->size ? file->data[offs] : 0;
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
221 compBuf[offs].stats[data]++;
1685
904904f145b4 Various fixes in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 1683
diff changeset
222 }
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
223
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
224 dmSortStats(&file->stats);
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
225 }
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
226 dmSortStats(&totalStats);
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
227
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
228
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229 for (size_t offs = 0; offs < compBufSize; offs++)
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
230 {
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
231 DMCompElem *el = &compBuf[offs];
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
232 for (int n = 0; n < SET_MAX_ELEMS; n++)
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
233 {
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
234 if (el->stats[n] > 0)
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
235 {
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
236 el->variants++;
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
237 el->data = n;
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
238 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
239 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
240 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
241
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
242 // Display results
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
243 for (size_t offs = 0, n = 0; offs < compBufSize; offs++)
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
244 {
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
245 DMCompElem *el = &compBuf[offs];
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
246 BOOL var = el->variants > 1;
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
247
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
248 if (n == 0)
1685
904904f145b4 Various fixes in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 1683
diff changeset
249 printf("%08" DM_PRIx_SIZE_T " | ", offs);
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
250
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
251 if (var)
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
252 printf("[%2d] ", el->variants);
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
253 else
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
254 printf(" %02x ", el->data);
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
255
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
256 if (++n >= 16)
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
257 {
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
258 printf("\n");
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
259 n = 0;
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
260 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
261 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
262
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
263 printf("\n");
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
264
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
265 // Attempt further analysis
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
266 for (int nfile = 0; nfile < nsrcFiles; nfile++)
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
267 {
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
268 DMSourceFile *file = &srcFiles[nfile];
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
269 size_t len = file->size > compBufSize ? compBufSize : file->size;
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
270 for (size_t offs = 0; offs + 4 < len; offs++)
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
271 {
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
272 DMCompElem *elem = &compBuf[offs];
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
273
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
274 for (int variant = 3; variant >= 0; variant--)
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
275 {
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
276 size_t nmax = (variant < 2) ? sizeof(Uint16) : sizeof(Uint32);
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
277 Uint32 tmp = 0;
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
278
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
279 for (size_t n = 0; n < nmax; n++)
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
280 {
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
281 size_t boffs = (variant & 1) ? n : nmax - n;
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
282
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
283 tmp <<= 8;
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
284 tmp |= file->data[offs + boffs];
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
285 }
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
286
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
287 if (file->size - tmp < 32)
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
288 {
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
289 elem->interest[variant] += 32 - (file->size - tmp);
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
290 elem->interestF[variant]++;
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
291 }
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
292 }
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
293 }
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
294 }
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
295
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
296 printf("\nMore findings:\n");
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
297 for (size_t offs = 0; offs + 4 < compBufSize; offs++)
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
298 {
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
299 DMCompElem *elem = &compBuf[offs];
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
300
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
301 for (int variant = 0; variant < 4; variant++)
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
302 if (elem->interestF[variant] > 0)
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
303 {
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
304 printf("%08" DM_PRIx_SIZE_T " | V%d : %d / %d\n",
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
305 offs, variant,
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
306 elem->interestF[variant], elem->interest[variant]);
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
307 }
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
308 }
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
309
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
310 printf("\nGlobal most used bytes:\n");
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
311 dmPrintStats(&totalStats, 16, totalSize);
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
312
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
313 for (int nfile = 0; nfile < nsrcFiles; nfile++)
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
314 {
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
315 DMSourceFile *file = &srcFiles[nfile];
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
316 printf("Most used bytes for '%s':\n", file->filename);
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
317 dmPrintStats(&file->stats, 16, file->size);
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
318 }
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
319
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
320 out:
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
321 for (int nfile = 0; nfile < nsrcFiles; nfile++)
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
322 {
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
323 DMSourceFile *file = &srcFiles[nfile];
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
324 dmFree(file->data);
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
325 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
326
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
327 return 0;
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
328 }