Question: #include Assignment - 4 . h #include #include #include #include using namespace SVF; using namespace llvm; using namespace std; / / Local set to
#include "Assignmenth
#include
#include
#include
#include
using namespace SVF;
using namespace llvm;
using namespace std;
Local set to store paths for testing verification
std::set collectedPaths;
Get sources function names read from checkersourceapi collected from a text file
std::set &TaintGraphTraversal::identifySources
static std::set sources;
for const CallICFGNode cs : paggetCallSiteSet
const SVFFunction fun SVFUtil::getCalleecsgetCallSite;
if checkersourceapi.findfungetName checkersourceapi.end
sources.insertcs;
return sources;
Get sinks function names read from checkersinkapi collected from a text file
std::set &TaintGraphTraversal::identifySinks
static std::set sinks;
for const CallICFGNode cs : paggetCallSiteSet
const SVFFunction fun SVFUtil::getCalleecsgetCallSite;
if checkersinkapi.findfungetName checkersinkapi.end
sinksinsertcs;
return sinks;
Start taint checking
void TaintGraphTraversal::taintChecking
Configure sources and sinks for taint analysis
readSrcSnkFromFileAssignmentSrcSnktxt;
ander new AndersenPTApag;
anderanalyze;
for const CallICFGNode src : identifySources
for const CallICFGNode snk : identifySinks
if aliasChecksrc snk
reachabilitysrc snk;
Output collected paths for testing verification
cout "Collected paths:" endl;
for const auto &path : collectedPaths
cout path endl;
Collect and format ICFG path details
void TaintGraphTraversal::collectICFGPathstd::vector &path
std::stringstream pathStr;
pathStr "START";
for sizet i ; i path.size; i
pathStr pathi;
pathStr END";
Store the formatted path in the local collectedPaths set
collectedPaths.insertpathStrstr;
Debug print to check path being added
cout "Adding path: pathStr.str endl;
Parse the SrcSnktxt file for sources and sinks
void TaintGraphTraversal::readSrcSnkFromFileconst string &filename
std::ifstream filefilename;
if file.isopen
return;
std::string line;
Read sources
if getlinefile line
std::istringstream sslinesubstr line.size; Remove
std::string api;
while ss api
checkersourceapi.insertapi;
Read sinks
if getlinefile line
std::istringstream sslinesubstr line.size; Remove
std::string api;
while ss api
checkersinkapi.insertapi;
file.close;
Perform alias checking with dyncast for safety
bool TaintGraphTraversal::aliasCheckconst CallICFGNode src const CallICFGNode snk
const RetICFGNode retNode SVFUtil::dyncastsrc;
const CallICFGNode callNode SVFUtil::dyncastsnk;
if retNode callNode
Return false if casting fails
return false;
const SVFVar srcRet retNodegetActualRet;
const auto &snkParams callNodegetActualParms;
for const auto param : snkParams
if anderaliassrcRetgetId paramgetId
return true;
return false;
Why does it not work and pass my test files:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
