svf-lib 1.0.2238 → 1.0.2239

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.
Files changed (165) hide show
  1. package/SVF-linux-aarch64/Release-build/bin/ae +0 -0
  2. package/SVF-linux-aarch64/Release-build/bin/cfl +0 -0
  3. package/SVF-linux-aarch64/Release-build/bin/dvf +0 -0
  4. package/SVF-linux-aarch64/Release-build/bin/llvm2svf +0 -0
  5. package/SVF-linux-aarch64/Release-build/bin/mta +0 -0
  6. package/SVF-linux-aarch64/Release-build/bin/saber +0 -0
  7. package/SVF-linux-aarch64/Release-build/bin/svf-ex +0 -0
  8. package/SVF-linux-aarch64/Release-build/bin/wpa +0 -0
  9. package/SVF-linux-aarch64/Release-build/include/AE/Core/AbstractState.h +406 -0
  10. package/SVF-linux-aarch64/Release-build/include/AE/Core/AbstractValue.h +157 -0
  11. package/SVF-linux-aarch64/Release-build/include/AE/Core/AddressValue.h +232 -0
  12. package/SVF-linux-aarch64/Release-build/include/AE/Core/ICFGWTO.h +82 -0
  13. package/SVF-linux-aarch64/Release-build/include/AE/Core/IntervalValue.h +1055 -0
  14. package/SVF-linux-aarch64/Release-build/include/AE/Core/NumericValue.h +1292 -0
  15. package/SVF-linux-aarch64/Release-build/include/AE/Core/RelExeState.h +226 -0
  16. package/SVF-linux-aarch64/Release-build/include/AE/Core/RelationSolver.h +91 -0
  17. package/SVF-linux-aarch64/Release-build/include/AE/Svfexe/AEDetector.h +323 -0
  18. package/SVF-linux-aarch64/Release-build/include/AE/Svfexe/AbsExtAPI.h +140 -0
  19. package/SVF-linux-aarch64/Release-build/include/AE/Svfexe/AbstractInterpretation.h +350 -0
  20. package/SVF-linux-aarch64/Release-build/include/CFL/CFGNormalizer.h +84 -0
  21. package/SVF-linux-aarch64/Release-build/include/CFL/CFGrammar.h +468 -0
  22. package/SVF-linux-aarch64/Release-build/include/CFL/CFLAlias.h +168 -0
  23. package/SVF-linux-aarch64/Release-build/include/CFL/CFLBase.h +118 -0
  24. package/SVF-linux-aarch64/Release-build/include/CFL/CFLGramGraphChecker.h +74 -0
  25. package/SVF-linux-aarch64/Release-build/include/CFL/CFLGraphBuilder.h +166 -0
  26. package/SVF-linux-aarch64/Release-build/include/CFL/CFLSVFGBuilder.h +58 -0
  27. package/SVF-linux-aarch64/Release-build/include/CFL/CFLSolver.h +374 -0
  28. package/SVF-linux-aarch64/Release-build/include/CFL/CFLStat.h +67 -0
  29. package/SVF-linux-aarch64/Release-build/include/CFL/CFLVF.h +68 -0
  30. package/SVF-linux-aarch64/Release-build/include/CFL/GrammarBuilder.h +100 -0
  31. package/SVF-linux-aarch64/Release-build/include/CFL/grammar/PAGGrammar.txt +15 -0
  32. package/SVF-linux-aarch64/Release-build/include/CFL/grammar/PEGGrammar.txt +11 -0
  33. package/SVF-linux-aarch64/Release-build/include/CFL/grammar/VFGGrammar.txt +7 -0
  34. package/SVF-linux-aarch64/Release-build/include/DDA/ContextDDA.h +230 -0
  35. package/SVF-linux-aarch64/Release-build/include/DDA/DDAClient.h +163 -0
  36. package/SVF-linux-aarch64/Release-build/include/DDA/DDAPass.h +102 -0
  37. package/SVF-linux-aarch64/Release-build/include/DDA/DDAStat.h +121 -0
  38. package/SVF-linux-aarch64/Release-build/include/DDA/DDAVFSolver.h +794 -0
  39. package/SVF-linux-aarch64/Release-build/include/DDA/FlowDDA.h +178 -0
  40. package/SVF-linux-aarch64/Release-build/include/FastCluster/LICENSE.TXT +13 -0
  41. package/SVF-linux-aarch64/Release-build/include/FastCluster/fastcluster.h +80 -0
  42. package/SVF-linux-aarch64/Release-build/include/Graphs/BasicBlockG.h +318 -0
  43. package/SVF-linux-aarch64/Release-build/include/Graphs/CDG.h +482 -0
  44. package/SVF-linux-aarch64/Release-build/include/Graphs/CFLGraph.h +232 -0
  45. package/SVF-linux-aarch64/Release-build/include/Graphs/CHG.h +369 -0
  46. package/SVF-linux-aarch64/Release-build/include/Graphs/CallGraph.h +498 -0
  47. package/SVF-linux-aarch64/Release-build/include/Graphs/ConsG.h +402 -0
  48. package/SVF-linux-aarch64/Release-build/include/Graphs/ConsGEdge.h +355 -0
  49. package/SVF-linux-aarch64/Release-build/include/Graphs/ConsGNode.h +418 -0
  50. package/SVF-linux-aarch64/Release-build/include/Graphs/DOTGraphTraits.h +188 -0
  51. package/SVF-linux-aarch64/Release-build/include/Graphs/GenericGraph.h +628 -0
  52. package/SVF-linux-aarch64/Release-build/include/Graphs/GraphPrinter.h +111 -0
  53. package/SVF-linux-aarch64/Release-build/include/Graphs/GraphTraits.h +150 -0
  54. package/SVF-linux-aarch64/Release-build/include/Graphs/GraphWriter.h +380 -0
  55. package/SVF-linux-aarch64/Release-build/include/Graphs/ICFG.h +331 -0
  56. package/SVF-linux-aarch64/Release-build/include/Graphs/ICFGEdge.h +281 -0
  57. package/SVF-linux-aarch64/Release-build/include/Graphs/ICFGNode.h +669 -0
  58. package/SVF-linux-aarch64/Release-build/include/Graphs/ICFGStat.h +164 -0
  59. package/SVF-linux-aarch64/Release-build/include/Graphs/IRGraph.h +398 -0
  60. package/SVF-linux-aarch64/Release-build/include/Graphs/SCC.h +375 -0
  61. package/SVF-linux-aarch64/Release-build/include/Graphs/SVFG.h +491 -0
  62. package/SVF-linux-aarch64/Release-build/include/Graphs/SVFGEdge.h +237 -0
  63. package/SVF-linux-aarch64/Release-build/include/Graphs/SVFGNode.h +501 -0
  64. package/SVF-linux-aarch64/Release-build/include/Graphs/SVFGOPT.h +363 -0
  65. package/SVF-linux-aarch64/Release-build/include/Graphs/SVFGStat.h +273 -0
  66. package/SVF-linux-aarch64/Release-build/include/Graphs/ThreadCallGraph.h +400 -0
  67. package/SVF-linux-aarch64/Release-build/include/Graphs/VFG.h +664 -0
  68. package/SVF-linux-aarch64/Release-build/include/Graphs/VFGEdge.h +295 -0
  69. package/SVF-linux-aarch64/Release-build/include/Graphs/VFGNode.h +1266 -0
  70. package/SVF-linux-aarch64/Release-build/include/Graphs/WTO.h +872 -0
  71. package/SVF-linux-aarch64/Release-build/include/MSSA/MSSAMuChi.h +722 -0
  72. package/SVF-linux-aarch64/Release-build/include/MSSA/MemPartition.h +169 -0
  73. package/SVF-linux-aarch64/Release-build/include/MSSA/MemRegion.h +489 -0
  74. package/SVF-linux-aarch64/Release-build/include/MSSA/MemSSA.h +452 -0
  75. package/SVF-linux-aarch64/Release-build/include/MSSA/SVFGBuilder.h +98 -0
  76. package/SVF-linux-aarch64/Release-build/include/MTA/LockAnalysis.h +533 -0
  77. package/SVF-linux-aarch64/Release-build/include/MTA/MHP.h +546 -0
  78. package/SVF-linux-aarch64/Release-build/include/MTA/MTA.h +98 -0
  79. package/SVF-linux-aarch64/Release-build/include/MTA/MTAStat.h +73 -0
  80. package/SVF-linux-aarch64/Release-build/include/MTA/TCT.h +620 -0
  81. package/SVF-linux-aarch64/Release-build/include/MemoryModel/AbstractPointsToDS.h +316 -0
  82. package/SVF-linux-aarch64/Release-build/include/MemoryModel/AccessPath.h +194 -0
  83. package/SVF-linux-aarch64/Release-build/include/MemoryModel/ConditionalPT.h +878 -0
  84. package/SVF-linux-aarch64/Release-build/include/MemoryModel/MutablePointsToDS.h +1025 -0
  85. package/SVF-linux-aarch64/Release-build/include/MemoryModel/PersistentPointsToCache.h +463 -0
  86. package/SVF-linux-aarch64/Release-build/include/MemoryModel/PersistentPointsToDS.h +955 -0
  87. package/SVF-linux-aarch64/Release-build/include/MemoryModel/PointerAnalysis.h +429 -0
  88. package/SVF-linux-aarch64/Release-build/include/MemoryModel/PointerAnalysisImpl.h +602 -0
  89. package/SVF-linux-aarch64/Release-build/include/MemoryModel/PointsTo.h +255 -0
  90. package/SVF-linux-aarch64/Release-build/include/MemoryModel/SVFLoop.h +167 -0
  91. package/SVF-linux-aarch64/Release-build/include/SABER/DoubleFreeChecker.h +76 -0
  92. package/SVF-linux-aarch64/Release-build/include/SABER/FileChecker.h +80 -0
  93. package/SVF-linux-aarch64/Release-build/include/SABER/LeakChecker.h +122 -0
  94. package/SVF-linux-aarch64/Release-build/include/SABER/ProgSlice.h +327 -0
  95. package/SVF-linux-aarch64/Release-build/include/SABER/SaberCheckerAPI.h +151 -0
  96. package/SVF-linux-aarch64/Release-build/include/SABER/SaberCondAllocator.h +317 -0
  97. package/SVF-linux-aarch64/Release-build/include/SABER/SaberSVFGBuilder.h +114 -0
  98. package/SVF-linux-aarch64/Release-build/include/SABER/SrcSnkDDA.h +327 -0
  99. package/SVF-linux-aarch64/Release-build/include/SABER/SrcSnkSolver.h +186 -0
  100. package/SVF-linux-aarch64/Release-build/include/SVF-LLVM/BasicTypes.h +280 -0
  101. package/SVF-linux-aarch64/Release-build/include/SVF-LLVM/BreakConstantExpr.h +94 -0
  102. package/SVF-linux-aarch64/Release-build/include/SVF-LLVM/CHGBuilder.h +78 -0
  103. package/SVF-linux-aarch64/Release-build/include/SVF-LLVM/CppUtil.h +184 -0
  104. package/SVF-linux-aarch64/Release-build/include/SVF-LLVM/DCHG.h +477 -0
  105. package/SVF-linux-aarch64/Release-build/include/SVF-LLVM/GEPTypeBridgeIterator.h +183 -0
  106. package/SVF-linux-aarch64/Release-build/include/SVF-LLVM/ICFGBuilder.h +160 -0
  107. package/SVF-linux-aarch64/Release-build/include/SVF-LLVM/LLVMLoopAnalysis.h +60 -0
  108. package/SVF-linux-aarch64/Release-build/include/SVF-LLVM/LLVMModule.h +594 -0
  109. package/SVF-linux-aarch64/Release-build/include/SVF-LLVM/LLVMUtil.h +438 -0
  110. package/SVF-linux-aarch64/Release-build/include/SVF-LLVM/ObjTypeInference.h +130 -0
  111. package/SVF-linux-aarch64/Release-build/include/SVF-LLVM/SVFIRBuilder.h +520 -0
  112. package/SVF-linux-aarch64/Release-build/include/SVF-LLVM/SVFLLVMValue.h +387 -0
  113. package/SVF-linux-aarch64/Release-build/include/SVF-LLVM/SVFModule.h +186 -0
  114. package/SVF-linux-aarch64/Release-build/include/SVF-LLVM/SymbolTableBuilder.h +132 -0
  115. package/SVF-linux-aarch64/Release-build/include/SVFIR/ObjTypeInfo.h +224 -0
  116. package/SVF-linux-aarch64/Release-build/include/SVFIR/PAGBuilderFromFile.h +80 -0
  117. package/SVF-linux-aarch64/Release-build/include/SVFIR/SVFIR.h +856 -0
  118. package/SVF-linux-aarch64/Release-build/include/SVFIR/SVFStatements.h +1328 -0
  119. package/SVF-linux-aarch64/Release-build/include/SVFIR/SVFType.h +578 -0
  120. package/SVF-linux-aarch64/Release-build/include/SVFIR/SVFValue.h +338 -0
  121. package/SVF-linux-aarch64/Release-build/include/SVFIR/SVFVariables.h +2204 -0
  122. package/SVF-linux-aarch64/Release-build/include/Util/Annotator.h +180 -0
  123. package/SVF-linux-aarch64/Release-build/include/Util/BitVector.h +55 -0
  124. package/SVF-linux-aarch64/Release-build/include/Util/CDGBuilder.h +107 -0
  125. package/SVF-linux-aarch64/Release-build/include/Util/CallGraphBuilder.h +62 -0
  126. package/SVF-linux-aarch64/Release-build/include/Util/Casting.h +426 -0
  127. package/SVF-linux-aarch64/Release-build/include/Util/CommandLine.h +530 -0
  128. package/SVF-linux-aarch64/Release-build/include/Util/CoreBitVector.h +214 -0
  129. package/SVF-linux-aarch64/Release-build/include/Util/CxtStmt.h +502 -0
  130. package/SVF-linux-aarch64/Release-build/include/Util/DPItem.h +618 -0
  131. package/SVF-linux-aarch64/Release-build/include/Util/ExtAPI.h +117 -0
  132. package/SVF-linux-aarch64/Release-build/include/Util/GeneralType.h +127 -0
  133. package/SVF-linux-aarch64/Release-build/include/Util/GraphReachSolver.h +186 -0
  134. package/SVF-linux-aarch64/Release-build/include/Util/NodeIDAllocator.h +203 -0
  135. package/SVF-linux-aarch64/Release-build/include/Util/Options.h +272 -0
  136. package/SVF-linux-aarch64/Release-build/include/Util/PTAStat.h +83 -0
  137. package/SVF-linux-aarch64/Release-build/include/Util/SVFBugReport.h +427 -0
  138. package/SVF-linux-aarch64/Release-build/include/Util/SVFLoopAndDomInfo.h +169 -0
  139. package/SVF-linux-aarch64/Release-build/include/Util/SVFStat.h +103 -0
  140. package/SVF-linux-aarch64/Release-build/include/Util/SVFUtil.h +478 -0
  141. package/SVF-linux-aarch64/Release-build/include/Util/SparseBitVector.h +1252 -0
  142. package/SVF-linux-aarch64/Release-build/include/Util/ThreadAPI.h +189 -0
  143. package/SVF-linux-aarch64/Release-build/include/Util/WorkList.h +317 -0
  144. package/SVF-linux-aarch64/Release-build/include/Util/Z3Expr.h +325 -0
  145. package/SVF-linux-aarch64/Release-build/include/Util/cJSON.h +300 -0
  146. package/SVF-linux-aarch64/Release-build/include/Util/config.h +26 -0
  147. package/SVF-linux-aarch64/Release-build/include/Util/iterator.h +407 -0
  148. package/SVF-linux-aarch64/Release-build/include/Util/iterator_range.h +76 -0
  149. package/SVF-linux-aarch64/Release-build/include/WPA/Andersen.h +435 -0
  150. package/SVF-linux-aarch64/Release-build/include/WPA/AndersenPWC.h +160 -0
  151. package/SVF-linux-aarch64/Release-build/include/WPA/CSC.h +95 -0
  152. package/SVF-linux-aarch64/Release-build/include/WPA/FlowSensitive.h +323 -0
  153. package/SVF-linux-aarch64/Release-build/include/WPA/Steensgaard.h +131 -0
  154. package/SVF-linux-aarch64/Release-build/include/WPA/TypeAnalysis.h +90 -0
  155. package/SVF-linux-aarch64/Release-build/include/WPA/VersionedFlowSensitive.h +295 -0
  156. package/SVF-linux-aarch64/Release-build/include/WPA/WPAFSSolver.h +246 -0
  157. package/SVF-linux-aarch64/Release-build/include/WPA/WPAPass.h +116 -0
  158. package/SVF-linux-aarch64/Release-build/include/WPA/WPASolver.h +205 -0
  159. package/SVF-linux-aarch64/Release-build/include/WPA/WPAStat.h +222 -0
  160. package/SVF-linux-aarch64/Release-build/lib/cmake/SVF/SVFConfig.cmake +58 -0
  161. package/SVF-linux-aarch64/Release-build/lib/cmake/SVF/SVFConfigVersion.cmake +43 -0
  162. package/SVF-linux-aarch64/Release-build/lib/extapi.bc +2449 -0
  163. package/SVF-linux-aarch64/Release-build/lib/libSvfCore.so +0 -0
  164. package/SVF-linux-aarch64/Release-build/lib/libSvfLLVM.so.16 +0 -0
  165. package/package.json +1 -1
