-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpeldr.cpp
More file actions
358 lines (212 loc) · 28.2 KB
/
peldr.cpp
File metadata and controls
358 lines (212 loc) · 28.2 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
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
346
347
348
349
350
351
352
353
354
355
356
357
358
//=================================\\
// [ OWNER ]
// CREATOR : Vladislav Khudash
// AGE : 17
// LOCATION : Ukraine
//
// [ PINFO ]
// DATE : 20.05.2026
// PROJECT : PELDR-BUILDER
// PLATFORM : WINDOWS
//=================================\\
#include <stdexcept>
#include <vector>
#include <time.h>
#include <random>
#include <io.h>
#include <fcntl.h>
#include <iostream>
#include <fstream>
#include <filesystem>
#include <windows.h>
#define IS_FLAG_GUI(g, i) \
( ((g)[(i)][0] == L'-') && ((g)[(i)][1] == L'w') && \
((g)[(i)][2] == L'\0') )
#define DEC_FUNC(typ) static inline typ
#define PERR(msg) do { \
std::wcerr << (msg) << L"\n"; \
return FALSE; \
} while (0)
namespace fs = std::filesystem;
using path_t = fs::path;
using array = std::vector<BYTE>;
static const BYTE KSZ[] = {16, 32, 64, 128};
static const BYTE STUB_EXE[] = {77,90,144,0,3,0,0,0,4,0,0,0,255,255,0,0,184,0,0,0,0,0,0,0,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,14,31,186,14,0,180,9,205,33,184,1,76,205,33,84,104,105,115,32,112,114,111,103,114,97,109,32,99,97,110,110,111,116,32,98,101,32,114,117,110,32,105,110,32,68,79,83,32,109,111,100,101,46,13,13,10,36,0,0,0,0,0,0,0,80,69,0,0,100,134,5,0,0,0,0,0,0,0,0,0,0,0,0,0,240,0,46,2,11,2,2,45,0,18,0,0,0,6,0,0,0,0,0,0,0,16,0,0,0,16,0,0,0,0,0,64,1,0,0,0,0,16,0,0,0,2,0,0,4,0,0,0,0,0,0,0,5,0,2,0,0,0,0,0,0,112,0,0,0,4,0,0,46,18,1,0,3,0,96,5,0,0,32,0,0,0,0,0,0,16,0,0,0,0,0,0,0,0,16,0,0,0,0,0,0,16,0,0,0,0,0,0,0,0,0,0,16,0,0,0,0,0,0,0,0,0,0,0,0,80,0,0,24,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,40,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,46,116,101,120,116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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,85,184,96,0,0,0,72,137,229,65,87,65,86,65,85,65,84,87,86,83,72,131,228,240,72,129,236,80,3,0,0,101,103,72,139,0,72,137,132,36,136,0,0,0,128,120,2,0,15,133,84,16,0,0,73,185,110,0,116,0,100,0,108,0,72,139,64,24,72,141,72,32,72,139,64,32,72,57,193,15,132,224,0,0,0,72,139,80,80,72,133,210,116,32,72,190,32,0,32,0,32,0,32,0,72,11,50,76,57,206,117,14,72,139,64,32,72,133,192,117,10,233,183,0,0,0,72,139,0,235,201,72,99,80,60,68,139,140,16,140,0,0,0,69,133,201,15,132,157,0,0,0,72,141,188,36,48,1,0,0,72,141,53,89,31,0,0,185,60,0,0,0,65,179,15,243,165,139,140,16,136,0,0,0,72,141,156,36,48,1,0,0,76,141,180,36,32,2,0,0,72,137,207,72,1,193,139,81,32,68,139,65,36,65,141,52,57,68,139,105,28,139,73,24,72,1,194,73,1,192,76,141,36,138,69,132,219,15,132,148,0,0,0,76,57,226,15,131,134,0,0,0,68,139,18,65,185,201,7,0,0,73,1,194,65,138,10,132,201,117,54,72,137,217,68,59,9,117,74,76,139,81,8,73,131,58,0,117,64,65,15,183,8,72,141,12,136,66,139,12,41,57,249,114,59,57,241,115,55,199,132,36,148,0,0,0,53,1,0,192,233,80,15,0,0,68,141,121,191,73,255,194,65,128,255,25,119,3,131,201,32,69,107,201,15,15,182,201,65,1,201,235,167,72,131,193,16,73,57,206,117,168,235,9,72,1,193,65,255,203,73,137,10,72,131,194,4,73,131,192,2,233,104,255,255,255,69,132,219,117,174,72,139,5,178,31,0,0,69,49,237,72,141,180,36,208,0,0,0,72,199,132,36,216,0,0,0,1,0,0,0,72,137,116,36,32,65,185,4,0,0,0,73,137,216,72,141,148,36,0,1,0,0,76,137,172,36,232,0,0,0,72,199,193,255,255,255,255,72,137,132,36,0,1,0,0,72,199,132,36,48,1,0,0,3,0,0,0,255,21,140,31,0,0,133,192,117,69,72,139,5,81,31,0,0,73,137,216,72,141,148,36,0,1,0,0,72,199,193,255,255,255,255,198,0,49,72,139,5,53,31,0,0,198,64,1,192,72,139,5,42,31,0,0,198,64,2,195,68,139,140,36,208,0,0,0,72,137,116,36,32,255,21,67,31,0,0,69,49,228,65,185,48,0,0,0,73,137,216,49,210,76,137,100,36,32,72,199,193,255,255,255,255,255,21,67,31,0,0,72,139,132,36,136,0,0,0,72,57,132,36,56,1,0,0,116,18,186,89,0,0,192,72,199,193,255,255,255,255,255,21,95,31,0,0,49,255,65,185,8,0,0,0,76,141,132,36,232,0,0,0,186,7,0,0,0,72,137,124,36,32,72,199,193,255,255,255,255,255,21,248,30,0,0,72,131,188,36,232,0,0,0,0,116,18,186,5,0,0,192,72,199,193,255,255,255,255,255,21,27,31,0,0,76,141,164,36,216,0,0,0,65,185,8,0,0,0,186,31,0,0,0,72,199,193,255,255,255,255,77,137,224,255,21,216,30,0,0,69,49,201,69,49,192,186,17,0,0,0,72,199,193,254,255,255,255,255,21,208,30,0,0,69,49,219,73,137,216,186,27,0,0,0,72,141,132,36,172,0,0,0,76,137,156,36,176,0,0,0,65,185,24,2,0,0,72,199,193,255,255,255,255,199,132,36,168,0,0,0,4,0,0,0,72,137,68,36,32,255,21,98,30,0,0,133,192,15,133,45,2,0,0,69,49,201,69,49,210,199,132,36,0,1,0,0,48,0,0,0,72,141,140,36,176,0,0,0,76,137,140,36,8,1,0,0,186,1,0,16,0,77,137,225,76,141,132,36,0,1,0,0,72,137,156,36,16,1,0,0,199,132,36,24,1,0,0,64,0,0,0,76,137,148,36,32,1,0,0,76,137,148,36,40,1,0,0,199,68,36,40,96,0,0,0,199,68,36,32,7,0,0,0,255,21,192,29,0,0,133,192,15,133,187,1,0,0,72,139,140,36,176,0,0,0,199,68,36,32,5,0,0,0,76,137,226,65,185,24,0,0,0,76,141,132,36,232,0,0,0,255,21,177,29,0,0,72,139,140,36,176,0,0,0,133,192,15,133,97,1,0,0,76,139,172,36,240,0,0,0,139,148,36,168,0,0,0,73,57,213,15,140,73,1,0,0,77,137,232,72,141,156,36,184,0,0,0,137,84,36,48,69,49,201,73,41,208,72,141,132,36,168,0,0,0,49,210,72,137,92,36,56,76,137,132,36,184,0,0,0,69,49,192,76,137,68,36,64,69,49,192,72,137,68,36,40,76,137,100,36,32,255,21,98,29,0,0,133,192,15,133,242,0,0,0,139,132,36,168,0,0,0,131,192,4,137,132,36,168,0,0,0,73,57,197,15,140,216,0,0,0,49,210,72,199,193,255,255,255,255,72,137,132,36,200,0,0,0,76,141,140,36,200,0,0,0,72,137,148,36,192,0,0,0,69,49,192,72,141,148,36,192,0,0,0,199,68,36,40,4,0,0,0,199,68,36,32,0,48,16,0,255,21,126,28,0,0,72,139,140,36,176,0,0,0,133,192,15,133,142,0,0,0,68,139,140,36,168,0,0,0,76,139,132,36,192,0,0,0,76,137,232,76,41,200,76,137,202,69,137,8,73,131,192,4,72,137,132,36,184,0,0,0,131,234,4,49,192,69,49,201,137,84,36,48,49,210,76,137,68,36,40,69,49,192,72,137,68,36,64,72,137,92,36,56,76,137,100,36,32,255,21,155,28,0,0,137,132,36,148,0,0,0,133,192,116,56,49,192,65,185,0,128,0,0,73,137,240,72,199,193,255,255,255,255,72,137,132,36,208,0,0,0,72,141,148,36,192,0,0,0,255,21,24,28,0,0,72,139,140,36,176,0,0,0,255,21,234,27,0,0,235,27,72,139,140,36,176,0,0,0,255,21,218,27,0,0,72,139,180,36,192,0,0,0,72,133,246,117,27,186,62,0,0,192,72,199,193,255,255,255,255,255,21,91,28,0,0,139,4,37,0,0,0,0,15,11,139,6,76,141,110,5,76,141,140,36,232,0,0,0,72,199,193,255,255,255,255,137,132,36,128,0,0,0,15,182,70,4,139,156,36,128,0,0,0,15,182,208,73,137,198,76,141,100,6,9,131,235,9,41,211,139,84,6,5,199,68,36,40,4,0,0,0,199,68,36,32,0,48,16,0,57,211,15,67,211,49,192,69,49,192,72,137,132,36,192,0,0,0,137,208,137,84,36,104,72,141,148,36,192,0,0,0,72,137,68,36,112,72,137,132,36,232,0,0,0,255,21,36,27,0,0,133,192,116,18,186,160,0,0,192,72,199,193,255,255,255,255,255,21,190,27,0,0,72,139,132,36,192,0,0,0,69,141,78,255,138,78,5,69,15,182,201,72,137,132,36,152,0,0,0,73,141,4,28,49,219,72,137,68,36,120,72,139,68,36,112,72,3,132,36,152,0,0,0,72,137,68,36,96,76,59,100,36,120,15,131,146,1,0,0,137,216,69,138,60,36,77,141,84,36,1,68,141,91,1,68,33,200,69,138,116,5,0,137,216,193,232,3,68,33,200,71,141,4,54,65,49,206,208,233,65,138,124,5,0,137,248,192,232,7,65,9,192,137,216,48,248,65,49,192,69,49,199,65,192,232,4,69,49,248,68,137,192,68,41,240,192,200,3,1,199,49,249,132,192,15,137,155,0,0,0,76,59,84,36,120,15,131,44,1,0,0,69,137,216,131,224,127,68,137,218,131,195,2,69,33,200,136,68,36,88,68,137,216,77,141,84,36,2,71,138,124,5,0,69,137,216,48,240,69,138,92,36,1,65,193,232,3,72,139,148,36,152,0,0,0,69,33,200,67,141,60,63,65,49,207,208,233,71,138,116,5,0,69,137,240,65,192,232,7,68,9,199,65,137,192,138,68,36,88,65,49,248,69,49,195,65,192,232,4,1,208,69,49,216,69,41,248,65,192,200,3,69,1,198,68,49,241,56,208,15,132,160,0,0,0,72,59,84,36,96,15,131,149,0,0,0,72,255,194,68,136,66,255,235,228,68,15,182,192,77,1,208,76,57,68,36,120,15,130,138,0,0,0,72,139,148,36,152,0,0,0,68,137,219,68,141,52,16,65,56,214,116,102,72,59,84,36,96,115,95,69,137,200,137,216,73,255,194,72,255,194,65,33,216,48,248,67,138,124,5,0,65,137,216,255,195,65,193,232,3,69,33,200,68,141,36,63,49,207,208,233,71,138,92,5,0,69,137,216,65,192,232,7,69,9,196,65,137,192,69,49,224,69,138,98,255,69,49,196,65,192,232,4,69,49,224,65,41,248,65,192,200,3,69,1,195,68,136,66,255,68,49,217,235,149,72,137,148,36,152,0,0,0,77,137,212,233,99,254,255,255,139,140,36,128,0,0,0,69,49,246,72,137,247,49,192,139,148,36,128,0,0,0,72,137,180,36,0,1,0,0,76,137,180,36,48,1,0,0,72,193,233,3,131,226,7,252,243,72,171,72,137,209,243,170,65,185,0,128,0,0,72,141,132,36,48,1,0,0,69,49,255,72,199,193,255,255,255,255,72,137,132,36,128,0,0,0,72,141,132,36,0,1,0,0,76,139,132,36,128,0,0,0,72,141,180,36,232,0,0,0,72,137,194,72,137,68,36,120,255,21,237,24,0,0,72,139,156,36,192,0,0,0,73,137,241,69,49,192,72,141,148,36,200,0,0,0,72,199,193,255,255,255,255,72,99,67,60,72,1,195,102,139,67,22,76,137,188,36,200,0,0,0,102,37,0,32,102,137,68,36,96,139,67,80,199,68,36,40,4,0,0,0,5,255,31,0,0,199,68,36,32,0,48,16,0,37,0,240,255,255,72,137,132,36,232,0,0,0,255,21,89,24,0,0,76,139,116,36,112,68,139,100,36,104,73,193,238,3,65,131,228,7,133,192,116,91,72,139,188,36,192,0,0,0,69,49,237,76,137,241,49,192,76,137,172,36,48,1,0,0,72,137,188,36,0,1,0,0,252,243,72,171,76,137,225,243,170,72,199,193,255,255,255,255,72,139,84,36,120,76,139,132,36,128,0,0,0,65,185,0,128,0,0,255,21,42,24,0,0,186,160,0,0,192,72,199,193,255,255,255,255,255,21,152,24,0,0,72,137,116,36,32,72,139,132,36,200,0,0,0,65,185,1,1,0,0,72,199,193,255,255,255,255,76,139,132,36,128,0,0,0,72,139,84,36,120,72,199,132,36,48,1,0,0,0,16,0,0,72,137,132,36,0,1,0,0,255,21,247,23,0,0,72,139,132,36,200,0,0,0,139,75,84,72,139,180,36,192,0,0,0,72,141,184,0,16,0,0,72,137,188,36,200,0,0,0,252,243,164,68,15,183,67,6,15,183,67,20,77,107,192,40,72,141,84,3,24,49,192,73,1,208,72,139,180,36,200,0,0,0,76,57,194,115,93,139,74,8,133,201,116,80,68,139,82,16,68,139,74,12,73,1,241,68,57,209,73,15,71,202,133,201,116,17,139,114,20,76,137,207,72,3,180,36,192,0,0,0,252,243,164,68,139,82,16,139,74,8,65,57,202,115,29,68,41,209,68,137,215,76,1,207,65,137,201,72,193,233,3,65,131,225,7,252,243,72,171,76,137,201,243,170,72,131,194,40,235,150,72,137,247,72,43,123,48,117,14,131,187,148,0,0,0,0,117,117,233,101,3,0,0,139,139,180,0,0,0,133,201,116,232,139,131,176,0,0,0,133,192,116,222,72,1,240,72,1,193,72,57,200,115,211,68,139,24,69,133,219,116,203,68,139,64,4,65,131,248,7,118,193,77,141,72,248,76,141,80,8,73,131,225,254,77,1,209,77,57,202,115,38,102,65,139,18,65,137,213,102,65,193,237,12,102,65,131,253,10,117,13,129,226,255,15,0,0,76,1,218,72,1,60,22,73,131,194,2,235,213,76,1,192,235,170,139,131,144,0,0,0,133,192,15,132,231,2,0,0,72,1,198,72,141,132,36,232,0,0,0,72,137,132,36,152,0,0,0,72,141,132,36,216,0,0,0,72,137,68,36,88,139,70,12,133,192,15,132,188,2,0,0,72,141,148,36,48,1,0,0,72,3,132,36,200,0,0,0,73,137,208,102,15,190,8,132,201,116,28,73,137,209,77,41,193,73,129,249,6,2,0,0,127,13,72,131,194,2,72,255,192,102,137,74,254,235,220,102,199,2,0,0,49,192,76,137,132,36,8,1,0,0,15,183,200,255,192,72,137,202,102,131,188,76,48,1,0,0,0,117,237,1,210,1,192,49,255,49,201,102,137,148,36,0,1,0,0,76,139,140,36,152,0,0,0,49,210,76,141,132,36,0,1,0,0,102,137,132,36,2,1,0,0,72,137,188,36,232,0,0,0,255,21,160,21,0,0,133,192,117,13,76,139,188,36,232,0,0,0,77,133,255,117,97,72,139,188,36,192,0,0,0,69,49,219,76,137,241,49,192,76,137,156,36,0,1,0,0,72,137,188,36,232,0,0,0,252,243,72,171,76,137,225,243,170,65,185,0,128,0,0,72,139,148,36,152,0,0,0,69,49,255,76,141,132,36,0,1,0,0,72,199,193,255,255,255,255,255,21,128,21,0,0,186,123,0,0,192,72,199,193,255,255,255,255,255,21,238,21,0,0,72,139,132,36,200,0,0,0,139,14,68,139,110,16,73,1,197,72,1,200,133,201,73,15,68,197,72,137,68,36,104,72,141,132,36,0,1,0,0,72,137,68,36,112,73,131,125,0,0,15,132,121,1,0,0,72,139,68,36,104,76,139,0,77,133,192,15,132,104,1,0,0,72,139,5,207,20,0,0,15,137,135,0,0,0,69,49,210,49,210,76,139,76,36,88,69,15,183,192,76,137,148,36,216,0,0,0,76,137,249,255,208,133,192,116,91,72,139,188,36,192,0,0,0,69,49,201,76,137,241,49,192,76,137,140,36,0,1,0,0,72,137,188,36,232,0,0,0,252,243,72,171,76,137,225,243,170,72,199,193,255,255,255,255,76,139,68,36,112,72,139,148,36,152,0,0,0,65,185,0,128,0,0,255,21,177,20,0,0,186,56,1,0,192,72,199,193,255,255,255,255,255,21,31,21,0,0,72,139,132,36,216,0,0,0,233,193,0,0,0,76,3,132,36,200,0,0,0,49,210,73,131,192,2,76,137,132,36,8,1,0,0,68,15,183,202,255,194,67,128,60,8,0,117,243,69,49,192,102,137,148,36,2,1,0,0,76,137,249,72,139,84,36,112,102,68,137,140,36,0,1,0,0,76,139,140,36,152,0,0,0,76,137,132,36,232,0,0,0,69,49,192,255,208,133,192,117,13,72,139,132,36,232,0,0,0,72,133,192,117,92,72,139,188,36,192,0,0,0,49,201,49,192,72,137,140,36,0,1,0,0,76,137,241,72,137,188,36,232,0,0,0,252,243,72,171,76,137,225,243,170,65,185,0,128,0,0,76,139,68,36,112,72,139,148,36,152,0,0,0,72,199,193,255,255,255,255,255,21,229,19,0,0,186,57,1,0,192,72,199,193,255,255,255,255,255,21,83,20,0,0,49,192,73,137,69,0,73,131,197,8,72,131,68,36,104,8,233,124,254,255,255,72,131,198,20,233,57,253,255,255,139,131,164,0,0,0,133,192,116,40,139,139,160,0,0,0,133,201,116,30,65,185,12,0,0,0,49,210,76,139,132,36,200,0,0,0,65,247,241,76,1,193,137,194,255,21,19,20,0,0,76,139,188,36,200,0,0,0,131,187,220,0,0,0,0,116,34,139,131,216,0,0,0,133,192,116,24,73,139,84,7,88,72,133,210,116,14,72,139,4,37,8,0,254,127,76,49,248,72,137,2,72,139,132,36,136,0,0,0,76,141,132,36,216,0,0,0,72,141,148,36,208,0,0,0,65,185,2,0,0,0,72,199,193,255,255,255,255,76,141,172,36,184,0,0,0,76,137,120,16,139,67,84,76,137,188,36,208,0,0,0,72,137,132,36,216,0,0,0,72,141,132,36,176,0,0,0,72,137,68,36,32,255,21,25,19,0,0,15,183,123,6,72,184,1,0,0,0,16,0,0,0,76,141,132,36,0,1,0,0,72,137,132,36,48,1,0,0,72,184,2,0,0,0,32,0,0,0,72,137,132,36,56,1,0,0,72,107,255,40,72,184,4,0,0,0,64,0,0,0,72,137,132,36,64,1,0,0,72,137,132,36,72,1,0,0,15,183,67,20,72,141,116,3,24,72,141,132,36,232,0,0,0,72,137,132,36,152,0,0,0,72,1,247,72,57,254,115,87,139,86,12,139,70,36,72,131,198,40,76,137,132,36,136,0,0,0,72,199,193,255,255,255,255,76,1,250,193,232,29,72,137,148,36,232,0,0,0,139,86,224,68,139,140,132,48,1,0,0,76,137,108,36,32,72,137,148,36,0,1,0,0,72,139,148,36,152,0,0,0,255,21,93,18,0,0,76,139,132,36,136,0,0,0,235,164,139,115,40,133,246,116,5,57,115,80,115,18,186,57,1,0,192,72,199,193,255,255,255,255,255,21,149,18,0,0,72,139,188,36,200,0,0,0,72,1,254,131,187,212,0,0,0,0,15,133,182,0,0,0,72,139,188,36,192,0,0,0,49,192,76,137,241,72,137,132,36,48,1,0,0,49,192,72,137,188,36,0,1,0,0,252,243,72,171,76,137,225,243,170,65,185,0,128,0,0,72,139,84,36,120,76,139,132,36,128,0,0,0,72,199,193,255,255,255,255,255,21,181,17,0,0,49,210,72,137,21,156,17,0,0,72,137,21,117,17,0,0,72,137,21,158,17,0,0,72,137,21,183,17,0,0,72,137,21,80,17,0,0,72,137,21,57,17,0,0,72,137,21,18,18,0,0,72,137,21,187,17,0,0,72,137,21,212,17,0,0,72,137,21,221,17,0,0,72,137,21,118,17,0,0,72,137,21,175,17,0,0,72,137,21,56,17,0,0,72,137,21,129,17,0,0,102,131,124,36,96,0,116,103,235,59,139,131,208,0,0,0,133,192,15,132,60,255,255,255,72,139,92,7,24,72,133,219,15,132,46,255,255,255,72,139,3,72,133,192,15,132,34,255,255,255,72,131,195,8,69,49,192,186,1,0,0,0,72,137,249,255,208,235,225,69,49,192,72,139,140,36,200,0,0,0,186,1,0,0,0,255,214,133,192,117,31,186,66,1,0,192,72,199,193,255,255,255,255,255,21,100,17,0,0,235,11,252,72,131,228,240,72,131,236,40,255,230,49,210,72,199,193,255,255,255,255,255,21,72,17,0,0,235,11,199,132,36,148,0,0,0,5,0,0,192,139,132,36,148,0,0,0,72,141,101,200,91,94,95,65,92,65,93,65,94,65,95,93,195,144,144,144,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,84,137,159,205,0,0,0,0,64,49,0,64,1,0,0,0,64,136,240,52,0,0,0,0,32,49,0,64,1,0,0,0,17,77,239,128,0,0,0,0,80,49,0,64,1,0,0,0,140,14,33,212,0,0,0,0,112,49,0,64,1,0,0,0,157,204,64,33,0,0,0,0,16,49,0,64,1,0,0,0,198,69,149,211,0,0,0,0,0,49,0,64,1,0,0,0,86,122,185,43,0,0,0,0,224,49,0,64,1,0,0,0,140,235,174,74,0,0,0,0,144,49,0,64,1,0,0,0,70,126,240,77,0,0,0,0,176,49,0,64,1,0,0,0,179,106,208,124,0,0,0,0,192,49,0,64,1,0,0,0,117,240,248,119,0,0,0,0,96,49,0,64,1,0,0,0,17,79,216,142,0,0,0,0,160,49,0,64,1,0,0,0,73,234,253,152,0,0,0,0,48,49,0,64,1,0,0,0,47,210,9,222,0,0,0,0,128,49,0,64,1,0,0,0,13,107,111,89,0,0,0,0,208,49,0,64,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
static const path_t PATH_OUTPUT = L"./peldr-";
DEC_FUNC(array) compress(const array &dt) {
const SIZE_T sz = dt.size();
const BYTE *d = dt.data();
array out;
out.reserve(sz);
SIZE_T i = 0;
while (i < sz) {
BYTE c = d[i];
BYTE r = 1;
SIZE_T u = ((sz - i) > 127)? 127 : sz - i;
while ((r < u) && (d[i + r] == c)) ++r;
if (r >= 3) {
out.push_back(0x80 | r);
out.push_back(c);
i += r;
}
else {
SIZE_T s = i;
SIZE_T u = (sz < (s + 126))? sz : s + 126;
while (i < u) {
if ( ((i + 2) < sz) && (d[i] == d[i + 1]) && (d[i] == d[i + 2]) )
break;
++i;
}
BYTE l = i - s;
if (l) {
out.push_back(l);
out.insert(out.end(), d + s, d + i);
}
}
}
return out;
}
DEC_FUNC(VOID) enc(array &dt, const array &key) {
SIZE_T idx = 0;
BYTE mask = static_cast<BYTE>(key.size() - 1);
BYTE stat = key[0];
for (BYTE &b : dt) {
SIZE_T j = idx;
BYTE k1 = key[ j & mask];
BYTE k2 = key[(j >> 3) & mask];
BYTE t = (( j & 0xFF) ^ ((j >> 8) & 0xFF)) & 0xFF;
BYTE y = ( ((k1 << 1 ) | (k2 >> 7)) ^ t ) & 0xFF;
BYTE m = (y ^ (y >> 4)) & 0xFF;
BYTE r = ((b << 3) | (b >> 5)) & 0xFF;
r = (r + (stat ^ k1)) & 0xFF;
r ^= m;
stat = ((b + k2) ^ (stat >> 1)) & 0xFF;
b = r;
++idx;
}
}
DEC_FUNC(BOOL) read_file(array &buf, const path_t &p) {
std::ifstream f(p, std::ios::binary | std::ios::ate);
if (!f) PERR(L"[ FAIL ]: cannot open file("+ p.wstring() +L")");
std::streamsize sz = f.tellg();
if (sz < sizeof(IMAGE_DOS_HEADER))
PERR(L"[ FAIL ]: file("+ p.wstring() +L") is small for PE");
f.seekg(0, std::ios::beg);
buf.resize(sz);
if (!f.read(reinterpret_cast<PCHAR>(buf.data()), sz))
PERR(L"[ FAIL ]: failed to read file("+ p.wstring() +L")");
return TRUE;
}
DEC_FUNC(BOOL) valid_pe_file(const array &raw, const path_t &p) {
auto dos = reinterpret_cast<const IMAGE_DOS_HEADER*>(raw.data());
if (dos->e_magic != IMAGE_DOS_SIGNATURE)
PERR(L"[ FAIL ]: file("+ p.wstring() +L") is not PE");
DWORD off = dos->e_lfanew;
if ((off > raw.size()) ||
((raw.size() - off) < sizeof(IMAGE_NT_HEADERS64))
) PERR(L"[ FAIL ]: invalid PE file("+ p.wstring() +L")");
auto nt = reinterpret_cast<const IMAGE_NT_HEADERS64*>(raw.data() + off);
if (nt->Signature != IMAGE_NT_SIGNATURE)
PERR(L"[ FAIL ]: invalid PE file("+ p.wstring() +L")");
if (nt->FileHeader.Machine != IMAGE_FILE_MACHINE_AMD64)
PERR(L"[ FAIL ]: PE file("+ p.wstring() +L") is not x64");
return TRUE;
}
DEC_FUNC(SIZE_T) build_exe(
BOOL gui,
const path_t fp,
const array &exe,
const array &key,
SIZE_T rawsz
) {
array stub(STUB_EXE, STUB_EXE + sizeof(STUB_EXE));
if (gui) {
auto dos = reinterpret_cast<PIMAGE_DOS_HEADER>(stub.data());
auto nt = reinterpret_cast<PIMAGE_NT_HEADERS64>(stub.data() + dos->e_lfanew);
nt->OptionalHeader.Subsystem = IMAGE_SUBSYSTEM_WINDOWS_GUI;
}
stub.reserve(
stub.size() +
(1 + key.size()) +
(4 + exe.size()) +
4
);
stub.push_back(static_cast<BYTE>(key.size()));
stub.insert(stub.end(), key.begin(), key.end());
for (BYTE i = 0; i < 4; ++i)
stub.push_back(static_cast<BYTE>( (rawsz >> (8 * i)) & 0xFF ));
stub.insert(stub.end(), exe.begin(), exe.end());
UINT32 tlLn = static_cast<UINT32>(stub.size() - sizeof(STUB_EXE));
for (BYTE i = 0; i < 4; ++i)
stub.push_back(static_cast<BYTE>( (tlLn >> (8 * i)) & 0xFF ));
std::ofstream f(fp, std::ios::binary);
if (!f) PERR(L"[ FAIL ]: failed to make output file("+ fp.wstring() +L")");
f.write(reinterpret_cast<const CHAR*>(stub.data()), stub.size());
f.close();
return stub.size();
}
DEC_FUNC(BOOL) setup(BOOL gui, const path_t &p, std::minstd_rand &gen) {
clock_t _s = clock();
array exe;
if (!read_file(exe, p)) return FALSE;
if (!valid_pe_file(exe, p)) return FALSE;
INT64 rawsz = exe.size();
BYTE kln = KSZ[gen() % sizeof(KSZ)];
array key(kln);
for (auto &b : key) b = static_cast<BYTE>(gen() & 0xFF);
exe = compress(exe);
enc(exe, key);
INT64 cmpsz = exe.size();
std::wcout << L"[ OK ]: compressed: (" <<
rawsz << L" -> " << cmpsz
<< L") bytes | saved: " << (rawsz - cmpsz) << L" bytes (" <<
(((rawsz - cmpsz) * 100) / rawsz)
<< L"%)\n";
path_t fp = PATH_OUTPUT.wstring() + p.filename().wstring();
SIZE_T fsz = build_exe(gui, fp, exe, key, rawsz);
if (fsz) std::wcout << L"[ OK ]: outfile(" <<
fp << L", " << fsz
<< L" bytes)\n";
clock_t _e = clock();
LONG ms = ((_e - _s) * 1000) / CLOCKS_PER_SEC;
LONG rem = ms % 1000;
std::wcout << L"[ INFO ]: time ................. ("
<< (ms / 1000) << L".";
if (rem < 100) std::wcout << L"0";
if (rem < 10 ) std::wcout << L"0";
std::wcout << rem << L"s)\n";
return TRUE;
}
INT wmain(INT argc, WCHAR *argv[]) {
std::random_device rd;
std::minstd_rand gen(rd());
_setmode(_fileno(stdout), _O_U16TEXT);
_setmode(_fileno(stderr), _O_U16TEXT);
if (argc < 2) {
path_t nm = argv[0];
std::wcerr << L"Usage: " << nm.wstring() << L" <exe|dll> [exe|dll ...]\n";
return EXIT_FAILURE;
}
BOOL IS_GUI = FALSE;
for (UINT i = 1; i < argc; ++i)
if (IS_FLAG_GUI(argv, i)) {
IS_GUI = TRUE;
break;
};
std::wcout << L"[ OK ]: Starting packing of (" <<
(argc - 1 - IS_GUI)
<< L") " <<
L"file mode(" << (IS_GUI? L"GUI" : L"CONSOLE")
<< L")\n\n\n\n\n";
UINT packed = 0;
for (UINT i = 1; i < argc; ++i) {
if (IS_FLAG_GUI(argv, i)) continue;
path_t fp = fs::absolute(argv[i]);
std::wcout << L"[ INFO ]: Start processing -> " << fp.wstring() << L"\n\n";
if (setup(IS_GUI, fp, gen)) ++packed;
std::wcout << L"\n[ INFO ]: End processing -> " << fp.wstring() << L"\n\n";
std::wcout << L"\n\n\n";
}
std::wcout << L"[ OK ]: Successfully packed of (" << packed << L")\n";
return EXIT_SUCCESS;
}