/// TODO: print each path once this method is called, and /// (1) add each path (a sequence of node IDs) as a string into std::set<std::string> paths /// in the format "START: 1->2->4->5->END", where -> indicate an ICFGEdge connects two ICFGNode IDs /// bonus: dump and append each program path to a `ICFGPaths.txt` in the form of /// ‘{ln: number cl: number, fl:name} -> {ln: number, cl: number, fl: name} -> {ln:number, cl: number, fl: name} /// ln : line number cl: column number fl:file name for further learning, you can review the code in SVF, SVFUtil void TaintGraphTraversal::printICFGPath(std::vector<const ICFGNode *> &path){ } // TODO: Implement your code to parse the two lines from `SrcSnk.txt` in the form of // line 1 for sources "{ api1 api2 api3 }" // line 2 for sinks "{ api1 api2 api3 }" void TaintGraphTraversal::readSrcSnkFromFile(const string& filename){ } /// TODO: Checking aliases of the two variables at source and sink. For example: /// src instruction: actualRet = source(); /// snk instruction: sink(actualParm,...); /// return true if actualRet is aliased with any parameter at the snk node (e.g., via ander->alias(..,..)) bool TaintGraphTraversal::aliasCheck(const CallICFGNode *src, const CallICFGNode *snk) { return true; } 这三个空分别应该填什么代码
时间: 2024-03-07 14:48:59 浏览: 152
第一个空:
```c++
void TaintGraphTraversal::printICFGPath(std::vector<const ICFGNode *> &path){
std::stringstream ss;
ss << "START: ";
for(auto node: path){
ss << node->getId();
if(node->getOutDegree() > 0){
ss << "->";
}
}
ss << "END";
std::string pathStr = ss.str();
paths.insert(pathStr);
std::ofstream file("ICFGPaths.txt", std::ios_base::app);
if(file.is_open()){
file << "{ln:" << path.front()->getInst()->getLine()
<< " cl:" << path.front()->getInst()->getColumn()
<< " fl:" << path.front()->getInst()->getFilename() << "}";
for(auto node: path){
file << " -> ";
file << "{ln:" << node->getInst()->getLine()
<< " cl:" << node->getInst()->getColumn()
<< " fl:" << node->getInst()->getFilename() << "}";
}
file << "\n";
file.close();
}
}
```
第二个空:
```c++
void TaintGraphTraversal::readSrcSnkFromFile(const string& filename){
std::ifstream file(filename);
if(file.is_open()){
std::string line1, line2;
std::getline(file, line1);
std::getline(file, line2);
std::regex re("\\{([^\\}]*)\\}");
std::smatch match;
std::vector<std::string> srcVec, snkVec;
while(std::regex_search(line1, match, re)){
srcVec.push_back(match[1]);
line1 = match.suffix().str();
}
while(std::regex_search(line2, match, re)){
snkVec.push_back(match[1]);
line2 = match.suffix().str();
}
file.close();
}
}
```
第三个空:
```c++
bool TaintGraphTraversal::aliasCheck(const CallICFGNode *src, const CallICFGNode *snk) {
const SVFFunction *srcFunc = src->getCallee();
const SVFFunction *snkFunc = snk->getCallee();
const SVFVariable *retVar = srcFunc->getRetVar();
std::vector<const SVFVariable *> paramVars = snkFunc->getParamVars();
for(auto paramVar: paramVars){
if(paramVar->alias(retVar)){
return true;
}
}
return false;
}
```
阅读全文