forked from google/bindiff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
statistics.h
166 lines (150 loc) · 5.47 KB
/
statistics.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// Copyright 2011-2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef STATISTICS_H_
#define STATISTICS_H_
#include <array>
#include <cstdint>
#include <string>
#include <vector>
#include "third_party/absl/strings/string_view.h"
namespace security::bindiff {
class Counts {
public:
enum Kind {
kBasicBlockMatchesLibrary = 0,
kBasicBlockMatchesNonLibrary,
kBasicBlocksPrimaryLibrary,
kBasicBlocksPrimaryNonLibrary,
kBasicBlocksSecondaryLibrary,
kBasicBlocksSecondaryNonLibrary,
kFlowGraphEdgeMatchesLibrary,
kFlowGraphEdgeMatchesNonLibrary,
kFlowGraphEdgesPrimaryLibrary,
kFlowGraphEdgesPrimaryNonLibrary,
kFlowGraphEdgesSecondaryLibrary,
kFlowGraphEdgesSecondaryNonLibrary,
kFunctionMatchesLibrary,
kFunctionMatchesNonLibrary,
kFunctionsPrimaryLibrary,
kFunctionsPrimaryNonLibrary,
kFunctionsSecondaryLibrary,
kFunctionsSecondaryNonLibrary,
kInstructionMatchesLibrary,
kInstructionMatchesNonLibrary,
kInstructionsPrimaryLibrary,
kInstructionsPrimaryNonLibrary,
kInstructionsSecondaryLibrary,
kInstructionsSecondaryNonLibrary,
kUiEntrySize,
// These are not shown in the UI
kBasicBlocksLibrary = kUiEntrySize,
kBasicBlocksNonLibrary,
kEdgesLibrary,
kEdgesNonLibrary,
kFunctionsLibrary,
kFunctionsNonLibrary,
kInstructionsLibrary,
kInstructionsNonLibrary,
kNumCountEntries, // Always last
};
constexpr const uint64_t& operator[](Kind key) const {
return counts_[static_cast<uint64_t>(key)];
}
constexpr uint64_t& operator[](Kind key) {
return counts_[static_cast<uint64_t>(key)];
}
static constexpr absl::string_view GetDisplayName(Kind key) {
switch (key) {
case kBasicBlockMatchesLibrary:
return "Basic Block Matches (Library)";
case kBasicBlockMatchesNonLibrary:
return "Basic Block Matches (Non-Library)";
case kBasicBlocksLibrary:
return "Basic Blocks (Library)";
case kBasicBlocksNonLibrary:
return "Basic Blocks (Non-Library)";
case kBasicBlocksPrimaryLibrary:
return "Basic Blocks Primary (Library)";
case kBasicBlocksPrimaryNonLibrary:
return "Basic Blocks Primary (Non-Library)";
case kBasicBlocksSecondaryLibrary:
return "Basic Blocks Secondary (Library)";
case kBasicBlocksSecondaryNonLibrary:
return "Basic Blocks Secondary (Non-Library)";
case kEdgesLibrary:
return "Edges (Library)";
case kEdgesNonLibrary:
return "Edges (Non-Library)";
case kFlowGraphEdgeMatchesLibrary:
return "Flow Graph Edge Matches (Library)";
case kFlowGraphEdgeMatchesNonLibrary:
return "Flow Graph Edge Matches (Non-Library)";
case kFlowGraphEdgesPrimaryLibrary:
return "Flow Graph Edges Primary (Library)";
case kFlowGraphEdgesPrimaryNonLibrary:
return "Flow Graph Edges Primary (Non-Library)";
case kFlowGraphEdgesSecondaryLibrary:
return "Flow Graph Edges Secondary (Library)";
case kFlowGraphEdgesSecondaryNonLibrary:
return "Flow Graph Edges Secondary (Non-Library)";
case kFunctionMatchesLibrary:
return "Function Matches (Library)";
case kFunctionMatchesNonLibrary:
return "Function Matches (Non-Library)";
case kFunctionsLibrary:
return "Functions (Library)";
case kFunctionsNonLibrary:
return "Functions (Non-Library)";
case kFunctionsPrimaryLibrary:
return "Functions Primary (Library)";
case kFunctionsPrimaryNonLibrary:
return "Functions Primary (Non-Library)";
case kFunctionsSecondaryLibrary:
return "Functions Secondary (Library)";
case kFunctionsSecondaryNonLibrary:
return "Functions Secondary (Non-Library)";
case kInstructionMatchesLibrary:
return "Instruction Matches (Library)";
case kInstructionMatchesNonLibrary:
return "Instruction Matches (Non-Library)";
case kInstructionsLibrary:
return "Instructions (Library)";
case kInstructionsNonLibrary:
return "Instructions (Non-Library)";
case kInstructionsPrimaryLibrary:
return "Instructions Primary (Library)";
case kInstructionsPrimaryNonLibrary:
return "Instructions Primary (Non-Library)";
case kInstructionsSecondaryLibrary:
return "Instructions Secondary (Library)";
case kInstructionsSecondaryNonLibrary:
return "Instructions Secondary (Non-Library)";
case kNumCountEntries:
break;
}
return "";
}
std::pair<absl::string_view, uint64_t> GetEntry(int index) const {
if (index >= 0 && index < kNumCountEntries) {
return {GetDisplayName(static_cast<Kind>(index)), counts_[index]};
}
return {"", 0};
}
void clear() { counts_.fill(0); }
static constexpr size_t ui_entry_size() { return kUiEntrySize; }
private:
std::array<uint64_t, kNumCountEntries> counts_ = {0};
};
} // namespace security::bindiff
#endif // STATISTICS_H_