Static Value-Flow Analysis
Loading...
Searching...
No Matches
AbsExtAPI.h
Go to the documentation of this file.
1//===- AbsExtAPI.h -- Abstract Interpretation External API handler-----//
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// Created on: Sep 9, 2024
25// Author: Xiao Cheng, Jiawei Wang
26//
27#pragma once
28
29#include <functional>
30
33#include "SVFIR/SVFIR.h"
34#include "Util/GeneralType.h"
35
36namespace SVF
37{
38
39class AbstractInterpretation;
40class AbstractState;
41class CallICFGNode;
42class ICFGNode;
43
49{
50public:
56
57 // Only AbstractInterpretation may construct the single owned AbsExtAPI
58 // instance (reachable through its private getUtils()). Keeping the
59 // constructor private prevents external callers from creating their own
60 // AbsExtAPI and invoking handleExtAPI()/handleMemcpy()/... directly.
62private:
68
69public:
73 void initExtFunMap();
74
81 std::string strRead(const ValVar* rhs, const ICFGNode* node);
82
87 void handleExtAPI(const CallICFGNode *call);
88
89 // --- Shared primitives used by string/memory handlers ---
90
93
95 static bool isValidLength(const IntervalValue& len);
96
98 IntervalValue getStrlen(const ValVar *strValue, const ICFGNode* node);
99
100 // --- String/memory operation handlers ---
101
102 void handleStrcpy(const CallICFGNode *call);
103 void handleStrcat(const CallICFGNode *call);
104 void handleStrncat(const CallICFGNode *call);
105 void handleMemcpy(const ValVar *dst, const ValVar *src, const IntervalValue& len, u32_t start_idx, const ICFGNode* node);
106 void handleMemset(const ValVar* dst, const IntervalValue& elem, const IntervalValue& len, const ICFGNode* node);
107
114
121 AbstractState& getAbsState(const ICFGNode* node);
122
123 void collectCheckPoint();
124 void checkPointAllSet();
125
127
128protected:
132 Map<std::string, std::function<void(const CallICFGNode*)>> func_map;
133};
134
135} // namespace SVF
newitem type
Definition cJSON.cpp:2739
Handles external API calls and manages abstract states.
Definition AbsExtAPI.h:49
AbstractInterpretation * ae
Owning AbstractInterpretation; provides state access.
Definition AbsExtAPI.h:129
AbstractState & getAbsState(const ICFGNode *node)
Retrieves the abstract state from the trace for a given ICFG node.
void collectCheckPoint()
void initExtFunMap()
Initializes the external function map.
Definition AbsExtAPI.cpp:42
IntervalValue getStrlen(const ValVar *strValue, const ICFGNode *node)
Calculate the length of a null-terminated string in abstract state.
void handleMemcpy(const ValVar *dst, const ValVar *src, const IntervalValue &len, u32_t start_idx, const ICFGNode *node)
Core memcpy: copy len bytes from src to dst starting at dst[start_idx].
void handleExtAPI(const CallICFGNode *call)
Handles an external API call.
void handleStrncat(const CallICFGNode *call)
static bool isValidLength(const IntervalValue &len)
Check if an interval length is usable (not bottom, not unbounded).
Set< const CallICFGNode * > checkpoints
Definition AbsExtAPI.h:126
void checkPointAllSet()
std::string strRead(const ValVar *rhs, const ICFGNode *node)
Reads a string from the abstract state.
u32_t getElementSize(const ValVar *var)
Get the byte size of each element for a pointer/array variable.
void handleMemset(const ValVar *dst, const IntervalValue &elem, const IntervalValue &len, const ICFGNode *node)
SVFIR * svfir
Pointer to the SVF intermediate representation.
Definition AbsExtAPI.h:130
ExtAPIType
Enumeration of external API types.
Definition AbsExtAPI.h:55
IntervalValue getRangeLimitFromType(const SVFType *type)
Gets the range limit from a type.
ICFG * icfg
Pointer to the interprocedural control flow graph.
Definition AbsExtAPI.h:131
void handleStrcat(const CallICFGNode *call)
void handleStrcpy(const CallICFGNode *call)
Map< std::string, std::function< void(const CallICFGNode *)> > func_map
Map of function names to handlers.
Definition AbsExtAPI.h:132
for isBitcode
Definition BasicTypes.h:70
std::unordered_map< Key, Value, Hash, KeyEqual, Allocator > Map
Definition GeneralType.h:56
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76
unsigned u32_t
Definition GeneralType.h:67