svf-tools 1.0.727 → 1.0.729
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/svf/include/AbstractExecution/ConsExeState.h +446 -0
- package/svf/include/AbstractExecution/ExeState.h +72 -5
- package/svf/include/AbstractExecution/IntervalExeState.h +13 -0
- package/svf/include/AbstractExecution/SVFIR2ConsExeState.h +149 -0
- package/svf/include/AbstractExecution/SymState.h +221 -0
- package/svf/lib/AbstractExecution/ConsExeState.cpp +606 -0
- package/svf/lib/AbstractExecution/ExeState.cpp +16 -7
- package/svf/lib/AbstractExecution/SVFIR2ConsExeState.cpp +808 -0
- package/svf/lib/AbstractExecution/SymState.cpp +37 -0
- package/svf-llvm/tools/LLVM2SVF/llvm2svf.cpp +3 -2
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
//===- SVFIR2ConsExeState.h ----SVFIR2ConsExeState-------------------------//
|
|
2
|
+
//
|
|
3
|
+
// SVF: Static Value-Flow Analysis
|
|
4
|
+
//
|
|
5
|
+
// Copyright (C) <2013-2022> <Yulei Sui>
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
// This program is free software: you can redistribute it and/or modify
|
|
9
|
+
// it under the terms of the GNU Affero General Public License as published by
|
|
10
|
+
// the Free Software Foundation, either version 3 of the License, or
|
|
11
|
+
// (at your option) any later version.
|
|
12
|
+
|
|
13
|
+
// This program is distributed in the hope that it will be useful,
|
|
14
|
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
+
// GNU Affero General Public License for more details.
|
|
17
|
+
|
|
18
|
+
// You should have received a copy of the GNU Affero General Public License
|
|
19
|
+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
20
|
+
//
|
|
21
|
+
//===----------------------------------------------------------------------===//
|
|
22
|
+
|
|
23
|
+
//
|
|
24
|
+
// Created by jiawei and xiao on 6/1/23.
|
|
25
|
+
//
|
|
26
|
+
|
|
27
|
+
#ifndef SVF_SVFIR2CONSEXESTATE_H
|
|
28
|
+
#define SVF_SVFIR2CONSEXESTATE_H
|
|
29
|
+
|
|
30
|
+
#include "AbstractExecution/ConsExeState.h"
|
|
31
|
+
#include "SVFIR/SVFIR.h"
|
|
32
|
+
|
|
33
|
+
namespace SVF
|
|
34
|
+
{
|
|
35
|
+
class SVFIR2ConsExeState
|
|
36
|
+
{
|
|
37
|
+
public:
|
|
38
|
+
typedef ExeState::VAddrs VAddrs;
|
|
39
|
+
|
|
40
|
+
SVFIR2ConsExeState() = default;
|
|
41
|
+
|
|
42
|
+
void setEs(ConsExeState *es)
|
|
43
|
+
{
|
|
44
|
+
_es = es;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
ConsExeState *getEs()
|
|
48
|
+
{
|
|
49
|
+
return _es;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
virtual ~SVFIR2ConsExeState();
|
|
53
|
+
|
|
54
|
+
/// Translator for llvm ir
|
|
55
|
+
//{%
|
|
56
|
+
/// https://llvm.org/docs/LangRef.html#alloca-instruction
|
|
57
|
+
void translateAddr(const AddrStmt *addr);
|
|
58
|
+
|
|
59
|
+
/// https://llvm.org/docs/LangRef.html#binary-operations
|
|
60
|
+
void translateBinary(const BinaryOPStmt *binary);
|
|
61
|
+
|
|
62
|
+
/// https://llvm.org/docs/LangRef.html#icmp-instruction
|
|
63
|
+
void translateCmp(const CmpStmt *cmp);
|
|
64
|
+
|
|
65
|
+
/// https://llvm.org/docs/LangRef.html#load-instruction
|
|
66
|
+
void translateLoad(const LoadStmt *load);
|
|
67
|
+
|
|
68
|
+
/// https://llvm.org/docs/LangRef.html#store-instruction
|
|
69
|
+
void translateStore(const StoreStmt *store);
|
|
70
|
+
|
|
71
|
+
/// https://llvm.org/docs/LangRef.html#conversion-operations
|
|
72
|
+
void translateCopy(const CopyStmt *copy);
|
|
73
|
+
|
|
74
|
+
/// https://llvm.org/docs/LangRef.html#call-instruction
|
|
75
|
+
void translateCall(const CallPE *callPE);
|
|
76
|
+
|
|
77
|
+
void translateRet(const RetPE *retPE);
|
|
78
|
+
|
|
79
|
+
/// https://llvm.org/docs/LangRef.html#getelementptr-instruction
|
|
80
|
+
void translateGep(const GepStmt *gep, bool isGlobal);
|
|
81
|
+
|
|
82
|
+
/// https://llvm.org/docs/LangRef.html#select-instruction
|
|
83
|
+
void translateSelect(const SelectStmt *select);
|
|
84
|
+
|
|
85
|
+
/// https://llvm.org/docs/LangRef.html#i-phi
|
|
86
|
+
void translatePhi(const PhiStmt *phi);
|
|
87
|
+
|
|
88
|
+
//%}
|
|
89
|
+
//%}
|
|
90
|
+
|
|
91
|
+
/// Return the expr of gep object given a base and offset
|
|
92
|
+
VAddrs getGepObjAddress(u32_t base, u32_t offset);
|
|
93
|
+
|
|
94
|
+
/// Return the offset expression of a GepStmt
|
|
95
|
+
std::pair<s32_t, s32_t> getGepOffset(const GepStmt *gep);
|
|
96
|
+
|
|
97
|
+
/// Init ConZ3Expr for ObjVar
|
|
98
|
+
void initObjVar(const ObjVar *objVar, u32_t varId);
|
|
99
|
+
|
|
100
|
+
void initValVar(const ValVar *objVar, u32_t varId);
|
|
101
|
+
|
|
102
|
+
void initSVFVar(u32_t varId);
|
|
103
|
+
|
|
104
|
+
void moveToGlobal();
|
|
105
|
+
|
|
106
|
+
/// The physical address starts with 0x7f...... + idx
|
|
107
|
+
static inline u32_t getVirtualMemAddress(u32_t idx)
|
|
108
|
+
{
|
|
109
|
+
return ExeState::getVirtualMemAddress(idx);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/// Check bit value of val start with 0x7F000000, filter by 0xFF000000
|
|
113
|
+
static inline bool isVirtualMemAddress(u32_t val)
|
|
114
|
+
{
|
|
115
|
+
return ExeState::isVirtualMemAddress(val);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/// Return the internal index if idx is an address otherwise return the value of idx
|
|
119
|
+
static inline u32_t getInternalID(u32_t idx)
|
|
120
|
+
{
|
|
121
|
+
return ExeState::getInternalID(idx);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
inline bool inVarToValTable(u32_t id) const
|
|
125
|
+
{
|
|
126
|
+
return _es->inVarToVal(id);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
inline bool inLocToValTable(u32_t id) const
|
|
130
|
+
{
|
|
131
|
+
return _es->inLocToVal(id);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
inline bool inVarToAddrsTable(u32_t id) const
|
|
135
|
+
{
|
|
136
|
+
return _es->inVarToAddrsTable(id);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
inline bool inLocToAddrsTable(u32_t id) const
|
|
140
|
+
{
|
|
141
|
+
return _es->inLocToAddrsTable(id);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
protected:
|
|
145
|
+
ConsExeState *_es{nullptr};
|
|
146
|
+
}; // end class SVFIR2ConsExeState
|
|
147
|
+
} // end namespace SVF
|
|
148
|
+
|
|
149
|
+
#endif // SVF_SVFIR2CONSEXESTATE_H
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
//===- SymState.h ----Symbolic State-------------------------//
|
|
2
|
+
//
|
|
3
|
+
// SVF: Static Value-Flow Analysis
|
|
4
|
+
//
|
|
5
|
+
// Copyright (C) <2013-2022> <Yulei Sui>
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
// This program is free software: you can redistribute it and/or modify
|
|
9
|
+
// it under the terms of the GNU Affero General Public License as published by
|
|
10
|
+
// the Free Software Foundation, either version 3 of the License, or
|
|
11
|
+
// (at your option) any later version.
|
|
12
|
+
|
|
13
|
+
// This program is distributed in the hope that it will be useful,
|
|
14
|
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
+
// GNU Affero General Public License for more details.
|
|
17
|
+
|
|
18
|
+
// You should have received a copy of the GNU Affero General Public License
|
|
19
|
+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
20
|
+
//
|
|
21
|
+
//===----------------------------------------------------------------------===//
|
|
22
|
+
|
|
23
|
+
//
|
|
24
|
+
// Created by jiawei and xiao on 6/1/23.
|
|
25
|
+
//
|
|
26
|
+
|
|
27
|
+
#ifndef SVF_SYMSTATE_H
|
|
28
|
+
#define SVF_SYMSTATE_H
|
|
29
|
+
|
|
30
|
+
#include "AbstractExecution/ConsExeState.h"
|
|
31
|
+
|
|
32
|
+
namespace SVF
|
|
33
|
+
{
|
|
34
|
+
/*!
|
|
35
|
+
* Symbolic state
|
|
36
|
+
*
|
|
37
|
+
* Execution State + Type State
|
|
38
|
+
*/
|
|
39
|
+
class SymState
|
|
40
|
+
{
|
|
41
|
+
|
|
42
|
+
public:
|
|
43
|
+
typedef std::string TypeState;
|
|
44
|
+
typedef std::vector<u32_t> KeyNodes;
|
|
45
|
+
typedef Set<KeyNodes> KeyNodesSet;
|
|
46
|
+
|
|
47
|
+
private:
|
|
48
|
+
ConsExeState _exeState; ///< Execution state: values of variables
|
|
49
|
+
TypeState _typeState; ///< Type state: FSM node
|
|
50
|
+
|
|
51
|
+
private:
|
|
52
|
+
/// Only for bug report
|
|
53
|
+
KeyNodesSet _keyNodesSet; ///< The nodes where abstract state changes
|
|
54
|
+
Z3Expr _branchCondition; ///< The branches current state passes
|
|
55
|
+
|
|
56
|
+
public:
|
|
57
|
+
/// Constructor
|
|
58
|
+
SymState() : _exeState(ConsExeState::nullExeState()), _typeState("") {}
|
|
59
|
+
|
|
60
|
+
/// Constructor
|
|
61
|
+
SymState(ConsExeState _es, TypeState _as);
|
|
62
|
+
|
|
63
|
+
/// Desstructor
|
|
64
|
+
virtual ~SymState() = default;
|
|
65
|
+
|
|
66
|
+
/// Copy Constructor
|
|
67
|
+
SymState(const SymState &rhs) : _exeState(rhs._exeState), _typeState(rhs._typeState), _keyNodesSet(rhs._keyNodesSet),
|
|
68
|
+
_branchCondition(rhs._branchCondition)
|
|
69
|
+
{
|
|
70
|
+
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/// Operator=
|
|
74
|
+
SymState &operator=(const SymState &rhs)
|
|
75
|
+
{
|
|
76
|
+
if (*this != rhs)
|
|
77
|
+
{
|
|
78
|
+
_typeState = rhs._typeState;
|
|
79
|
+
_exeState = rhs._exeState;
|
|
80
|
+
_keyNodesSet = rhs._keyNodesSet;
|
|
81
|
+
_branchCondition = rhs._branchCondition;
|
|
82
|
+
}
|
|
83
|
+
return *this;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
/// Move Constructor
|
|
88
|
+
SymState(SymState &&rhs) noexcept: _exeState(SVFUtil::move(rhs._exeState)),
|
|
89
|
+
_typeState(SVFUtil::move(rhs._typeState)),
|
|
90
|
+
_keyNodesSet(SVFUtil::move(rhs._keyNodesSet)),
|
|
91
|
+
_branchCondition(rhs._branchCondition)
|
|
92
|
+
{
|
|
93
|
+
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/// Move operator=
|
|
97
|
+
SymState &operator=(SymState &&rhs) noexcept
|
|
98
|
+
{
|
|
99
|
+
if (this != &rhs)
|
|
100
|
+
{
|
|
101
|
+
_typeState = SVFUtil::move(rhs._typeState);
|
|
102
|
+
_exeState = SVFUtil::move(rhs._exeState);
|
|
103
|
+
_keyNodesSet = SVFUtil::move(rhs._keyNodesSet);
|
|
104
|
+
_branchCondition = rhs._branchCondition;
|
|
105
|
+
}
|
|
106
|
+
return *this;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const KeyNodesSet &getKeyNodesSet() const
|
|
110
|
+
{
|
|
111
|
+
return _keyNodesSet;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
void insertKeyNode(NodeID id)
|
|
116
|
+
{
|
|
117
|
+
if (_keyNodesSet.empty())
|
|
118
|
+
{
|
|
119
|
+
_keyNodesSet.insert(KeyNodes{id});
|
|
120
|
+
}
|
|
121
|
+
else
|
|
122
|
+
{
|
|
123
|
+
for (const auto &df: _keyNodesSet)
|
|
124
|
+
{
|
|
125
|
+
const_cast<KeyNodes &>(df).push_back(id);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
void setKeyNodesSet(KeyNodesSet ns)
|
|
131
|
+
{
|
|
132
|
+
_keyNodesSet = SVFUtil::move(ns);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
void clearKeyNodesSet()
|
|
136
|
+
{
|
|
137
|
+
_keyNodesSet.clear();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
inline const Z3Expr &getBranchCondition() const
|
|
141
|
+
{
|
|
142
|
+
return _branchCondition;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
inline void setBranchCondition(const Z3Expr &br)
|
|
146
|
+
{
|
|
147
|
+
_branchCondition = br;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const TypeState &getAbstractState() const
|
|
151
|
+
{
|
|
152
|
+
return _typeState;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
TypeState &getAbstractState()
|
|
156
|
+
{
|
|
157
|
+
return _typeState;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
void setAbsState(const TypeState &absState)
|
|
161
|
+
{
|
|
162
|
+
_typeState = absState;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const ConsExeState &getExecutionState() const
|
|
166
|
+
{
|
|
167
|
+
return _exeState;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
ConsExeState &getExecutionState()
|
|
171
|
+
{
|
|
172
|
+
return _exeState;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/// Overloading Operator==
|
|
176
|
+
inline bool operator==(const SymState &rhs) const
|
|
177
|
+
{
|
|
178
|
+
return _typeState == rhs.getAbstractState() && _exeState == rhs.getExecutionState();
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/// Overloading Operator!=
|
|
182
|
+
inline bool operator!=(const SymState &rhs) const
|
|
183
|
+
{
|
|
184
|
+
return !(*this == rhs);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/// Overloading Operator==
|
|
188
|
+
inline bool operator<(const SymState &rhs) const
|
|
189
|
+
{
|
|
190
|
+
if (_typeState != rhs.getAbstractState())
|
|
191
|
+
return _typeState < rhs.getAbstractState();
|
|
192
|
+
if (_exeState != rhs.getExecutionState())
|
|
193
|
+
return _exeState < rhs.getExecutionState();
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
inline bool isNullSymState() const
|
|
198
|
+
{
|
|
199
|
+
return getExecutionState().isNullState() && getAbstractState().empty();
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
} // end namespace SVF
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
/// Specialise hash for SymState
|
|
209
|
+
template<>
|
|
210
|
+
struct std::hash<SVF::SymState>
|
|
211
|
+
{
|
|
212
|
+
size_t operator()(const SVF::SymState &symState) const
|
|
213
|
+
{
|
|
214
|
+
|
|
215
|
+
SVF::Hash<std::pair<SVF::SymState::TypeState, SVF::ConsExeState>> pairH;
|
|
216
|
+
|
|
217
|
+
return pairH(make_pair(symState.getAbstractState(), symState.getExecutionState()));
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
#endif // SVF_SYMSTATE_H
|