svf-lib 1.0.2072 → 1.0.2074

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.
Binary file
Binary file
@@ -46,8 +46,9 @@
46
46
  #ifndef Z3_EXAMPLE_INTERVAL_DOMAIN_H
47
47
  #define Z3_EXAMPLE_INTERVAL_DOMAIN_H
48
48
 
49
- #include "AE/Core/IntervalValue.h"
50
49
  #include "AE/Core/AbstractValue.h"
50
+ #include "AE/Core/IntervalValue.h"
51
+ #include "SVFIR/SVFVariables.h"
51
52
  #include "Util/Z3Expr.h"
52
53
 
53
54
  #include <iomanip>
@@ -79,6 +80,21 @@ public:
79
80
 
80
81
  virtual ~AbstractState() = default;
81
82
 
83
+ // getGepObjAddrs
84
+ AddressValue getGepObjAddrs(u32_t pointer, IntervalValue offset);
85
+
86
+ // initObjVar
87
+ void initObjVar(ObjVar* objVar);
88
+ // getElementIndex
89
+ IntervalValue getElementIndex(const GepStmt* gep);
90
+ // getByteOffset
91
+ IntervalValue getByteOffset(const GepStmt* gep);
92
+ // printAbstractState
93
+ // loadValue
94
+ AbstractValue loadValue(NodeID varId);
95
+ // storeValue
96
+ void storeValue(NodeID varId, AbstractValue val);
97
+
82
98
 
83
99
  /// The physical address starts with 0x7f...... + idx
84
100
  static inline u32_t getVirtualMemAddress(u32_t idx)
@@ -258,14 +274,9 @@ public:
258
274
  /// domain narrow with other, and return the narrowed domain
259
275
  AbstractState narrowing(const AbstractState&other);
260
276
 
261
- /// domain widen with other, important! other widen this.
262
- void widenWith(const AbstractState&other);
263
-
264
277
  /// domain join with other, important! other widen this.
265
278
  void joinWith(const AbstractState&other);
266
279
 
267
- /// domain narrow with other, important! other widen this.
268
- void narrowWith(const AbstractState&other);
269
280
 
270
281
  /// domain meet with other, important! other widen this.
271
282
  void meetWith(const AbstractState&other);
@@ -299,8 +310,7 @@ public:
299
310
  }
300
311
 
301
312
 
302
- /// Print values of all expressions
303
- void printExprValues(std::ostream &oss) const;
313
+ void printAbstractState() const;
304
314
 
305
315
  std::string toString() const
306
316
  {
@@ -386,9 +396,6 @@ public:
386
396
  }
387
397
 
388
398
 
389
- protected:
390
- void printTable(const VarToAbsValMap&table, std::ostream &oss) const;
391
-
392
399
  };
393
400
 
394
401
  }
@@ -29,9 +29,9 @@
29
29
  //
30
30
 
31
31
  #include "AE/Core/ICFGWTO.h"
32
- #include "AE/Svfexe/SVFIR2AbsState.h"
33
32
  #include "Util/SVFBugReport.h"
34
33
  #include "WPA/Andersen.h"
34
+ #include "AE/Core/AbstractState.h"
35
35
 
36
36
  namespace SVF