@@ -0,0 +1,226 @@
1
+ //===- RelExeState.h ----Relation Execution States for Interval Domains-------//
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
+ * RelExeState.h
24
+ *
25
+ * Created on: Aug 15, 2022
26
+ * Author: Jiawei Ren, Xiao Cheng
27
+ *
28
+ */
29
+
30
+ #ifndef Z3_EXAMPLE_RELEXESTATE_H
31
+ #define Z3_EXAMPLE_RELEXESTATE_H
32
+
33
+ #include "AE/Core/AddressValue.h"
34
+ #include "Util/Z3Expr.h"
35
+
36
+ namespace SVF
37
+ {
38
+
39
+ class RelExeState
40
+ {
41
+ friend class SVFIR2AbsState;
42
+
43
+ public:
44
+ typedef Map<u32_t, Z3Expr> VarToValMap;
45
+ typedef VarToValMap AddrToValMap;
46
+
47
+ protected:
48
+ VarToValMap _varToVal;
49
+ AddrToValMap _addrToVal;
50
+
51
+ public:
52
+ RelExeState() = default;
53
+
54
+ RelExeState(VarToValMap &varToVal, AddrToValMap&locToVal) : _varToVal(varToVal), _addrToVal(locToVal) {}
55
+
56
+ RelExeState(const RelExeState &rhs) : _varToVal(rhs.getVarToVal()), _addrToVal(rhs.getLocToVal())
57
+ {
58
+
59
+ }
60
+
61
+ virtual ~RelExeState() = default;
62
+
63
+ RelExeState &operator=(const RelExeState &rhs);
64
+
65
+ RelExeState(RelExeState &&rhs) noexcept: _varToVal(std::move(rhs._varToVal)),
66
+ _addrToVal(std::move(rhs._addrToVal))
67
+ {
68
+
69
+ }
70
+
71
+ RelExeState &operator=(RelExeState &&rhs) noexcept
72
+ {
73
+ if (&rhs != this)
74
+ {
75
+ _varToVal = std::move(rhs._varToVal);
76
+ _addrToVal = std::move(rhs._addrToVal);
77
+ }
78
+ return *this;
79
+ }
80
+
81
+ /// Overloading Operator==
82
+ bool operator==(const RelExeState &rhs) const;
83
+
84
+ /// Overloading Operator!=
85
+ inline bool operator!=(const RelExeState &rhs) const
86
+ {
87
+ return !(*this == rhs);
88
+ }
89
+
90
+ /// Overloading Operator==
91
+ bool operator<(const RelExeState &rhs) const;
92
+
93
+
94
+ static z3::context &getContext()
95
+ {
96
+ return Z3Expr::getContext();
97
+ }
98
+
99
+ const VarToValMap &getVarToVal() const
100
+ {
101
+ return _varToVal;
102
+ }
103
+
104
+ const AddrToValMap&getLocToVal() const
105
+ {
106
+ return _addrToVal;
107
+ }
108
+
109
+ inline Z3Expr &operator[](u32_t varId)
110
+ {
111
+ return getZ3Expr(varId);
112
+ }
113
+
114
+ u32_t hash() const
115
+ {
116
+ size_t h = getVarToVal().size() * 2;
117
+ SVF::Hash<SVF::u32_t> hf;
118
+ for (const auto &t: getVarToVal())
119
+ {
120
+ h ^= hf(t.first) + 0x9e3779b9 + (h << 6) + (h >> 2);
121
+ h ^= hf(t.second.id()) + 0x9e3779b9 + (h << 6) + (h >> 2);
122
+ }
123
+
124
+ size_t h2 = getVarToVal().size() * 2;
125
+
126
+ for (const auto &t: getLocToVal())
127
+ {
128
+ h2 ^= hf(t.first) + 0x9e3779b9 + (h2 << 6) + (h2 >> 2);
129
+ h2 ^= hf(t.second.id()) + 0x9e3779b9 + (h2 << 6) + (h2 >> 2);
130
+ }
131
+ SVF::Hash<std::pair<SVF::u32_t, SVF::u32_t>> pairH;
132
+
133
+ return pairH(std::make_pair(h, h2));
134
+ }
135
+
136
+ /// Return true if map has varId
137
+ inline bool existsVar(u32_t varId) const
138
+ {
139
+ return _varToVal.count(varId);
140
+ }
141
+
142
+ /// Return Z3 expression eagerly based on SVFVar ID
143
+ virtual inline Z3Expr &getZ3Expr(u32_t varId)
144
+ {
145
+ return _varToVal[varId];
146
+ }
147
+
148
+ /// Return Z3 expression lazily based on SVFVar ID
149
+ virtual inline Z3Expr toZ3Expr(u32_t varId) const
150
+ {
151
+ return getContext().int_const(std::to_string(varId).c_str());
152
+ }
153
+
154
+ /// Extract sub SVFVar IDs of a Z3Expr
155
+ void extractSubVars(const Z3Expr &expr, Set<u32_t> &res);
156
+
157
+ /// Extract all related SVFVar IDs based on compare expr
158
+ void extractCmpVars(const Z3Expr &expr, Set<u32_t> &res);
159
+
160
+ /// Build relational Z3Expr
161
+ Z3Expr buildRelZ3Expr(u32_t cmp, s32_t succ, Set<u32_t> &vars, Set<u32_t> &initVars);
162
+
163
+ /// Store value to location
164
+ void store(const Z3Expr &loc, const Z3Expr &value);
165
+
166
+ /// Load value at location
167
+ Z3Expr &load(const Z3Expr &loc);
168
+
169
+ /// The physical address starts with 0x7f...... + idx
170
+ static inline u32_t getVirtualMemAddress(u32_t idx)
171
+ {
172
+ return AddressValue::getVirtualMemAddress(idx);
173
+ }
174
+
175
+ /// Check bit value of val start with 0x7F000000, filter by 0xFF000000
176
+ static inline bool isVirtualMemAddress(u32_t val)
177
+ {
178
+ if (val == 0)
179
+ assert(false && "val cannot be 0");
180
+ return AddressValue::isVirtualMemAddress(val);
181
+ }
182
+
183
+ /// Return the internal index if idx is an address otherwise return the value of idx
184
+ static inline u32_t getInternalID(u32_t idx)
185
+ {
186
+ return AddressValue::getInternalID(idx);
187
+ }
188
+
189
+ /// Return int value from an expression if it is a numeral, otherwise return an approximate value
190
+ static inline s32_t z3Expr2NumValue(const Z3Expr &e)
191
+ {
192
+ assert(e.is_numeral() && "not numeral?");
193
+ return e.get_numeral_int64();
194
+ }
195
+
196
+ /// Print values of all expressions
197
+ void printExprValues();
198
+
199
+ private:
200
+ bool eqVarToValMap(const VarToValMap &lhs, const VarToValMap &rhs) const;
201
+
202
+ bool lessThanVarToValMap(const VarToValMap &lhs, const VarToValMap &rhs) const;
203
+
204
+ protected:
205
+ inline void store(u32_t objId, const Z3Expr &z3Expr)
206
+ {
207
+ _addrToVal[objId] = z3Expr.simplify();
208
+ }
209
+
210
+ inline Z3Expr &load(u32_t objId)
211
+ {
212
+ return _addrToVal[objId];
213
+ }
214
+ }; // end class RelExeState
215
+ } // end namespace SVF
216
+
217
+ template<>
218
+ struct std::hash<SVF::RelExeState>
219
+ {
220
+ size_t operator()(const SVF::RelExeState &exeState) const
221
+ {
222
+ return exeState.hash();
223
+ }
224
+ };
225
+
226
+ #endif //Z3_EXAMPLE_RELEXESTATE_H
@@ -0,0 +1,91 @@
1
+ //===- RelationSolver.h ----Relation Solver for Interval Domains-----------//
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
+ * RelationSolver.h
24
+ *
25
+ * Created on: Aug 4, 2022
26
+ * Author: Jiawei Ren
27
+ *
28
+ */
29
+
30
+ #ifndef Z3_EXAMPLE_RELATIONSOLVER_H
31
+ #define Z3_EXAMPLE_RELATIONSOLVER_H
32
+
33
+ #include "AE/Core/AbstractState.h"
34
+ #include "Util/Z3Expr.h"
35
+
36
+ namespace SVF
37
+ {
38
+ class RelationSolver
39
+ {
40
+ public:
41
+ RelationSolver() = default;
42
+
43
+ /* gamma_hat, beta and abstract_consequence works on
44
+ IntervalESBase (the last element of inputs) for RSY or bilateral solver */
45
+
46
+ /// Return Z3Expr according to valToValMap
47
+ Z3Expr gamma_hat(const AbstractState&exeState) const;
48
+
49
+ /// Return Z3Expr according to another valToValMap
50
+ Z3Expr gamma_hat(const AbstractState&alpha, const AbstractState&exeState) const;
51
+
52
+ /// Return Z3Expr from a NodeID
53
+ Z3Expr gamma_hat(u32_t id, const AbstractState&exeState) const;
54
+
55
+ AbstractState abstract_consequence(const AbstractState&lower, const AbstractState&upper, const AbstractState&domain) const;
56
+
57
+ AbstractState beta(const Map<u32_t, s32_t> &sigma, const AbstractState&exeState) const;
58
+
59
+
60
+ /// Return Z3 expression lazily based on SVFVar ID
61
+ virtual inline Z3Expr toIntZ3Expr(u32_t varId) const
62
+ {
63
+ return Z3Expr::getContext().int_const(std::to_string(varId).c_str());
64
+ }
65
+
66
+ inline Z3Expr toIntVal(s32_t f) const
67
+ {
68
+ return Z3Expr::getContext().int_val(f);
69
+ }
70
+ inline Z3Expr toRealVal(BoundedDouble f) const
71
+ {
72
+ return Z3Expr::getContext().real_val(std::to_string(f.getFVal()).c_str());
73
+ }
74
+
75
+ /* two optional solvers: RSY and bilateral */
76
+
77
+ AbstractState bilateral(const AbstractState& domain, const Z3Expr &phi, u32_t descend_check = 0);
78
+
79
+ AbstractState RSY(const AbstractState& domain, const Z3Expr &phi);
80
+
81
+ Map<u32_t, s32_t> BoxedOptSolver(const Z3Expr& phi, Map<u32_t, s32_t>& ret, Map<u32_t, s32_t>& low_values, Map<u32_t, s32_t>& high_values);
82
+
83
+ AbstractState BS(const AbstractState& domain, const Z3Expr &phi);
84
+
85
+ void updateMap(Map<u32_t, s32_t>& map, u32_t key, const s32_t& value);
86
+
87
+ void decide_cpa_ext(const Z3Expr &phi, Map<u32_t, Z3Expr>&, Map<u32_t, s32_t>&, Map<u32_t, s32_t>&, Map<u32_t, s32_t>&, Map<u32_t, s32_t>&);
88
+ };
89
+ }
90
+
91
+ #endif //Z3_EXAMPLE_RELATIONSOLVER_H
@@ -0,0 +1,323 @@
1
+ //===- AEDetector.h -- Vulnerability Detectors---------------------------------//
2
+ //
3
+ // SVF: Static Value-Flow Analysis
4
+ //
5
+ // Copyright (C) <2013-> <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
+ //
25
+ // Created by Jiawei Wang on 2024/8/20.
26
+ //
27
+ #pragma once
28
+ #include <SVFIR/SVFIR.h>
29
+ #include <AE/Core/AbstractState.h>
30
+ #include "Util/SVFBugReport.h"
31
+
32
+ namespace SVF
33
+ {
34
+ /**
35
+ * @class AEDetector
36
+ * @brief Base class for all detectors.
37
+ */
38
+ class AEDetector
39
+ {
40
+ public:
41
+ /**
42
+ * @enum DetectorKind
43
+ * @brief Enumerates the types of detectors available.
44
+ */
45
+ enum DetectorKind
46
+ {
47
+ BUF_OVERFLOW, ///< Detector for buffer overflow issues.
48
+ UNKNOWN, ///< Default type if the kind is not specified.
49
+ };
50
+
51
+ /**
52
+ * @brief Constructor initializes the detector kind to UNKNOWN.
53
+ */
54
+ AEDetector(): kind(UNKNOWN) {}
55
+
56
+ /**
57
+ * @brief Virtual destructor for safe polymorphic use.
58
+ */
59
+ virtual ~AEDetector() = default;
60
+
61
+ /**
62
+ * @brief Check if the detector is of the UNKNOWN kind.
63
+ * @param detector Pointer to the detector.
64
+ * @return True if the detector is of type UNKNOWN, false otherwise.
65
+ */
66
+ static bool classof(const AEDetector* detector)
67
+ {
68
+ return detector->getKind() == AEDetector::UNKNOWN;
69
+ }
70
+
71
+ /**
72
+ * @brief Pure virtual function for detecting issues within a node.
73
+ * @param as Reference to the abstract state.
74
+ * @param node Pointer to the ICFG node.
75
+ */
76
+ virtual void detect(AbstractState& as, const ICFGNode* node) = 0;
77
+
78
+ /**
79
+ * @brief Pure virtual function for handling stub external API calls. (e.g. UNSAFE_BUFACCESS)
80
+ * @param call Pointer to the ext call ICFG node.
81
+ */
82
+ virtual void handleStubFunctions(const CallICFGNode* call) = 0;
83
+
84
+ /**
85
+ * @brief Pure virtual function to report detected bugs.
86
+ */
87
+ virtual void reportBug() = 0;
88
+
89
+ /**
90
+ * @brief Get the kind of the detector.
91
+ * @return The kind of the detector.
92
+ */
93
+ DetectorKind getKind() const
94
+ {
95
+ return kind;
96
+ }
97
+
98
+ protected:
99
+ DetectorKind kind; ///< The kind of the detector.
100
+ };
101
+
102
+ /**
103
+ * @class AEException
104
+ * @brief Exception class for handling errors in Abstract Execution.
105
+ */
106
+ class AEException : public std::exception
107
+ {
108
+ public:
109
+ /**
110
+ * @brief Constructor initializes the exception with a message.
111
+ * @param message The error message.
112
+ */
113
+ AEException(const std::string& message)
114
+ : msg_(message) {}
115
+
116
+ /**
117
+ * @brief Provides the error message.
118
+ * @return The error message as a C-string.
119
+ */
120
+ virtual const char* what() const throw()
121
+ {
122
+ return msg_.c_str();
123
+ }
124
+
125
+ private:
126
+ std::string msg_; ///< The error message.
127
+ };
128
+
129
+ /**
130
+ * @class BufOverflowDetector
131
+ * @brief Detector for identifying buffer overflow issues.
132
+ */
133
+ class BufOverflowDetector : public AEDetector
134
+ {
135
+ friend class AbstractInterpretation;
136
+ public:
137
+ /**
138
+ * @brief Constructor initializes the detector kind to BUF_OVERFLOW and sets up external API buffer overflow rules.
139
+ */
140
+ BufOverflowDetector()
141
+ {
142
+ kind = BUF_OVERFLOW;
143
+ initExtAPIBufOverflowCheckRules();
144
+ }
145
+
146
+ /**
147
+ * @brief Destructor.
148
+ */
149
+ ~BufOverflowDetector() = default;
150
+
151
+ /**
152
+ * @brief Check if the detector is of the BUF_OVERFLOW kind.
153
+ * @param detector Pointer to the detector.
154
+ * @return True if the detector is of type BUF_OVERFLOW, false otherwise.
155
+ */
156
+ static bool classof(const AEDetector* detector)
157
+ {
158
+ return detector->getKind() == AEDetector::BUF_OVERFLOW;
159
+ }
160
+
161
+ /**
162
+ * @brief Updates the offset of a GEP object from its base.
163
+ * @param gepAddrs Address value for GEP.
164
+ * @param objAddrs Address value for the object.
165
+ * @param offset The interval value of the offset.
166
+ */
167
+ void updateGepObjOffsetFromBase(AddressValue gepAddrs,
168
+ AddressValue objAddrs,
169
+ IntervalValue offset);
170
+
171
+ /**
172
+ * @brief Detect buffer overflow issues within a node.
173
+ * @param as Reference to the abstract state.
174
+ * @param node Pointer to the ICFG node.
175
+ */
176
+ void detect(AbstractState& as, const ICFGNode*);
177
+
178
+
179
+ /**
180
+ * @brief Handles external API calls related to buffer overflow detection.
181
+ * @param call Pointer to the call ICFG node.
182
+ */
183
+ void handleStubFunctions(const CallICFGNode*);
184
+
185
+ /**
186
+ * @brief Adds an offset to a GEP object.
187
+ * @param obj Pointer to the GEP object.
188
+ * @param offset The interval value of the offset.
189
+ */
190
+ void addToGepObjOffsetFromBase(const GepObjVar* obj, const IntervalValue& offset)
191
+ {
192
+ gepObjOffsetFromBase[obj] = offset;
193
+ }
194
+
195
+ /**
196
+ * @brief Checks if a GEP object has an associated offset.
197
+ * @param obj Pointer to the GEP object.
198
+ * @return True if the GEP object has an offset, false otherwise.
199
+ */
200
+ bool hasGepObjOffsetFromBase(const GepObjVar* obj) const
201
+ {
202
+ return gepObjOffsetFromBase.find(obj) != gepObjOffsetFromBase.end();
203
+ }
204
+
205
+ /**
206
+ * @brief Retrieves the offset of a GEP object from its base.
207
+ * @param obj Pointer to the GEP object.
208
+ * @return The interval value of the offset.
209
+ */
210
+ IntervalValue getGepObjOffsetFromBase(const GepObjVar* obj) const
211
+ {
212
+ if (hasGepObjOffsetFromBase(obj))
213
+ return gepObjOffsetFromBase.at(obj);
214
+ else
215
+ assert(false && "GepObjVar not found in gepObjOffsetFromBase");
216
+ }
217
+
218
+ /**
219
+ * @brief Retrieves the access offset for a given object and GEP statement.
220
+ * @param as Reference to the abstract state.
221
+ * @param objId The ID of the object.
222
+ * @param gep Pointer to the GEP statement.
223
+ * @return The interval value of the access offset.
224
+ */
225
+ IntervalValue getAccessOffset(AbstractState& as, NodeID objId, const GepStmt* gep);
226
+
227
+ /**
228
+ * @brief Adds a bug to the reporter based on an exception.
229
+ * @param e The exception that was thrown.
230
+ * @param node Pointer to the ICFG node where the bug was detected.
231
+ */
232
+ void addBugToReporter(const AEException& e, const ICFGNode* node)
233
+ {
234
+
235
+ GenericBug::EventStack eventStack;
236
+ SVFBugEvent sourceInstEvent(SVFBugEvent::EventType::SourceInst, node);
237
+ eventStack.push_back(sourceInstEvent); // Add the source instruction event to the event stack
238
+
239
+ if (eventStack.empty())
240
+ {
241
+ return; // If the event stack is empty, return early
242
+ }
243
+
244
+ std::string loc = eventStack.back().getEventLoc(); // Get the location of the last event in the stack
245
+
246
+ // Check if the bug at this location has already been reported
247
+ if (bugLoc.find(loc) != bugLoc.end())
248
+ {
249
+ return; // If the bug location is already reported, return early
250
+ }
251
+ else
252
+ {
253
+ bugLoc.insert(loc); // Otherwise, mark this location as reported
254
+ }
255
+
256
+ // Add the bug to the recorder with details from the event stack
257
+ recoder.addAbsExecBug(GenericBug::FULLBUFOVERFLOW, eventStack, 0, 0, 0, 0);
258
+ nodeToBugInfo[node] = e.what(); // Record the exception information for the node
259
+ }
260
+
261
+ /**
262
+ * @brief Reports all detected buffer overflow bugs.
263
+ */
264
+ void reportBug()
265
+ {
266
+ if (!nodeToBugInfo.empty())
267
+ {
268
+ std::cerr << "######################Buffer Overflow (" + std::to_string(nodeToBugInfo.size())
269
+ + " found)######################\n";
270
+ std::cerr << "---------------------------------------------\n";
271
+ for (const auto& it : nodeToBugInfo)
272
+ {
273
+ std::cerr << it.second << "\n---------------------------------------------\n";
274
+ }
275
+ }
276
+ }
277
+
278
+ /**
279
+ * @brief Initializes external API buffer overflow check rules.
280
+ */
281
+ void initExtAPIBufOverflowCheckRules();
282
+
283
+ /**
284
+ * @brief Handles external API calls related to buffer overflow detection.
285
+ * @param as Reference to the abstract state.
286
+ * @param call Pointer to the call ICFG node.
287
+ */
288
+ void detectExtAPI(AbstractState& as, const CallICFGNode *call);
289
+
290
+ /**
291
+ * @brief Checks if memory can be safely accessed.
292
+ * @param as Reference to the abstract state.
293
+ * @param value Pointer to the SVF var.
294
+ * @param len The interval value representing the length of the memory access.
295
+ * @return True if the memory access is safe, false otherwise.
296
+ */
297
+ bool canSafelyAccessMemory(AbstractState& as, const SVFVar *value, const IntervalValue &len);
298
+
299
+ private:
300
+ /**
301
+ * @brief Detects buffer overflow in 'strcat' function calls.
302
+ * @param as Reference to the abstract state.
303
+ * @param call Pointer to the call ICFG node.
304
+ * @return True if a buffer overflow is detected, false otherwise.
305
+ */
306
+ bool detectStrcat(AbstractState& as, const CallICFGNode *call);
307
+
308
+ /**
309
+ * @brief Detects buffer overflow in 'strcpy' function calls.
310
+ * @param as Reference to the abstract state.
311
+ * @param call Pointer to the call ICFG node.
312
+ * @return True if a buffer overflow is detected, false otherwise.
313
+ */
314
+ bool detectStrcpy(AbstractState& as, const CallICFGNode *call);
315
+
316
+ private:
317
+ Map<const GepObjVar*, IntervalValue> gepObjOffsetFromBase; ///< Maps GEP objects to their offsets from the base.
318
+ Map<std::string, std::vector<std::pair<u32_t, u32_t>>> extAPIBufOverflowCheckRules; ///< Rules for checking buffer overflows in external APIs.
319
+ Set<std::string> bugLoc; ///< Set of locations where bugs have been reported.
320
+ SVFBugReport recoder; ///< Recorder for abstract execution bugs.
321
+ Map<const ICFGNode*, std::string> nodeToBugInfo; ///< Maps ICFG nodes to bug information.
322
+ };
323
+ }