-
Notifications
You must be signed in to change notification settings - Fork 145
/
fixed_points.h
109 lines (91 loc) · 3.61 KB
/
fixed_points.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
// 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 FIXED_POINTS_H_
#define FIXED_POINTS_H_
#include <set>
#include <string>
#include "third_party/zynamics/bindiff/change_classifier.h"
#include "third_party/zynamics/bindiff/flow_graph.h"
#include "third_party/zynamics/bindiff/instruction.h"
#include "third_party/zynamics/binexport/util/types.h"
namespace security::bindiff {
class MatchingContext;
class BasicBlockFixedPoint {
public:
BasicBlockFixedPoint(FlowGraph* primary,
FlowGraph::Vertex primary_basic_block,
FlowGraph* secondary,
FlowGraph::Vertex secondary_basic_block,
const std::string& matching_step);
FlowGraph::Vertex GetPrimaryVertex() const;
FlowGraph::Vertex GetSecondaryVertex() const;
const std::string& GetMatchingStep() const;
void SetMatchingStep(const std::string& matching_step);
const InstructionMatches& GetInstructionMatches() const;
InstructionMatches& GetInstructionMatches();
private:
const std::string* matching_step_;
FlowGraph::Vertex primary_vertex_;
FlowGraph::Vertex secondary_vertex_;
InstructionMatches instruction_matches_;
};
bool operator<(const BasicBlockFixedPoint& one,
const BasicBlockFixedPoint& two);
using BasicBlockFixedPoints = std::set<BasicBlockFixedPoint>;
class FixedPoint {
public:
explicit FixedPoint(FlowGraph* primary = nullptr,
FlowGraph* secondary = nullptr,
const std::string& matching_step = "");
void Create(FlowGraph* primary, FlowGraph* secondary);
FlowGraph* GetPrimary() const;
FlowGraph* GetSecondary() const;
const std::string& GetMatchingStep() const;
void SetMatchingStep(const std::string& matching_step);
BasicBlockFixedPoints::iterator Add(FlowGraph::Vertex primary_vertex,
FlowGraph::Vertex secondary_vertex,
const std::string& step_name);
BasicBlockFixedPoints& GetBasicBlockFixedPoints();
const BasicBlockFixedPoints& GetBasicBlockFixedPoints() const;
void SetConfidence(double confidence);
double GetConfidence() const;
void SetSimilarity(double similarity);
double GetSimilarity() const;
int GetFlags() const;
void SetFlags(int flags);
bool HasFlag(ChangeType flag) const;
void SetFlag(ChangeType flag);
void SetCommentsPorted(bool ported);
bool GetCommentsPorted() const;
private:
const std::string* matching_step_;
FlowGraph* primary_;
FlowGraph* secondary_;
BasicBlockFixedPoints basic_block_fixed_points_;
double confidence_ = 0.0;
double similarity_ = 0.0;
int flags_ = CHANGE_NONE;
bool comments_ported_ = false;
};
bool operator<(const FixedPoint& one, const FixedPoint& two);
struct FixedPointComparator {
bool operator()(const FixedPoint* lhs, const FixedPoint* rhs) const {
return *lhs < *rhs;
}
};
using FixedPoints = std::set<FixedPoint>;
using FixedPointRefs = std::set<FixedPoint*, FixedPointComparator>;
const std::string* FindString(const std::string& name);
} // namespace security::bindiff
#endif // FIXED_POINTS_H_