|
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 (Map< const ICFGNode *, AbstractState > &traces) | |
| Constructor for AbsExtAPI. | |
| void | initExtFunMap () |
| Initializes the external function map. | |
| std::string | strRead (AbstractState &as, const SVFVar *rhs) |
| Reads a string from the abstract state. | |
| void | handleExtAPI (const CallICFGNode *call) |
| Handles an external API call. | |
| u32_t | getElementSize (AbstractState &as, const SVFVar *var) |
| Get the byte size of each element for a pointer/array variable. | |
| IntervalValue | getStrlen (AbstractState &as, const SVF::SVFVar *strValue) |
| 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 (AbstractState &as, const SVF::SVFVar *dst, const SVF::SVFVar *src, IntervalValue len, u32_t start_idx) |
Core memcpy: copy len bytes from src to dst starting at dst[start_idx]. | |
| void | handleMemset (AbstractState &as, const SVFVar *dst, IntervalValue elem, IntervalValue len) |
| IntervalValue | getRangeLimitFromType (const SVFType *type) |
| Gets the range limit from a type. | |
| AbstractState & | getAbsStateFromTrace (const ICFGNode *node) |
| Retrieves the abstract state from the trace for a given ICFG node. | |
Static Public Member Functions | |
| static bool | isValidLength (const IntervalValue &len) |
| Check if an interval length is usable (not bottom, not unbounded). | |
Protected Attributes | |
| SVFIR * | svfir |
| Pointer to the SVF intermediate representation. | |
| ICFG * | icfg |
| Pointer to the interprocedural control flow graph. | |
| Map< const ICFGNode *, AbstractState > & | abstractTrace |
| Map of ICFG nodes to abstract states. | |
| 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 | ( | Map< const ICFGNode *, AbstractState > & | traces | ) |
Constructor for AbsExtAPI.
| abstractTrace | Reference to a map of ICFG nodes to abstract states. |
Definition at line 35 of file AbsExtAPI.cpp.
| AbstractState & AbsExtAPI::getAbsStateFromTrace | ( | 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 338 of file AbsExtAPI.cpp.
| u32_t AbsExtAPI::getElementSize | ( | AbstractState & | as, |
| const SVFVar * | var | ||
| ) |
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 463 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 696 of file AbsExtAPI.cpp.
| IntervalValue AbsExtAPI::getStrlen | ( | AbstractState & | as, |
| const SVF::SVFVar * | strValue | ||
| ) |
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 496 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 381 of file AbsExtAPI.cpp.
| void AbsExtAPI::handleMemcpy | ( | AbstractState & | as, |
| const SVF::SVFVar * | dst, | ||
| const SVF::SVFVar * | src, | ||
| IntervalValue | len, | ||
| u32_t | start_idx | ||
| ) |
Core memcpy: copy len bytes from src to dst starting at dst[start_idx].
Definition at line 595 of file AbsExtAPI.cpp.
| void AbsExtAPI::handleMemset | ( | AbstractState & | as, |
| const SVFVar * | dst, | ||
| IntervalValue | elem, | ||
| IntervalValue | len | ||
| ) |
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 636 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 570 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 557 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 583 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 488 of file AbsExtAPI.cpp.
| std::string AbsExtAPI::strRead | ( | AbstractState & | as, |
| const SVFVar * | rhs | ||
| ) |
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 351 of file AbsExtAPI.cpp.
|
protected |
Map of ICFG nodes to abstract states.
Definition at line 114 of file AbsExtAPI.h.
|
protected |
Map of function names to handlers.
Definition at line 115 of file AbsExtAPI.h.
|
protected |
Pointer to the interprocedural control flow graph.
Definition at line 113 of file AbsExtAPI.h.
|
protected |
Pointer to the SVF intermediate representation.
Definition at line 112 of file AbsExtAPI.h.