-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMasterWindows.cpp
More file actions
391 lines (312 loc) · 9.6 KB
/
MasterWindows.cpp
File metadata and controls
391 lines (312 loc) · 9.6 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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
// MasterWindows.cpp :
//
#include "stdafx.h"
#include "MasterWindows.h"
#include "afxdialogex.h"
#include "puPEinfoData.h"
#include "SectionInfo.h"
#include "AddSection.h"
#include "studData.h"
#include "CompressionData.h"
#include "UnShell.h"
CString UnShllerProcPath;
char g_filenameonly[MAX_PATH] = { 0, };
// MasterWindows
IMPLEMENT_DYNAMIC(MasterWindows, CDialogEx)
#define NEWSECITONNAME ".VMP"
MasterWindows::MasterWindows(CWnd* pParent /*=NULL*/)
: CDialogEx(MasterWindows::IDD, pParent)
, m_MasterStaticTextStr(_T(""))
{
}
MasterWindows::~MasterWindows()
{
}
void MasterWindows::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_STATIC1, m_MasterStaticText);
DDX_Text(pDX, IDC_STATIC1, m_MasterStaticTextStr);
DDX_Control(pDX, IDC_BITMAP_LOG, m_bitmapZionloab);
}
BEGIN_MESSAGE_MAP(MasterWindows, CDialogEx)
ON_BN_CLICKED(IDC_BUTTON1, &MasterWindows::OnBnClickedButton1)
ON_WM_DROPFILES()
ON_BN_CLICKED(IDC_BUTTON4, &MasterWindows::OnBnClickedButton4)
// ON_BN_CLICKED(IDC_BUTTON3, &MasterWindows::OnBnClickedButton3)
ON_BN_CLICKED(IDC_BUTTON9, &MasterWindows::OnBnClickedButton9)
ON_BN_CLICKED(IDC_BUTTON3, &MasterWindows::OnBnClickedButton3)
ON_BN_CLICKED(IDC_BUTTON2, &MasterWindows::OnBnClickedButton2)
ON_WM_CTLCOLOR()
ON_WM_PAINT()
END_MESSAGE_MAP()
BOOL MasterWindows::OnInitDialog()
{
CDialogEx::OnInitDialog();
ChangeWindowMessageFilter(WM_DROPFILES, MSGFLT_ADD);
ChangeWindowMessageFilter(0x0049, MSGFLT_ADD);
SetIcon(LoadIcon(AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDI_ICON1)), TRUE);
CBitmap* d = new CBitmap();
d->LoadBitmapW(IDB_BITMAP2);
m_bitmapZionloab.SetBitmap((HBITMAP)d->m_hObject);
// m_Logbmp.SetBitmap((HBITMAP)d->m_hObject);
//加载位图
CBitmap bmp;
bmp.LoadBitmapW(MAKEINTRESOURCE(IDB_BITMAP1));
//添加位图
m_bmp.Attach(bmp);
//创建兼容DC
CDC* pDc = GetDC();
m_dc.CreateCompatibleDC(pDc);
//用完之后释放
ReleaseDC(pDc);
//把位图对象选入DC中
m_dc.SelectObject(&m_bmp);
//使窗口无效,这样OnPaint函数就会被触发,使之被画出来
Invalidate(FALSE);
return TRUE;
}
// 一键加壳
void MasterWindows::OnBnClickedButton1()
{
UpdateData(TRUE);
if (m_MasterStaticTextStr.IsEmpty())
{
AfxMessageBox(L"请先拖入文件");
return;
}
// ☆ 先增加新区~段后压缩
CString nStr, tmep;
PuPEInfo obj_Peinfo;
// 1. 新增区段
if (!NewSection())
AfxMessageBox(L"添加新区段失败");
CloseHandle(obj_Peinfo.puFileHandle()); UpdateData(TRUE);
// 保存Path,拷贝使用
nStr = m_MasterStaticTextStr;
// 获取文件名
tmep = m_MasterStaticTextStr;
int n = tmep.ReverseFind('\\') + 1;
int m = tmep.GetLength() - n;
tmep = tmep.Right(m);
DWORD dwNum = 0;
dwNum = WideCharToMultiByte(CP_OEMCP, NULL, tmep, -1, NULL, NULL, 0, NULL);
WideCharToMultiByte(CP_OEMCP, NULL, tmep, -1, g_filenameonly, dwNum, 0, NULL);
if (g_filenameonly)
strcat(g_filenameonly, "_FileData.txt");
else
{
strcpy(g_filenameonly, "FileData.txt");
AfxMessageBox(L"转换文件名有问题");
}
obj_Peinfo.puOpenFileLoad(m_MasterStaticTextStr);
// 2. 压缩全部区段 压缩的时候不清空数据目录表以及区段大小(不压缩新增区段)
CompressionData obj_ComperData;
CloseHandle(obj_Peinfo.puFileHandle()); UpdateData(TRUE);
obj_Peinfo.puOpenFileLoad(m_MasterStaticTextStr);
if (!obj_ComperData.puCompressSection())
AfxMessageBox(L"CompressSection failuer!");
CloseHandle(obj_Peinfo.puFileHandle());
m_MasterStaticTextStr = "C:\\Users\\CompressionMask.exe";
obj_Peinfo.puOpenFileLoad(m_MasterStaticTextStr);
// 3. Stud壳数据拷贝/操作
studData obj_stuData;
obj_stuData.puLoadLibraryStud();
obj_stuData.puRepairReloCationStud();
if (obj_stuData.puCopyStud())
{
CloseHandle(obj_Peinfo.puFileHandle());
UpdateData(TRUE);
// 这些操作只为了最后保留一个有效加壳文件,其实垃圾exe清理
int nstatus = CopyFile(L"C:\\Users\\CompressionMask.exe", nStr, FALSE);
if (nstatus)
{
m_MasterStaticTextStr = nStr;
DeleteFile(L"C:\\Users\\CompressionMask.exe");
}
obj_Peinfo.puOpenFileLoad(m_MasterStaticTextStr);
AfxMessageBox(m_MasterStaticTextStr + L" Success!");
}
else
AfxMessageBox(L"StudWrite failure!");
// 4、收尾工作
CloseHandle(obj_Peinfo.puFileHandle());
}
void MasterWindows::OnDropFiles(HDROP hDropInfo)
{
int DropCount = DragQueryFile(hDropInfo, -1, NULL, 0);
char wcStr[MAX_PATH] = {};
for (int i = 0; i < DropCount; ++i)
{
wcStr[0] = 0;
DragQueryFileA(hDropInfo, i, wcStr, MAX_PATH);
m_MasterStaticTextStr = wcStr;
}
UpdateData(FALSE);
ShowPEInfoData(m_MasterStaticTextStr);
DragFinish(hDropInfo);
CDialogEx::OnDropFiles(hDropInfo);
}
void MasterWindows::ShowPEInfoData(const CString & FileName)
{
PuPEInfo obj_puPe; CString Tempstr; DWORD TempdwCode = 0;
if (!obj_puPe.puOpenFileLoad(FileName))
return;
PIMAGE_NT_HEADERS pNtHeadre = (PIMAGE_NT_HEADERS)obj_puPe.puGetNtHeadre();
PIMAGE_FILE_HEADER pFileHeadre = (PIMAGE_FILE_HEADER)&pNtHeadre->FileHeader;
PIMAGE_OPTIONAL_HEADER pOption = (PIMAGE_OPTIONAL_HEADER)&pNtHeadre->OptionalHeader;
TempdwCode = pFileHeadre->NumberOfSections;
Tempstr.Format(L"%d", TempdwCode);
SetDlgItemText(IDC_EDIT9, Tempstr);
// OEP
TempdwCode = pOption->AddressOfEntryPoint;
Tempstr.Format(L"%08X", TempdwCode);
SetDlgItemText(IDC_EDIT1, Tempstr);
TempdwCode = pOption->ImageBase;
Tempstr.Format(L"%08X", TempdwCode);
SetDlgItemText(IDC_EDIT3, Tempstr);
TempdwCode = pOption->Magic;
Tempstr.Format(L"%04X", TempdwCode);
SetDlgItemText(IDC_EDIT2, Tempstr);
TempdwCode = pOption->NumberOfRvaAndSizes;
Tempstr.Format(L"%08X", TempdwCode);
SetDlgItemText(IDC_EDIT7, Tempstr);
TempdwCode = pOption->BaseOfCode;
Tempstr.Format(L"%08X", TempdwCode);
SetDlgItemText(IDC_EDIT4, Tempstr);
#ifdef _WIN64
#else
TempdwCode = pOption->BaseOfData;
Tempstr.Format(L"%08X", TempdwCode);
SetDlgItemText(IDC_EDIT5, Tempstr);
#endif
TempdwCode = pOption->SectionAlignment;
Tempstr.Format(L"%08X", TempdwCode);
SetDlgItemText(IDC_EDIT6, Tempstr);
TempdwCode = pOption->FileAlignment;
Tempstr.Format(L"%08X", TempdwCode);
SetDlgItemText(IDC_EDIT8, Tempstr);
}
// PE_View
void MasterWindows::OnBnClickedButton4()
{
UpdateData(TRUE);
if (m_MasterStaticTextStr.IsEmpty())
{
AfxMessageBox(L"请先拖入文件");
return;
}
SectionInfo obj_section;
obj_section.DoModal();
return;
}
// NewSection
void MasterWindows::OnBnClickedButton9()
{
UpdateData(TRUE);
if (m_MasterStaticTextStr.IsEmpty())
{
AfxMessageBox(L"请先拖入文件");
return;
}
if (NewSection())
AfxMessageBox(L"Success");
else
AfxMessageBox(L"Fauilter");
}
BOOL MasterWindows::NewSection()
{
AddSection obj_addsection; BOOL nRet = TRUE;
BYTE Name[] = ".VMP";
// 遗留问题,添加区段必须提前申请大小,所以拷贝Stub崩溃排查此处大小,这里是Stud-DLL大小
const DWORD SectionSize = 0x19600;
obj_addsection.puModifySectioNumber();
nRet = obj_addsection.puModifySectionInfo(Name, SectionSize);
obj_addsection.puModifyProgramEntryPoint();
obj_addsection.puModifySizeofImage();
nRet = obj_addsection.puAddNewSectionByData(SectionSize);
return nRet;
}
// Only_ComperData
void MasterWindows::OnBnClickedButton3()
{
UpdateData(TRUE);
if (m_MasterStaticTextStr.IsEmpty())
{
AfxMessageBox(L"请先拖入文件");
return;
}
UpdateData(TRUE);
if (m_MasterStaticTextStr.IsEmpty())
{
AfxMessageBox(L"请先拖入文件");
return;
}
CompressionData obj_ComperData;
if (!obj_ComperData.puCompressSection())
AfxMessageBox(L"CompressSection failuer!");
else
AfxMessageBox(L"CompressSection Seucess!");
}
// 一键脱壳
void MasterWindows::OnBnClickedButton2()
{
UpdateData(TRUE);
if (m_MasterStaticTextStr.IsEmpty())
{
AfxMessageBox(L"请先拖入文件");
return;
}
// 判断是否我们的壳,否则不给脱壳
UnShllerProcPath = m_MasterStaticTextStr;
UnShell obj_Unshell;
obj_Unshell.puRepCompressionData();
obj_Unshell.puDeleteSectionInfo();
if (obj_Unshell.puSaveUnShell())
{
// 只保留脱壳后原始文件,命名一致性
int nRet = CopyFile(L"C:\\Users\\Administrator\\Desktop\\UnShellNewPro.exe", m_MasterStaticTextStr, FALSE);
if (nRet)
{
DeleteFile(L"C:\\Users\\Administrator\\Desktop\\UnShellNewPro.exe");
}
AfxMessageBox(L"puSaveUnShell_Success");
}
}
HBRUSH MasterWindows::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);
switch (pWnd->GetDlgCtrlID())
{
case IDC_STATIC :
case IDC_STATIC_PEINFO :
case IDC_STATIC_NAME:
case IDC_BUTTON1 :
case IDC_BUTTON4 :
case IDC_BUTTON9 :
case IDC_BUTTON3 :
case IDC_BUTTON2 :
{
pDC->SetBkColor(RGB(255, 255, 255));
return (HBRUSH)GetStockObject(HOLLOW_BRUSH);
}
break;
default:
return CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
}
// TODO: 如果默认的不是所需画笔,则返回另一个画笔
return hbr;
}
void MasterWindows::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
// Do not call CDialogEx::OnPaint() for painting messages
CRect rect = { 0 };
GetClientRect(&rect);
BITMAP bm;
m_bmp.GetBitmap(&bm);
dc.StretchBlt(0, 0, rect.Width(), rect.Height(),
&m_dc, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
CDialogEx::OnPaint();
}