|
Static Value-Flow Analysis
|
Handles external API calls and manages abstract states. More...
#include <AbsExtAPI.h>
Public Types | |
| enum | ExtAPIType { UNCLASSIFIED , MEMCPY , MEMSET , STRCPY , STRCAT } |
| Enumeration of external API types. More... | |
Public Member Functions | |
| void | initExtFunMap () |
| Initializes the external function map. | |
| std::string | strRead (const ValVar *rhs, const ICFGNode *node) |
| Reads a string from the abstract state. | |
| void | handleExtAPI (const CallICFGNode *call) |
| Handles an external API call. | |
| u32_t | getElementSize (const ValVar *var) |
| Get the byte size of each element for a pointer/array variable. | |
| IntervalValue | getStrlen (const ValVar *strValue, const ICFGNode *node) |
| Calculate the length of a null-terminated string in abstract state. | |
| void | handleStrcpy (const CallICFGNode *call) |
| void | handleStrcat (const CallICFGNode *call) |
| void | handleStrncat (const CallICFGNode *call) |
| 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 | handleMemset (const ValVar *dst, const IntervalValue &elem, const IntervalValue &len, const ICFGNode *node) |
| IntervalValue | getRangeLimitFromType (const SVFType *type) |
| Gets the range limit from a type. | |
| AbstractState & | getAbsState (const ICFGNode *node) |
| Retrieves the abstract state from the trace for a given ICFG node. | |
| void | collectCheckPoint () |
| void | checkPointAllSet () |
Static Public Member Functions | |
| static bool | isValidLength (const IntervalValue &len) |
| Check if an interval length is usable (not bottom, not unbounded). | |
Public Attributes | |
| Set< const CallICFGNode * > | checkpoints |
Protected Attributes | |
| AbstractInterpretation * | ae |
| Owning AbstractInterpretation; provides state access. | |
| SVFIR * | svfir |
| Pointer to the SVF intermediate representation. | |
| ICFG * | icfg |
| Pointer to the interprocedural control flow graph. | |
| Map< std::string, std::function< void(const CallICFGNode *)> > | func_map |
| Map of function names to handlers. | |
Private Member Functions | |
| AbsExtAPI (AbstractInterpretation *ae) | |
| Constructor for AbsExtAPI. | |
Friends | |
| class | AbstractInterpretation |
Handles external API calls and manages abstract states.
Definition at line 42 of file AbsExtAPI.h.
Enumeration of external API types.
| Enumerator | |
|---|---|
| UNCLASSIFIED | |
| MEMCPY | |
| MEMSET | |
| STRCPY | |
| STRCAT | |
Definition at line 49 of file AbsExtAPI.h.
|
private |
Constructor for AbsExtAPI.
| ae | Reference to the AbstractInterpretation instance. |
Definition at line 35 of file AbsExtAPI.cpp.
| void AbsExtAPI::checkPointAllSet | ( | ) |
Definition at line 307 of file AbsExtAPI.cpp.
| void AbsExtAPI::collectCheckPoint | ( | ) |
Definition at line 267 of file AbsExtAPI.cpp.
| AbstractState & AbsExtAPI::getAbsState | ( | const ICFGNode * | node | ) |
Retrieves the abstract state from the trace for a given ICFG node.
| node | Pointer to the ICFG node. |
| Assertion | if no trace exists for the node. |
Definition at line 262 of file AbsExtAPI.cpp.
Get the byte size of each element for a pointer/array variable.
Get the byte size of each element for a pointer/array variable. Shared by handleMemcpy, handleMemset, and getStrlen to avoid duplication.
Definition at line 426 of file AbsExtAPI.cpp.
| IntervalValue AbsExtAPI::getRangeLimitFromType | ( | const SVFType * | type | ) |
Gets the range limit from a type.
| type | Pointer to the SVF type. |
This function, getRangeLimitFromType, calculates the lower and upper bounds of a numeric range for a given SVFType. It is used to determine the possible value range of integer types. If the type is an SVFIntegerType, it calculates the bounds based on the size and signedness of the type. The calculated bounds are returned as an IntervalValue representing the lower (lb) and upper (ub) limits of the range.
| type | The SVFType for which to calculate the value range. |
Definition at line 642 of file AbsExtAPI.cpp.
| IntervalValue AbsExtAPI::getStrlen | ( | const ValVar * | strValue, |
| const ICFGNode * | node | ||
| ) |
Calculate the length of a null-terminated string in abstract state.
Calculate the length of a null-terminated string in abstract state. Scans memory from the base of strValue looking for a '\0' byte. Returns an IntervalValue: exact length if '\0' found, otherwise [0, MaxFieldLimit].
Definition at line 450 of file AbsExtAPI.cpp.
| void AbsExtAPI::handleExtAPI | ( | const CallICFGNode * | call | ) |
Handles an external API call.
| call | Pointer to the call ICFG node. |
Definition at line 351 of file AbsExtAPI.cpp.
| void AbsExtAPI::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].
Definition at line 545 of file AbsExtAPI.cpp.
| void AbsExtAPI::handleMemset | ( | const ValVar * | dst, |
| const IntervalValue & | elem, | ||
| const IntervalValue & | len, | ||
| const ICFGNode * | node | ||
| ) |
Core memset: fill dst with elem for len bytes. Note: elemSize here uses the pointee type's full size (not array element size) to match how LLVM memset/wmemset intrinsics measure len. For a pointer to wchar_t[100], elemSize = sizeof(wchar_t[100]), so range_val reflects the number of top-level GEP fields, not individual array elements.
Definition at line 585 of file AbsExtAPI.cpp.
| void AbsExtAPI::handleStrcat | ( | const CallICFGNode * | call | ) |
strcat(dst, src): append all of src after the end of dst. Covers: strcat, __strcat_chk, wcscat, __wcscat_chk
Definition at line 522 of file AbsExtAPI.cpp.
| void AbsExtAPI::handleStrcpy | ( | const CallICFGNode * | call | ) |
strcpy(dst, src): copy all of src (including '\0') into dst. Covers: strcpy, __strcpy_chk, stpcpy, wcscpy, __wcscpy_chk
Definition at line 511 of file AbsExtAPI.cpp.
| void AbsExtAPI::handleStrncat | ( | const CallICFGNode * | call | ) |
strncat(dst, src, n): append at most n bytes of src after the end of dst. Covers: strncat, __strncat_chk, wcsncat, __wcsncat_chk
Definition at line 534 of file AbsExtAPI.cpp.
| void AbsExtAPI::initExtFunMap | ( | ) |
Initializes the external function map.
Definition at line 42 of file AbsExtAPI.cpp.
|
static |
Check if an interval length is usable (not bottom, not unbounded).
Check if an interval length is usable for memory operations. Returns false for bottom (no information) or unbounded lower bound (cannot determine a concrete start for iteration).
Definition at line 442 of file AbsExtAPI.cpp.
Reads a string from the abstract state.
| as | Reference to the abstract state. |
| rhs | Pointer to the SVF variable representing the string. |
Definition at line 322 of file AbsExtAPI.cpp.
|
friend |
Definition at line 55 of file AbsExtAPI.h.
|
protected |
Owning AbstractInterpretation; provides state access.
Definition at line 123 of file AbsExtAPI.h.
| Set<const CallICFGNode*> SVF::AbsExtAPI::checkpoints |
Definition at line 120 of file AbsExtAPI.h.
|
protected |
Map of function names to handlers.
Definition at line 126 of file AbsExtAPI.h.
|
protected |
Pointer to the interprocedural control flow graph.
Definition at line 125 of file AbsExtAPI.h.
|
protected |
Pointer to the SVF intermediate representation.
Definition at line 124 of file AbsExtAPI.h.