-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheckFile.cpp
55 lines (44 loc) · 1.24 KB
/
checkFile.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
#include "checkFile.h"
void checkFile(QString & fileName){
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly)){
QMessageBox msgBox;
msgBox.setText("File is not opened");
msgBox.exec();
return;
}
QByteArray dataFile = file.readAll();
QFile base("data/virusbase");
if (!base.open(QIODevice::ReadOnly)){
QMessageBox msgBox;
msgBox.setText("Base of signatures not found");
msgBox.exec();
return;
}
QVector<QByteArray> foundViruses;
while(!base.atEnd()){
QByteArray signature = base.readLine();
if (signature[signature.size() - 1] == '\n'){
signature.remove(signature.size() - 1, 1);
}
if (foundViruses.indexOf(signature) != -1){
continue;
}
if (dataFile.indexOf(signature) != -1){
foundViruses.push_back(signature);
}
}
QString result;
QMessageBox msgBox;
if (!foundViruses.empty()){
result = "File is infected by : \n";
foreach (QByteArray var,foundViruses ) {
result += (var + "\n");
}
}else{
result = "File is not infected";
}
file.close();
msgBox.setText(result);
msgBox.exec();
}