annotate tools/fanalyze.c @ 2249:6ba4aed198e4

Cosmetic.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 15 Jun 2019 20:20:57 +0300
parents 2e656da1b10b
children 3739e2ac8bb1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
2234
ef1845cb436e Improve help, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2232
diff changeset
2 * Fanalyze - Commandline tool for analyzing similarities between multiple files
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * Programmed and designed by Matti 'ccr' Hamalainen
2232
ba639902d57c Bump copyright and version.
Matti Hamalainen <ccr@tnsp.org>
parents: 2229
diff changeset
4 * (C) Copyright 2018-2019 Tecnic Software productions (TNSP)
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 *
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 * Please read file 'COPYING' for information on license and distribution.
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 */
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 #include "dmtool.h"
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 #include "dmlib.h"
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 #include "dmargs.h"
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 #include "dmfile.h"
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12
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
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
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
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
23 Uint8 stats[SET_MAX_ELEMS];
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
24 Uint8 variants, data;
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
25 int interest[16];
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
26 int interestF[16];
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
27 } DMCompElem;
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
28
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
29
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
30 typedef struct
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
31 {
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
32 int count;
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
33 Uint8 value;
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
34 } DMStatValue;
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
35
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
36
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
37 typedef struct
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
38 {
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
39 DMStatValue cv[SET_MAX_ELEMS];
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
40 } DMStats;
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
41
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
42
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
43 typedef struct
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
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;
2249
6ba4aed198e4 Cosmetic.
Matti Hamalainen <ccr@tnsp.org>
parents: 2248
diff changeset
47 size_t size;
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
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
2249
6ba4aed198e4 Cosmetic.
Matti Hamalainen <ccr@tnsp.org>
parents: 2248
diff changeset
114
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
115 enum
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
116 {
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
117 FA_ANALYZE,
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
118 FA_GREP,
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
119 FA_OFFSET,
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
120 };
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
121
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
122
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123 /* Global variables
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124 */
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
125 int setMode = FA_ANALYZE;
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
126 int nsrcFiles = 0; // Number of source files
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
127 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
128 DMStats totalStats;
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
129 int nsetGrepValues = 0;
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
130 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
131
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133 /* Arguments
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134 */
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 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
136 {
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137 { 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
138 { 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
139 { 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
140 { 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
141 };
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143 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
144
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146 void argShowHelp()
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
147 {
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148 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
149 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
150
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
151 fprintf(stdout,
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
152 "\n"
2234
ef1845cb436e Improve help, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2232
diff changeset
153 "Fanalyze is a simplistic commandline tool to assist analysis of similarities\n"
ef1845cb436e Improve help, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2232
diff changeset
154 "between multiple files of same format (but different content). It provides\n"
ef1845cb436e Improve help, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2232
diff changeset
155 "automatic analysis (default operating mode), binary grep functionality (-g)\n"
ef1845cb436e Improve help, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2232
diff changeset
156 "and offset data display (-o)\n"
ef1845cb436e Improve help, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2232
diff changeset
157 "\n"
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
158 "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
159 "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
160 "-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
161 "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
162 );
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
163 }
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
164
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
165
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
166 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
167 {
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
168 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
169 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
170 {
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
171 *mval = 0;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
172 return FALSE;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
173 }
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
174
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
175 switch (type)
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
176 {
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
177 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
178 *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
179 break;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
180
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
181 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
182 *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
183 break;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
184
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
185 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
186 *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
187 break;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
188
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
189 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
190 *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
191 break;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
192
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
193 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
194 *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
195 break;
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 default:
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
198 *mval = 0;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
199 return FALSE;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
200 }
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
201 return TRUE;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
202 }
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
203
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
204
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
205 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
206 {
2229
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
207 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
208
2229
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
209 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
210 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
211 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
212 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
213
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
214 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
215 {
2248
2e656da1b10b Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2234
diff changeset
216 const char *veol = (n + 1 < node->nvalues) ? " " : "\n";
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
217
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
218 if (match)
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 Uint32 mval;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
221 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
222 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
223 }
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
224 else
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
225 {
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
226 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
227 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
228 else
2229
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
229 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
230 }
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
231 }
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
232 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
233
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
234
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
235 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
236 {
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
237 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
238 char *vspec, *vstr, *vsep;
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
239 DMGrepValue val;
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
240 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
241 BOOL more;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
242
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
243 memset(&val, 0, sizeof(val));
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
244
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
245 if (setMode != FA_ANALYZE && setMode != mode)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
246 {
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
247 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
248 return DMERR_INVALID_ARGS;
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
249 }
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
250 setMode = mode;
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 // 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
253 if (specsep != NULL)
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
254 {
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
255 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
256 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
257 }
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
258 else
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
259 {
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
260 vspec = NULL;
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
261 vstr = dm_strdup(arg);
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
262 }
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
263
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
264 // Parse spec if any
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
265 if (vspec != NULL)
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 BOOL vendianess = TRUE;
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
268 char *vtmp = vspec;
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 // Get endianess specifier, if any
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
271 if (dm_strncasecmp(vtmp, "le", 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 = TRUE;
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 else
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
277 if (dm_strncasecmp(vtmp, "be", 2) == 0)
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
278 {
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
279 vendianess = FALSE;
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
280 vtmp += 2;
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
281 }
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
282
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
283 // Get value bit size
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
284 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
285 {
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
286 val.type = DMGV_UINT8;
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
287 vtmp += 1;
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, "16", 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_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
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
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
296 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
297 {
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
298 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
299 vtmp += 2;
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
300 }
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
301 else
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
302 {
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
303 ret = dmError(DMERR_INVALID_ARGS,
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
304 "Invalid grep type '%s'.\n",
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
305 vspec);
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
306 goto out;
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
307 }
2045
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 switch (tolower(*vtmp))
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
310 {
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
311 case 'd':
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
312 val.disp = DMGS_DEC;
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
313 break;
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
314
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
315 case 'x': case 'h':
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
316 val.disp = DMGS_HEX;
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
317 break;
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
318
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
319 case 0:
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
320 break;
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
321
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
322 default:
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
323 ret = dmError(DMERR_INVALID_ARGS,
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
324 "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
325 vspec);
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
326 goto out;
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
327 }
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
328 }
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
329
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
330 // 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
331 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
332 do
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
333 {
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
334 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
335 {
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
336 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
337 "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
338 vstr);
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
339 goto out;
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
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
342 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
343 {
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
344 *vsep = 0;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
345 more = TRUE;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
346 }
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
347 else
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
348 more = FALSE;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
349
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
350 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
351 {
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
352 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
353 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
354 {
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
355 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
356 "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
357 goto out;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
358 }
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
359 }
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
360 else
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
361 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
362 {
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
363 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
364 "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
365 vtmp);
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
366 goto out;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
367 }
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
368
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
369 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
370
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
371 if (more)
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
372 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
373 } while (more);
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
374
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
375 if (val.vwildcards[0])
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
376 {
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
377 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
378 "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
379 goto out;
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
380 }
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
381
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
382 if (mode == FA_GREP)
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
383 {
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
384 // Check if we need to guess size
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
385 if (val.type < 0)
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 for (int n = DMGV_last; n >= 0; n--)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
388 {
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
389 const DMGrepType *def = &dmGrepTypes[n];
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
390 if (val.values[0] <= def->nmax)
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
391 val.type = n;
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
392 }
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
393 }
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
394
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
395 if (val.type < 0)
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
396 {
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
397 ret = dmError(DMERR_INVALID_ARGS,
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
398 "Could not guess value type for '%s'.\n",
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
399 arg);
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
400 goto out;
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
401 }
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
402
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
403 // Check range
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
404 for (int n = 0; n < val.nvalues; n++)
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
405 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
406 {
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
407 ret = dmError(DMERR_INVALID_ARGS,
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
408 "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
409 val.values[n], 0, dmGrepTypes[val.type].nmax,
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
410 dmGrepTypes[val.type].name);
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
411
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
412 goto out;
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
413 }
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
414 }
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
415 else
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
416 if (mode == FA_OFFSET)
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
417 {
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
418 if (val.type < 0)
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
419 val.type = DMGV_UINT8;
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
420 }
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
421
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
422 if (nsetGrepValues < SET_MAX_VALUES)
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
423 {
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
424 DMGrepValue *node = &setGrepValues[nsetGrepValues++];
2228
02d17784fdef Variables -> struct cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2225
diff changeset
425 memcpy(node, &val, sizeof(val));
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
426
2229
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
427 if (mode == FA_GREP)
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
428 {
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
429 dmPrint(1, "Grep %s: ",
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
430 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
431
2229
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
432 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
433 }
2028
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 else
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
436 {
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
437 ret = dmError(DMERR_BOUNDS,
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
438 "Too many values specified (max %d).",
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
439 SET_MAX_VALUES);
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 out:
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
443 dmFree(vspec);
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
444 dmFree(vstr);
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
445 return ret;
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
446 }
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
447
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
448
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
449 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
450 {
1995
ea6337c873c6 Silence an unused function argument warning.
Matti Hamalainen <ccr@tnsp.org>
parents: 1685
diff changeset
451 (void) optArg;
ea6337c873c6 Silence an unused function argument warning.
Matti Hamalainen <ccr@tnsp.org>
parents: 1685
diff changeset
452
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
453 switch (optN)
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
454 {
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
455 case 0:
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
456 argShowHelp();
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
457 exit(0);
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
458 break;
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
459
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
460 case 1:
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
461 dmVerbosity++;
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
462 break;
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
463
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
464 case 2:
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
465 return argParseGrepValue(optArg, FA_GREP) == DMERR_OK;
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
466
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
467 case 3:
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
468 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
469
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
470 default:
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
471 dmErrorMsg("Unknown argument '%s'.\n", currArg);
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
472 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
473 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
474
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
475 return TRUE;
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
476 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
477
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
478
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
479 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
480 {
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
481 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
482 {
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
483 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
484 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
485 return TRUE;
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
486 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
487 else
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
488 {
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
489 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
490 SET_MAX_FILES);
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
491 return TRUE;
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
492 }
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
493 }
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
494
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
495
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
496 void dmInitStats(DMStats *stats)
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
497 {
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
498 for (size_t n = 0; n < SET_MAX_ELEMS; n++)
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
499 {
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
500 stats->cv[n].count = 0;
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
501 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
502 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
503 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
504
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
505
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
506 int dmCompareStatFunc(const void *va, const void *vb)
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
507 {
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
508 const DMStatValue *pa = va, *pb = vb;
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
509 return pb->count - pa->count;
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
510 }
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
511
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
512
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
513 void dmPrintStats(DMStats *stats, const int nmax, const size_t size)
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
514 {
2011
8e38fa3c4f98 Fix use of qsort().
Matti Hamalainen <ccr@tnsp.org>
parents: 1996
diff changeset
515 qsort(&stats->cv, SET_MAX_ELEMS, sizeof(DMStatValue), dmCompareStatFunc);
8e38fa3c4f98 Fix use of qsort().
Matti Hamalainen <ccr@tnsp.org>
parents: 1996
diff changeset
516
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
517 for (int n = 0; n < nmax; n++)
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
518 {
2011
8e38fa3c4f98 Fix use of qsort().
Matti Hamalainen <ccr@tnsp.org>
parents: 1996
diff changeset
519 printf("$%02x (%d = %1.2f%%), ",
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
520 stats->cv[n].value,
2011
8e38fa3c4f98 Fix use of qsort().
Matti Hamalainen <ccr@tnsp.org>
parents: 1996
diff changeset
521 stats->cv[n].count,
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
522 ((float) stats->cv[n].count * 100.0f) / (float) size);
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
523 }
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
524 printf("\n\n");
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
525 }
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
526
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
527
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
528 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
529 {
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
530 DMCompElem *compBuf = NULL;
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
531 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
532 int res;
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
533
2234
ef1845cb436e Improve help, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2232
diff changeset
534 dmInitProg("fanalyze", "Simple tool for file format analysis",
ef1845cb436e Improve help, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2232
diff changeset
535 "0.4", 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
536 dmVerbosity = 1;
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
537
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
538 dmInitStats(&totalStats);
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
539
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
540 // Parse arguments
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
541 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
542 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
543 exit(1);
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
544
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
545 if (nsrcFiles < 1)
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 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
548 goto out;
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
549 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
550
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
551 // 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
552 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
553 {
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
554 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
555 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
556 {
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
557 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
558 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
559 goto out;
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
560 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
561
1685
904904f145b4 Various fixes in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 1683
diff changeset
562 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
563 nfile + 1, file->filename, file->size);
904904f145b4 Various fixes in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 1683
diff changeset
564
904904f145b4 Various fixes in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 1683
diff changeset
565 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
566 compBufSize = file->size;
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
567
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
568 totalSize += file->size;
2011
8e38fa3c4f98 Fix use of qsort().
Matti Hamalainen <ccr@tnsp.org>
parents: 1996
diff changeset
569 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
570 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
571
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
572
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
573 //
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
574 // Check what operating mode we are in
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
575 //
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
576 if (setMode == FA_GREP)
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
577 {
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
578 for (int nfile = 0; nfile < nsrcFiles; nfile++)
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
579 {
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
580 DMSourceFile *file = &srcFiles[nfile];
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
581 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
582
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
583 for (int n = 0; n < nsetGrepValues; n++)
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
584 {
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
585 DMGrepValue *node = &setGrepValues[n];
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
586 const DMGrepType *def = &dmGrepTypes[node->type];
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
587
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
588 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
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 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
591 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
592 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
593 {
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
594 Uint32 mval;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
595 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
596
2225
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
597 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
598 {
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
599 match = FALSE;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
600 break;
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
601 }
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
602 }
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
603
837c79747ea4 Add functionality for grepping multiple consecutive values (8/16/32 le/be)
Matti Hamalainen <ccr@tnsp.org>
parents: 2045
diff changeset
604 if (match)
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
605 {
2229
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
606 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
607 dmPrintGrepValueList(node, TRUE, file, offs);
2028
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
608 }
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
609 }
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
610 }
8a9ef75fd3cd Implemement simple binary grep functionality in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2011
diff changeset
611 }
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
612 }
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
613 else
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
614 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
615 {
2034
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 {
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
618 DMSourceFile *file = &srcFiles[nfile];
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
619 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
620 }
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
621
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
622 printf(" offset :");
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
623 for (int nfile = 0; nfile < nsrcFiles; nfile++)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
624 printf(" %03d ", nfile + 1);
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
625 printf("\n");
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
626
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
627 printf("==========");
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
628 for (int nfile = 0; nfile < nsrcFiles; nfile++)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
629 printf("===========");
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
630 printf("\n");
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
631
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
632 for (int n = 0; n < nsetGrepValues; n++)
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
633 {
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
634 DMGrepValue *node = &setGrepValues[n];
2045
1662730053d0 Implement controllable decimal/hexadecimal formatting for offset display mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 2042
diff changeset
635 const DMGrepType *def = &dmGrepTypes[node->type];
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
636
2229
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
637 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
638 {
2229
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
639 printf("%08x : ", node->values[nv]);
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
640
2229
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
641 for (int nfile = 0; nfile < nsrcFiles; nfile++)
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
642 {
2229
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
643 DMSourceFile *file = &srcFiles[nfile];
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
644 Uint32 mval;
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
645 char mstr[32];
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
646 int npad, nwidth;
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
647
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
648 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
649 {
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
650 char mfmt[16];
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
651 nwidth = def->bsize * 2;
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
652 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
653 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
654
2229
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
655 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
656 }
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
657 else
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
658 {
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
659 strcpy(mstr, "----");
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
660 nwidth = 4;
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
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
663 npad = (10 - nwidth) / 2;
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
664 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
665 fputc(' ', stdout);
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
666
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
667 fputs(mstr, stdout);
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
668
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
669 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
670 fputc(' ', stdout);
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
671 }
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
672
2229
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
673 printf(" [%s]\n",
72e15cc14927 Make the offset mode (-o) also support lists of offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 2228
diff changeset
674 dmGrepDisp[node->disp].name);
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
675 }
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
676 }
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
677 }
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
678 else
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
679 if (setMode == FA_ANALYZE)
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 // Allocate comparision buffer
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
682 // XXX: integer overflow?
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
683 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
684 compBufSize, compBufSize * sizeof(DMCompElem));
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
685
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
686 if ((compBuf = dmCalloc(compBufSize, sizeof(DMCompElem))) == NULL)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
687 {
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
688 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
689 goto out;
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
2234
ef1845cb436e Improve help, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2232
diff changeset
692 //
ef1845cb436e Improve help, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2232
diff changeset
693 // Basic file data comparision
ef1845cb436e Improve help, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2232
diff changeset
694 //
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
695 dmPrint(2, "Analyzing ..\n");
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
696 for (int nfile = 0; nfile < nsrcFiles; nfile++)
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 DMSourceFile *file = &srcFiles[nfile];
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 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
701 {
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
702 Uint8 bv = file->data[offs];
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
703 totalStats.cv[bv].count++;
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
704 file->stats.cv[bv].count++;
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
705 }
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
706
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
707 for (size_t offs = 0; offs < compBufSize; offs++)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
708 {
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
709 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
710 compBuf[offs].stats[data]++;
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
711 }
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
712 }
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
713
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
714 for (size_t offs = 0; offs < compBufSize; offs++)
1685
904904f145b4 Various fixes in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 1683
diff changeset
715 {
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
716 DMCompElem *el = &compBuf[offs];
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
717 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
718 {
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
719 if (el->stats[n] > 0)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
720 {
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
721 el->variants++;
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
722 el->data = n;
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 }
1685
904904f145b4 Various fixes in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 1683
diff changeset
725 }
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
726
2234
ef1845cb436e Improve help, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2232
diff changeset
727 //
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
728 // Display results
2234
ef1845cb436e Improve help, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2232
diff changeset
729 //
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
730 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
731 {
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
732 DMCompElem *el = &compBuf[offs];
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
733 BOOL var = el->variants > 1;
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
734
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
735 if (n == 0)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
736 printf("%08" DM_PRIx_SIZE_T " | ", offs);
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
737
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
738 if (var)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
739 printf("[%2d] ", el->variants);
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
740 else
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
741 printf(" %02x ", el->data);
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
742
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
743 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
744 {
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
745 printf("\n");
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
746 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
747 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
748 }
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 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
751
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
752 // Attempt further analysis
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
753 for (int nfile = 0; nfile < nsrcFiles; nfile++)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
754 {
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
755 DMSourceFile *file = &srcFiles[nfile];
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
756 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
757 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
758 {
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
759 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
760
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
761 for (int variant = 3; variant >= 0; variant--)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
762 {
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
763 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
764 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
765
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
766 for (size_t n = 0; n < nmax; n++)
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 size_t boffs = (variant & 1) ? n : nmax - n;
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 tmp <<= 8;
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
771 tmp |= file->data[offs + boffs];
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
772 }
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
773
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
774 if (file->size - tmp < 32)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
775 {
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
776 elem->interest[variant] += 32 - (file->size - tmp);
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
777 elem->interestF[variant]++;
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
778 }
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
779 }
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
780 }
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
781 }
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
782
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
783 printf("\nMore findings:\n");
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
784 for (size_t offs = 0; offs + 4 < compBufSize; offs++)
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
785 {
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
786 DMCompElem *elem = &compBuf[offs];
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
787
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
788 for (int variant = 0; variant < 4; variant++)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
789 if (elem->interestF[variant] > 0)
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
790 {
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
791 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
792 offs, variant,
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
793 elem->interestF[variant], elem->interest[variant]);
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
794 }
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
795 }
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
796
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
797 printf("\nGlobal most used bytes:\n");
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
798 dmPrintStats(&totalStats, 16, totalSize);
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
799
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
800 for (int nfile = 0; nfile < nsrcFiles; nfile++)
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
801 {
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
802 DMSourceFile *file = &srcFiles[nfile];
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
803 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
804 dmPrintStats(&file->stats, 16, file->size);
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
805 }
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
806 }
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
807 else
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
808 {
2034
45ad06bb60c4 Implement offset dump mode in fanalyze.
Matti Hamalainen <ccr@tnsp.org>
parents: 2032
diff changeset
809 dmErrorMsg("Invalid operating mode?\n");
1996
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
810 }
4a4c3e15b8c2 Add more analyzing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1995
diff changeset
811
1682
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
812 out:
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
813 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
814 {
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
815 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
816 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
817 }
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
818
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
819 return 0;
2cfb4806cf71 Add simple and naively implemented multi-file bindiff type file analyzer utility 'fanalyze'.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
820 }