-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlantC4.cpp
57 lines (50 loc) · 1.69 KB
/
PlantC4.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//=--RewriteUtils.cpp---------------------------------------------*- C++-*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// This class contains implementation of the functions and
// classes of PlantC4.h
//===----------------------------------------------------------------------===//
#include "clang/CheckMate/PlantC4.h"
#include "clang/CheckMate/CheckMateGlobalOptions.h"
#include "clang/Tooling/Transformer/SourceCode.h"
#include <stdlib.h>
#include <unistd.h>
using namespace llvm;
using namespace clang;
char* PlantC4::getFileNameFromPath(const char* path )
{
if( path == NULL )
return NULL;
char * pFileName = const_cast<char*>(path);
for( char * pCur = const_cast<char*>(path); *pCur != '\0'; pCur++)
{
if( *pCur == '/' || *pCur == '\\' )
pFileName = pCur+1;
}
return pFileName;
}
void PlantC4::fetch_path_from_file_path(std::string & file_path, const std::string & fileName)
{
// Search for the substring in string
size_t pos = file_path.find(fileName);
if (pos != std::string::npos)
{
// If found then erase it from string
file_path.erase(pos, fileName.length());
}
}
bool PlantC4::ConvertTaintedToVanilla() {
auto ListOfTaintedFiles = Info.TaintedRewriteFileVector;
for(auto TaintedFilePath : ListOfTaintedFiles){
// switch to C4 directory to execute the script
chdir("../tools/C4");
std::string Command ="";
Command = "./exec.sh " + TaintedFilePath;
std::system(Command.c_str());
}
return true;
}