Mercurial > hg > dmlib
annotate tools/fanalyze.c @ 2228:02d17784fdef
Variables -> struct cleanup.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 14 Jun 2019 18:33:10 +0300 |
parents | 837c79747ea4 |
children | 72e15cc14927 |
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; |
2228
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
232 DMGrepValue val; |
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
233 int ret = DMERR_OK; |
2225
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
234 BOOL more; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
235 |
2228
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
236 memset(&val, 0, sizeof(val)); |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
237 |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
238 if (setMode != FA_ANALYZE && setMode != mode) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
239 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
240 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
|
241 return DMERR_INVALID_ARGS; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
242 } |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
243 setMode = mode; |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
244 |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
245 // 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
|
246 if (specsep != NULL) |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
247 { |
2225
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
248 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
|
249 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
|
250 } |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
251 else |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
252 { |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
253 vspec = NULL; |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
254 vstr = dm_strdup(arg); |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
255 } |
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 // Parse spec if any |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
258 if (vspec != NULL) |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
259 { |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
260 BOOL vendianess = TRUE; |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
261 char *vtmp = vspec; |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
262 |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
263 // Get endianess specifier, if any |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
264 if (dm_strncasecmp(vtmp, "le", 2) == 0) |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
265 { |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
266 vendianess = TRUE; |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
267 vtmp += 2; |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
268 } |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
269 else |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
270 if (dm_strncasecmp(vtmp, "be", 2) == 0) |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
271 { |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
272 vendianess = FALSE; |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
273 vtmp += 2; |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
274 } |
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 // Get value bit size |
2045
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
277 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
|
278 { |
2228
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
279 val.type = DMGV_UINT8; |
2045
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
280 vtmp += 1; |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
281 } |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
282 else |
2045
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
283 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
|
284 { |
2228
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
285 val.type = vendianess ? DMGV_UINT16_LE : DMGV_UINT16_BE; |
2045
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
286 vtmp += 2; |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
287 } |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
288 else |
2045
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
289 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
|
290 { |
2228
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
291 val.type = vendianess ? DMGV_UINT32_LE : DMGV_UINT32_BE; |
2045
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
292 vtmp += 2; |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
293 } |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
294 else |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
295 { |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
296 ret = dmError(DMERR_INVALID_ARGS, |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
297 "Invalid grep type '%s'.\n", |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
298 vspec); |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
299 goto out; |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
300 } |
2045
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
301 |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
302 switch (tolower(*vtmp)) |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
303 { |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
304 case 'd': |
2228
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
305 val.disp = DMGS_DEC; |
2045
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
306 break; |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
307 |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
308 case 'x': case 'h': |
2228
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
309 val.disp = DMGS_HEX; |
2045
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
310 break; |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
311 |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
312 case 0: |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
313 break; |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
314 |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
315 default: |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
316 ret = dmError(DMERR_INVALID_ARGS, |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
317 "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
|
318 vspec); |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
319 goto out; |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
320 } |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
321 } |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
322 |
2225
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
323 // 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
|
324 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
|
325 do |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
326 { |
2228
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
327 if (val.nvalues >= SET_MAX_GREPLIST) |
2225
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
328 { |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
329 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
|
330 "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
|
331 vstr); |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
332 goto out; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
333 } |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
334 |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
335 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
|
336 { |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
337 *vsep = 0; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
338 more = TRUE; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
339 } |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
340 else |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
341 more = FALSE; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
342 |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
343 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
|
344 { |
2228
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
345 val.vwildcards[val.nvalues] = TRUE; |
2225
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
346 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
|
347 { |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
348 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
|
349 "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
|
350 goto out; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
351 } |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
352 } |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
353 else |
2228
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
354 if (!dmGetIntVal(vtmp, &val.values[val.nvalues], NULL)) |
2225
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
355 { |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
356 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
|
357 "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
|
358 vtmp); |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
359 goto out; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
360 } |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
361 |
2228
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
362 val.nvalues++; |
2225
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
363 |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
364 if (more) |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
365 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
|
366 } while (more); |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
367 |
2228
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
368 if (val.vwildcards[0]) |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
369 { |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
370 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
|
371 "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
|
372 goto out; |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
373 } |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
374 |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
375 if (mode == FA_GREP) |
2028
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 // Check if we need to guess size |
2228
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
378 if (val.type < 0) |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
379 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
380 for (int n = DMGV_last; n >= 0; n--) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
381 { |
2045
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
382 const DMGrepType *def = &dmGrepTypes[n]; |
2228
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
383 if (val.values[0] <= def->nmax) |
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
384 val.type = n; |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
385 } |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
386 } |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
387 |
2228
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
388 if (val.type < 0) |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
389 { |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
390 ret = dmError(DMERR_INVALID_ARGS, |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
391 "Could not guess value type for '%s'.\n", |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
392 arg); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
393 goto out; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
394 } |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
395 |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
396 // Check range |
2228
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
397 for (int n = 0; n < val.nvalues; n++) |
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
398 if (!val.vwildcards[n] && val.values[n] > dmGrepTypes[val.type].nmax) |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
399 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
400 ret = dmError(DMERR_INVALID_ARGS, |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
401 "Integer value %d <= %d <= %d out of range for type %s.\n", |
2228
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
402 val.values[n], 0, dmGrepTypes[val.type].nmax, |
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
403 dmGrepTypes[val.type].name); |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
404 |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
405 goto out; |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
406 } |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
407 } |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
408 else |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
409 if (mode == FA_OFFSET) |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
410 { |
2228
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
411 if (val.type < 0) |
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
412 val.type = DMGV_UINT8; |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
413 } |
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 if (nsetGrepValues < SET_MAX_VALUES) |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
416 { |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
417 DMGrepValue *node = &setGrepValues[nsetGrepValues++]; |
2228
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
418 memcpy(node, &val, sizeof(val)); |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
419 |
2225
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
420 dmMsg(1, "Grep %ss : ", |
2228
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
421 dmGrepTypes[val.type].name); |
2225
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
422 |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
423 dmPrintGrepValueList(node, FALSE, NULL, 0); |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
424 } |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
425 else |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
426 { |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
427 ret = dmError(DMERR_BOUNDS, |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
428 "Too many values specified (max %d).", |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
429 SET_MAX_VALUES); |
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 |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
432 out: |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
433 dmFree(vspec); |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
434 dmFree(vstr); |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
435 return ret; |
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 |
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
439 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
|
440 { |
1995
ea6337c873c6
Silence an unused function argument warning.
Matti Hamalainen <ccr@tnsp.org>
parents:
1685
diff
changeset
|
441 (void) optArg; |
ea6337c873c6
Silence an unused function argument warning.
Matti Hamalainen <ccr@tnsp.org>
parents:
1685
diff
changeset
|
442 |
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
443 switch (optN) |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
444 { |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
445 case 0: |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
446 argShowHelp(); |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
447 exit(0); |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
448 break; |
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
449 |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
450 case 1: |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
451 dmVerbosity++; |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
452 break; |
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
453 |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
454 case 2: |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
455 return argParseGrepValue(optArg, FA_GREP) == DMERR_OK; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
456 |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
457 case 3: |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
458 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
|
459 |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
460 default: |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
461 dmErrorMsg("Unknown argument '%s'.\n", currArg); |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
462 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
|
463 } |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
464 |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
465 return TRUE; |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
466 } |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
467 |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
468 |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
469 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
|
470 { |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
471 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
|
472 { |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
473 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
|
474 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
|
475 return TRUE; |
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 else |
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 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
|
480 SET_MAX_FILES); |
1996 | 481 return TRUE; |
482 } | |
483 } | |
484 | |
485 | |
486 void dmInitStats(DMStats *stats) | |
487 { | |
488 for (size_t n = 0; n < SET_MAX_ELEMS; n++) | |
489 { | |
490 stats->cv[n].count = 0; | |
491 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
|
492 } |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
493 } |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
494 |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
495 |
1996 | 496 int dmCompareStatFunc(const void *va, const void *vb) |
497 { | |
498 const DMStatValue *pa = va, *pb = vb; | |
499 return pb->count - pa->count; | |
500 } | |
501 | |
502 | |
503 void dmPrintStats(DMStats *stats, const int nmax, const size_t size) | |
504 { | |
2011 | 505 qsort(&stats->cv, SET_MAX_ELEMS, sizeof(DMStatValue), dmCompareStatFunc); |
506 | |
1996 | 507 for (int n = 0; n < nmax; n++) |
508 { | |
2011 | 509 printf("$%02x (%d = %1.2f%%), ", |
1996 | 510 stats->cv[n].value, |
2011 | 511 stats->cv[n].count, |
1996 | 512 ((float) stats->cv[n].count * 100.0f) / (float) size); |
513 } | |
514 printf("\n\n"); | |
515 } | |
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
516 |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
517 |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
518 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
|
519 { |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
520 DMCompElem *compBuf = NULL; |
1996 | 521 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
|
522 int res; |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
523 |
2035 | 524 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
|
525 dmVerbosity = 1; |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
526 |
1996 | 527 dmInitStats(&totalStats); |
528 | |
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
529 // Parse arguments |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
530 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
|
531 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
|
532 exit(1); |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
533 |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
534 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
|
535 { |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
536 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
|
537 goto out; |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
538 } |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
539 |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
540 // 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
|
541 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
|
542 { |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
543 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
|
544 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
|
545 { |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
546 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
|
547 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
|
548 goto out; |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
549 } |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
550 |
1685
904904f145b4
Various fixes in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
1683
diff
changeset
|
551 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
|
552 nfile + 1, file->filename, file->size); |
904904f145b4
Various fixes in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
1683
diff
changeset
|
553 |
904904f145b4
Various fixes in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
1683
diff
changeset
|
554 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
|
555 compBufSize = file->size; |
1996 | 556 |
557 totalSize += file->size; | |
2011 | 558 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
|
559 } |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
560 |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
561 |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
562 // |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
563 // Check what operating mode we are in |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
564 // |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
565 if (setMode == FA_GREP) |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
566 { |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
567 for (int nfile = 0; nfile < nsrcFiles; nfile++) |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
568 { |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
569 DMSourceFile *file = &srcFiles[nfile]; |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
570 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
|
571 |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
572 for (int n = 0; n < nsetGrepValues; n++) |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
573 { |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
574 DMGrepValue *node = &setGrepValues[n]; |
2045
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
575 const DMGrepType *def = &dmGrepTypes[node->type]; |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
576 |
2225
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
577 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
|
578 { |
2225
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
579 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
|
580 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
|
581 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
|
582 { |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
583 Uint32 mval; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
584 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
|
585 |
2225
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
586 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
|
587 { |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
588 match = FALSE; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
589 break; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
590 } |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
591 } |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
592 |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
593 if (match) |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
594 { |
2225
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
595 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
|
596 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
|
597 |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
598 dmPrintGrepValueList(node, TRUE, file, offs); |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
599 } |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
600 } |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
601 } |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
602 } |
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
603 } |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
604 else |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
605 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
|
606 { |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
607 for (int nfile = 0; nfile < nsrcFiles; nfile++) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
608 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
609 DMSourceFile *file = &srcFiles[nfile]; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
610 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
|
611 } |
1996 | 612 |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
613 printf(" offset :"); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
614 for (int nfile = 0; nfile < nsrcFiles; nfile++) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
615 printf(" %03d ", nfile + 1); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
616 printf("\n"); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
617 |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
618 printf("=========="); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
619 for (int nfile = 0; nfile < nsrcFiles; nfile++) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
620 printf("==========="); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
621 printf("\n"); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
622 |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
623 for (int n = 0; n < nsetGrepValues; n++) |
1996 | 624 { |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
625 DMGrepValue *node = &setGrepValues[n]; |
2045
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
626 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
|
627 printf("%08x : ", node->values[0]); |
2034
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 nfile = 0; nfile < nsrcFiles; nfile++) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
630 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
631 DMSourceFile *file = &srcFiles[nfile]; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
632 Uint32 mval; |
2042 | 633 char mstr[32]; |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
634 int npad, nwidth; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
635 |
2225
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
636 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
|
637 { |
2042 | 638 char mfmt[16]; |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
639 nwidth = def->bsize * 2; |
2045
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
640 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
|
641 nwidth, dmGrepDisp[node->disp].fmt); |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
642 |
2042 | 643 snprintf(mstr, sizeof(mstr), mfmt, mval); |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
644 } |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
645 else |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
646 { |
2042 | 647 strcpy(mstr, "----"); |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
648 nwidth = 4; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
649 } |
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 npad = (10 - nwidth) / 2; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
652 for (int q = 0; q < npad; q++) |
2042 | 653 fputc(' ', stdout); |
654 | |
655 fputs(mstr, stdout); | |
2034
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 for (int q = 0; q < npad; q++) |
2042 | 658 fputc(' ', stdout); |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
659 } |
2045
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
660 |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
661 printf(" [%s]\n", |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
662 dmGrepDisp[node->disp].name); |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
663 } |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
664 } |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
665 else |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
666 if (setMode == FA_ANALYZE) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
667 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
668 // Allocate comparision buffer |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
669 // XXX: integer overflow? |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
670 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
|
671 compBufSize, compBufSize * sizeof(DMCompElem)); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
672 |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
673 if ((compBuf = dmCalloc(compBufSize, sizeof(DMCompElem))) == NULL) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
674 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
675 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
|
676 goto out; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
677 } |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
678 |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
679 // Begin analyzing .. |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
680 dmPrint(2, "Analyzing ..\n"); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
681 for (int nfile = 0; nfile < nsrcFiles; nfile++) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
682 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
683 DMSourceFile *file = &srcFiles[nfile]; |
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 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
|
686 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
687 Uint8 bv = file->data[offs]; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
688 totalStats.cv[bv].count++; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
689 file->stats.cv[bv].count++; |
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 |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
692 for (size_t offs = 0; offs < compBufSize; offs++) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
693 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
694 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
|
695 compBuf[offs].stats[data]++; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
696 } |
1996 | 697 } |
698 | |
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
699 for (size_t offs = 0; offs < compBufSize; offs++) |
1685
904904f145b4
Various fixes in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
1683
diff
changeset
|
700 { |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
701 DMCompElem *el = &compBuf[offs]; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
702 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
|
703 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
704 if (el->stats[n] > 0) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
705 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
706 el->variants++; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
707 el->data = n; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
708 } |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
709 } |
1685
904904f145b4
Various fixes in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
1683
diff
changeset
|
710 } |
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
711 |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
712 // Display results |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
713 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
|
714 { |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
715 DMCompElem *el = &compBuf[offs]; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
716 BOOL var = el->variants > 1; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
717 |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
718 if (n == 0) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
719 printf("%08" DM_PRIx_SIZE_T " | ", offs); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
720 |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
721 if (var) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
722 printf("[%2d] ", el->variants); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
723 else |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
724 printf(" %02x ", el->data); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
725 |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
726 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
|
727 { |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
728 printf("\n"); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
729 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
|
730 } |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
731 } |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
732 |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
733 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
|
734 |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
735 // Attempt further analysis |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
736 for (int nfile = 0; nfile < nsrcFiles; nfile++) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
737 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
738 DMSourceFile *file = &srcFiles[nfile]; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
739 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
|
740 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
|
741 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
742 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
|
743 |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
744 for (int variant = 3; variant >= 0; variant--) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
745 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
746 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
|
747 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
|
748 |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
749 for (size_t n = 0; n < nmax; n++) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
750 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
751 size_t boffs = (variant & 1) ? n : nmax - n; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
752 |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
753 tmp <<= 8; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
754 tmp |= file->data[offs + boffs]; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
755 } |
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
756 |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
757 if (file->size - tmp < 32) |
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 elem->interest[variant] += 32 - (file->size - tmp); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
760 elem->interestF[variant]++; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
761 } |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
762 } |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
763 } |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
764 } |
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
765 |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
766 printf("\nMore findings:\n"); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
767 for (size_t offs = 0; offs + 4 < compBufSize; offs++) |
1996 | 768 { |
769 DMCompElem *elem = &compBuf[offs]; | |
770 | |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
771 for (int variant = 0; variant < 4; variant++) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
772 if (elem->interestF[variant] > 0) |
1996 | 773 { |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
774 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
|
775 offs, variant, |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
776 elem->interestF[variant], elem->interest[variant]); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
777 } |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
778 } |
1996 | 779 |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
780 printf("\nGlobal most used bytes:\n"); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
781 dmPrintStats(&totalStats, 16, totalSize); |
1996 | 782 |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
783 for (int nfile = 0; nfile < nsrcFiles; nfile++) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
784 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
785 DMSourceFile *file = &srcFiles[nfile]; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
786 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
|
787 dmPrintStats(&file->stats, 16, file->size); |
1996 | 788 } |
789 } | |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
790 else |
1996 | 791 { |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
792 dmErrorMsg("Invalid operating mode?\n"); |
1996 | 793 } |
794 | |
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
795 out: |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
796 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
|
797 { |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
798 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
|
799 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
|
800 } |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
801 |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
802 return 0; |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
803 } |