37
37
  {
@@ -137,8 +137,8 @@ protected:
137
137
  /// Global ICFGNode is handled at the entry of the program,
138
138
  virtual void handleGlobalNode();
139
139
 
140
- /// mark recursive functions by detecting SCC in callgraph
141
- void markRecursiveFuns();
140
+ /// Mark recursive functions in the call graph
141
+ void initWTO();
142
142
 
143
143
  /**
144
144
  * Check if execution state exist by merging states of predecessor nodes
@@ -146,7 +146,7 @@ protected:
146
146
  * @param curNode The ICFGNode to analyse
147
147
  * @return if this node has preceding execution state
148
148
  */
149
- bool propagateStateIfFeasible(const ICFGNode* curNode);
149
+ bool mergeStatesFromPredecessors(const ICFGNode* curNode);
150
150
 
151
151
  /**
152
152
  * Check if execution state exist at the branch edge
@@ -161,14 +161,7 @@ protected:
161
161
  *
162
162
  * @param block basic block that has one instruction or a series of instructions
163
163
  */
164
- virtual void handleWTONode(const ICFGSingletonWTO *icfgSingletonWto);
165
-
166
- /**
167
- * handle one instruction in ICFGNode
168
- *
169
- * @param node ICFGNode which has a single instruction
170
- */
171
- virtual void handleICFGNode(const ICFGNode* node);
164
+ virtual void handleSingletonWTO(const ICFGSingletonWTO *icfgSingletonWto);
172
165
 
173
166
  /**
174
167
  * handle call node in ICFGNode
@@ -182,14 +175,10 @@ protected:
182
175
  *
183
176
  * @param cycle WTOCycle which has weak topo order of basic blocks and nested cycles
184
177
  */
185
- virtual void handleCycle(const ICFGCycleWTO* cycle);
178
+ virtual void handleCycleWTO(const ICFGCycleWTO* cycle);
179
+
180
+ void handleWTOComponents(const std::list<const ICFGWTOComp*>& wtoComps);
186
181
 
187
- /**
188
- * handle user defined function, ext function is not included.
189
- *
190
- * @param func SVFFunction which has a series of basic blocks
191
- */
192
- virtual void handleFunc(const SVFFunction* func);
193
182
 
194
183
  /**
195
184
  * handle SVF Statement like CmpStmt, CallStmt, GepStmt, LoadStmt, StoreStmt, etc.
@@ -332,11 +321,34 @@ protected:
332
321
  void AccessMemoryViaCallArgs(const SVF::SVFArgument *arg, SVF::FILOWorkList<const SVFValue *>& worklist, Set<const SVFValue *>& visited);
333
322
 
334
323
 
324
+ void updateStateOnAddr(const AddrStmt *addr);
325
+
326
+ void updateStateOnBinary(const BinaryOPStmt *binary);
327
+
328
+ void updateStateOnCmp(const CmpStmt *cmp);
329
+
330
+ void updateStateOnLoad(const LoadStmt *load);
331
+
332
+ void updateStateOnStore(const StoreStmt *store);
333
+
334
+ void updateStateOnCopy(const CopyStmt *copy);
335
+
336
+ void updateStateOnCall(const CallPE *callPE);
337
+
338
+ void updateStateOnRet(const RetPE *retPE);
339
+
340
+ void updateStateOnGep(const GepStmt *gep);
341
+
342
+ void updateStateOnSelect(const SelectStmt *select);
343
+
344
+ void updateStateOnPhi(const PhiStmt *phi);
345
+
346
+ IntervalValue getRangeLimitFromType(const SVFType* type);
347
+
348
+
335
349
  /// protected data members, also used in subclasses
336
350
  SVFIR* _svfir;
337
- PTACallGraph* _callgraph;
338
351
  /// Execution State, used to store the Interval Value of every SVF variable
339
- SVFIR2AbsState* _svfir2AbsState;
340
352
  AEAPI* _api{nullptr};
341
353
 
342
354
  ICFG* _icfg;
@@ -347,7 +359,6 @@ protected:
347
359
  SVFBugReport _recoder;
348
360
  std::vector<const CallICFGNode*> _callSiteStack;
349
361
  Map<const ICFGNode*, std::string> _nodeToBugInfo;
350
- AndersenWaveDiff* _ander;
351
362
  Map<const SVFFunction*, ICFGWTO*> _funcToWTO;
352
363
  Set<const SVFFunction*> _recursiveFuns;
353
364
 
@@ -363,13 +374,8 @@ private:
363
374
  virtual void indirectCallFunPass(const CallICFGNode* callNode);
364
375
 
365
376
  protected:
366
- // helper functions in handleCycle
367
- bool isFixPointAfterWidening(const ICFGNode* cycle_head,
368
- AbstractState& pre_as);
369
- bool isFixPointAfterNarrowing(const SVF::ICFGNode* cycle_head,
370
- SVF::AbstractState& pre_as);
371
377
 
372
- AbstractState& getAbsState(const ICFGNode* node)
378
+ AbstractState& getAbsStateFromTrace(const ICFGNode* node)
373
379
  {
374
380
  const ICFGNode* repNode = _icfg->getRepNode(node);
375
381
  if (_postAbsTrace.count(repNode) == 0)
@@ -382,6 +388,12 @@ protected:
382
388
  }
383
389
  }
384
390
 
391
+ bool hasAbsStateFromTrace(const ICFGNode* node)
392
+ {
393
+ const ICFGNode* repNode = _icfg->getRepNode(node);
394
+ return _postAbsTrace.count(repNode) != 0;
395
+ }
396
+
385
397
  protected:
386
398
  // there data should be shared with subclasses
387
399
  Map<std::string, std::function<void(const CallSite &)>> _func_map;
@@ -174,12 +174,23 @@ private:
174
174
  */
175
175
  virtual void handleSVFStatement(const SVFStmt *stmt) override;
176
176
 
177
- /**
178
- * handle ICFGNode regarding buffer overflow checking
179
- *
180
- * @param node ICFGNode
181
- */
182
- virtual void handleICFGNode(const SVF::ICFGNode *node) override;
177
+ // TODO: will delete later
178
+ virtual void handleSingletonWTO(const ICFGSingletonWTO *icfgSingletonWto) override
179
+ {
180
+ AbstractInterpretation::handleSingletonWTO(icfgSingletonWto);
181
+ const ICFGNode* repNode = _icfg->getRepNode(icfgSingletonWto->node());
182
+ if (_postAbsTrace.count(repNode) == 0)
183
+ {
184
+ return;
185
+ }
186
+ const std::vector<const ICFGNode*>& worklist_vec = _icfg->getSubNodes(icfgSingletonWto->node());
187
+
188
+ for (auto it = worklist_vec.begin(); it != worklist_vec.end(); ++it)
189
+ {
190
+ const ICFGNode* curNode = *it;
191
+ detectBufOverflow(curNode);
192
+ }
193
+ }
183
194
 
184
195
  /**
185
196
  * check buffer overflow at ICFGNode which is a checkpoint
@@ -27,7 +27,6 @@
27
27
  // The implementation is based on
28
28
  // Xiao Cheng, Jiawei Wang and Yulei Sui. Precise Sparse Abstract Execution via Cross-Domain Interaction.
29
29
  // 46th International Conference on Software Engineering. (ICSE24)
30
- #include "AE/Svfexe/SVFIR2AbsState.h"
31
30
  #include "Graphs/ICFG.h"
32
31
 
33
32
  namespace SVF
Binary file
@@ -143,10 +143,10 @@ protected:
143
143
  /**
144
144
  * Check if execution state exist by merging states of predecessor nodes
145
145
  *
146
- * @param curNode The ICFGNode to analyse
146
+ * @param icfgNode The icfg node to analyse
147
147
  * @return if this node has preceding execution state
148
148
  */
149
- bool mergeStatesFromPredecessors(const ICFGNode* curNode);
149
+ bool mergeStatesFromPredecessors(const ICFGNode * icfgNode);
150
150
 
151
151
  /**
152
152
  * Check if execution state exist at the branch edge
@@ -179,6 +179,8 @@ protected:
179
179
 
180
180
  void handleWTOComponents(const std::list<const ICFGWTOComp*>& wtoComps);
181
181
 
182
+ void handleWTOComponent(const ICFGWTOComp* wtoComp);
183
+
182
184
 
183
185
  /**
184
186
  * handle SVF Statement like CmpStmt, CallStmt, GepStmt, LoadStmt, StoreStmt, etc.
@@ -378,20 +380,20 @@ protected:
378
380
  AbstractState& getAbsStateFromTrace(const ICFGNode* node)
379
381
  {
380
382
  const ICFGNode* repNode = _icfg->getRepNode(node);
381
- if (_postAbsTrace.count(repNode) == 0)
383
+ if (_abstractTrace.count(repNode) == 0)
382
384
  {
383
385
  assert(0 && "No preAbsTrace for this node");
384
386
  }
385
387
  else
386
388
  {
387
- return _postAbsTrace[repNode];
389
+ return _abstractTrace[repNode];
388
390
  }
389
391
  }
390
392
 
391
393
  bool hasAbsStateFromTrace(const ICFGNode* node)
392
394
  {
393
395
  const ICFGNode* repNode = _icfg->getRepNode(node);
394
- return _postAbsTrace.count(repNode) != 0;
396
+ return _abstractTrace.count(repNode) != 0;
395
397
  }
396
398
 
397
399
  protected:
@@ -399,8 +401,7 @@ protected:
399
401
  Map<std::string, std::function<void(const CallSite &)>> _func_map;
400
402
  Set<const CallICFGNode*> _checkpoints;
401
403
  Set<std::string> _checkpoint_names;
402
- Map<const ICFGNode*, AbstractState> _preAbsTrace;
403
- Map<const ICFGNode*, AbstractState> _postAbsTrace;
404
+ Map<const ICFGNode*, AbstractState> _abstractTrace; // abstract states immediately after nodes
404
405
  std::string _moduleName;
405
406
  };
406
407
  }
@@ -178,12 +178,12 @@ private:
178
178
  virtual void handleSingletonWTO(const ICFGSingletonWTO *icfgSingletonWto) override
179
179
  {
180
180
  AbstractInterpretation::handleSingletonWTO(icfgSingletonWto);
181
- const ICFGNode* repNode = _icfg->getRepNode(icfgSingletonWto->node());
182
- if (_postAbsTrace.count(repNode) == 0)
181
+ const ICFGNode* repNode = _icfg->getRepNode(icfgSingletonWto->getICFGNode());
182
+ if (_abstractTrace.count(repNode) == 0)
183
183
  {
184
184
  return;
185
185
  }
186
- const std::vector<const ICFGNode*>& worklist_vec = _icfg->getSubNodes(icfgSingletonWto->node());
186
+ const std::vector<const ICFGNode*>& worklist_vec = _icfg->getSubNodes(icfgSingletonWto->getICFGNode());
187
187
 
188
188
  for (auto it = worklist_vec.begin(); it != worklist_vec.end(); ++it)
189
189
  {
@@ -341,7 +341,7 @@ public:
341
341
  }
342
342
 
343
343
  /// Return the graph node
344
- const NodeT* node() const
344
+ const NodeT* getICFGNode() const
345
345
  {
346
346
  return _node;
347
347
  }
@@ -457,7 +457,7 @@ public:
457
457
  std::string str;
458
458
  std::stringstream rawstr(str);
459
459
  rawstr << "(";
460
- rawstr << _head->node()->getId() << ", ";
460
+ rawstr << _head->getICFGNode()->getId() << ", ";
461
461
  for (auto it = begin(), et = end(); it != et;)
462
462
  {
463
463
  rawstr << (*it)->toString();
@@ -698,7 +698,7 @@ protected:
698
698
 
699
699
  void visit(const WTOCycleT& cycle) override
700
700
  {
701
- const NodeT* head = cycle.head()->node();
701
+ const NodeT* head = cycle.head()->getICFGNode();
702
702
  WTOCycleDepthPtr previous_cycleDepth = _wtoCycleDepth;
703
703
  _nodeToWTOCycleDepth.insert(std::make_pair(head, _wtoCycleDepth));
704
704
  _wtoCycleDepth =
@@ -714,7 +714,7 @@ protected:
714
714
  void visit(const WTONodeT& node) override
715
715
  {
716
716
  _nodeToWTOCycleDepth.insert(
717
- std::make_pair(node.node(), _wtoCycleDepth));
717
+ std::make_pair(node.getICFGNode(), _wtoCycleDepth));
718
718
  }
719
719
 
720
720
  }; // end class WTOCycleDepthBuilder
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svf-lib",
3
- "version": "1.0.2072",
3
+ "version": "1.0.2074",
4
4
  "description": "SVF's npm support",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,191 +0,0 @@
1
- //===- SVFIR2AbsState.h -- SVF IR Translation to Interval Domain-----//
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
- * SVFIR2AbsState.h
24
- *
25
- * Created on: Aug 7, 2022
26
- * Author: Jiawei Wang, Xiao Cheng
27
- *
28
- */
29
- // The implementation is based on
30
- // Xiao Cheng, Jiawei Wang and Yulei Sui. Precise Sparse Abstract Execution via Cross-Domain Interaction.
31
- // 46th International Conference on Software Engineering. (ICSE24)
32
-
33
- #ifndef Z3_EXAMPLE_SVFIR2ITVEXESTATE_H
34
- #define Z3_EXAMPLE_SVFIR2ITVEXESTATE_H
35
-
36
- #include "AE/Core/AbstractState.h"
37
- #include "AE/Core/RelExeState.h"
38
- #include "SVFIR/SVFIR.h"
39
-
40
- namespace SVF
41
- {
42
- class SVFIR2AbsState
43
- {
44
- public:
45
- static AbstractValue globalNulladdrs;
46
- public:
47
- SVFIR2AbsState(SVFIR *ir) : _svfir(ir) {}
48
-
49
-
50
- void setRelEs(const RelExeState &relEs)
51
- {
52
- _relEs = relEs;
53
- }
54
-
55
- RelExeState &getRelEs()
56
- {
57
- return _relEs;
58
- }
59
-
60
- void widenAddrs(AbstractState& es, AbstractState&lhs, const AbstractState&rhs);
61
-
62
- void narrowAddrs(AbstractState& es, AbstractState&lhs, const AbstractState&rhs);
63
-
64
- /// Return the field address given a pointer points to a struct object and an offset
65
- AddressValue getGepObjAddress(AbstractState& es, u32_t pointer, APOffset offset);
66
-
67
- /// Return the value range of Integer SVF Type, e.g. unsigned i8 Type->[0, 255], signed i8 Type->[-128, 127]
68
- IntervalValue getRangeLimitFromType(const SVFType* type);
69
-
70
- IntervalValue getZExtValue(const AbstractState& es, const SVFVar* var);
71
- IntervalValue getSExtValue(const AbstractState& es, const SVFVar* var);
72
- IntervalValue getFPToSIntValue(const AbstractState& es, const SVFVar* var);
73
- IntervalValue getFPToUIntValue(const AbstractState& es, const SVFVar* var);
74
- IntervalValue getSIntToFPValue(const AbstractState& es, const SVFVar* var);
75
- IntervalValue getUIntToFPValue(const AbstractState& es, const SVFVar* var);
76
- IntervalValue getTruncValue(const AbstractState& es, const SVFVar* var, const SVFType* dstType);
77
- IntervalValue getFPTruncValue(const AbstractState& es, const SVFVar* var, const SVFType* dstType);
78
-
79
- /// Return the byte offset expression of a GepStmt
80
- /// elemBytesize is the element byte size of an static alloc or heap alloc array
81
- /// e.g. GepStmt* gep = [i32*10], x, and x is [0,3]
82
- /// std::pair<s32_t, s32_t> byteOffset = getByteOffset(gep);
83
- /// byteOffset should be [0, 12] since i32 is 4 bytes.
84
- IntervalValue getByteOffset(const AbstractState& es, const GepStmt *gep);
85
-
86
- /// Return the offset expression of a GepStmt
87
- IntervalValue getElementIndex(const AbstractState& es, const GepStmt *gep);
88
-
89
-
90
- static z3::context &getContext()
91
- {
92
- return Z3Expr::getContext();
93
- }
94
-
95
- void applySummary(AbstractState&es);
96
-
97
-
98
- /// Init ObjVar
99
- void initObjVar(AbstractState& as, const ObjVar* var);
100
-
101
-
102
- inline AbstractValue &getAddrs(AbstractState& es, u32_t id)
103
- {
104
- if (inVarToAddrsTable(es, id))
105
- return es[id];
106
- else
107
- return globalNulladdrs;
108
- }
109
-
110
- inline bool inVarTable(const AbstractState& es, u32_t id) const
111
- {
112
- return es.inVarToValTable(id) || es.inVarToAddrsTable(id);
113
- }
114
-
115
- inline bool inAddrTable(const AbstractState& es, u32_t id) const
116
- {
117
- return es.inAddrToValTable(id) || es.inAddrToAddrsTable(id);
118
- }
119
-
120
- /// whether the variable is in varToVal table
121
- inline bool inVarToValTable(const AbstractState& es, u32_t id) const
122
- {
123
- return es.inVarToValTable(id);
124
- }
125
-
126
- /// whether the variable is in varToAddrs table
127
- inline bool inVarToAddrsTable(const AbstractState& es, u32_t id) const
128
- {
129
- return es.inVarToAddrsTable(id);
130
- }
131
-
132
-
133
- /// whether the memory address stores a interval value
134
- inline bool inLocToValTable(const AbstractState& es, u32_t id) const
135
- {
136
- return es.inAddrToValTable(id);
137
- }
138
-
139
- /// whether the memory address stores memory addresses
140
- inline bool inLocToAddrsTable(const AbstractState& es, u32_t id) const
141
- {
142
- return es.inAddrToAddrsTable(id);
143
- }
144
-
145
- void handleAddr(AbstractState& es, const AddrStmt *addr);
146
-
147
- void handleBinary(AbstractState& es, const BinaryOPStmt *binary);
148
-
149
- void handleCmp(AbstractState& es, const CmpStmt *cmp);
150
-
151
- void handleLoad(AbstractState& es, const LoadStmt *load);
152
-
153
- void handleStore(AbstractState& es, const StoreStmt *store);
154
-
155
- void handleCopy(AbstractState& es, const CopyStmt *copy);
156
-
157
- void handleCall(AbstractState& es, const CallPE *callPE);
158
-
159
- void handleRet(AbstractState& es, const RetPE *retPE);
160
-
161
- void handleGep(AbstractState& es, const GepStmt *gep);
162
-
163
- void handleSelect(AbstractState& es, const SelectStmt *select);
164
-
165
- void handlePhi(AbstractState& es, const PhiStmt *phi);
166
-
167
- /// Return the internal index if idx is an address otherwise return the value of idx
168
- static inline u32_t getInternalID(u32_t idx)
169
- {
170
- return AbstractState::getInternalID(idx);
171
- }
172
-
173
- /// The physical address starts with 0x7f...... + idx
174
- static inline u32_t getVirtualMemAddress(u32_t idx)
175
- {
176
- return AbstractState::getVirtualMemAddress(idx);
177
- }
178
-
179
- /// Check bit value of val start with 0x7F000000, filter by 0xFF000000
180
- static inline bool isVirtualMemAddress(u32_t val)
181
- {
182
- return AbstractState::isVirtualMemAddress(val);
183
- }
184
-
185
- private:
186
- SVFIR *_svfir;
187
- RelExeState _relEs;
188
- };
189
- }
190
-
191
- #endif //Z3_EXAMPLE_SVFIR2ITVEXESTATE_H