|
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 | |
| AbsExtAPI (AbstractStateManager *mgr) | |
| Constructor for AbsExtAPI. | |
| 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 & | getAbstractState (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 | |
| AbstractStateManager * | mgr |
| Pointer to the state manager. | |
| 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. | |
Handles external API calls and manages abstract states.
Definition at line 43 of file AbsExtAPI.h.
Enumeration of external API types.
| Enumerator | |
|---|---|
| UNCLASSIFIED | |
| MEMCPY | |
| MEMSET | |
| STRCPY | |
| STRCAT | |
Definition at line 50 of file AbsExtAPI.h.
| AbsExtAPI::AbsExtAPI | ( | AbstractStateManager * | mgr | ) |
Constructor for AbsExtAPI.
| ae | Reference to the AbstractInterpretation instance. |
Definition at line 35 of file AbsExtAPI.cpp.
| void AbsExtAPI::checkPointAllSet | ( | ) |
Definition at line 345 of file AbsExtAPI.cpp.
| void AbsExtAPI::collectCheckPoint | ( | ) |
Definition at line 305 of file AbsExtAPI.cpp.
| AbstractState & AbsExtAPI::getAbstractState | ( | 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 300 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 464 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 680 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 488 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 389 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 583 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 623 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 560 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 549 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 572 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 480 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 360 of file AbsExtAPI.cpp.
| Set<const CallICFGNode*> SVF::AbsExtAPI::checkpoints |
Definition at line 114 of file AbsExtAPI.h.
|
protected |
Map of function names to handlers.
Definition at line 120 of file AbsExtAPI.h.
|
protected |
Pointer to the interprocedural control flow graph.
Definition at line 119 of file AbsExtAPI.h.
|
protected |
Pointer to the state manager.
Definition at line 117 of file AbsExtAPI.h.
|
protected |
Pointer to the SVF intermediate representation.
Definition at line 118 of file AbsExtAPI.h.