annotate tools/fanalyze.c @ 2267:3739e2ac8bb1

Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum specified length from input files.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 17 Jun 2019 07:29:06 +0300
parents 6ba4aed198e4
children f2ff364065eb
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
2267
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
13 #define SET_MAX_FILES 64
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
14 #define SET_MAX_ELEMS 256
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
15 #define SET_MAX_VALUES 64
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
16 #define SET_MAX_GREPLIST 64
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
17
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
18 #define SET_MAX_SEQUENCES 1024
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
19 #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
20
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 /* Typedefs
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 typedef struct
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 {
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
26 Uint8 stats[SET_MAX_ELEMS];
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
27 Uint8 variants, data;
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
28 int interest[16];
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
29 int interestF[16];
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
30 } DMCompElem;
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
31
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
32
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
33 typedef struct
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 int count;
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
36 Uint8 value;
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
37 } DMStatValue;
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
38
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
39
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
40 typedef struct
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 DMStatValue cv[SET_MAX_ELEMS];
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
43 } DMStats;
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
44
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
45
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
46 typedef struct
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
47 {
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 char *filename;
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 Uint8 *data;
2249
6ba4aed198e4 Cosmetic.
Matti Hamalainen <ccr@tnsp.org>
parents: 2248
diff changeset
50 size_t size;
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
51 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
52 BOOL analyzed;
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 } DMSourceFile;
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55
2267
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
56 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
57 {
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
58 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
59 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
60 } DMMatchPlace;
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
61
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
62
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
63 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
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 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
66 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
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 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
69 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
70 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
71 } DMMatchSeq;
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
72
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
73
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
74 enum
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
75 {
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
76 DMGV_UINT8 = 0,
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
77 DMGV_UINT16_LE,
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
78 DMGV_UINT16_BE,
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
79 DMGV_UINT32_LE,
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
80 DMGV_UINT32_BE,
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
81
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
82 DMGV_last
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
83 };
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
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
86 enum
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
87 {
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
88 DMGS_HEX = 0,
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
89 DMGS_DEC,
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
90 DMGS_last
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
91 };
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
92
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
93
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
94 typedef struct
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
95 {
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
96 int type;
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
97 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
98 int nvalues;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
99 Uint32 values[SET_MAX_GREPLIST];
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
100 BOOL vwildcards[SET_MAX_GREPLIST];
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
101 } DMGrepValue;
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
102
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
103
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
104 typedef struct
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
105 {
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
106 char *name;
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
107 Uint32 nmax;
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
108 unsigned int bsize;
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
109 } DMGrepType;
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
110
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
111
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
112 static const DMGrepType dmGrepTypes[DMGV_last] =
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
113 {
2040
3a7ce77c7f2d Fix integer overflows vs. shifts.
Matti Hamalainen <ccr@tnsp.org>
parents: 2035
diff changeset
114 { "8bit (byte)" , (1ULL << 8) - 1, 1 },
3a7ce77c7f2d Fix integer overflows vs. shifts.
Matti Hamalainen <ccr@tnsp.org>
parents: 2035
diff changeset
115 { "16bit (word) LE" , (1ULL << 16) - 1, 2 },
3a7ce77c7f2d Fix integer overflows vs. shifts.
Matti Hamalainen <ccr@tnsp.org>
parents: 2035
diff changeset
116 { "16bit (word) BE" , (1ULL << 16) - 1, 2 },
3a7ce77c7f2d Fix integer overflows vs. shifts.
Matti Hamalainen <ccr@tnsp.org>
parents: 2035
diff changeset
117 { "32bit (word) LE" , (1ULL << 32) - 1, 4 },
3a7ce77c7f2d Fix integer overflows vs. shifts.
Matti Hamalainen <ccr@tnsp.org>
parents: 2035
diff changeset
118 { "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
119 };
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
120
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
121
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
122 typedef struct
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
123 {
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
124 char *name;
2229
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
125 char *fmtPrefix;
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
126 char *fmt;
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
127 } DMGrepDisp;
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
128
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
129
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
130 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
131 {
2229
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
132 { "hex", "0", "x" },
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
133 { "dec", "" , "d" },
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
134 };
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
135
2249
6ba4aed198e4 Cosmetic.
Matti Hamalainen <ccr@tnsp.org>
parents: 2248
diff changeset
136
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
137 enum
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
138 {
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
139 FA_ANALYZE,
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
140 FA_GREP,
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
141 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
142 FA_MATCHES,
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
143 };
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
144
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
145
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146 /* Global variables
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
147 */
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
148 int setMode = FA_ANALYZE;
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
149 int nsrcFiles = 0; // Number of source files
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
150 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
151 DMStats totalStats;
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
152 int nsetGrepValues = 0;
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
153 DMGrepValue setGrepValues[SET_MAX_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
154 size_t optMinMatchLen = 8;
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
155
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
156 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
157 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
158
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160 /* Arguments
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161 */
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162 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
163 {
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164 { 0, '?', "help", "Show this help", OPT_NONE },
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165 { 1, 'v', "verbose", "Be more verbose", OPT_NONE },
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
166 { 2, 'g', "grep", "Binary grep <val>[,<val2>...][:<le|be>[8|16|32]]", OPT_ARGREQ },
2229
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
167 { 3, 'o', "offset", "Show data in offset <offs>[,<offs2>...][:<le|be>[8|16|32][d|x]]", OPT_ARGREQ },
2267
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
168 { 4, 'm', "match", "Find matching sequences minimum of <n> bytes long", OPT_NONE },
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
169 { 5, 'n', "minmatch", "Minimum match sequence length", OPT_ARGREQ },
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170 };
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172 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
173
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
175 void argShowHelp()
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
176 {
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177 dmPrintBanner(stdout, dmProgName, "[options] <input file #1> <input file #2> [...]");
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178 dmArgsPrintHelp(stdout, optList, optListN, 0);
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
179
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
180 fprintf(stdout,
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
181 "\n"
2234
ef1845cb436e Improve help, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2232
diff changeset
182 "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
183 "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
184 "automatic analysis (default operating mode), binary grep functionality (-g)\n"
ef1845cb436e Improve help, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2232
diff changeset
185 "and offset data display (-o)\n"
ef1845cb436e Improve help, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2232
diff changeset
186 "\n"
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
187 "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
188 "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
189 "-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
190 "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
191 "\n"
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
192 "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
193 "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
194 );
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
195 }
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
196
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
197
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
198 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
199 {
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
200 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
201 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
202 {
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
203 *mval = 0;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
204 return FALSE;
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 switch (type)
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 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
210 *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
211 break;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
212
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
213 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
214 *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
215 break;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
216
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
217 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
218 *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
219 break;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
220
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
221 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
222 *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
223 break;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
224
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
225 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
226 *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
227 break;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
228
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
229 default:
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
230 *mval = 0;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
231 return FALSE;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
232 }
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
233 return TRUE;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
234 }
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
235
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
236
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
237 void dmPrintGrepValueList(const DMGrepValue *node, const BOOL match, DMSourceFile *file, const size_t offs)
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
238 {
2229
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
239 char mfmt[16];
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
240
2229
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
241 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
242 dmGrepDisp[node->disp].fmtPrefix,
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
243 dmGrepTypes[node->type].bsize * 2,
2229
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
244 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
245
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
246 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
247 {
2248
2e656da1b10b Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2234
diff changeset
248 const char *veol = (n + 1 < node->nvalues) ? " " : "\n";
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
249
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
250 if (match)
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
251 {
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
252 Uint32 mval;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
253 dmGetData(node->type, file, offs + n, &mval);
2229
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
254 dmPrint(1, 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
255 }
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
256 else
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
257 {
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
258 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
259 dmPrint(1, "?%s", veol);
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
260 else
2229
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
261 dmPrint(1, 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
262 }
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
263 }
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
264 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
265
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
266
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
267 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
268 {
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
269 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
270 char *vspec, *vstr, *vsep;
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
271 DMGrepValue val;
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
272 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
273 BOOL more;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
274
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
275 memset(&val, 0, sizeof(val));
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
276
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
277 if (setMode != FA_ANALYZE && setMode != mode)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
278 {
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
279 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
280 return DMERR_INVALID_ARGS;
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
281 }
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
282 setMode = mode;
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
283
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
284 // 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
285 if (specsep != NULL)
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
286 {
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
287 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
288 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
289 }
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
290 else
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
291 {
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
292 vspec = NULL;
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
293 vstr = dm_strdup(arg);
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
294 }
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
295
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
296 // Parse spec if any
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
297 if (vspec != NULL)
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
298 {
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
299 BOOL vendianess = TRUE;
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
300 char *vtmp = vspec;
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 // Get endianess specifier, if any
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
303 if (dm_strncasecmp(vtmp, "le", 2) == 0)
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 vendianess = TRUE;
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
306 vtmp += 2;
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
307 }
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
308 else
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
309 if (dm_strncasecmp(vtmp, "be", 2) == 0)
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
310 {
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
311 vendianess = FALSE;
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
312 vtmp += 2;
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
313 }
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 // Get value bit size
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
316 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
317 {
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
318 val.type = DMGV_UINT8;
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
319 vtmp += 1;
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
320 }
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
321 else
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
322 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
323 {
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
324 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
325 vtmp += 2;
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
326 }
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
327 else
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
328 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
329 {
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
330 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
331 vtmp += 2;
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
332 }
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
333 else
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
334 {
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
335 ret = dmError(DMERR_INVALID_ARGS,
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
336 "Invalid grep type '%s'.\n",
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
337 vspec);
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
338 goto out;
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
339 }
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
340
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
341 switch (tolower(*vtmp))
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
342 {
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
343 case 'd':
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
344 val.disp = DMGS_DEC;
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
345 break;
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
346
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
347 case 'x': case 'h':
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
348 val.disp = DMGS_HEX;
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
349 break;
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 case 0:
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
352 break;
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
353
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
354 default:
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
355 ret = dmError(DMERR_INVALID_ARGS,
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
356 "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
357 vspec);
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
358 goto out;
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
359 }
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
360 }
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
361
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
362 // 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
363 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
364 do
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
365 {
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
366 if (val.nvalues >= SET_MAX_GREPLIST)
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
367 {
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
368 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
369 "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
370 vstr);
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
371 goto out;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
372 }
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
373
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
374 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
375 {
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
376 *vsep = 0;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
377 more = TRUE;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
378 }
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
379 else
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
380 more = FALSE;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
381
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
382 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
383 {
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
384 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
385 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
386 {
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
387 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
388 "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
389 goto out;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
390 }
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 else
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
393 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
394 {
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
395 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
396 "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
397 vtmp);
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
398 goto out;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
399 }
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
400
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
401 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
402
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
403 if (more)
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
404 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
405 } while (more);
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
406
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
407 if (val.vwildcards[0])
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
408 {
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
409 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
410 "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
411 goto out;
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
412 }
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
413
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
414 if (mode == FA_GREP)
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
415 {
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
416 // Check if we need to guess size
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
417 if (val.type < 0)
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
418 {
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
419 for (int n = DMGV_last; n >= 0; n--)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
420 {
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
421 const DMGrepType *def = &dmGrepTypes[n];
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
422 if (val.values[0] <= def->nmax)
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
423 val.type = n;
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
424 }
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
425 }
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
426
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
427 if (val.type < 0)
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
428 {
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
429 ret = dmError(DMERR_INVALID_ARGS,
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
430 "Could not guess value type for '%s'.\n",
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
431 arg);
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
432 goto out;
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
433 }
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 // Check range
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
436 for (int n = 0; n < val.nvalues; n++)
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
437 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
438 {
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 "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
441 val.values[n], 0, dmGrepTypes[val.type].nmax,
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
442 dmGrepTypes[val.type].name);
2034
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 goto out;
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
445 }
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
446 }
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
447 else
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
448 if (mode == FA_OFFSET)
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
449 {
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
450 if (val.type < 0)
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
451 val.type = DMGV_UINT8;
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
452 }
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
453
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
454 if (nsetGrepValues < SET_MAX_VALUES)
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 DMGrepValue *node = &setGrepValues[nsetGrepValues++];
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
457 memcpy(node, &val, sizeof(val));
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
458
2229
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
459 if (mode == FA_GREP)
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
460 {
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
461 dmPrint(1, "Grep %s: ",
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
462 dmGrepTypes[val.type].name);
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
463
2229
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
464 dmPrintGrepValueList(node, FALSE, NULL, 0);
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
465 }
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
466 }
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
467 else
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
468 {
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
469 ret = dmError(DMERR_BOUNDS,
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
470 "Too many values specified (max %d).",
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
471 SET_MAX_VALUES);
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
472 }
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
473
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
474 out:
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
475 dmFree(vspec);
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
476 dmFree(vstr);
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
477 return ret;
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
478 }
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
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
481 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
482 {
1995
ea6337c873c6 Silence an unused function argument warning.
Matti Hamalainen <ccr@tnsp.org>
parents: 1685
diff changeset
483 (void) optArg;
ea6337c873c6 Silence an unused function argument warning.
Matti Hamalainen <ccr@tnsp.org>
parents: 1685
diff changeset
484
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
485 switch (optN)
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
486 {
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
487 case 0:
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
488 argShowHelp();
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
489 exit(0);
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
490 break;
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
491
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
492 case 1:
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
493 dmVerbosity++;
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
494 break;
1682
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 2:
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
497 return argParseGrepValue(optArg, FA_GREP) == DMERR_OK;
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
498
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
499 case 3:
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
500 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
501
2267
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
502 case 4:
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
503 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
504 break;
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
505
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
506 case 5:
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
507 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
508 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
509 {
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
510 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
511 optArg);
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
512 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
513 }
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
514 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
515
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
516 default:
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
517 dmErrorMsg("Unknown argument '%s'.\n", currArg);
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
518 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
519 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
520
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
521 return TRUE;
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
522 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
523
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
524
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
525 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
526 {
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
527 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
528 {
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
529 DMSourceFile *file = &srcFiles[nsrcFiles++];
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
530 file->filename = currArg;
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
531 return TRUE;
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
532 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
533 else
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
534 {
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
535 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
536 SET_MAX_FILES);
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
537 return TRUE;
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
538 }
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
539 }
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
540
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
541
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
542 void dmInitStats(DMStats *stats)
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
543 {
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
544 for (size_t n = 0; n < SET_MAX_ELEMS; n++)
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
545 {
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
546 stats->cv[n].count = 0;
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
547 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
548 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
549 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
550
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
551
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
552 int dmCompareStatFunc(const void *va, const void *vb)
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
553 {
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
554 const DMStatValue *pa = va, *pb = vb;
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
555 return pb->count - pa->count;
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
556 }
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
557
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 void dmPrintStats(DMStats *stats, const int nmax, const size_t size)
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
560 {
2011
8e38fa3c4f98 Fix use of qsort().
Matti Hamalainen <ccr@tnsp.org>
parents: 1996
diff changeset
561 qsort(&stats->cv, SET_MAX_ELEMS, sizeof(DMStatValue), dmCompareStatFunc);
8e38fa3c4f98 Fix use of qsort().
Matti Hamalainen <ccr@tnsp.org>
parents: 1996
diff changeset
562
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
563 for (int n = 0; n < nmax; n++)
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
564 {
2011
8e38fa3c4f98 Fix use of qsort().
Matti Hamalainen <ccr@tnsp.org>
parents: 1996
diff changeset
565 printf("$%02x (%d = %1.2f%%), ",
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
566 stats->cv[n].value,
2011
8e38fa3c4f98 Fix use of qsort().
Matti Hamalainen <ccr@tnsp.org>
parents: 1996
diff changeset
567 stats->cv[n].count,
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
568 ((float) stats->cv[n].count * 100.0f) / (float) size);
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
569 }
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
570 printf("\n\n");
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
571 }
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
572
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
573
2267
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
574 void dmAddMatchSequence(Uint8 *data, const size_t len, DMSourceFile *file, size_t offs)
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
575 {
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
576 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
577
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
578 // 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
579 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
580 {
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
581 DMMatchSeq *node = &dmSequences[n];
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
582 if (node->len == len &&
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
583 (node->data == data ||
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
584 memcmp(node->data, data, node->len) == 0))
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
585 {
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
586 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
587 break;
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
588 }
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
589 }
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
590
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
591 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
592 {
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
593 // 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
594 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
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 dmErrorMsg("Too many matching sequences found.\n");
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
597 return;
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
598 }
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
599
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
600 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
601 seq->data = data;
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
602 seq->len = len;
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
603 }
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
604 else
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
605 {
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
606 // Check for existing
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
607 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
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 DMMatchPlace *place = &seq->places[n];
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 (place->offs == offs && 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
611 return;
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
612 }
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
613 }
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 // 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
616 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
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 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
619 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
620 place->offs = offs;
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
621 }
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
622 else
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
623 return;
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
624
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
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
627
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
628 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
629 {
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
630 DMCompElem *compBuf = NULL;
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
631 size_t compBufSize = 0, totalSize = 0;
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
632 int res;
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
633
2267
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
634 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
635
2234
ef1845cb436e Improve help, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2232
diff changeset
636 dmInitProg("fanalyze", "Simple tool for file format analysis",
ef1845cb436e Improve help, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2232
diff changeset
637 "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
638 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
639
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
640 dmInitStats(&totalStats);
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
641
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
642 // Parse arguments
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
643 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
644 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
645 exit(1);
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
646
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
647 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
648 {
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
649 dmErrorMsg("Nothing to do. (try --help)\n");
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
650 goto out;
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
651 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
652
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
653 // 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
654 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
655 {
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
656 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
657 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
658 {
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
659 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
660 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
661 goto out;
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
662 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
663
1685
904904f145b4 Various fixes in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 1683
diff changeset
664 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
665 nfile + 1, file->filename, file->size);
904904f145b4 Various fixes in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 1683
diff changeset
666
904904f145b4 Various fixes in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 1683
diff changeset
667 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
668 compBufSize = file->size;
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
669
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
670 totalSize += file->size;
2011
8e38fa3c4f98 Fix use of qsort().
Matti Hamalainen <ccr@tnsp.org>
parents: 1996
diff changeset
671 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
672 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
673
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
674
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
675 //
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
676 // Check what operating mode we are in
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
677 //
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
678 if (setMode == FA_GREP)
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
679 {
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
680 for (int nfile = 0; nfile < nsrcFiles; nfile++)
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
681 {
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
682 DMSourceFile *file = &srcFiles[nfile];
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
683 dmPrint(0, "\n%s\n", file->filename);
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
684
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
685 for (int n = 0; n < nsetGrepValues; n++)
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
686 {
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
687 DMGrepValue *node = &setGrepValues[n];
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
688 const DMGrepType *def = &dmGrepTypes[node->type];
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
689
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
690 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
691 {
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
692 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
693 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
694 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
695 {
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
696 Uint32 mval;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
697 dmGetData(node->type, file, offs + n, &mval);
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
698
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
699 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
700 {
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
701 match = FALSE;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
702 break;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
703 }
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
704 }
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
705
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
706 if (match)
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
707 {
2229
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
708 dmPrint(0, "%08x : ", offs);
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
709 dmPrintGrepValueList(node, TRUE, file, offs);
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
710 }
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
711 }
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
712 }
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
713 }
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
714 }
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
715 else
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
716 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
717 {
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
718 for (int nfile = 0; nfile < nsrcFiles; nfile++)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
719 {
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
720 DMSourceFile *file = &srcFiles[nfile];
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
721 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
722 }
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
723
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
724 printf(" offset :");
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
725 for (int nfile = 0; nfile < nsrcFiles; nfile++)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
726 printf(" %03d ", nfile + 1);
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
727 printf("\n");
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
728
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
729 printf("==========");
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
730 for (int nfile = 0; nfile < nsrcFiles; nfile++)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
731 printf("===========");
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
732 printf("\n");
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
733
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
734 for (int n = 0; n < nsetGrepValues; n++)
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
735 {
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
736 DMGrepValue *node = &setGrepValues[n];
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
737 const DMGrepType *def = &dmGrepTypes[node->type];
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
738
2229
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
739 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
740 {
2229
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
741 printf("%08x : ", node->values[nv]);
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
742
2229
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
743 for (int nfile = 0; nfile < nsrcFiles; nfile++)
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
744 {
2229
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
745 DMSourceFile *file = &srcFiles[nfile];
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
746 Uint32 mval;
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
747 char mstr[32];
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
748 int npad, nwidth;
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
749
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
750 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
751 {
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
752 char mfmt[16];
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
753 nwidth = def->bsize * 2;
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
754 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
755 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
756
2229
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
757 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
758 }
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
759 else
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
760 {
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
761 strcpy(mstr, "----");
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
762 nwidth = 4;
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
763 }
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
764
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
765 npad = (10 - nwidth) / 2;
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
766 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
767 fputc(' ', stdout);
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
768
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
769 fputs(mstr, stdout);
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
770
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
771 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
772 fputc(' ', stdout);
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
773 }
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
774
2229
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
775 printf(" [%s]\n",
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
776 dmGrepDisp[node->disp].name);
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
777 }
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
778 }
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
779 }
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
780 else
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
781 if (setMode == FA_ANALYZE)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
782 {
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
783 // Allocate comparision buffer
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
784 // XXX: integer overflow?
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
785 dmPrint(2, "Allocating %d element (%d bytes) comparision buffer.\n",
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
786 compBufSize, compBufSize * sizeof(DMCompElem));
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
787
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
788 if ((compBuf = dmCalloc(compBufSize, sizeof(DMCompElem))) == NULL)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
789 {
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
790 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
791 goto out;
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
792 }
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
793
2234
ef1845cb436e Improve help, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2232
diff changeset
794 //
ef1845cb436e Improve help, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2232
diff changeset
795 // Basic file data comparision
ef1845cb436e Improve help, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2232
diff changeset
796 //
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
797 dmPrint(2, "Analyzing ..\n");
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
798 for (int nfile = 0; nfile < nsrcFiles; nfile++)
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 DMSourceFile *file = &srcFiles[nfile];
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
801
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
802 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
803 {
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
804 Uint8 bv = file->data[offs];
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
805 totalStats.cv[bv].count++;
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
806 file->stats.cv[bv].count++;
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
807 }
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
808
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
809 for (size_t offs = 0; offs < compBufSize; offs++)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
810 {
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
811 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
812 compBuf[offs].stats[data]++;
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
813 }
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
814 }
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
815
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
816 for (size_t offs = 0; offs < compBufSize; offs++)
1685
904904f145b4 Various fixes in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 1683
diff changeset
817 {
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
818 DMCompElem *el = &compBuf[offs];
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
819 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
820 {
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
821 if (el->stats[n] > 0)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
822 {
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
823 el->variants++;
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
824 el->data = n;
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
825 }
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
826 }
1685
904904f145b4 Various fixes in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 1683
diff changeset
827 }
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
828
2234
ef1845cb436e Improve help, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2232
diff changeset
829 //
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
830 // Display results
2234
ef1845cb436e Improve help, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2232
diff changeset
831 //
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
832 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
833 {
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
834 DMCompElem *el = &compBuf[offs];
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
835 BOOL var = el->variants > 1;
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
836
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
837 if (n == 0)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
838 printf("%08" DM_PRIx_SIZE_T " | ", offs);
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 if (var)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
841 printf("[%2d] ", el->variants);
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
842 else
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
843 printf(" %02x ", el->data);
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 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
846 {
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
847 printf("\n");
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
848 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
849 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
850 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
851
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
852 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
853
2267
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
854 //
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
855 // 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
856 //
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
857 for (int nfile = 0; nfile < nsrcFiles; nfile++)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
858 {
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
859 DMSourceFile *file = &srcFiles[nfile];
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
860 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
861 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
862 {
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
863 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
864
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
865 for (int variant = 3; variant >= 0; variant--)
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 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
868 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
869
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
870 for (size_t n = 0; n < nmax; n++)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
871 {
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
872 size_t boffs = (variant & 1) ? n : nmax - n;
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
873
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
874 tmp <<= 8;
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
875 tmp |= file->data[offs + boffs];
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
876 }
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
877
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
878 if (file->size - tmp < 32)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
879 {
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
880 elem->interest[variant] += 32 - (file->size - tmp);
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
881 elem->interestF[variant]++;
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
882 }
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
883 }
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
884 }
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
885 }
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
886
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
887 printf("\nMore findings:\n");
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
888 for (size_t offs = 0; offs + 4 < compBufSize; offs++)
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
889 {
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
890 DMCompElem *elem = &compBuf[offs];
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
891
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
892 for (int variant = 0; variant < 4; variant++)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
893 if (elem->interestF[variant] > 0)
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
894 {
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
895 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
896 offs, variant,
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
897 elem->interestF[variant], elem->interest[variant]);
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
898 }
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
899 }
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
900
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
901 printf("\nGlobal most used bytes:\n");
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
902 dmPrintStats(&totalStats, 16, totalSize);
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
903
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
904 for (int nfile = 0; nfile < nsrcFiles; nfile++)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
905 {
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
906 DMSourceFile *file = &srcFiles[nfile];
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
907 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
908 dmPrintStats(&file->stats, 16, file->size);
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
909 }
2267
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
910
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
911 }
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
912 else
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
913 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
914 {
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
915 //
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
916 // 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
917 //
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
918 dmPrint(2, "Attempting to find matching sequences of %" DM_PRIu_SIZE_T" bytes or more\n",
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
919 optMinMatchLen);
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
920
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
921 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
922 {
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
923 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
924
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
925 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
926 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
927 {
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
928 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
929
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
930 // Find longest possible matching sequence in file2, if any
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
931 size_t moffs1 = 0, moffs2 = 0;
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
932 while (moffs1 + optMinMatchLen < file1->size &&
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
933 moffs2 + optMinMatchLen < file2->size)
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
934 {
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
935 size_t cnt;
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
936 for (cnt = 0; moffs1 + cnt < file1->size && moffs2 + cnt < file2->size; cnt++)
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
937 {
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
938 if (file1->data[moffs1 + cnt] != file2->data[moffs2 + cnt])
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
939 break;
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
940 }
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
941
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
942 if (cnt >= optMinMatchLen)
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
943 {
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
944 // Match found
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
945 dmAddMatchSequence(file1->data + moffs1, cnt, file1, moffs1);
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
946 dmAddMatchSequence(file2->data + moffs2, cnt, file2, moffs2);
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
947
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
948 moffs1 += cnt;
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
949 }
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
950 else
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
951 {
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
952 moffs1++;
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
953 moffs2++;
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
954 }
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
955 }
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
956 }
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
957 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
958 }
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
959
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
960 //
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
961 // 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
962 //
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
963 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
964 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
965
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
966 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
967 {
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
968 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
969
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
970 printf("\nSeq of %" DM_PRIu_SIZE_T " bytes in %d places (%d files)\n",
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
971 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
972
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
973 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
974 {
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
975 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
976 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
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 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
979 printf(" ");
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
980
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
981 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
982 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
983 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
984
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
985 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
986 {
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
987 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
988 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
989 }
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
990 }
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
991 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
992 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
993 }
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
994
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
995 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
996 {
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
997 DMMatchPlace *place = &seq->places[nplace];
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
998 printf(" %08" DM_PRIx_SIZE_T ": %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
999 place->offs,
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1000 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
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 }
3739e2ac8bb1 Add 'beta' level feature to fanalyze, for finding matching byte sequences of minimum
Matti Hamalainen <ccr@tnsp.org>
parents: 2249
diff changeset
1003 }
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
1004 }
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
1005 else
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
1006 {
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
1007 dmErrorMsg("Invalid operating mode?\n");
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
1008 }
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
1009
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1010 out:
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1011 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
1012 {
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1013 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
1014 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
1015 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1016
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1017 return 0;
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1018 }