forked from huming17/php-decoder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeevalwidget.cpp
More file actions
153 lines (134 loc) · 3.73 KB
/
deevalwidget.cpp
File metadata and controls
153 lines (134 loc) · 3.73 KB
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
#include <QLocalSocket>
#include <QLocalServer>
#include <QFileDialog>
#include <QProcess>
#include <QTimer>
#include <QDir>
#include <QDebug>
#include "util.h"
#include "deevalwidget.h"
#include "ui_deevalwidget.h"
typedef void (QProcess::*QPROCESS_FINISH_SIGNAL_TYPE)
(int exitCode, QProcess::ExitStatus exitStatus);
DeEvalWidget::DeEvalWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::DeEvalWidget)
{
ui->setupUi(this);
}
DeEvalWidget::~DeEvalWidget()
{
delete ui;
}
void DeEvalWidget::on_browFileButton_clicked()
{
QString path = QFileDialog::getOpenFileName(this,
QStringLiteral("选择文件"),ui->pathEdit->text());
if ( path.isEmpty() ) {
return;
}
ui->pathEdit->setText(path);
}
void DeEvalWidget::on_browDirButton_clicked()
{
QString path = QFileDialog::getExistingDirectory(this,
QStringLiteral("选择文件夹"),ui->pathEdit->text());
if ( path.isEmpty() ) {
return;
}
ui->pathEdit->setText(path);
}
void DeEvalWidget::on_decodeButton_clicked()
{
ui->progressBar->setValue(0);
ui->logTextEdit->clear();
QString text = ui->pathEdit->text();
QString rootPath;
if ( QFileInfo(text).isFile() ) {
rootPath = QFileInfo(text).absoluteDir().absolutePath();
} else {
rootPath = QDir(text).absolutePath();
}
QString resultDirPath = createTempDir();
QStringList fileList = getFileList(text);
for(int i=0;i<fileList.length();i++){
QString file = fileList.value(i);
bool checked = ui->phpFileOnlyCheckBox->checkState()==Qt::Checked;
bool isPhp = (new QFileInfo(file))->suffix()=="php";
if ( checked && isPhp || !checked ) {
QString relativePath = QDir(rootPath).relativeFilePath(file);
ui->logTextEdit->appendPlainText(file+"...");
if ( decodeFile(file, resultDirPath + "/" + relativePath) ){
ui->logTextEdit->appendPlainText(QStringLiteral("完成"));
} else {
ui->logTextEdit->appendPlainText(QStringLiteral("失败"));
}
}
ui->progressBar->setValue((i+1.0)/fileList.length()*100);
qApp->processEvents();
}
QProcess::startDetached("explorer",QStringList(QDir::toNativeSeparators(resultDirPath)));
}
bool DeEvalWidget::decodeFile(const QString &path, const QString &resultPath)
{
//创建临时文件
QString tempFilePath = ".\\deeval\\sandbox\\temp.php";
if ( !overwriteFile(path,tempFilePath) ) {
qDebug()<<"copy file error!";
return false;
}
QLocalServer server;
server.listen("phpdecoder");
//创建解密php进程
QProcess process, *pProcess = &process;
QStringList args;
args<<tempFilePath<<"-c"<<".\\deeval\\php.ini";
process.setArguments(args);
process.setProgram(".\\deeval\\php.exe");
process.start();
bool isRunning = process.waitForStarted();
bool *pIsRunning = &isRunning;
if ( !isRunning ) {
qDebug()<<"start process error: "<<process.error()<<process.errorString();
return false;
}
connect(&process,(QPROCESS_FINISH_SIGNAL_TYPE)&QProcess::finished,[=](){
*pIsRunning = false;
qDebug()<<"output:"<<pProcess->readAll();
});
//解密php进程超时处理
QTimer timer;
timer.setInterval(10*1000);
connect(&timer,&QTimer::timeout,[=](){
qDebug()<<"php process timeout!";
pProcess->terminate();
*pIsRunning = false;
});
timer.start();
//接收解密数据
QByteArray data;
while(isRunning) {
if ( server.waitForNewConnection(50) ) {
QLocalSocket *socket = server.nextPendingConnection();
data.clear();
while ( socket->waitForReadyRead(-1) ) {
data += socket->readAll();
qApp->processEvents();
}
socket->close();
delete socket;
qDebug()<<data;
}
qApp->processEvents();
}
if ( data.isEmpty() ) {
qDebug()<<"no data received!";
return false;
}
data = "<?php " + data + "?>";
if ( ui->prettyCheckBox->checkState()==Qt::Checked ) {
data = prettyCode(data);
}
//写入新文件
return putFileContents(resultPath,data);
}