-
Notifications
You must be signed in to change notification settings - Fork 2
/
middle3.cpp
executable file
·345 lines (306 loc) · 10.3 KB
/
middle3.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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
#include "middle3.h"
#include <QDebug>
#include <QProcess>
#include "filePath.h"
#include <QFile>
middle3::middle3(QWidget *parent) :
QWidget(parent)
{
return_num = '0';
tabWidget = new QTabWidget();
tabWidget->setIconSize(QSize(220,220));
tabWidget->setStyleSheet("QTabBar::tab {height: 40px; width:220px;color: black;font-size:20px;padding: 5px;margin-left:40px;}"
"QTabBar::tab:selected { background: lightgray; } ");
//新建第一个页面的部件,全盘查杀
widget1 = new QWidget();
QVBoxLayout *mainLayout = new QVBoxLayout(widget1);
QHBoxLayout *hLayout4 = new QHBoxLayout(widget1);
QLineEdit *tip1 = new QLineEdit("上次查杀时间:");
tip1->setFixedSize(220,60);
tip1->setStyleSheet("QLineEdit{font-size : 20px;color:blue;background-color:rgb(255,0,0,0);margin-top:20;margin-left:60;}");
tip1->setFrame(false);
tip1->setReadOnly(true);
time = new QLineEdit(widget1);
time->setStyleSheet("QLineEdit{font-size : 40px;color:black;background-color:rgb(255,0,0,0);background-position:center;background-attachment:fixed;background-image:url(:images/dariay.png);margin-top:20;margin-right:10;}");
time->setFixedSize(240,100);
time->setAlignment(Qt::AlignCenter);
time->setFrame(false);
time->setReadOnly(true);
hLayout4->addWidget(tip1);
hLayout4->addWidget(time);
QHBoxLayout *hLayout = new QHBoxLayout(widget1);
QLineEdit *tip = new QLineEdit("全盘查杀比较慢,请耐心等候");
tip->setFixedSize(300,50);
tip->setStyleSheet("QLineEdit{font-size : 20px;color:gray;background-color:rgb(255,0,0,0);margin-top:20;margin-right:20;margin-left:20;}");
tip->setFrame(false);
tip->setReadOnly(true);
QPushButton *kill_pushbutton = new QPushButton("开始查杀");
QPushButton *stop_pushbutton = new QPushButton("停止查杀");
kill_pushbutton->setStyleSheet("QPushButton{color:green;margin-top:20;border: 1px solid green;border-radius:15px;height:30px;margin-left:30px}");
stop_pushbutton->setStyleSheet("QPushButton{color:blue;margin-top:20;border: 1px solid blue;border-radius:15px;height:30px;margin-right:30px}");
hLayout->addWidget(tip);
hLayout->addWidget(kill_pushbutton);
hLayout->addWidget(stop_pushbutton);
QHBoxLayout *hLayout0 = new QHBoxLayout(widget1);
QLabel *label3 = new QLabel(widget1);
QImage img;
img.load(":images/safefile.png");
QImage* imgScaled = new QImage;
*imgScaled=img.scaled(100,100,Qt::KeepAspectRatio);
label3->setPixmap(QPixmap::fromImage(*imgScaled));
label3->setStyleSheet("QLabel{margin-left:100;}");
safnum = new QLineEdit(widget1);
safnum->setStyleSheet("QLineEdit{font-size : 40px;color:black;background-color:rgb(255,0,0,0);margin-left:20;}");
safnum->setFrame(false);
safnum->setFixedSize(200,60);
safnum->setAlignment(Qt::AlignCenter);
safnum->setText("0");
QLineEdit *saffile = new QLineEdit("安全文件 !");
saffile->setStyleSheet("QLineEdit{font-size : 25px;color:blue;background-color:rgb(255,0,0,0);margin-left:20;}");
saffile->setFrame(false);
saffile->setReadOnly(true);
hLayout0->addWidget(label3);
hLayout0->addWidget(safnum);
hLayout0->addWidget(saffile);
QHBoxLayout *hLayout1 = new QHBoxLayout(widget1);
QLabel *label4 = new QLabel(widget1);
QImage img2;
img2.load(":images/virusfile.png");
QImage* imgScaled2 = new QImage;
*imgScaled2=img2.scaled(100, 100,Qt::KeepAspectRatio);
label4->setPixmap(QPixmap::fromImage(*imgScaled2));
label4->setStyleSheet("QLabel{margin-left:100;}");
virnum = new QLineEdit(widget1);
virnum->setStyleSheet("QLineEdit{font-size : 40px;color:red;background-color:rgb(255,0,0,0);margin-left:20;}");
virnum->setFrame(false);
virnum->setFixedSize(200,60);
virnum->setAlignment(Qt::AlignCenter);
virnum->setText("0");
QLineEdit *virfile = new QLineEdit("危险文件 !");
virfile->setReadOnly(true);
virfile->setStyleSheet("QLineEdit{font-size : 25px;color:red;background-color:rgb(255,0,0,0);margin-left:20;}");
virfile->setFrame(false);
hLayout1->addWidget(label4);
hLayout1->addWidget(virnum);
hLayout1->addWidget(virfile);
result_label1 = new QTextEdit(widget1);
QPalette pl1 = result_label1->palette();
pl1.setBrush(QPalette::Base,QBrush(QColor(255,0,0,0)));
result_label1->setPalette(pl1);
result_label1->setAlignment(Qt::AlignTop);
result_label1->setReadOnly(true);
mainLayout->setSpacing(10);
mainLayout->addLayout(hLayout4);
mainLayout->addLayout(hLayout);
mainLayout->addLayout(hLayout0);
mainLayout->addLayout(hLayout1);
mainLayout->addWidget(result_label1);
widget1->setLayout(mainLayout);
connect(kill_pushbutton, SIGNAL(clicked()), this, SLOT(all_file()));
//新建第二个页面的部件,选择查杀
widget2 = new QWidget();
QHBoxLayout *mainLayout2 = new QHBoxLayout(widget2);
mainLayout2->setSpacing(30);
QVBoxLayout *vLayout1 = new QVBoxLayout(widget2);
vLayout1->setMargin(0);
vLayout1->setSpacing(0);
QLabel *label = new QLabel(widget2);
QPixmap map(":images/file.png");
label->setPixmap(map);
vLayout1->addWidget(label);
QLabel *label2 = new QLabel(widget2);
label2->setText("请输入需要查杀的目录:");
label2->setFixedHeight(25);
label2->setAlignment(Qt::AlignCenter);
fileline = new QLineEdit(widget2);
fileline->setText("/home");
fileline->setStyleSheet("QLineEdit{color:gray;background-color:rgb(255,0,0,0)}");
fileline->setFrame(false);
fileline->setFixedSize(150,60);
fileline->setTextMargins(20,0,0,0);
scan_pushbutton = new QPushButton("浏览...");
scan_pushbutton->setStyleSheet("QPushButton{color:blue;border: 1px solid blue;border-radius:15px;height:30px;margin-left:10px}");
execute_pushbutton = new QPushButton("开始查杀");
execute_pushbutton->setStyleSheet("QPushButton{color:green;border: 1px solid green;border-radius:15px;height:30px;margin-left:10px}");
QFont tip_font2 = label2->font();
tip_font2.setPointSize(14);
tip_font2.setItalic(true);
tip_font2.setBold(true);
label2->setFont(tip_font2);
vLayout1->addWidget(label2);
QHBoxLayout *hLayout3 = new QHBoxLayout(widget2);
hLayout3->addWidget(scan_pushbutton);
hLayout3->addWidget(execute_pushbutton);
hLayout3->setMargin(30);
vLayout1->addWidget(fileline);
vLayout1->addLayout(hLayout3);
QVBoxLayout *vLayout2 = new QVBoxLayout(widget2);
QHBoxLayout *hLayout2 = new QHBoxLayout(widget2);
QLabel *label1= new QLabel(widget2);
label1->setText("运行结果:");
label1->setAlignment(Qt::AlignLeft);
label1->setFixedHeight(25);
QFont tip_font = label1->font();
tip_font.setPointSize(14);
tip_font.setBold(true);
label1->setFont(tip_font);
hLayout2->addWidget(label1);
hLayout2->setSpacing(0);
hLayout2->setMargin(30);
result_label = new QTextEdit(widget2);
QPalette pl = result_label->palette();
pl.setBrush(QPalette::Base,QBrush(QColor(255,0,0,0)));
result_label->setPalette(pl);
result_label->setAlignment(Qt::AlignTop);
result_label->setReadOnly(true);
vLayout2->setMargin(0);
vLayout2->setSpacing(0);
vLayout2->addLayout(hLayout2);
vLayout2->addWidget(result_label);
mainLayout2->addLayout(vLayout1);
mainLayout2->addLayout(vLayout2);
widget2->setLayout(mainLayout2);
QIcon icon1(":images/full_scan.png");
tabWidget->addTab(widget1,icon1,"");
QIcon icon2(":images/custom_scan.png");
tabWidget->addTab(widget2, icon2,"");
QVBoxLayout *layout = new QVBoxLayout();
layout->addWidget(tabWidget);
this->setLayout(layout);
connect(scan_pushbutton, SIGNAL(clicked()), this, SLOT(show_file()));
connect(execute_pushbutton, SIGNAL(clicked()), this, SLOT(scan_file()));
connect(stop_pushbutton, SIGNAL(clicked()), this, SLOT(kill_process()));
connect(fileline, SIGNAL(textChanged(QString)), this, SLOT(get_file()));
temp = 0;
flag = 0;
myThread = new QProcess;
myThread1 = new QProcess;
//定时器,实时刷新
timer = new QTimer(this);
QWidget::connect( timer, SIGNAL( timeout() ), this, SLOT( timer_update_currentTabInfo() ) );
timer->start(0075);
}
//刷新页面槽函数
void middle3::timer_update_currentTabInfo()
{
myThread1->start("bash modify.sh");
if(!myThread1->waitForStarted())
{
qDebug()<<"failed start!";
}
while(true == myThread1->waitForFinished());
{
QString ver1 = myThread1->readAllStandardOutput();
time->setText(ver1);
}
myThread->start("bash ps-file.sh");
if(!myThread->waitForStarted())
{
qDebug()<<"failed start!";
}
while(true == myThread->waitForFinished());
{
bool ok2;
QString ver = myThread->readAllStandardOutput();
int dec = ver.toInt(&ok2,10);
if(dec >=1)
{
QFile fromFile1("/tmp/filenum.sh");
fromFile1.open(QIODevice::ReadOnly);
QTextStream in1(&fromFile1);
while(!in1.atEnd())
{
line = in1.readLine();
}
}
}
if((line.toInt() == 0 || line.toInt() > temp) && flag == 1)
{
result_label1->setText("查杀中,请稍后。。。");
temp++;
char str[10];
QString str1;
sprintf(str,"%d",temp);
str1 = str;
safnum->setText(str1);
}
if(line.toInt() == temp && temp != 0)
{
result_label1->setText("无病毒文件,亲可以放心啦~");
}
}
void middle3:: scan_file()
{
// int totalline = 0;
QString ver = "查杀中,请稍后。。。";
result_label->setText(ver);
QProcess *thread = new QProcess;
thread->start("bash select-virus.sh "+gettext);
if(!thread->waitForStarted())
{
qDebug()<<"failed start!";
}
while(true == thread->waitForFinished());
{
ver = thread->readAllStandardOutput();
if(ver == "")
{
ver = "没有需要查杀的文件。。。";
result_label->setText(ver);
}
else
result_label->setText(ver);
}
}
void middle3::show_file()
{
filepath = new filePath;
fileline->setText("/home");
result_label->clear();
}
void middle3::get_file()
{
gettext = fileline->text();
}
void middle3::all_file()
{
flag = 1;
temp = 0;
line = '0';
QFile fromFile("/tmp/filenum.sh");
fromFile.open(QIODevice::WriteOnly);
fromFile.write("0",1);
fromFile.close();
result_label1->setText("查杀中,请稍后。。。");
QProcess *thread1 = new QProcess;
thread1->start("bash all-virus.sh");
if(!thread1->waitForStarted())
{
qDebug()<<"failed start!";
}
while(true == thread1->waitForFinished());
{
return_num = thread1->readAllStandardOutput();
}
}
void middle3::kill_process()
{
QProcess *thread = new QProcess;
thread->start("killall all-file");
if(!thread->waitForStarted())
{
qDebug()<<"failed start!";
}
while(true == thread->waitForFinished());
{
// ver = thread->readAllStandardOutput();
safnum->setText("0");
flag = 0;
temp = 0;
line = "0";
result_label1->setText("点击按钮查杀!");
}
}
middle3::~middle3()
{
}