annotate tools/fanalyze.c @ 2478:0d13de7edb30

Fix two meaningless memory leaks.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 27 Apr 2020 20:39:35 +0300
parents 275374725598
children fcaf2db0cd05
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 /*
2234
ef1845cb436e Improve help, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2232
diff changeset
2 * Fanalyze - Commandline tool for analyzing similarities between multiple files
1682
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
2232
ba639902d57c Bump copyright and version.
Matti Hamalainen <ccr@tnsp.org>
parents: 2229
diff changeset
4 * (C) Copyright 2018-2019 Tecnic Software productions (TNSP)
1682
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
2269
f350c7514785 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2268
diff changeset
13 #define SET_MAX_FILES 64
f350c7514785 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2268
diff changeset
14 #define SET_MAX_ELEMS 256
2268
f2ff364065eb Add constant define for maximum number of variants.
Matti Hamalainen <ccr@tnsp.org>
parents: 2267
diff changeset
15 #define SET_MAX_VARIANTS 4
2267
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
16
2269
f350c7514785 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2268
diff changeset
17 #define SET_MAX_GREP_VALUES 64
f350c7514785 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2268
diff changeset
18 #define SET_MAX_GREP_LIST 64
f350c7514785 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2268
diff changeset
19
f350c7514785 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2268
diff changeset
20 #define SET_MAX_SEQUENCES 1024
f350c7514785 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2268
diff changeset
21 #define SET_MAX_PLACES 1024
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 /* Typedefs
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 */
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 typedef struct
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 {
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
28 Uint8 stats[SET_MAX_ELEMS];
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
29 Uint8 variants, data;
2268
f2ff364065eb Add constant define for maximum number of variants.
Matti Hamalainen <ccr@tnsp.org>
parents: 2267
diff changeset
30 int interest[SET_MAX_VARIANTS];
f2ff364065eb Add constant define for maximum number of variants.
Matti Hamalainen <ccr@tnsp.org>
parents: 2267
diff changeset
31 int interestF[SET_MAX_VARIANTS];
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
32 } DMCompElem;
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 int count;
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
38 Uint8 value;
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
39 } DMStatValue;
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
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
42 typedef struct
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
43 {
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
44 DMStatValue cv[SET_MAX_ELEMS];
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
45 } DMStats;
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
46
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
47
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
48 typedef struct
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
49 {
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 char *filename;
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 Uint8 *data;
2249
6ba4aed198e4 Cosmetic.
Matti Hamalainen <ccr@tnsp.org>
parents: 2248
diff changeset
52 size_t size;
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
53 DMStats stats;
2267
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
54 BOOL analyzed;
2396
679732e4cfed Implement counting of matching files for each match sequence.
Matti Hamalainen <ccr@tnsp.org>
parents: 2389
diff changeset
55 size_t index;
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 } DMSourceFile;
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58
2267
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
59 typedef struct
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
60 {
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
61 DMSourceFile *file; // pointer to file struct where match was found
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
62 size_t offs; // offset to match in file data
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
63 } DMMatchPlace;
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
64
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
65
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
66 typedef struct
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
67 {
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
68 size_t len; // length of the matching sequence
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
69 Uint8 *data; // "const" pointer to data in one file, don't free()
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
70
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
71 int nfiles; // number of separate files match was found
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
72 int nplaces; // number of places where match was found
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
73 DMMatchPlace places[SET_MAX_PLACES];
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
74 } DMMatchSeq;
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
75
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
76
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
77 enum
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
78 {
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
79 DMGV_UINT8 = 0,
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
80 DMGV_UINT16_LE,
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
81 DMGV_UINT16_BE,
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
82 DMGV_UINT32_LE,
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
83 DMGV_UINT32_BE,
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
84
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
85 DMGV_last
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
86 };
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
87
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
88
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
89 enum
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
90 {
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
91 DMGS_HEX = 0,
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
92 DMGS_DEC,
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
93 DMGS_last
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
94 };
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
95
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
96
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
97 typedef struct
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
98 {
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
99 int type;
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
100 int disp;
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
101 int nvalues;
2269
f350c7514785 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2268
diff changeset
102 Uint32 values[SET_MAX_GREP_LIST];
f350c7514785 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2268
diff changeset
103 BOOL vwildcards[SET_MAX_GREP_LIST];
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
104 } DMGrepValue;
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
105
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
106
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
107 typedef struct
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
108 {
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
109 char *name;
2433
2fcd8d712b1e More improvements to the grep mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2432
diff changeset
110 char *desc;
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
111 Uint32 nmax;
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
112 unsigned int bsize;
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
113 } DMGrepType;
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
114
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
115
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
116 static const DMGrepType dmGrepTypes[DMGV_last] =
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
117 {
2433
2fcd8d712b1e More improvements to the grep mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2432
diff changeset
118 { "8" , "8bit (byte)" , (1ULL << 8) - 1, 1 },
2fcd8d712b1e More improvements to the grep mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2432
diff changeset
119 { "le16" , "16bit (word) LE" , (1ULL << 16) - 1, 2 },
2fcd8d712b1e More improvements to the grep mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2432
diff changeset
120 { "be16" , "16bit (word) BE" , (1ULL << 16) - 1, 2 },
2fcd8d712b1e More improvements to the grep mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2432
diff changeset
121 { "le32" , "32bit (word) LE" , (1ULL << 32) - 1, 4 },
2fcd8d712b1e More improvements to the grep mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2432
diff changeset
122 { "be32" , "32bit (word) BE" , (1ULL << 32) - 1, 4 },
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
123 };
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
124
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
125
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
126 typedef struct
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
127 {
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
128 char *name;
2229
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
129 char *fmtPrefix;
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
130 char *fmt;
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
131 } DMGrepDisp;
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
132
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
133
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
134 static const DMGrepDisp dmGrepDisp[DMGS_last] =
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
135 {
2229
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
136 { "hex", "0", "x" },
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
137 { "dec", "" , "d" },
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
138 };
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
139
2249
6ba4aed198e4 Cosmetic.
Matti Hamalainen <ccr@tnsp.org>
parents: 2248
diff changeset
140
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
141 enum
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
142 {
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
143 FA_ANALYZE,
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
144 FA_GREP,
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
145 FA_OFFSET,
2267
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
146 FA_MATCHES,
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
147 };
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
148
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
149
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150 /* Global variables
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151 */
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
152 int setMode = FA_ANALYZE;
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
153 int nsrcFiles = 0; // Number of source files
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
154 DMSourceFile srcFiles[SET_MAX_FILES]; // Source file names
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
155 DMStats totalStats;
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
156 int nsetGrepValues = 0;
2269
f350c7514785 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2268
diff changeset
157 DMGrepValue setGrepValues[SET_MAX_GREP_VALUES];
2267
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
158 size_t optMinMatchLen = 8;
2433
2fcd8d712b1e More improvements to the grep mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2432
diff changeset
159 BOOL optOffsetMode = FALSE;
2267
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
160
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
161 DMMatchSeq dmSequences[SET_MAX_SEQUENCES];
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
162 int ndmSequences = 0;
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165 /* Arguments
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 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
168 {
2408
60e119262c67 Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents: 2402
diff changeset
169 { 0, '?', "help" , "Show this help", OPT_NONE },
2410
bc05bcfc4598 Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents: 2408
diff changeset
170 { 1, 0, "license" , "Print out this program's license agreement", OPT_NONE },
2408
60e119262c67 Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents: 2402
diff changeset
171 { 2, 'v', "verbose" , "Be more verbose", OPT_NONE },
60e119262c67 Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents: 2402
diff changeset
172
60e119262c67 Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents: 2402
diff changeset
173 { 10, 'g', "grep" , "Binary grep <val>[,<val2>...][:<le|be>[8|16|32]]", OPT_ARGREQ },
60e119262c67 Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents: 2402
diff changeset
174 { 12, 'o', "offset" , "Show data in offset <offs>[,<offs2>...][:<le|be>[8|16|32][d|x]]", OPT_ARGREQ },
60e119262c67 Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents: 2402
diff changeset
175 { 14, 'm', "match" , "Find matching sequences minimum of <n> bytes long", OPT_NONE },
60e119262c67 Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents: 2402
diff changeset
176 { 16, 'n', "minmatch" , "Minimum match sequence length", OPT_ARGREQ },
2433
2fcd8d712b1e More improvements to the grep mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2432
diff changeset
177
2fcd8d712b1e More improvements to the grep mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2432
diff changeset
178 { 18, 'O', "offset-mode" , "Output -o offset list when in grep mode (-g)", OPT_NONE },
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
179 };
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
180
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
181 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
182
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
184 void argShowHelp()
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
185 {
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186 dmPrintBanner(stdout, dmProgName, "[options] <input file #1> <input file #2> [...]");
2402
b7cd5dd0b82e Merge one more change from th-libs args processing.
Matti Hamalainen <ccr@tnsp.org>
parents: 2396
diff changeset
187 dmArgsPrintHelp(stdout, optList, optListN, 0, 80 - 2);
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
188
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
189 fprintf(stdout,
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
190 "\n"
2234
ef1845cb436e Improve help, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2232
diff changeset
191 "Fanalyze is a simplistic commandline tool to assist analysis of similarities\n"
ef1845cb436e Improve help, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2232
diff changeset
192 "between multiple files of same format (but different content). It provides\n"
ef1845cb436e Improve help, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2232
diff changeset
193 "automatic analysis (default operating mode), binary grep functionality (-g)\n"
ef1845cb436e Improve help, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2232
diff changeset
194 "and offset data display (-o)\n"
ef1845cb436e Improve help, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2232
diff changeset
195 "\n"
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
196 "Value lists for grep function can contain wildcard '?' (or '#') which\n"
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
197 "matches any value of the specified (or inferred) type. For example:\n"
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
198 "-g 0x0f,7,5,?,5,?,? will match sequence of bytes 0f 07 05 ?? 05 ?? ??\n"
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
199 "and -g 0xe,0x1001,?,2023:le16 will match le16 value 000e 1001 ???? 07e7\n"
2267
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
200 "\n"
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
201 "NOTICE! Matching sequences search (-m) is considered unfinished and\n"
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
202 "under development.\n"
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
203 );
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
204 }
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
205
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
206
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
207 BOOL dmGetData(const int type, const DMSourceFile *file, const size_t offs, Uint32 *mval)
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
208 {
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
209 Uint8 *data = file->data + offs;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
210 if (offs + dmGrepTypes[type].bsize >= file->size)
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
211 {
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
212 *mval = 0;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
213 return FALSE;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
214 }
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
215
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
216 switch (type)
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
217 {
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
218 case DMGV_UINT8:
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
219 *mval = *((Uint8 *) data);
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
220 break;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
221
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
222 case DMGV_UINT16_LE:
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
223 *mval = DM_LE16_TO_NATIVE(*((Uint16 *) data));
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
224 break;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
226 case DMGV_UINT16_BE:
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
227 *mval = DM_BE16_TO_NATIVE(*((Uint16 *) data));
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
228 break;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
229
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
230 case DMGV_UINT32_LE:
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
231 *mval = DM_LE32_TO_NATIVE(*((Uint32 *) data));
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
232 break;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
233
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
234 case DMGV_UINT32_BE:
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
235 *mval = DM_BE32_TO_NATIVE(*((Uint32 *) data));
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
236 break;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
237
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
238 default:
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
239 *mval = 0;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
240 return FALSE;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
241 }
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
242 return TRUE;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
243 }
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
244
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
245
2432
758223ba6551 Only print grep value lists if verbosity >= 1.
Matti Hamalainen <ccr@tnsp.org>
parents: 2431
diff changeset
246 void dmPrintGrepValueList(FILE *fh, const DMGrepValue *node, const BOOL match, DMSourceFile *file, const size_t offs)
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
247 {
2229
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
248 char mfmt[16];
2431
ca548150de6b Fix grepping of consecutive values in fanalyze when using > byte size types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2430
diff changeset
249 unsigned int bsize = dmGrepTypes[node->type].bsize;
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
250
2229
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
251 snprintf(mfmt, sizeof(mfmt), "%%%s%d%s%%s",
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
252 dmGrepDisp[node->disp].fmtPrefix,
2431
ca548150de6b Fix grepping of consecutive values in fanalyze when using > byte size types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2430
diff changeset
253 bsize * 2,
2229
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
254 dmGrepDisp[node->disp].fmt);
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
255
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
256 for (int n = 0; n < node->nvalues; n++)
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
257 {
2432
758223ba6551 Only print grep value lists if verbosity >= 1.
Matti Hamalainen <ccr@tnsp.org>
parents: 2431
diff changeset
258 const char *veol = (n + 1 < node->nvalues) ? " " : "";
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
259
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
260 if (match)
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
261 {
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
262 Uint32 mval;
2431
ca548150de6b Fix grepping of consecutive values in fanalyze when using > byte size types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2430
diff changeset
263 dmGetData(node->type, file, offs + n * bsize, &mval);
2432
758223ba6551 Only print grep value lists if verbosity >= 1.
Matti Hamalainen <ccr@tnsp.org>
parents: 2431
diff changeset
264 fprintf(fh, mfmt, mval, veol);
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
265 }
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
266 else
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
267 {
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
268 if (node->vwildcards[n])
2432
758223ba6551 Only print grep value lists if verbosity >= 1.
Matti Hamalainen <ccr@tnsp.org>
parents: 2431
diff changeset
269 fprintf(fh, "?%s", veol);
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
270 else
2432
758223ba6551 Only print grep value lists if verbosity >= 1.
Matti Hamalainen <ccr@tnsp.org>
parents: 2431
diff changeset
271 fprintf(fh, mfmt, node->values[n], veol);
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
272 }
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
273 }
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
274 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
275
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
276
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
277 int argParseGrepValue(const char *arg, const int mode)
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
278 {
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
279 const char *specsep = strchr(arg, ':');
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
280 char *vspec, *vstr, *vsep;
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
281 DMGrepValue val;
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
282 int ret = DMERR_OK;
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
283 BOOL more;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
284
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
285 memset(&val, 0, sizeof(val));
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
286
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
287 if (setMode != FA_ANALYZE && setMode != mode)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
288 {
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
289 dmErrorMsg("Options specifying multiple operating modes can't be used.\n");
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
290 return DMERR_INVALID_ARGS;
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
291 }
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
292 setMode = mode;
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
293
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
294 // Do we have spec?
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
295 if (specsep != NULL)
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
296 {
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
297 vspec = dm_strdup_trim(specsep + 1, DM_TRIM_BOTH);
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
298 vstr = dm_strndup_trim(arg, specsep - arg, DM_TRIM_BOTH);
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
299 }
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
300 else
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
301 {
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
302 vspec = NULL;
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
303 vstr = dm_strdup(arg);
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
304 }
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
305
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
306 // Parse spec if any
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
307 if (vspec != NULL)
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
308 {
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
309 BOOL vendianess = TRUE;
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
310 char *vtmp = vspec;
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
311
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
312 // Get endianess specifier, if any
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
313 if (dm_strncasecmp(vtmp, "le", 2) == 0)
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
314 {
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
315 vendianess = TRUE;
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
316 vtmp += 2;
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
317 }
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
318 else
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
319 if (dm_strncasecmp(vtmp, "be", 2) == 0)
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
320 {
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
321 vendianess = FALSE;
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
322 vtmp += 2;
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
323 }
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
324
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
325 // Get value bit size
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
326 if (strncmp(vtmp, "8", 1) == 0)
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
327 {
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
328 val.type = DMGV_UINT8;
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
329 vtmp += 1;
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
330 }
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
331 else
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
332 if (strncmp(vtmp, "16", 2) == 0)
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
333 {
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
334 val.type = vendianess ? DMGV_UINT16_LE : DMGV_UINT16_BE;
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
335 vtmp += 2;
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
336 }
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
337 else
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
338 if (strncmp(vtmp, "32", 2) == 0)
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
339 {
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
340 val.type = vendianess ? DMGV_UINT32_LE : DMGV_UINT32_BE;
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
341 vtmp += 2;
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
342 }
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
343 else
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
344 {
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
345 ret = dmError(DMERR_INVALID_ARGS,
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
346 "Invalid grep type '%s'.\n",
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
347 vspec);
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
348 goto out;
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
349 }
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
350
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
351 switch (tolower(*vtmp))
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
352 {
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
353 case 'd':
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
354 val.disp = DMGS_DEC;
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
355 break;
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
356
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
357 case 'x': case 'h':
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
358 val.disp = DMGS_HEX;
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
359 break;
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
360
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
361 case 0:
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
362 break;
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
363
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
364 default:
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
365 ret = dmError(DMERR_INVALID_ARGS,
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
366 "Invalid grep view type '%s'.\n",
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
367 vspec);
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
368 goto out;
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
369 }
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
370 }
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
371
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
372 // Get list of values
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
373 char *vtmp = vstr;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
374 do
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
375 {
2269
f350c7514785 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2268
diff changeset
376 if (val.nvalues >= SET_MAX_GREP_LIST)
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
377 {
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
378 ret = dmError(DMERR_BOUNDS,
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
379 "Too many greplist values specified '%s'.\n",
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
380 vstr);
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
381 goto out;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
382 }
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
383
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
384 if ((vsep = strchr(vtmp, ',')) != NULL)
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
385 {
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
386 *vsep = 0;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
387 more = TRUE;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
388 }
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
389 else
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
390 more = FALSE;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
391
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
392 if (vtmp[0] == '#' || vtmp[0] == '?')
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
393 {
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
394 val.vwildcards[val.nvalues] = TRUE;
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
395 if (mode == FA_OFFSET)
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
396 {
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
397 ret = dmError(DMERR_INVALID_ARGS,
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
398 "Offset mode does not allow wildcard values.\n");
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
399 goto out;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
400 }
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
401 }
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
402 else
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
403 if (!dmGetIntVal(vtmp, &val.values[val.nvalues], NULL))
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
404 {
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
405 ret = dmError(DMERR_INVALID_ARGS,
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
406 "Not a valid integer value '%s'.\n",
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
407 vtmp);
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
408 goto out;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
409 }
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
410
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
411 val.nvalues++;
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
412
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
413 if (more)
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
414 vtmp = vsep + 1;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
415 } while (more);
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
416
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
417 if (val.vwildcards[0])
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
418 {
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
419 ret = dmError(DMERR_INVALID_ARGS,
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
420 "First grep value can not be a wildcard.\n");
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
421 goto out;
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
422 }
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
423
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
424 if (mode == FA_GREP)
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
425 {
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
426 // Check if we need to guess size
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
427 if (val.type < 0)
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
428 {
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
429 for (int n = DMGV_last; n >= 0; n--)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
430 {
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
431 const DMGrepType *def = &dmGrepTypes[n];
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
432 if (val.values[0] <= def->nmax)
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
433 val.type = n;
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
434 }
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
435 }
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
436
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
437 if (val.type < 0)
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
438 {
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
439 ret = dmError(DMERR_INVALID_ARGS,
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
440 "Could not guess value type for '%s'.\n",
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
441 arg);
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
442 goto out;
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
443 }
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
444
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
445 // Check range
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
446 for (int n = 0; n < val.nvalues; n++)
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
447 if (!val.vwildcards[n] && val.values[n] > dmGrepTypes[val.type].nmax)
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
448 {
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
449 ret = dmError(DMERR_INVALID_ARGS,
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
450 "Integer value %d <= %d <= %d out of range for type %s.\n",
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
451 val.values[n], 0, dmGrepTypes[val.type].nmax,
2433
2fcd8d712b1e More improvements to the grep mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2432
diff changeset
452 dmGrepTypes[val.type].desc);
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
453
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
454 goto out;
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
455 }
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
456 }
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
457 else
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
458 if (mode == FA_OFFSET)
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
459 {
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
460 if (val.type < 0)
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
461 val.type = DMGV_UINT8;
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
462 }
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
463
2269
f350c7514785 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2268
diff changeset
464 if (nsetGrepValues < SET_MAX_GREP_VALUES)
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
465 {
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
466 DMGrepValue *node = &setGrepValues[nsetGrepValues++];
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
467 memcpy(node, &val, sizeof(val));
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
468
2229
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
469 if (mode == FA_GREP)
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
470 {
2430
190f5caaf1a8 Use printf() here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 2429
diff changeset
471 printf("Grep %s: ",
2433
2fcd8d712b1e More improvements to the grep mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2432
diff changeset
472 dmGrepTypes[val.type].desc);
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
473
2432
758223ba6551 Only print grep value lists if verbosity >= 1.
Matti Hamalainen <ccr@tnsp.org>
parents: 2431
diff changeset
474 dmPrintGrepValueList(stdout, node, FALSE, NULL, 0);
758223ba6551 Only print grep value lists if verbosity >= 1.
Matti Hamalainen <ccr@tnsp.org>
parents: 2431
diff changeset
475 printf("\n");
2229
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
476 }
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
477 }
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
478 else
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
479 {
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
480 ret = dmError(DMERR_BOUNDS,
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
481 "Too many values specified (max %d).",
2269
f350c7514785 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2268
diff changeset
482 SET_MAX_GREP_VALUES);
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
483 }
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
484
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
485 out:
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
486 dmFree(vspec);
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
487 dmFree(vstr);
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
488 return ret;
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
489 }
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
490
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
491
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
492 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
493 {
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
494 switch (optN)
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
495 {
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
496 case 0:
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
497 argShowHelp();
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
498 exit(0);
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
499 break;
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
500
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
501 case 1:
2410
bc05bcfc4598 Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents: 2408
diff changeset
502 dmPrintLicense(stdout);
bc05bcfc4598 Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents: 2408
diff changeset
503 exit(0);
bc05bcfc4598 Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents: 2408
diff changeset
504 break;
bc05bcfc4598 Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents: 2408
diff changeset
505
bc05bcfc4598 Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents: 2408
diff changeset
506 case 2:
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
507 dmVerbosity++;
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
508 break;
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
509
2408
60e119262c67 Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents: 2402
diff changeset
510 case 10:
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
511 return argParseGrepValue(optArg, FA_GREP) == DMERR_OK;
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
512
2408
60e119262c67 Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents: 2402
diff changeset
513 case 12:
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
514 return argParseGrepValue(optArg, FA_OFFSET) == DMERR_OK;
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
515
2408
60e119262c67 Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents: 2402
diff changeset
516 case 14:
2267
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
517 setMode = FA_MATCHES;
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
518 break;
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
519
2408
60e119262c67 Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents: 2402
diff changeset
520 case 16:
2267
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
521 optMinMatchLen = atoi(optArg);
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
522 if (optMinMatchLen < 2 || optMinMatchLen > 16*1024)
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
523 {
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
524 dmErrorMsg("Invalid minimum match length '%s'.\n",
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
525 optArg);
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
526 return FALSE;
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
527 }
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
528 return TRUE;
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
529
2433
2fcd8d712b1e More improvements to the grep mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2432
diff changeset
530 case 18:
2fcd8d712b1e More improvements to the grep mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2432
diff changeset
531 optOffsetMode = TRUE;
2fcd8d712b1e More improvements to the grep mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2432
diff changeset
532 break;
2fcd8d712b1e More improvements to the grep mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2432
diff changeset
533
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
534 default:
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
535 dmErrorMsg("Unknown argument '%s'.\n", currArg);
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
536 return FALSE;
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
537 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
538
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
539 return TRUE;
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
540 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
541
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
542
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
543 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
544 {
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
545 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
546 {
2396
679732e4cfed Implement counting of matching files for each match sequence.
Matti Hamalainen <ccr@tnsp.org>
parents: 2389
diff changeset
547 DMSourceFile *file = &srcFiles[nsrcFiles];
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
548 file->filename = currArg;
2396
679732e4cfed Implement counting of matching files for each match sequence.
Matti Hamalainen <ccr@tnsp.org>
parents: 2389
diff changeset
549 file->index = nsrcFiles;
679732e4cfed Implement counting of matching files for each match sequence.
Matti Hamalainen <ccr@tnsp.org>
parents: 2389
diff changeset
550 nsrcFiles++;
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
551 return TRUE;
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
552 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
553 else
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
554 {
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
555 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
556 SET_MAX_FILES);
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
557 return TRUE;
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
558 }
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
559 }
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
560
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
561
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
562 void dmInitStats(DMStats *stats)
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
563 {
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
564 for (size_t n = 0; n < SET_MAX_ELEMS; n++)
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
565 {
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
566 stats->cv[n].count = 0;
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
567 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
568 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
569 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
570
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
571
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
572 int dmCompareStatFunc(const void *va, const void *vb)
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
573 {
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
574 const DMStatValue *pa = va, *pb = vb;
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
575 return pb->count - pa->count;
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
576 }
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
577
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
578
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
579 void dmPrintStats(DMStats *stats, const int nmax, const size_t size)
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
580 {
2011
8e38fa3c4f98 Fix use of qsort().
Matti Hamalainen <ccr@tnsp.org>
parents: 1996
diff changeset
581 qsort(&stats->cv, SET_MAX_ELEMS, sizeof(DMStatValue), dmCompareStatFunc);
8e38fa3c4f98 Fix use of qsort().
Matti Hamalainen <ccr@tnsp.org>
parents: 1996
diff changeset
582
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
583 for (int n = 0; n < nmax; n++)
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
584 {
2011
8e38fa3c4f98 Fix use of qsort().
Matti Hamalainen <ccr@tnsp.org>
parents: 1996
diff changeset
585 printf("$%02x (%d = %1.2f%%), ",
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
586 stats->cv[n].value,
2011
8e38fa3c4f98 Fix use of qsort().
Matti Hamalainen <ccr@tnsp.org>
parents: 1996
diff changeset
587 stats->cv[n].count,
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
588 ((float) stats->cv[n].count * 100.0f) / (float) size);
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
589 }
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
590 printf("\n\n");
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
591 }
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
592
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
593
2270
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
594 BOOL dmAddMatchSequence(Uint8 *data, const size_t len, DMSourceFile *file, size_t offs)
2267
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
595 {
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
596 DMMatchSeq *seq = NULL;
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
597
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
598 // Check for existing match sequence
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
599 for (int n = 0; n < ndmSequences; n++)
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
600 {
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
601 DMMatchSeq *node = &dmSequences[n];
2270
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
602 if (node->len >= len &&
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
603 memcmp(node->data + node->len - len, data, len) == 0)
2267
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
604 {
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
605 seq = node;
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
606 break;
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
607 }
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
608 }
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
609
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
610 if (seq == NULL)
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
611 {
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
612 // No sequence found, add a new one
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
613 if (ndmSequences + 1 >= SET_MAX_SEQUENCES)
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
614 {
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
615 dmErrorMsg("Too many matching sequences found.\n");
2270
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
616 return FALSE;
2267
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
617 }
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
618
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
619 seq = &dmSequences[ndmSequences++];
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
620 }
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
621 else
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
622 {
2270
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
623 // Check for existing place
2267
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
624 for (int n = 0; n < seq->nplaces; n++)
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
625 {
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
626 DMMatchPlace *place = &seq->places[n];
2270
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
627 if (place->file == file &&
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
628 place->offs + seq->len == offs + len)
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
629 return TRUE;
2267
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
630 }
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
631 }
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
632
2270
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
633 seq->data = data;
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
634 seq->len = len;
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
635
2267
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
636 // Add another file + offset
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
637 if (seq->nplaces < SET_MAX_PLACES)
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
638 {
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
639 DMMatchPlace *place = &seq->places[seq->nplaces++];
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
640 place->file = file;
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
641 place->offs = offs;
2270
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
642
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
643 return TRUE;
2267
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
644 }
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
645 else
2270
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
646 return FALSE;
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
647 }
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
648
2267
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
649
2270
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
650 int dmCompareMatchPlaces(const void *pa, const void *pb)
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
651 {
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
652 const DMMatchPlace *va = (DMMatchPlace *) pa,
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
653 *vb = (DMMatchPlace *) pb;
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
654
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
655 return va->offs - vb->offs;
2267
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
656 }
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
657
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
658
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
659 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
660 {
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
661 DMCompElem *compBuf = NULL;
2396
679732e4cfed Implement counting of matching files for each match sequence.
Matti Hamalainen <ccr@tnsp.org>
parents: 2389
diff changeset
662 size_t compBufSize = 0, totalSize = 0, fileFlagsSize;
679732e4cfed Implement counting of matching files for each match sequence.
Matti Hamalainen <ccr@tnsp.org>
parents: 2389
diff changeset
663 BOOL *fileFlags = NULL;
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
664 int res;
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
665
2267
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
666 memset(&dmSequences, 0, sizeof(dmSequences));
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
667
2234
ef1845cb436e Improve help, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2232
diff changeset
668 dmInitProg("fanalyze", "Simple tool for file format analysis",
ef1845cb436e Improve help, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2232
diff changeset
669 "0.4", NULL, NULL);
2267
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
670 dmVerbosity = 0;
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
671
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
672 dmInitStats(&totalStats);
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
673
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
674 // Parse arguments
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
675 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
676 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
677 exit(1);
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
678
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
679 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
680 {
2441
275374725598 Show help when no arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 2434
diff changeset
681 argShowHelp();
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
682 goto out;
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
683 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
684
2396
679732e4cfed Implement counting of matching files for each match sequence.
Matti Hamalainen <ccr@tnsp.org>
parents: 2389
diff changeset
685 // Allocate file flags
679732e4cfed Implement counting of matching files for each match sequence.
Matti Hamalainen <ccr@tnsp.org>
parents: 2389
diff changeset
686 fileFlagsSize = sizeof(BOOL) * nsrcFiles;
679732e4cfed Implement counting of matching files for each match sequence.
Matti Hamalainen <ccr@tnsp.org>
parents: 2389
diff changeset
687 if ((fileFlags = dmMalloc(fileFlagsSize)) == NULL)
679732e4cfed Implement counting of matching files for each match sequence.
Matti Hamalainen <ccr@tnsp.org>
parents: 2389
diff changeset
688 {
679732e4cfed Implement counting of matching files for each match sequence.
Matti Hamalainen <ccr@tnsp.org>
parents: 2389
diff changeset
689 dmErrorMsg("Could not allocate %" DM_PRIu_SIZE_T " bytes of memory for file flag array.\n",
679732e4cfed Implement counting of matching files for each match sequence.
Matti Hamalainen <ccr@tnsp.org>
parents: 2389
diff changeset
690 fileFlagsSize);
679732e4cfed Implement counting of matching files for each match sequence.
Matti Hamalainen <ccr@tnsp.org>
parents: 2389
diff changeset
691 goto out;
679732e4cfed Implement counting of matching files for each match sequence.
Matti Hamalainen <ccr@tnsp.org>
parents: 2389
diff changeset
692 }
679732e4cfed Implement counting of matching files for each match sequence.
Matti Hamalainen <ccr@tnsp.org>
parents: 2389
diff changeset
693
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
694 // 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
695 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
696 {
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
697 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
698 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
699 {
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
700 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
701 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
702 goto out;
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
703 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
704
1685
904904f145b4 Various fixes in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 1683
diff changeset
705 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
706 nfile + 1, file->filename, file->size);
904904f145b4 Various fixes in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 1683
diff changeset
707
904904f145b4 Various fixes in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 1683
diff changeset
708 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
709 compBufSize = file->size;
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
710
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
711 totalSize += file->size;
2011
8e38fa3c4f98 Fix use of qsort().
Matti Hamalainen <ccr@tnsp.org>
parents: 1996
diff changeset
712 dmInitStats(&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
713 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
714
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
715
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
716 //
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
717 // Check what operating mode we are in
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
718 //
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
719 if (setMode == FA_GREP)
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
720 {
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
721 for (int nfile = 0; nfile < nsrcFiles; nfile++)
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
722 {
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
723 DMSourceFile *file = &srcFiles[nfile];
2429
ebb4650f3cc1 Use printf() instead of dmPrint() for some things.
Matti Hamalainen <ccr@tnsp.org>
parents: 2410
diff changeset
724 printf("\n%s\n", file->filename);
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
725
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
726 for (int n = 0; n < nsetGrepValues; n++)
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
727 {
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
728 DMGrepValue *node = &setGrepValues[n];
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
729 const DMGrepType *def = &dmGrepTypes[node->type];
2433
2fcd8d712b1e More improvements to the grep mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2432
diff changeset
730 BOOL sep = FALSE;
2fcd8d712b1e More improvements to the grep mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2432
diff changeset
731
2fcd8d712b1e More improvements to the grep mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2432
diff changeset
732 if (optOffsetMode)
2434
0d86e7ff49e1 Print binary name and input file name when outputting -o options.
Matti Hamalainen <ccr@tnsp.org>
parents: 2433
diff changeset
733 {
0d86e7ff49e1 Print binary name and input file name when outputting -o options.
Matti Hamalainen <ccr@tnsp.org>
parents: 2433
diff changeset
734 printf("%s %s -o ",
0d86e7ff49e1 Print binary name and input file name when outputting -o options.
Matti Hamalainen <ccr@tnsp.org>
parents: 2433
diff changeset
735 argv[0], file->filename);
0d86e7ff49e1 Print binary name and input file name when outputting -o options.
Matti Hamalainen <ccr@tnsp.org>
parents: 2433
diff changeset
736 }
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
737
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
738 for (size_t offs = 0; offs + (def->bsize * node->nvalues) < file->size; offs++)
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
739 {
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
740 BOOL match = TRUE;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
741 for (int n = 0; n < node->nvalues; n++)
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
742 if (!node->vwildcards[n])
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
743 {
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
744 Uint32 mval;
2431
ca548150de6b Fix grepping of consecutive values in fanalyze when using > byte size types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2430
diff changeset
745 dmGetData(node->type, file, offs + n * def->bsize, &mval);
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
746
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
747 if (mval != node->values[n])
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
748 {
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
749 match = FALSE;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
750 break;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
751 }
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
752 }
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
753
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
754 if (match)
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
755 {
2433
2fcd8d712b1e More improvements to the grep mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2432
diff changeset
756 if (optOffsetMode)
2432
758223ba6551 Only print grep value lists if verbosity >= 1.
Matti Hamalainen <ccr@tnsp.org>
parents: 2431
diff changeset
757 {
2433
2fcd8d712b1e More improvements to the grep mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2432
diff changeset
758 printf("%s0x%" DM_PRIx_SIZE_T, sep ? "," : "", offs);
2fcd8d712b1e More improvements to the grep mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2432
diff changeset
759 sep = TRUE;
2432
758223ba6551 Only print grep value lists if verbosity >= 1.
Matti Hamalainen <ccr@tnsp.org>
parents: 2431
diff changeset
760 }
2433
2fcd8d712b1e More improvements to the grep mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2432
diff changeset
761 else
2fcd8d712b1e More improvements to the grep mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2432
diff changeset
762 printf("%08" DM_PRIx_SIZE_T, offs);
2fcd8d712b1e More improvements to the grep mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2432
diff changeset
763
2fcd8d712b1e More improvements to the grep mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2432
diff changeset
764 if (!optOffsetMode)
2fcd8d712b1e More improvements to the grep mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2432
diff changeset
765 {
2fcd8d712b1e More improvements to the grep mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2432
diff changeset
766 if (dmVerbosity >= 1)
2fcd8d712b1e More improvements to the grep mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2432
diff changeset
767 {
2fcd8d712b1e More improvements to the grep mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2432
diff changeset
768 printf(" : ");
2fcd8d712b1e More improvements to the grep mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2432
diff changeset
769 dmPrintGrepValueList(stdout, node, TRUE, file, offs);
2fcd8d712b1e More improvements to the grep mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2432
diff changeset
770 }
2fcd8d712b1e More improvements to the grep mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2432
diff changeset
771 printf("\n");
2fcd8d712b1e More improvements to the grep mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2432
diff changeset
772 }
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
773 }
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
774 }
2433
2fcd8d712b1e More improvements to the grep mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2432
diff changeset
775
2fcd8d712b1e More improvements to the grep mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2432
diff changeset
776 if (optOffsetMode)
2fcd8d712b1e More improvements to the grep mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2432
diff changeset
777 printf(":%s\n", def->name);
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
778 }
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
779 }
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
780 }
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
781 else
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
782 if (setMode == FA_OFFSET)
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
783 {
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
784 for (int nfile = 0; nfile < nsrcFiles; nfile++)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
785 {
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
786 DMSourceFile *file = &srcFiles[nfile];
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
787 dmPrint(1, "#%03d: %s\n", nfile + 1, file->filename);
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
788 }
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
789
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
790 printf(" offset :");
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
791 for (int nfile = 0; nfile < nsrcFiles; nfile++)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
792 printf(" %03d ", nfile + 1);
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
793 printf("\n");
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
794
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
795 printf("==========");
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
796 for (int nfile = 0; nfile < nsrcFiles; nfile++)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
797 printf("===========");
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
798 printf("\n");
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
799
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
800 for (int n = 0; n < nsetGrepValues; n++)
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
801 {
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
802 DMGrepValue *node = &setGrepValues[n];
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
803 const DMGrepType *def = &dmGrepTypes[node->type];
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
804
2229
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
805 for (int nv = 0; nv < node->nvalues; nv++)
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
806 {
2229
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
807 printf("%08x : ", node->values[nv]);
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
808
2229
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
809 for (int nfile = 0; nfile < nsrcFiles; nfile++)
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
810 {
2229
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
811 DMSourceFile *file = &srcFiles[nfile];
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
812 Uint32 mval;
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
813 char mstr[32];
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
814 int npad, nwidth;
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
815
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
816 if (dmGetData(node->type, file, node->values[nv], &mval))
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
817 {
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
818 char mfmt[16];
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
819 nwidth = def->bsize * 2;
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
820 snprintf(mfmt, sizeof(mfmt), "%%0%d%s",
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
821 nwidth, dmGrepDisp[node->disp].fmt);
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
822
2229
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
823 snprintf(mstr, sizeof(mstr), mfmt, mval);
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
824 }
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
825 else
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
826 {
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
827 strcpy(mstr, "----");
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
828 nwidth = 4;
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
829 }
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
830
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
831 npad = (10 - nwidth) / 2;
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
832 for (int q = 0; q < npad; q++)
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
833 fputc(' ', stdout);
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
834
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
835 fputs(mstr, stdout);
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
836
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
837 for (int q = 0; q < npad; q++)
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
838 fputc(' ', stdout);
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
839 }
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
840
2229
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
841 printf(" [%s]\n",
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
842 dmGrepDisp[node->disp].name);
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
843 }
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
844 }
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
845 }
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
846 else
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
847 if (setMode == FA_ANALYZE)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
848 {
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
849 // Allocate comparision buffer
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
850 // XXX: integer overflow?
2389
647671a9a0b8 More printf() format specifier size_t -related fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 2384
diff changeset
851 dmPrint(2, "Allocating %" DM_PRIu_SIZE_T " element (%" DM_PRIu_SIZE_T
647671a9a0b8 More printf() format specifier size_t -related fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 2384
diff changeset
852 " bytes) comparision buffer.\n",
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
853 compBufSize, compBufSize * sizeof(DMCompElem));
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
854
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
855 if ((compBuf = dmCalloc(compBufSize, sizeof(DMCompElem))) == NULL)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
856 {
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
857 dmErrorMsg("Out of memory. Could not allocate comparision buffer!\n");
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
858 goto out;
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
859 }
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
860
2234
ef1845cb436e Improve help, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2232
diff changeset
861 //
ef1845cb436e Improve help, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2232
diff changeset
862 // Basic file data comparision
ef1845cb436e Improve help, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2232
diff changeset
863 //
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
864 dmPrint(2, "Analyzing ..\n");
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
865 for (int nfile = 0; nfile < nsrcFiles; nfile++)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
866 {
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
867 DMSourceFile *file = &srcFiles[nfile];
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
868
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
869 for (size_t offs = 0; offs < file->size; offs++)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
870 {
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
871 Uint8 bv = file->data[offs];
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
872 totalStats.cv[bv].count++;
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
873 file->stats.cv[bv].count++;
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
874 }
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
875
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
876 for (size_t offs = 0; offs < compBufSize; offs++)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
877 {
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
878 Uint8 data = offs < file->size ? file->data[offs] : 0;
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
879 compBuf[offs].stats[data]++;
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
880 }
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
881 }
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
882
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
883 for (size_t offs = 0; offs < compBufSize; offs++)
1685
904904f145b4 Various fixes in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 1683
diff changeset
884 {
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
885 DMCompElem *el = &compBuf[offs];
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
886 for (int n = 0; n < SET_MAX_ELEMS; n++)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
887 {
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
888 if (el->stats[n] > 0)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
889 {
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
890 el->variants++;
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
891 el->data = n;
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
892 }
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
893 }
1685
904904f145b4 Various fixes in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 1683
diff changeset
894 }
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
895
2234
ef1845cb436e Improve help, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2232
diff changeset
896 //
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
897 // Display results
2234
ef1845cb436e Improve help, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2232
diff changeset
898 //
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
899 for (size_t offs = 0, n = 0; offs < compBufSize; offs++)
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
900 {
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
901 DMCompElem *el = &compBuf[offs];
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
902 BOOL var = el->variants > 1;
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
903
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
904 if (n == 0)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
905 printf("%08" DM_PRIx_SIZE_T " | ", offs);
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
906
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
907 if (var)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
908 printf("[%2d] ", el->variants);
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
909 else
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
910 printf(" %02x ", el->data);
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
911
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
912 if (++n >= 16)
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
913 {
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
914 printf("\n");
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
915 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
916 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
917 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
918
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
919 printf("\n");
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
920
2267
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
921 //
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
922 // Attempt further analysis
2267
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
923 //
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
924 for (int nfile = 0; nfile < nsrcFiles; nfile++)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
925 {
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
926 DMSourceFile *file = &srcFiles[nfile];
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
927 size_t len = file->size > compBufSize ? compBufSize : file->size;
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
928 for (size_t offs = 0; offs + 4 < len; offs++)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
929 {
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
930 DMCompElem *elem = &compBuf[offs];
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
931
2268
f2ff364065eb Add constant define for maximum number of variants.
Matti Hamalainen <ccr@tnsp.org>
parents: 2267
diff changeset
932 for (int variant = SET_MAX_VARIANTS - 1; variant >= 0; variant--)
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
933 {
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
934 size_t nmax = (variant < 2) ? sizeof(Uint16) : sizeof(Uint32);
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
935 Uint32 tmp = 0;
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
936
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
937 for (size_t n = 0; n < nmax; n++)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
938 {
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
939 size_t boffs = (variant & 1) ? n : nmax - n;
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
940
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
941 tmp <<= 8;
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
942 tmp |= file->data[offs + boffs];
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
943 }
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
944
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
945 if (file->size - tmp < 32)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
946 {
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
947 elem->interest[variant] += 32 - (file->size - tmp);
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
948 elem->interestF[variant]++;
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
949 }
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
950 }
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
951 }
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
952 }
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
953
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
954 printf("\nMore findings:\n");
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
955 for (size_t offs = 0; offs + 4 < compBufSize; offs++)
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
956 {
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
957 DMCompElem *elem = &compBuf[offs];
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
958
2268
f2ff364065eb Add constant define for maximum number of variants.
Matti Hamalainen <ccr@tnsp.org>
parents: 2267
diff changeset
959 for (int variant = 0; variant < SET_MAX_VARIANTS; variant++)
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
960 if (elem->interestF[variant] > 0)
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
961 {
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
962 printf("%08" DM_PRIx_SIZE_T " | V%d : %d / %d\n",
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
963 offs, variant,
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
964 elem->interestF[variant], elem->interest[variant]);
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
965 }
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
966 }
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
967
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
968 printf("\nGlobal most used bytes:\n");
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
969 dmPrintStats(&totalStats, 16, totalSize);
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
970
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
971 for (int nfile = 0; nfile < nsrcFiles; nfile++)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
972 {
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
973 DMSourceFile *file = &srcFiles[nfile];
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
974 printf("Most used bytes for '%s':\n", file->filename);
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
975 dmPrintStats(&file->stats, 16, file->size);
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
976 }
2267
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
977
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
978 }
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
979 else
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
980 if (setMode == FA_MATCHES)
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
981 {
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
982 //
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
983 // Attempt to find matching sequences of N+
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
984 //
2274
a4c1fafd442a Add a progress indicator when "slow" matching is expected.
Matti Hamalainen <ccr@tnsp.org>
parents: 2273
diff changeset
985 BOOL slow = FALSE;
a4c1fafd442a Add a progress indicator when "slow" matching is expected.
Matti Hamalainen <ccr@tnsp.org>
parents: 2273
diff changeset
986 int ss = 0;
2429
ebb4650f3cc1 Use printf() instead of dmPrint() for some things.
Matti Hamalainen <ccr@tnsp.org>
parents: 2410
diff changeset
987 printf("Attempting to find matching sequences of %" DM_PRIu_SIZE_T " bytes or more.\n",
2267
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
988 optMinMatchLen);
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
989
2273
6878aad714ce Add a slowness warning (the threshold value will probably need adjusting.)
Matti Hamalainen <ccr@tnsp.org>
parents: 2272
diff changeset
990 if (totalSize > 32*1024)
6878aad714ce Add a slowness warning (the threshold value will probably need adjusting.)
Matti Hamalainen <ccr@tnsp.org>
parents: 2272
diff changeset
991 {
6878aad714ce Add a slowness warning (the threshold value will probably need adjusting.)
Matti Hamalainen <ccr@tnsp.org>
parents: 2272
diff changeset
992 dmPrint(0,
6878aad714ce Add a slowness warning (the threshold value will probably need adjusting.)
Matti Hamalainen <ccr@tnsp.org>
parents: 2272
diff changeset
993 "WARNING! Total data size is large, and the matching \"algorithm\"\n"
6878aad714ce Add a slowness warning (the threshold value will probably need adjusting.)
Matti Hamalainen <ccr@tnsp.org>
parents: 2272
diff changeset
994 "used is horribly inefficient. This will be quite slow ...\n");
2274
a4c1fafd442a Add a progress indicator when "slow" matching is expected.
Matti Hamalainen <ccr@tnsp.org>
parents: 2273
diff changeset
995 slow = TRUE;
2273
6878aad714ce Add a slowness warning (the threshold value will probably need adjusting.)
Matti Hamalainen <ccr@tnsp.org>
parents: 2272
diff changeset
996 }
6878aad714ce Add a slowness warning (the threshold value will probably need adjusting.)
Matti Hamalainen <ccr@tnsp.org>
parents: 2272
diff changeset
997
2267
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
998 for (int nfile1 = 0; nfile1 < nsrcFiles; nfile1++)
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
999 {
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1000 DMSourceFile *file1 = &srcFiles[nfile1];
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1001
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1002 for (int nfile2 = 0; nfile2 < nsrcFiles; nfile2++)
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1003 if (nfile2 != nfile1 && !file1->analyzed)
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1004 {
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1005 DMSourceFile *file2 = &srcFiles[nfile2];
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1006
2274
a4c1fafd442a Add a progress indicator when "slow" matching is expected.
Matti Hamalainen <ccr@tnsp.org>
parents: 2273
diff changeset
1007 if (slow)
a4c1fafd442a Add a progress indicator when "slow" matching is expected.
Matti Hamalainen <ccr@tnsp.org>
parents: 2273
diff changeset
1008 {
a4c1fafd442a Add a progress indicator when "slow" matching is expected.
Matti Hamalainen <ccr@tnsp.org>
parents: 2273
diff changeset
1009 dmPrint(0,
a4c1fafd442a Add a progress indicator when "slow" matching is expected.
Matti Hamalainen <ccr@tnsp.org>
parents: 2273
diff changeset
1010 "Processing .. %1.1f%%\r",
a4c1fafd442a Add a progress indicator when "slow" matching is expected.
Matti Hamalainen <ccr@tnsp.org>
parents: 2273
diff changeset
1011 (float) ss * 100.0f / (float) (nsrcFiles * (nsrcFiles - 1)));
a4c1fafd442a Add a progress indicator when "slow" matching is expected.
Matti Hamalainen <ccr@tnsp.org>
parents: 2273
diff changeset
1012 ss++;
a4c1fafd442a Add a progress indicator when "slow" matching is expected.
Matti Hamalainen <ccr@tnsp.org>
parents: 2273
diff changeset
1013 }
2284
519c8726b235 Remove comment.
Matti Hamalainen <ccr@tnsp.org>
parents: 2274
diff changeset
1014
2270
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
1015 for (size_t moffs1 = 0; moffs1 + optMinMatchLen < file1->size;)
2267
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1016 {
2270
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
1017 size_t cnt = 0;
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
1018 for (size_t moffs2 = 0; moffs2 + optMinMatchLen < file2->size; moffs2++)
2267
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1019 {
2270
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
1020 for (cnt = 0; moffs1 + cnt + optMinMatchLen < file1->size &&
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
1021 moffs2 + cnt + optMinMatchLen < file2->size; cnt++)
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
1022 {
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
1023 if (file1->data[moffs1 + cnt] != file2->data[moffs2 + cnt])
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
1024 break;
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
1025 }
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
1026
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
1027 if (cnt >= optMinMatchLen)
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
1028 {
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
1029 // Match found
2272
4f52b7f5fe51 Bail out from the matching search if we exceed the match limits.
Matti Hamalainen <ccr@tnsp.org>
parents: 2271
diff changeset
1030 if (!dmAddMatchSequence(file1->data + moffs1, cnt, file1, moffs1) ||
4f52b7f5fe51 Bail out from the matching search if we exceed the match limits.
Matti Hamalainen <ccr@tnsp.org>
parents: 2271
diff changeset
1031 !dmAddMatchSequence(file2->data + moffs2, cnt, file2, moffs2))
4f52b7f5fe51 Bail out from the matching search if we exceed the match limits.
Matti Hamalainen <ccr@tnsp.org>
parents: 2271
diff changeset
1032 goto done;
4f52b7f5fe51 Bail out from the matching search if we exceed the match limits.
Matti Hamalainen <ccr@tnsp.org>
parents: 2271
diff changeset
1033
2270
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
1034 moffs1 += cnt;
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
1035 }
2267
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1036 }
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1037
2270
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
1038 if (cnt < optMinMatchLen)
2267
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1039 moffs1++;
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1040 }
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1041 }
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1042 file1->analyzed = TRUE;
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1043 }
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1044
2272
4f52b7f5fe51 Bail out from the matching search if we exceed the match limits.
Matti Hamalainen <ccr@tnsp.org>
parents: 2271
diff changeset
1045 done:
4f52b7f5fe51 Bail out from the matching search if we exceed the match limits.
Matti Hamalainen <ccr@tnsp.org>
parents: 2271
diff changeset
1046
2274
a4c1fafd442a Add a progress indicator when "slow" matching is expected.
Matti Hamalainen <ccr@tnsp.org>
parents: 2273
diff changeset
1047 if (slow)
a4c1fafd442a Add a progress indicator when "slow" matching is expected.
Matti Hamalainen <ccr@tnsp.org>
parents: 2273
diff changeset
1048 dmPrint(0, "\n\n");
a4c1fafd442a Add a progress indicator when "slow" matching is expected.
Matti Hamalainen <ccr@tnsp.org>
parents: 2273
diff changeset
1049
2270
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
1050 for (int nmatch = 0; nmatch < ndmSequences; nmatch++)
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
1051 {
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
1052 DMMatchSeq *seq = &dmSequences[nmatch];
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
1053
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
1054 qsort(&seq->places, seq->nplaces, sizeof(DMMatchPlace),
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
1055 dmCompareMatchPlaces);
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
1056 }
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
1057
2267
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1058 //
2396
679732e4cfed Implement counting of matching files for each match sequence.
Matti Hamalainen <ccr@tnsp.org>
parents: 2389
diff changeset
1059 // Count number of files
679732e4cfed Implement counting of matching files for each match sequence.
Matti Hamalainen <ccr@tnsp.org>
parents: 2389
diff changeset
1060 //
679732e4cfed Implement counting of matching files for each match sequence.
Matti Hamalainen <ccr@tnsp.org>
parents: 2389
diff changeset
1061 for (int nmatch = 0; nmatch < ndmSequences; nmatch++)
679732e4cfed Implement counting of matching files for each match sequence.
Matti Hamalainen <ccr@tnsp.org>
parents: 2389
diff changeset
1062 {
679732e4cfed Implement counting of matching files for each match sequence.
Matti Hamalainen <ccr@tnsp.org>
parents: 2389
diff changeset
1063 DMMatchSeq *seq = &dmSequences[nmatch];
679732e4cfed Implement counting of matching files for each match sequence.
Matti Hamalainen <ccr@tnsp.org>
parents: 2389
diff changeset
1064 memset(fileFlags, 0, fileFlagsSize);
679732e4cfed Implement counting of matching files for each match sequence.
Matti Hamalainen <ccr@tnsp.org>
parents: 2389
diff changeset
1065
679732e4cfed Implement counting of matching files for each match sequence.
Matti Hamalainen <ccr@tnsp.org>
parents: 2389
diff changeset
1066 for (int nplace = 0; nplace < seq->nplaces; nplace++)
679732e4cfed Implement counting of matching files for each match sequence.
Matti Hamalainen <ccr@tnsp.org>
parents: 2389
diff changeset
1067 {
679732e4cfed Implement counting of matching files for each match sequence.
Matti Hamalainen <ccr@tnsp.org>
parents: 2389
diff changeset
1068 DMMatchPlace *place = &seq->places[nplace];
679732e4cfed Implement counting of matching files for each match sequence.
Matti Hamalainen <ccr@tnsp.org>
parents: 2389
diff changeset
1069 if (!fileFlags[place->file->index])
679732e4cfed Implement counting of matching files for each match sequence.
Matti Hamalainen <ccr@tnsp.org>
parents: 2389
diff changeset
1070 {
679732e4cfed Implement counting of matching files for each match sequence.
Matti Hamalainen <ccr@tnsp.org>
parents: 2389
diff changeset
1071 fileFlags[place->file->index] = TRUE;
679732e4cfed Implement counting of matching files for each match sequence.
Matti Hamalainen <ccr@tnsp.org>
parents: 2389
diff changeset
1072 seq->nfiles++;
679732e4cfed Implement counting of matching files for each match sequence.
Matti Hamalainen <ccr@tnsp.org>
parents: 2389
diff changeset
1073 }
679732e4cfed Implement counting of matching files for each match sequence.
Matti Hamalainen <ccr@tnsp.org>
parents: 2389
diff changeset
1074 }
679732e4cfed Implement counting of matching files for each match sequence.
Matti Hamalainen <ccr@tnsp.org>
parents: 2389
diff changeset
1075 }
679732e4cfed Implement counting of matching files for each match sequence.
Matti Hamalainen <ccr@tnsp.org>
parents: 2389
diff changeset
1076
679732e4cfed Implement counting of matching files for each match sequence.
Matti Hamalainen <ccr@tnsp.org>
parents: 2389
diff changeset
1077 //
2267
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1078 // Display results
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1079 //
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1080 dmPrint(0, "Found %d matching sequence groups of %" DM_PRIu_SIZE_T " bytes minimum.\n",
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1081 ndmSequences, optMinMatchLen);
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1082
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1083 for (int nmatch = 0; nmatch < ndmSequences; nmatch++)
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1084 {
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1085 DMMatchSeq *seq = &dmSequences[nmatch];
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1086
2396
679732e4cfed Implement counting of matching files for each match sequence.
Matti Hamalainen <ccr@tnsp.org>
parents: 2389
diff changeset
1087 printf("\nSeq of %" DM_PRIu_SIZE_T " bytes in %d places (in %d files)\n",
2267
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1088 seq->len, seq->nplaces, seq->nfiles);
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1089
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1090 if (dmVerbosity > 0)
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1091 {
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1092 int n = 0;
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1093 for (size_t offs = 0; offs < seq->len; offs++)
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1094 {
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1095 if (n == 0)
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1096 printf(" ");
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1097
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1098 printf("%02x%s",
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1099 seq->data[offs],
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1100 offs + 1 < seq->len ? " " : "");
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1101
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1102 if (++n >= 16)
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1103 {
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1104 printf("\n");
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1105 n = 0;
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1106 }
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1107 }
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1108 if (n > 0)
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1109 printf("\n");
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1110 }
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1111
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1112 for (int nplace = 0; nplace < seq->nplaces; nplace++)
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1113 {
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1114 DMMatchPlace *place = &seq->places[nplace];
2270
0f0218dcccf8 More fixes to the matching sequence search functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 2269
diff changeset
1115 printf(" %08" DM_PRIx_SIZE_T "-%08" DM_PRIx_SIZE_T ": %s\n",
2267
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1116 place->offs,
2271
dcf9abeec930 Fix matched area end offset display.
Matti Hamalainen <ccr@tnsp.org>
parents: 2270
diff changeset
1117 place->offs + seq->len - 1,
2267
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1118 place->file->filename);
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1119
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1120 }
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1121 }
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
1122 }
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
1123 else
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
1124 {
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
1125 dmErrorMsg("Invalid operating mode?\n");
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
1126 }
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
1127
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1128 out:
2478
0d13de7edb30 Fix two meaningless memory leaks.
Matti Hamalainen <ccr@tnsp.org>
parents: 2441
diff changeset
1129 dmFree(fileFlags);
0d13de7edb30 Fix two meaningless memory leaks.
Matti Hamalainen <ccr@tnsp.org>
parents: 2441
diff changeset
1130 dmFree(compBuf);
0d13de7edb30 Fix two meaningless memory leaks.
Matti Hamalainen <ccr@tnsp.org>
parents: 2441
diff changeset
1131
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1132 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
1133 {
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1134 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
1135 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
1136 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1137
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1138 return 0;
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1139 }