Mercurial > hg > dmlib
annotate tools/fanalyze.c @ 2225:837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
and also wildcard values specified with '?'.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 14 Jun 2019 18:00:18 +0300 |
parents | 1662730053d0 |
children | 02d17784fdef |
rev | line source |
---|---|
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1 /* |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2 * Fanalyze - Analyze similarities between multiple files |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3 * Programmed and designed by Matti 'ccr' Hamalainen |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
4 * (C) Copyright 2018 Tecnic Software productions (TNSP) |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
5 * |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
6 * Please read file 'COPYING' for information on license and distribution. |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
7 */ |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
8 #include "dmtool.h" |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
9 #include "dmlib.h" |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
10 #include "dmargs.h" |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
11 #include "dmfile.h" |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
12 |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
13 #define SET_MAX_FILES 64 |
1996 | 14 #define SET_MAX_ELEMS 256 |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
15 #define SET_MAX_VALUES 64 |
2225
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
16 #define SET_MAX_GREPLIST 64 |
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
17 |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
18 |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
19 /* Typedefs |
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 typedef struct |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
22 { |
1996 | 23 Uint8 stats[SET_MAX_ELEMS]; |
24 Uint8 variants, data; | |
25 int interest[16]; | |
26 int interestF[16]; | |
27 } DMCompElem; | |
28 | |
29 | |
30 typedef struct | |
31 { | |
32 int count; | |
33 Uint8 value; | |
34 } DMStatValue; | |
35 | |
36 | |
37 typedef struct | |
38 { | |
39 DMStatValue cv[SET_MAX_ELEMS]; | |
40 } DMStats; | |
41 | |
42 | |
43 typedef struct | |
44 { | |
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
45 char *filename; |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
46 Uint8 *data; |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
47 size_t size; // offset, crop_start, crop_end, doCrop? |
1996 | 48 DMStats stats; |
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
49 } DMSourceFile; |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
50 |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
51 |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
52 enum |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
53 { |
2045
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
54 DMGV_UINT8 = 0, |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
55 DMGV_UINT16_LE, |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
56 DMGV_UINT16_BE, |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
57 DMGV_UINT32_LE, |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
58 DMGV_UINT32_BE, |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
59 |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
60 DMGV_last |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
61 }; |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
62 |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
63 |
2045
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
64 enum |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
65 { |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
66 DMGS_HEX = 0, |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
67 DMGS_DEC, |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
68 DMGS_last |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
69 }; |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
70 |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
71 |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
72 typedef struct |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
73 { |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
74 int type; |
2045
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
75 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
|
76 int nvalues; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
77 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
|
78 BOOL vwildcards[SET_MAX_GREPLIST]; |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
79 } DMGrepValue; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
80 |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
81 |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
82 typedef struct |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
83 { |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
84 char *name; |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
85 Uint32 nmax; |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
86 unsigned int bsize; |
2045
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
87 } DMGrepType; |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
88 |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
89 |
2045
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
90 static const DMGrepType dmGrepTypes[DMGV_last] = |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
91 { |
2040
3a7ce77c7f2d
Fix integer overflows vs. shifts.
Matti Hamalainen <ccr@tnsp.org>
parents:
2035
diff
changeset
|
92 { "8bit (byte)" , (1ULL << 8) - 1, 1 }, |
3a7ce77c7f2d
Fix integer overflows vs. shifts.
Matti Hamalainen <ccr@tnsp.org>
parents:
2035
diff
changeset
|
93 { "16bit (word) LE" , (1ULL << 16) - 1, 2 }, |
3a7ce77c7f2d
Fix integer overflows vs. shifts.
Matti Hamalainen <ccr@tnsp.org>
parents:
2035
diff
changeset
|
94 { "16bit (word) BE" , (1ULL << 16) - 1, 2 }, |
3a7ce77c7f2d
Fix integer overflows vs. shifts.
Matti Hamalainen <ccr@tnsp.org>
parents:
2035
diff
changeset
|
95 { "32bit (word) LE" , (1ULL << 32) - 1, 4 }, |
3a7ce77c7f2d
Fix integer overflows vs. shifts.
Matti Hamalainen <ccr@tnsp.org>
parents:
2035
diff
changeset
|
96 { "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
|
97 }; |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
98 |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
99 |
2045
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
100 typedef struct |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
101 { |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
102 char *name; |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
103 char *fmt; |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
104 } DMGrepDisp; |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
105 |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
106 |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
107 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
|
108 { |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
109 { "hex", "x" }, |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
110 { "dec", "d" }, |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
111 }; |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
112 |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
113 enum |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
114 { |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
115 FA_ANALYZE, |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
116 FA_GREP, |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
117 FA_OFFSET, |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
118 }; |
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 |
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
121 /* Global variables |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
122 */ |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
123 int setMode = FA_ANALYZE; |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
124 int nsrcFiles = 0; // Number of source files |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
125 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
|
126 DMStats totalStats; |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
127 int nsetGrepValues = 0; |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
128 DMGrepValue setGrepValues[SET_MAX_VALUES]; |
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
129 |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
130 |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
131 /* Arguments |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
132 */ |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
133 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
|
134 { |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
135 { 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
|
136 { 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
|
137 { 2, 'g', "grep", "Binary grep <val>[,<val2>...][:<le|be>[8|16|32]]", OPT_ARGREQ }, |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
138 { 3, 'o', "offset", "Show data in offset <offset>:<le|be>[8|16|32][d|x]]", 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
|
139 }; |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
140 |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
141 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
|
142 |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
143 |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
144 void argShowHelp() |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
145 { |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
146 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
|
147 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
|
148 |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
149 fprintf(stdout, |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
150 "\n" |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
151 "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
|
152 "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
|
153 "-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
|
154 "and -g 0xe,0x1001,?,2023:le16 will match le16 value 000e 1001 ???? 07e7\n" |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
155 ); |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
156 } |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
157 |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
158 |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
159 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
|
160 { |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
161 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
|
162 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
|
163 { |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
164 *mval = 0; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
165 return FALSE; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
166 } |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
167 |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
168 switch (type) |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
169 { |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
170 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
|
171 *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
|
172 break; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
173 |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
174 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
|
175 *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
|
176 break; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
177 |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
178 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
|
179 *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
|
180 break; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
181 |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
182 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
|
183 *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
|
184 break; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
185 |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
186 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
|
187 *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
|
188 break; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
189 |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
190 default: |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
191 *mval = 0; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
192 return FALSE; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
193 } |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
194 return TRUE; |
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 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
|
199 { |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
200 char vfmt[16]; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
201 |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
202 snprintf(vfmt, sizeof(vfmt), "%%%s%d%s%%s", |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
203 node->disp == DMGS_HEX ? "0" : "", |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
204 dmGrepTypes[node->type].bsize * 2, |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
205 node->disp == DMGS_HEX ? "x" : "d"); |
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 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
|
208 { |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
209 const char *veol = (n < node->nvalues - 1) ? " " : "\n"; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
210 |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
211 if (match) |
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 Uint32 mval; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
214 dmGetData(node->type, file, offs + n, &mval); |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
215 dmPrint(1, vfmt, mval, veol); |
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 else |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
218 { |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
219 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
|
220 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
|
221 else |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
222 dmPrint(1, vfmt, node->values[n], veol); |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
223 } |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
224 } |
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
225 } |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
226 |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
227 |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
228 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
|
229 { |
2225
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
230 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
|
231 char *vspec, *vstr, *vsep; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
232 int vdisp = DMGS_HEX, vtype = -1, ret = DMERR_OK, nvalues; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
233 BOOL more; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
234 Uint32 vvalues[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
|
235 BOOL vwildcards[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
|
236 |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
237 memset(vwildcards, 0, sizeof(vwildcards)); |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
238 |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
239 if (setMode != FA_ANALYZE && setMode != mode) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
240 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
241 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
|
242 return DMERR_INVALID_ARGS; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
243 } |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
244 setMode = mode; |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
245 |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
246 // 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
|
247 if (specsep != NULL) |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
248 { |
2225
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
249 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
|
250 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
|
251 } |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
252 else |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
253 { |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
254 vspec = NULL; |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
255 vstr = dm_strdup(arg); |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
256 } |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
257 |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
258 // Parse spec if any |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
259 if (vspec != NULL) |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
260 { |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
261 BOOL vendianess = TRUE; |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
262 char *vtmp = vspec; |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
263 |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
264 // Get endianess specifier, if any |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
265 if (dm_strncasecmp(vtmp, "le", 2) == 0) |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
266 { |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
267 vendianess = TRUE; |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
268 vtmp += 2; |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
269 } |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
270 else |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
271 if (dm_strncasecmp(vtmp, "be", 2) == 0) |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
272 { |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
273 vendianess = FALSE; |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
274 vtmp += 2; |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
275 } |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
276 |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
277 // Get value bit size |
2045
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
278 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
|
279 { |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
280 vtype = DMGV_UINT8; |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
281 vtmp += 1; |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
282 } |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
283 else |
2045
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
284 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
|
285 { |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
286 vtype = vendianess ? DMGV_UINT16_LE : DMGV_UINT16_BE; |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
287 vtmp += 2; |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
288 } |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
289 else |
2045
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
290 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
|
291 { |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
292 vtype = vendianess ? DMGV_UINT32_LE : DMGV_UINT32_BE; |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
293 vtmp += 2; |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
294 } |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
295 else |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
296 { |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
297 ret = dmError(DMERR_INVALID_ARGS, |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
298 "Invalid grep type '%s'.\n", |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
299 vspec); |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
300 goto out; |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
301 } |
2045
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
302 |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
303 switch (tolower(*vtmp)) |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
304 { |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
305 case 'd': |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
306 vdisp = DMGS_DEC; |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
307 break; |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
308 |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
309 case 'x': case 'h': |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
310 vdisp = DMGS_HEX; |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
311 break; |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
312 |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
313 case 0: |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
314 break; |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
315 |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
316 default: |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
317 ret = dmError(DMERR_INVALID_ARGS, |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
318 "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
|
319 vspec); |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
320 goto out; |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
321 } |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
322 } |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
323 |
2225
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
324 // 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
|
325 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
|
326 nvalues = 0; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
327 do |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
328 { |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
329 if (nvalues >= 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
|
330 { |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
331 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
|
332 "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
|
333 vstr); |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
334 goto out; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
335 } |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
336 |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
337 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
|
338 { |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
339 *vsep = 0; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
340 more = TRUE; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
341 } |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
342 else |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
343 more = FALSE; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
344 |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
345 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
|
346 { |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
347 vwildcards[nvalues] = TRUE; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
348 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
|
349 { |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
350 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
|
351 "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
|
352 goto out; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
353 } |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
354 } |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
355 else |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
356 if (!dmGetIntVal(vtmp, &vvalues[nvalues], NULL)) |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
357 { |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
358 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
|
359 "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
|
360 vtmp); |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
361 goto out; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
362 } |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
363 |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
364 nvalues++; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
365 |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
366 if (more) |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
367 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
|
368 } while (more); |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
369 |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
370 if (vwildcards[0]) |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
371 { |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
372 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
|
373 "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
|
374 goto out; |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
375 } |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
376 |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
377 if (mode == FA_GREP) |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
378 { |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
379 // Check if we need to guess size |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
380 if (vtype < 0) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
381 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
382 for (int n = DMGV_last; n >= 0; n--) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
383 { |
2045
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
384 const DMGrepType *def = &dmGrepTypes[n]; |
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 (vvalues[0] <= def->nmax) |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
386 vtype = n; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
387 } |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
388 } |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
389 |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
390 if (vtype < 0) |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
391 { |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
392 ret = dmError(DMERR_INVALID_ARGS, |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
393 "Could not guess value type for '%s'.\n", |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
394 arg); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
395 goto out; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
396 } |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
397 |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
398 // Check range |
2225
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
399 for (int n = 0; n < nvalues; n++) |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
400 if (!vwildcards[n] && vvalues[n] > dmGrepTypes[vtype].nmax) |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
401 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
402 ret = dmError(DMERR_INVALID_ARGS, |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
403 "Integer value %d <= %d <= %d out of range for type %s.\n", |
2225
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
404 vvalues[n], 0, dmGrepTypes[vtype].nmax, dmGrepTypes[vtype].name); |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
405 |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
406 goto out; |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
407 } |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
408 } |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
409 else |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
410 if (mode == FA_OFFSET) |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
411 { |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
412 if (vtype < 0) |
2045
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
413 vtype = DMGV_UINT8; |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
414 } |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
415 |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
416 if (nsetGrepValues < SET_MAX_VALUES) |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
417 { |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
418 DMGrepValue *node = &setGrepValues[nsetGrepValues++]; |
2225
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
419 |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
420 node->type = vtype; |
2045
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
421 node->disp = vdisp; |
2225
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
422 node->nvalues = nvalues; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
423 memcpy(node->values, vvalues, sizeof(vvalues[0]) * nvalues); |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
424 memcpy(node->vwildcards, vwildcards, sizeof(vwildcards[0]) * nvalues); |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
425 |
2225
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
426 dmMsg(1, "Grep %ss : ", |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
427 dmGrepTypes[vtype].name); |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
428 |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
429 dmPrintGrepValueList(node, FALSE, NULL, 0); |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
430 } |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
431 else |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
432 { |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
433 ret = dmError(DMERR_BOUNDS, |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
434 "Too many values specified (max %d).", |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
435 SET_MAX_VALUES); |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
436 } |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
437 |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
438 out: |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
439 dmFree(vspec); |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
440 dmFree(vstr); |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
441 return ret; |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
442 } |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
443 |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
444 |
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
445 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
|
446 { |
1995
ea6337c873c6
Silence an unused function argument warning.
Matti Hamalainen <ccr@tnsp.org>
parents:
1685
diff
changeset
|
447 (void) optArg; |
ea6337c873c6
Silence an unused function argument warning.
Matti Hamalainen <ccr@tnsp.org>
parents:
1685
diff
changeset
|
448 |
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
449 switch (optN) |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
450 { |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
451 case 0: |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
452 argShowHelp(); |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
453 exit(0); |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
454 break; |
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
455 |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
456 case 1: |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
457 dmVerbosity++; |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
458 break; |
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
459 |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
460 case 2: |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
461 return argParseGrepValue(optArg, FA_GREP) == DMERR_OK; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
462 |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
463 case 3: |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
464 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
|
465 |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
466 default: |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
467 dmErrorMsg("Unknown argument '%s'.\n", currArg); |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
468 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
|
469 } |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
470 |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
471 return TRUE; |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
472 } |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
473 |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
474 |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
475 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
|
476 { |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
477 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
|
478 { |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
479 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
|
480 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
|
481 return TRUE; |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
482 } |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
483 else |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
484 { |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
485 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
|
486 SET_MAX_FILES); |
1996 | 487 return TRUE; |
488 } | |
489 } | |
490 | |
491 | |
492 void dmInitStats(DMStats *stats) | |
493 { | |
494 for (size_t n = 0; n < SET_MAX_ELEMS; n++) | |
495 { | |
496 stats->cv[n].count = 0; | |
497 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
|
498 } |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
499 } |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
500 |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
501 |
1996 | 502 int dmCompareStatFunc(const void *va, const void *vb) |
503 { | |
504 const DMStatValue *pa = va, *pb = vb; | |
505 return pb->count - pa->count; | |
506 } | |
507 | |
508 | |
509 void dmPrintStats(DMStats *stats, const int nmax, const size_t size) | |
510 { | |
2011 | 511 qsort(&stats->cv, SET_MAX_ELEMS, sizeof(DMStatValue), dmCompareStatFunc); |
512 | |
1996 | 513 for (int n = 0; n < nmax; n++) |
514 { | |
2011 | 515 printf("$%02x (%d = %1.2f%%), ", |
1996 | 516 stats->cv[n].value, |
2011 | 517 stats->cv[n].count, |
1996 | 518 ((float) stats->cv[n].count * 100.0f) / (float) size); |
519 } | |
520 printf("\n\n"); | |
521 } | |
1682
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 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
|
525 { |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
526 DMCompElem *compBuf = NULL; |
1996 | 527 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
|
528 int res; |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
529 |
2035 | 530 dmInitProg("fanalyze", "File format analyzer", "0.3", NULL, NULL); |
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
531 dmVerbosity = 1; |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
532 |
1996 | 533 dmInitStats(&totalStats); |
534 | |
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
535 // Parse arguments |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
536 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
|
537 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
|
538 exit(1); |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
539 |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
540 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
|
541 { |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
542 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
|
543 goto out; |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
544 } |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
545 |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
546 // 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
|
547 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
|
548 { |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
549 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
|
550 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
|
551 { |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
552 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
|
553 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
|
554 goto out; |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
555 } |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
556 |
1685
904904f145b4
Various fixes in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
1683
diff
changeset
|
557 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
|
558 nfile + 1, file->filename, file->size); |
904904f145b4
Various fixes in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
1683
diff
changeset
|
559 |
904904f145b4
Various fixes in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
1683
diff
changeset
|
560 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
|
561 compBufSize = file->size; |
1996 | 562 |
563 totalSize += file->size; | |
2011 | 564 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
|
565 } |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
566 |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
567 |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
568 // |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
569 // Check what operating mode we are in |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
570 // |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
571 if (setMode == FA_GREP) |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
572 { |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
573 for (int nfile = 0; nfile < nsrcFiles; nfile++) |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
574 { |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
575 DMSourceFile *file = &srcFiles[nfile]; |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
576 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
|
577 |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
578 for (int n = 0; n < nsetGrepValues; n++) |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
579 { |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
580 DMGrepValue *node = &setGrepValues[n]; |
2045
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
581 const DMGrepType *def = &dmGrepTypes[node->type]; |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
582 |
2225
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
583 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
|
584 { |
2225
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
585 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
|
586 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
|
587 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
|
588 { |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
589 Uint32 mval; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
590 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
|
591 |
2225
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
592 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
|
593 { |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
594 match = FALSE; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
595 break; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
596 } |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
597 } |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
598 |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
599 if (match) |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
600 { |
2225
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
601 dmPrint(0, "%08x : %s match ", |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
602 offs, def->name); |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
603 |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
604 dmPrintGrepValueList(node, TRUE, file, offs); |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
605 } |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
606 } |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
607 } |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
608 } |
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
609 } |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
610 else |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
611 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
|
612 { |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
613 for (int nfile = 0; nfile < nsrcFiles; nfile++) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
614 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
615 DMSourceFile *file = &srcFiles[nfile]; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
616 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
|
617 } |
1996 | 618 |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
619 printf(" offset :"); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
620 for (int nfile = 0; nfile < nsrcFiles; nfile++) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
621 printf(" %03d ", nfile + 1); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
622 printf("\n"); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
623 |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
624 printf("=========="); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
625 for (int nfile = 0; nfile < nsrcFiles; nfile++) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
626 printf("==========="); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
627 printf("\n"); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
628 |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
629 for (int n = 0; n < nsetGrepValues; n++) |
1996 | 630 { |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
631 DMGrepValue *node = &setGrepValues[n]; |
2045
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
632 const DMGrepType *def = &dmGrepTypes[node->type]; |
2225
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
633 printf("%08x : ", node->values[0]); |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
634 |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
635 for (int nfile = 0; nfile < nsrcFiles; nfile++) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
636 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
637 DMSourceFile *file = &srcFiles[nfile]; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
638 Uint32 mval; |
2042 | 639 char mstr[32]; |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
640 int npad, nwidth; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
641 |
2225
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
642 if (dmGetData(node->type, file, node->values[0], &mval)) |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
643 { |
2042 | 644 char mfmt[16]; |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
645 nwidth = def->bsize * 2; |
2045
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
646 snprintf(mfmt, sizeof(mfmt), "%%0%d%s", |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
647 nwidth, dmGrepDisp[node->disp].fmt); |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
648 |
2042 | 649 snprintf(mstr, sizeof(mstr), mfmt, mval); |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
650 } |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
651 else |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
652 { |
2042 | 653 strcpy(mstr, "----"); |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
654 nwidth = 4; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
655 } |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
656 |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
657 npad = (10 - nwidth) / 2; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
658 for (int q = 0; q < npad; q++) |
2042 | 659 fputc(' ', stdout); |
660 | |
661 fputs(mstr, stdout); | |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
662 |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
663 for (int q = 0; q < npad; q++) |
2042 | 664 fputc(' ', stdout); |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
665 } |
2045
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
666 |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
667 printf(" [%s]\n", |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
668 dmGrepDisp[node->disp].name); |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
669 } |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
670 } |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
671 else |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
672 if (setMode == FA_ANALYZE) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
673 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
674 // Allocate comparision buffer |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
675 // XXX: integer overflow? |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
676 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
|
677 compBufSize, compBufSize * sizeof(DMCompElem)); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
678 |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
679 if ((compBuf = dmCalloc(compBufSize, sizeof(DMCompElem))) == NULL) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
680 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
681 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
|
682 goto out; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
683 } |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
684 |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
685 // Begin analyzing .. |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
686 dmPrint(2, "Analyzing ..\n"); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
687 for (int nfile = 0; nfile < nsrcFiles; nfile++) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
688 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
689 DMSourceFile *file = &srcFiles[nfile]; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
690 |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
691 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
|
692 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
693 Uint8 bv = file->data[offs]; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
694 totalStats.cv[bv].count++; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
695 file->stats.cv[bv].count++; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
696 } |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
697 |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
698 for (size_t offs = 0; offs < compBufSize; offs++) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
699 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
700 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
|
701 compBuf[offs].stats[data]++; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
702 } |
1996 | 703 } |
704 | |
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
705 for (size_t offs = 0; offs < compBufSize; offs++) |
1685
904904f145b4
Various fixes in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
1683
diff
changeset
|
706 { |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
707 DMCompElem *el = &compBuf[offs]; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
708 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
|
709 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
710 if (el->stats[n] > 0) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
711 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
712 el->variants++; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
713 el->data = n; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
714 } |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
715 } |
1685
904904f145b4
Various fixes in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
1683
diff
changeset
|
716 } |
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 // Display results |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
719 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
|
720 { |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
721 DMCompElem *el = &compBuf[offs]; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
722 BOOL var = el->variants > 1; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
723 |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
724 if (n == 0) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
725 printf("%08" DM_PRIx_SIZE_T " | ", offs); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
726 |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
727 if (var) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
728 printf("[%2d] ", el->variants); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
729 else |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
730 printf(" %02x ", el->data); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
731 |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
732 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
|
733 { |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
734 printf("\n"); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
735 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
|
736 } |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
737 } |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
738 |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
739 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
|
740 |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
741 // Attempt further analysis |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
742 for (int nfile = 0; nfile < nsrcFiles; nfile++) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
743 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
744 DMSourceFile *file = &srcFiles[nfile]; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
745 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
|
746 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
|
747 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
748 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
|
749 |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
750 for (int variant = 3; variant >= 0; variant--) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
751 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
752 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
|
753 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
|
754 |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
755 for (size_t n = 0; n < nmax; n++) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
756 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
757 size_t boffs = (variant & 1) ? n : nmax - n; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
758 |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
759 tmp <<= 8; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
760 tmp |= file->data[offs + boffs]; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
761 } |
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
762 |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
763 if (file->size - tmp < 32) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
764 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
765 elem->interest[variant] += 32 - (file->size - tmp); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
766 elem->interestF[variant]++; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
767 } |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
768 } |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
769 } |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
770 } |
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
771 |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
772 printf("\nMore findings:\n"); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
773 for (size_t offs = 0; offs + 4 < compBufSize; offs++) |
1996 | 774 { |
775 DMCompElem *elem = &compBuf[offs]; | |
776 | |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
777 for (int variant = 0; variant < 4; variant++) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
778 if (elem->interestF[variant] > 0) |
1996 | 779 { |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
780 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
|
781 offs, variant, |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
782 elem->interestF[variant], elem->interest[variant]); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
783 } |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
784 } |
1996 | 785 |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
786 printf("\nGlobal most used bytes:\n"); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
787 dmPrintStats(&totalStats, 16, totalSize); |
1996 | 788 |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
789 for (int nfile = 0; nfile < nsrcFiles; nfile++) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
790 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
791 DMSourceFile *file = &srcFiles[nfile]; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
792 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
|
793 dmPrintStats(&file->stats, 16, file->size); |
1996 | 794 } |
795 } | |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
796 else |
1996 | 797 { |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
798 dmErrorMsg("Invalid operating mode?\n"); |
1996 | 799 } |
800 | |
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
801 out: |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
802 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
|
803 { |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
804 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
|
805 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
|
806 } |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
807 |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
808 return 0; |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
809 } |