-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdevaic.sh
109 lines (83 loc) · 3.36 KB
/
devaic.sh
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/bash
echo -e "\n\n"
echo "██████╗ ███████╗██╗ ██╗ █████╗ ██╗ ██████╗"
echo "██╔══██╗██╔════╝██║ ██║██╔══██╗██║██╔════╝"
echo "██║ ██║█████╗ ██║ ██║███████║██║██║ "
echo "██║ ██║██╔══╝ ╚██╗ ██╔╝██╔══██║██║██║ "
echo "██████╔╝███████╗ ╚████╔╝ ██║ ██║██║╚██████╗"
echo "╚═════╝ ╚══════╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═════╝"
echo -e "\n\n"
#Detection of Vulnerabilities in AI-generated Code
SRC_DIR=$PWD
INP_DIR=$SRC_DIR"/input"
SCRIPT_DIR=$SRC_DIR"/script_py"
RES_DIR=$SRC_DIR"/results"
GEN_DIR=$SRC_DIR"/generated_file"
PATH_1="/opt/homebrew/opt/grep/libexec/gnubin"
PATH_2="/usr/local/opt/grep/libexec/gnubin"
name_os=$(uname)
timestamp=$(date +"%Y-%m-%d_%H-%M-%S")
#---------- ADJUSTING THE FILENAME ----------
echo "$1" | grep -q "/"
if [ $? -eq 0 ]; then
new_name=$(echo $1 | awk -F "/" '{print $2}' )
else
new_name=$1
fi
filename_res="[$timestamp]"_"$new_name"
type=$(echo $filename_res | awk -F '.' '{print $2}')
echo "$1" | grep -q ".txt"
if [ $? -eq 1 ]; then
filename_res=$(echo $filename_res | sed "s/.$type/.txt/g")
fi
#define the names of the generated files
det_file="DET_$filename_res"
input_file="INPUT_$filename_res"
tmp_file="MOD_INPUT_$filename_res"
#define the paths of the generated files
det_path=$RES_DIR/detection/$det_file
input_path=$GEN_DIR/$input_file
tmp_path=$GEN_DIR/$tmp_file
#---------- CONVERTING JSON TO TXT ----------
if [ $type == "json" ]; then
cat $1 | grep -q "\"code\":"
if [ $? -eq 0 ]; then
python3 $SCRIPT_DIR/convert_json_to_txt.py $1 $tmp_path
else
python3 $SCRIPT_DIR/convert_json_wo_keys.py $1 $tmp_path
fi
fi
### ---------- SETUP ----------
if [ $name_os = "Darwin" ]; then #MAC-OS system
ls $PATH_1 > /dev/null 2>&1;
if [ $? -eq 0 ]; then #if the path already exists, it is not exported
echo $PATH | grep -q "$PATH_1"
if [ $? -eq 1 ]; then
export "PATH=$PATH_1:$PATH";
fi
else
ls $PATH_2 > /dev/null 2>&1;
if [ $? -eq 0 ]; then #if the path already exists, it is not exported
echo $PATH | grep -q "$PATH_2"
if [ $? -eq 1 ]; then
export "PATH=$PATH_2:$PATH";
fi
fi;
fi
if [ $type == "json" ]; then
python3 $SCRIPT_DIR/preprocessing_macos.py $tmp_path $input_path
rm $tmp_path
elif [ $type == "txt" ]; then
python3 $SCRIPT_DIR/preprocessing_macos.py $1 $input_path
fi
elif [ $name_os = "Linux" ]; then #LINUX system
if [ $type == "json" ]; then
python3 $SCRIPT_DIR/preprocessing.py $tmp_path $input_path
rm $tmp_path
elif [ $type == "txt" ]; then
python3 $SCRIPT_DIR/preprocessing.py $1 $input_path
fi
fi
#---------- LAUNCHING THE TOOL ----------
echo -e "[***] Vulnerability Scanning ...\n"
$SRC_DIR/tool_derem.sh $input_path $det_path 2> /dev/null