Mercurial > hg > dmlib
annotate tools/fanalyze.c @ 2229:72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Also improve the readability of the output.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 14 Jun 2019 18:39:59 +0300 |
parents | 02d17784fdef |
children | ba639902d57c |
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; |
2229
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
103 char *fmtPrefix; |
2045
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
104 char *fmt; |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
105 } DMGrepDisp; |
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 |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
108 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
|
109 { |
2229
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
110 { "hex", "0", "x" }, |
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
111 { "dec", "" , "d" }, |
2045
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
112 }; |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
113 |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
114 enum |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
115 { |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
116 FA_ANALYZE, |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
117 FA_GREP, |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
118 FA_OFFSET, |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
119 }; |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
120 |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
121 |
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
122 /* Global variables |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
123 */ |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
124 int setMode = FA_ANALYZE; |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
125 int nsrcFiles = 0; // Number of source files |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
126 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
|
127 DMStats totalStats; |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
128 int nsetGrepValues = 0; |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
129 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
|
130 |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
131 |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
132 /* Arguments |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
133 */ |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
134 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
|
135 { |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
136 { 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
|
137 { 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
|
138 { 2, 'g', "grep", "Binary grep <val>[,<val2>...][:<le|be>[8|16|32]]", OPT_ARGREQ }, |
2229
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
139 { 3, 'o', "offset", "Show data in offset <offs>[,<offs2>...][:<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
|
140 }; |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
141 |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
142 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
|
143 |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
144 |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
145 void argShowHelp() |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
146 { |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
147 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
|
148 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
|
149 |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
150 fprintf(stdout, |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
151 "\n" |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
152 "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
|
153 "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
|
154 "-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
|
155 "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
|
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 |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
160 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
|
161 { |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
162 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
|
163 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
|
164 { |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
165 *mval = 0; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
166 return FALSE; |
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 |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
169 switch (type) |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
170 { |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
171 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
|
172 *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
|
173 break; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
174 |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
175 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
|
176 *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
|
177 break; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
178 |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
179 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
|
180 *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
|
181 break; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
182 |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
183 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
|
184 *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
|
185 break; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
186 |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
187 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
|
188 *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
|
189 break; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
190 |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
191 default: |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
192 *mval = 0; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
193 return FALSE; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
194 } |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
195 return TRUE; |
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 |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
199 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
|
200 { |
2229
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
201 char mfmt[16]; |
2225
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
202 |
2229
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
203 snprintf(mfmt, sizeof(mfmt), "%%%s%d%s%%s", |
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
204 dmGrepDisp[node->disp].fmtPrefix, |
2225
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
205 dmGrepTypes[node->type].bsize * 2, |
2229
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
206 dmGrepDisp[node->disp].fmt); |
2225
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
207 |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
208 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
|
209 { |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
210 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
|
211 |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
212 if (match) |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
213 { |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
214 Uint32 mval; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
215 dmGetData(node->type, file, offs + n, &mval); |
2229
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
216 dmPrint(1, mfmt, mval, veol); |
2225
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
217 } |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
218 else |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
219 { |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
220 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
|
221 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
|
222 else |
2229
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
223 dmPrint(1, mfmt, node->values[n], veol); |
2225
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
224 } |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
225 } |
1682
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 |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
228 |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
229 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
|
230 { |
2225
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
231 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
|
232 char *vspec, *vstr, *vsep; |
2228
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
233 DMGrepValue val; |
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
234 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
|
235 BOOL more; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
236 |
2228
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
237 memset(&val, 0, sizeof(val)); |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
238 |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
239 if (setMode != FA_ANALYZE && setMode != mode) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
240 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
241 dmErrorMsg("Options specifying multiple operating modes can't be used.\n"); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
242 return DMERR_INVALID_ARGS; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
243 } |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
244 setMode = mode; |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
245 |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
246 // Do we have spec? |
2225
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
247 if (specsep != NULL) |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
248 { |
2225
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
249 vspec = dm_strdup_trim(specsep + 1, DM_TRIM_BOTH); |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
250 vstr = dm_strndup_trim(arg, specsep - arg, DM_TRIM_BOTH); |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
251 } |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
252 else |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
253 { |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
254 vspec = NULL; |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
255 vstr = dm_strdup(arg); |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
256 } |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
257 |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
258 // Parse spec if any |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
259 if (vspec != NULL) |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
260 { |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
261 BOOL vendianess = TRUE; |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
262 char *vtmp = vspec; |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
263 |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
264 // Get endianess specifier, if any |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
265 if (dm_strncasecmp(vtmp, "le", 2) == 0) |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
266 { |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
267 vendianess = TRUE; |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
268 vtmp += 2; |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
269 } |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
270 else |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
271 if (dm_strncasecmp(vtmp, "be", 2) == 0) |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
272 { |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
273 vendianess = FALSE; |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
274 vtmp += 2; |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
275 } |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
276 |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
277 // Get value bit size |
2045
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
278 if (strncmp(vtmp, "8", 1) == 0) |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
279 { |
2228
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
280 val.type = DMGV_UINT8; |
2045
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
281 vtmp += 1; |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
282 } |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
283 else |
2045
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
284 if (strncmp(vtmp, "16", 2) == 0) |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
285 { |
2228
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
286 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
|
287 vtmp += 2; |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
288 } |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
289 else |
2045
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
290 if (strncmp(vtmp, "32", 2) == 0) |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
291 { |
2228
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
292 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
|
293 vtmp += 2; |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
294 } |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
295 else |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
296 { |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
297 ret = dmError(DMERR_INVALID_ARGS, |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
298 "Invalid grep type '%s'.\n", |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
299 vspec); |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
300 goto out; |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
301 } |
2045
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
302 |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
303 switch (tolower(*vtmp)) |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
304 { |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
305 case 'd': |
2228
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
306 val.disp = DMGS_DEC; |
2045
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
307 break; |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
308 |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
309 case 'x': case 'h': |
2228
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
310 val.disp = DMGS_HEX; |
2045
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
311 break; |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
312 |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
313 case 0: |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
314 break; |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
315 |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
316 default: |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
317 ret = dmError(DMERR_INVALID_ARGS, |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
318 "Invalid grep view type '%s'.\n", |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
319 vspec); |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
320 goto out; |
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
321 } |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
322 } |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
323 |
2225
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
324 // Get list of values |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
325 char *vtmp = vstr; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
326 do |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
327 { |
2228
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
328 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
|
329 { |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
330 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
|
331 "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
|
332 vstr); |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
333 goto out; |
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 |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
336 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
|
337 { |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
338 *vsep = 0; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
339 more = TRUE; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
340 } |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
341 else |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
342 more = FALSE; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
343 |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
344 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
|
345 { |
2228
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
346 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
|
347 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
|
348 { |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
349 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
|
350 "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
|
351 goto out; |
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 } |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
354 else |
2228
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
355 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
|
356 { |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
357 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
|
358 "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
|
359 vtmp); |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
360 goto out; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
361 } |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
362 |
2228
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
363 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
|
364 |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
365 if (more) |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
366 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
|
367 } while (more); |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
368 |
2228
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
369 if (val.vwildcards[0]) |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
370 { |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
371 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
|
372 "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
|
373 goto out; |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
374 } |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
375 |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
376 if (mode == FA_GREP) |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
377 { |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
378 // Check if we need to guess size |
2228
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
379 if (val.type < 0) |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
380 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
381 for (int n = DMGV_last; n >= 0; n--) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
382 { |
2045
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
383 const DMGrepType *def = &dmGrepTypes[n]; |
2228
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
384 if (val.values[0] <= def->nmax) |
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
385 val.type = n; |
2034
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 } |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
388 |
2228
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
389 if (val.type < 0) |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
390 { |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
391 ret = dmError(DMERR_INVALID_ARGS, |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
392 "Could not guess value type for '%s'.\n", |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
393 arg); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
394 goto out; |
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 |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
397 // Check range |
2228
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
398 for (int n = 0; n < val.nvalues; n++) |
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
399 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
|
400 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
401 ret = dmError(DMERR_INVALID_ARGS, |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
402 "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
|
403 val.values[n], 0, dmGrepTypes[val.type].nmax, |
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
404 dmGrepTypes[val.type].name); |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
405 |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
406 goto out; |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
407 } |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
408 } |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
409 else |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
410 if (mode == FA_OFFSET) |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
411 { |
2228
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
412 if (val.type < 0) |
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
413 val.type = DMGV_UINT8; |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
414 } |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
415 |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
416 if (nsetGrepValues < SET_MAX_VALUES) |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
417 { |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
418 DMGrepValue *node = &setGrepValues[nsetGrepValues++]; |
2228
02d17784fdef
Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
2225
diff
changeset
|
419 memcpy(node, &val, sizeof(val)); |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
420 |
2229
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
421 if (mode == FA_GREP) |
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
422 { |
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
423 dmPrint(1, "Grep %s: ", |
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
424 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
|
425 |
2229
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
426 dmPrintGrepValueList(node, FALSE, NULL, 0); |
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
427 } |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
428 } |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
429 else |
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 ret = dmError(DMERR_BOUNDS, |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
432 "Too many values specified (max %d).", |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
433 SET_MAX_VALUES); |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
434 } |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
435 |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
436 out: |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
437 dmFree(vspec); |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
438 dmFree(vstr); |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
439 return ret; |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
440 } |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
441 |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
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 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
|
444 { |
1995
ea6337c873c6
Silence an unused function argument warning.
Matti Hamalainen <ccr@tnsp.org>
parents:
1685
diff
changeset
|
445 (void) optArg; |
ea6337c873c6
Silence an unused function argument warning.
Matti Hamalainen <ccr@tnsp.org>
parents:
1685
diff
changeset
|
446 |
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
447 switch (optN) |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
448 { |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
449 case 0: |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
450 argShowHelp(); |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
451 exit(0); |
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 1: |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
455 dmVerbosity++; |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
456 break; |
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
457 |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
458 case 2: |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
459 return argParseGrepValue(optArg, FA_GREP) == DMERR_OK; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
460 |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
461 case 3: |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
462 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
|
463 |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
464 default: |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
465 dmErrorMsg("Unknown argument '%s'.\n", currArg); |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
466 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
|
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 return TRUE; |
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 |
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 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
|
474 { |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
475 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
|
476 { |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
477 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
|
478 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
|
479 return TRUE; |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
480 } |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
481 else |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
482 { |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
483 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
|
484 SET_MAX_FILES); |
1996 | 485 return TRUE; |
486 } | |
487 } | |
488 | |
489 | |
490 void dmInitStats(DMStats *stats) | |
491 { | |
492 for (size_t n = 0; n < SET_MAX_ELEMS; n++) | |
493 { | |
494 stats->cv[n].count = 0; | |
495 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
|
496 } |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
497 } |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
498 |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
499 |
1996 | 500 int dmCompareStatFunc(const void *va, const void *vb) |
501 { | |
502 const DMStatValue *pa = va, *pb = vb; | |
503 return pb->count - pa->count; | |
504 } | |
505 | |
506 | |
507 void dmPrintStats(DMStats *stats, const int nmax, const size_t size) | |
508 { | |
2011 | 509 qsort(&stats->cv, SET_MAX_ELEMS, sizeof(DMStatValue), dmCompareStatFunc); |
510 | |
1996 | 511 for (int n = 0; n < nmax; n++) |
512 { | |
2011 | 513 printf("$%02x (%d = %1.2f%%), ", |
1996 | 514 stats->cv[n].value, |
2011 | 515 stats->cv[n].count, |
1996 | 516 ((float) stats->cv[n].count * 100.0f) / (float) size); |
517 } | |
518 printf("\n\n"); | |
519 } | |
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
520 |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
521 |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
522 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
|
523 { |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
524 DMCompElem *compBuf = NULL; |
1996 | 525 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
|
526 int res; |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
527 |
2035 | 528 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
|
529 dmVerbosity = 1; |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
530 |
1996 | 531 dmInitStats(&totalStats); |
532 | |
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
533 // Parse arguments |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
534 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
|
535 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
|
536 exit(1); |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
537 |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
538 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
|
539 { |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
540 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
|
541 goto out; |
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 |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
544 // 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
|
545 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
|
546 { |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
547 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
|
548 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
|
549 { |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
550 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
|
551 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
|
552 goto out; |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
553 } |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
554 |
1685
904904f145b4
Various fixes in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
1683
diff
changeset
|
555 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
|
556 nfile + 1, file->filename, file->size); |
904904f145b4
Various fixes in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
1683
diff
changeset
|
557 |
904904f145b4
Various fixes in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
1683
diff
changeset
|
558 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
|
559 compBufSize = file->size; |
1996 | 560 |
561 totalSize += file->size; | |
2011 | 562 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
|
563 } |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
564 |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
565 |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
566 // |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
567 // Check what operating mode we are in |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
568 // |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
569 if (setMode == FA_GREP) |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
570 { |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
571 for (int nfile = 0; nfile < nsrcFiles; nfile++) |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
572 { |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
573 DMSourceFile *file = &srcFiles[nfile]; |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
574 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
|
575 |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
576 for (int n = 0; n < nsetGrepValues; n++) |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
577 { |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
578 DMGrepValue *node = &setGrepValues[n]; |
2045
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
579 const DMGrepType *def = &dmGrepTypes[node->type]; |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
580 |
2225
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
581 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
|
582 { |
2225
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
583 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
|
584 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
|
585 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
|
586 { |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
587 Uint32 mval; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
588 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
|
589 |
2225
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
590 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
|
591 { |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
592 match = FALSE; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
593 break; |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
594 } |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
595 } |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
596 |
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
597 if (match) |
2028
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
598 { |
2229
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
599 dmPrint(0, "%08x : ", offs); |
2225
837c79747ea4
Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents:
2045
diff
changeset
|
600 dmPrintGrepValueList(node, TRUE, file, offs); |
2028
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 } |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
603 } |
8a9ef75fd3cd
Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2011
diff
changeset
|
604 } |
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
605 } |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
606 else |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
607 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
|
608 { |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
609 for (int nfile = 0; nfile < nsrcFiles; nfile++) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
610 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
611 DMSourceFile *file = &srcFiles[nfile]; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
612 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
|
613 } |
1996 | 614 |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
615 printf(" offset :"); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
616 for (int nfile = 0; nfile < nsrcFiles; nfile++) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
617 printf(" %03d ", nfile + 1); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
618 printf("\n"); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
619 |
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 for (int nfile = 0; nfile < nsrcFiles; nfile++) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
622 printf("==========="); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
623 printf("\n"); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
624 |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
625 for (int n = 0; n < nsetGrepValues; n++) |
1996 | 626 { |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
627 DMGrepValue *node = &setGrepValues[n]; |
2045
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
628 const DMGrepType *def = &dmGrepTypes[node->type]; |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
629 |
2229
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
630 for (int nv = 0; nv < node->nvalues; nv++) |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
631 { |
2229
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
632 printf("%08x : ", node->values[nv]); |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
633 |
2229
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
634 for (int nfile = 0; nfile < nsrcFiles; nfile++) |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
635 { |
2229
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
636 DMSourceFile *file = &srcFiles[nfile]; |
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
637 Uint32 mval; |
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
638 char mstr[32]; |
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
639 int npad, nwidth; |
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
640 |
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
641 if (dmGetData(node->type, file, node->values[nv], &mval)) |
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
642 { |
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
643 char mfmt[16]; |
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
644 nwidth = def->bsize * 2; |
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
645 snprintf(mfmt, sizeof(mfmt), "%%0%d%s", |
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
646 nwidth, dmGrepDisp[node->disp].fmt); |
2045
1662730053d0
Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
647 |
2229
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
648 snprintf(mstr, sizeof(mstr), mfmt, mval); |
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
649 } |
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
650 else |
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
651 { |
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
652 strcpy(mstr, "----"); |
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
653 nwidth = 4; |
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
654 } |
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
655 |
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
656 npad = (10 - nwidth) / 2; |
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
657 for (int q = 0; q < npad; q++) |
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
658 fputc(' ', stdout); |
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
659 |
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
660 fputs(mstr, stdout); |
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
661 |
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
662 for (int q = 0; q < npad; q++) |
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
663 fputc(' ', stdout); |
2034
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 |
2229
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
666 printf(" [%s]\n", |
72e15cc14927
Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents:
2228
diff
changeset
|
667 dmGrepDisp[node->disp].name); |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
668 } |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
669 } |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
670 } |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
671 else |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
672 if (setMode == FA_ANALYZE) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
673 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
674 // Allocate comparision buffer |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
675 // XXX: integer overflow? |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
676 dmPrint(2, "Allocating %d element (%d bytes) comparision buffer.\n", |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
677 compBufSize, compBufSize * sizeof(DMCompElem)); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
678 |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
679 if ((compBuf = dmCalloc(compBufSize, sizeof(DMCompElem))) == NULL) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
680 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
681 dmErrorMsg("Out of memory. Could not allocate comparision buffer!\n"); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
682 goto out; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
683 } |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
684 |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
685 // Begin analyzing .. |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
686 dmPrint(2, "Analyzing ..\n"); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
687 for (int nfile = 0; nfile < nsrcFiles; nfile++) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
688 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
689 DMSourceFile *file = &srcFiles[nfile]; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
690 |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
691 for (size_t offs = 0; offs < file->size; offs++) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
692 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
693 Uint8 bv = file->data[offs]; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
694 totalStats.cv[bv].count++; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
695 file->stats.cv[bv].count++; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
696 } |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
697 |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
698 for (size_t offs = 0; offs < compBufSize; offs++) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
699 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
700 Uint8 data = offs < file->size ? file->data[offs] : 0; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
701 compBuf[offs].stats[data]++; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
702 } |
1996 | 703 } |
704 | |
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
705 for (size_t offs = 0; offs < compBufSize; offs++) |
1685
904904f145b4
Various fixes in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
1683
diff
changeset
|
706 { |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
707 DMCompElem *el = &compBuf[offs]; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
708 for (int n = 0; n < SET_MAX_ELEMS; n++) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
709 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
710 if (el->stats[n] > 0) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
711 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
712 el->variants++; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
713 el->data = n; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
714 } |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
715 } |
1685
904904f145b4
Various fixes in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
1683
diff
changeset
|
716 } |
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
717 |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
718 // Display results |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
719 for (size_t offs = 0, n = 0; offs < compBufSize; offs++) |
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
720 { |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
721 DMCompElem *el = &compBuf[offs]; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
722 BOOL var = el->variants > 1; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
723 |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
724 if (n == 0) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
725 printf("%08" DM_PRIx_SIZE_T " | ", offs); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
726 |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
727 if (var) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
728 printf("[%2d] ", el->variants); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
729 else |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
730 printf(" %02x ", el->data); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
731 |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
732 if (++n >= 16) |
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
733 { |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
734 printf("\n"); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
735 n = 0; |
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
736 } |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
737 } |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
738 |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
739 printf("\n"); |
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
740 |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
741 // Attempt further analysis |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
742 for (int nfile = 0; nfile < nsrcFiles; nfile++) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
743 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
744 DMSourceFile *file = &srcFiles[nfile]; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
745 size_t len = file->size > compBufSize ? compBufSize : file->size; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
746 for (size_t offs = 0; offs + 4 < len; offs++) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
747 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
748 DMCompElem *elem = &compBuf[offs]; |
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
749 |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
750 for (int variant = 3; variant >= 0; variant--) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
751 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
752 size_t nmax = (variant < 2) ? sizeof(Uint16) : sizeof(Uint32); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
753 Uint32 tmp = 0; |
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
754 |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
755 for (size_t n = 0; n < nmax; n++) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
756 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
757 size_t boffs = (variant & 1) ? n : nmax - n; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
758 |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
759 tmp <<= 8; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
760 tmp |= file->data[offs + boffs]; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
761 } |
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
762 |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
763 if (file->size - tmp < 32) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
764 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
765 elem->interest[variant] += 32 - (file->size - tmp); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
766 elem->interestF[variant]++; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
767 } |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
768 } |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
769 } |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
770 } |
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
771 |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
772 printf("\nMore findings:\n"); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
773 for (size_t offs = 0; offs + 4 < compBufSize; offs++) |
1996 | 774 { |
775 DMCompElem *elem = &compBuf[offs]; | |
776 | |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
777 for (int variant = 0; variant < 4; variant++) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
778 if (elem->interestF[variant] > 0) |
1996 | 779 { |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
780 printf("%08" DM_PRIx_SIZE_T " | V%d : %d / %d\n", |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
781 offs, variant, |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
782 elem->interestF[variant], elem->interest[variant]); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
783 } |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
784 } |
1996 | 785 |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
786 printf("\nGlobal most used bytes:\n"); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
787 dmPrintStats(&totalStats, 16, totalSize); |
1996 | 788 |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
789 for (int nfile = 0; nfile < nsrcFiles; nfile++) |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
790 { |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
791 DMSourceFile *file = &srcFiles[nfile]; |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
792 printf("Most used bytes for '%s':\n", file->filename); |
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
793 dmPrintStats(&file->stats, 16, file->size); |
1996 | 794 } |
795 } | |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
796 else |
1996 | 797 { |
2034
45ad06bb60c4
Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents:
2032
diff
changeset
|
798 dmErrorMsg("Invalid operating mode?\n"); |
1996 | 799 } |
800 | |
1682
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
801 out: |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
802 for (int nfile = 0; nfile < nsrcFiles; nfile++) |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
803 { |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
804 DMSourceFile *file = &srcFiles[nfile]; |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
805 dmFree(file->data); |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
806 } |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
807 |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
808 return 0; |
2cfb4806cf71
Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
809 } |