-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmain.cpp
1502 lines (1443 loc) · 58.8 KB
/
main.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
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
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#pragma GCC optimize(3) //优化
#include <windows.h>
#include <tlhelp32.h>
#include <winternl.h>
#include <fltuser.h>
#include <userenv.h>
#include <commctrl.h>
#include <versionhelpers.h>
#include <string>
#include <cstdlib>
#include <ctime>
#include <cmath>
#undef UNICODE
#undef _UNICODE
BOOL GetMythwarePasswordFromRegedit(char *str);
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam);
DWORD WINAPI KeyHookThreadProc(LPVOID lpParameter);
DWORD WINAPI MouseHookThreadProc(LPVOID lpParameter);
DWORD WINAPI ThreadProc(LPVOID lpParameter);
BOOL CALLBACK SetWindowFont(HWND hwndChild, LPARAM lParam);
bool SetupTrayIcon(HWND m_hWnd, HINSTANCE hInstance);
LRESULT CALLBACK CBTProc(int nCode, WPARAM wParam, LPARAM lParam);
void InitNTAPI();
LPCSTR RandomWindowTitle();
BOOL EnableDebugPrivilege();
DWORD GetProcessIDFromName(LPCSTR szName);
bool KillProcess(DWORD dwProcessID, int way);
BOOL SuspendProcess(DWORD dwProcessID, BOOL suspend);
int GetProcessState(DWORD dwProcessID);
#define KILL_FORCE 1
#define KILL_DEFAULT 2
#define Set(dest, source) *(PVOID*)&(dest) = (PVOID)(source) //强行修改不同指针型数据的值
LONG WINAPI GlobalExceptionHandler(EXCEPTION_POINTERS* exceptionInfo);
inline void PrtError(LPCSTR szDes, LRESULT lResult);
inline LPSTR FormatLogTime();
std::string sOutPut;
#define Print(text) sOutPut=sOutPut+FormatLogTime()+text
#define Println(text) Print(text); sOutPut+="\r\n"
#define ge error = GetLastError()
HHOOK kbdHook, mseHook;
HWND hwnd, focus; /* A 'HANDLE', hence the H, or a pointer to our window */
/* This is where all the input to the window goes to */
LPCSTR MythwareFilename = "StudentMain.exe";//把这个改成别的便可以“兼容”更多电子教室
HWND hBdCst;
//LONG fullScreenStyle = WS_POPUP | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, windowingStyle = fullScreenStyle | WS_OVERLAPPEDWINDOW ^ WS_OVERLAPPED;
NOTIFYICONDATA icon;
HMENU hMenu;//托盘菜单
int width = 528, height = 250, w, h, mwSts;
bool asking = false, ask = false, closingProcess = false;
DWORD error = -1;//用于调试
POINT p, pt;
HWND BtAbt, BtKmw, TxOut, TxLnk, BtTop, BtCur, BtKbh, BtSnp, BtWnd;
LPCSTR helpText = "极域工具包 v1.2.1 | 小流汗黄豆 | 交流群828869154\n\
额外功能:1. 快捷键Alt+C双击杀掉当前进程,Alt+W最小化顶层窗口,Alt+B唤起主窗口\n\
2. 当鼠标移至屏幕左上角/右上角时,可以选择最小化/关闭焦点窗口(你也可以关闭此功能)\n\
3. 最小化时隐藏到任务栏托盘,左键双击打开主界面,右键单击调出菜单\n\
4. 解禁工具可解禁Chrome和Edge的小游戏;若提示设置失败,可能是无权限或指定注册表键值不存在,在此情况下,通常本身就无需解禁\n\
5. 解键盘锁功能如果对Alt+Ctrl+Delete无效时,重新勾选即可;对极域的大多数操作都只在2015/2016版测试通过\n\
6. 启动时附加-s或/s命令行可以System权限启动\n\
7. MeltdownDFC为冰点还原密码破解工具,crdisk为其他保护系统删除工具(慎用!)";
HANDLE thread/*用来刷新置顶,用Timer会有bug*/, mouHook/*解鼠标锁*/, keyHook/*解键盘锁*/;
UINT WM_TASKBAR;
struct MW_INFO{
HWND hwndOfBoardcast;
DWORD pid;
bool bNotResponding;
};
struct{ //重新实现VB的随机数功能
int m_rndSeed = 327680;
void Randomize(double Number){
int num = m_rndSeed, num2;
unsigned char bytes[sizeof(double)];
memcpy(bytes, &Number, sizeof(double));
memcpy(&num2, bytes + 4, sizeof(int));
num2 = ((num2 & 65535) ^ (num2 >> 16)) << 8;
num = (num & -16776961) | num2;
m_rndSeed = num;
}
float Rnd(){
return Rnd(1.f);
}
float Rnd(float Number){
int num = m_rndSeed;
if ((double)Number != 0.0){
if ((double)Number < 0.0)
{
num = *(int*)(&Number);
long long num2 = (long long)num & (long long)((unsigned long long)(-1));
num = (int)((num2 + (num2 >> 24)) & 16777215L);
}
num = (int)(((long long)num * 1140671485L + 12820163L) & 16777215L);
}
m_rndSeed = num;
return (float)num / 16777216.f;
}
} VBMath;
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
switch (Message) {
case WM_CREATE: {
//获取系统版本号
OSVERSIONINFO vi = {sizeof(OSVERSIONINFO)};
GetVersionEx(&vi);
SYSTEM_INFO si = {};
GetNativeSystemInfo(&si);
char szVersion[BUFSIZ] = {};
sprintf(szVersion, "系统版本:%u.%u.%u %d-bit\n程序版本:%s %d-bit\n",
vi.dwMajorVersion, vi.dwMinorVersion, vi.dwBuildNumber, (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 || si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64) ? 64 : 32,
"1.2.1", sizeof(PVOID)*8);
sOutPut += szVersion;
EnableDebugPrivilege();//提权
w = GetSystemMetrics(SM_CXSCREEN) - 1;//屏幕宽度(注意比实际可达到的坐标多1)
h = GetSystemMetrics(SM_CYSCREEN) - 1;//屏幕高度
WM_TASKBAR = RegisterWindowMessage("TaskbarCreated");//任务栏创建事件
thread = CreateThread(NULL, 0, ThreadProc, NULL, 0, NULL);//置顶窗口
keyHook = CreateThread(NULL, 0, KeyHookThreadProc, NULL, CREATE_SUSPENDED, NULL);//键盘锁
mouHook = CreateThread(NULL, 0, MouseHookThreadProc, NULL, CREATE_SUSPENDED, NULL);//鼠标锁
SetTimer(hwnd, 1, 1000, NULL); //检测鼠标左上角
SetTimer(hwnd, 2, 2000, NULL); //检测极域状态、更新标题
RegisterHotKey(hwnd, 0, MOD_ALT, 'C'); //Alt+C+C强制结束当前程序
RegisterHotKey(hwnd, 1, MOD_ALT, 'W'); //Alt+W最小化顶层窗口
if(!RegisterHotKey(hwnd, 2, MOD_ALT, 'B')) //Alt+B显示此窗口
if(MessageBox(hwnd, "注册系统级热键 Alt+B 失败,有可能该应用的另一实例还在运行,请先关闭它再重新启动本程序!否则唤出窗口功能将失效!若点击“取消”则阻止程序继续启动", "极 域 工 具 包", MB_OKCANCEL | MB_ICONWARNING)==IDCANCEL){
PostQuitMessage(0);
return FALSE;
}
HINSTANCE hi = ((LPCREATESTRUCT) lParam)->hInstance;
TxLnk = CreateWindow("SysLink", "极域工具包 <a href=\"https://blog.csdn.net/weixin_42112038?type=blog\">博客</a>", WS_CHILD | WS_VISIBLE | WS_TABSTOP, 8, 8, 120, 20, hwnd, HMENU(1001), hi, NULL);
BtAbt = CreateWindow(WC_BUTTON, "关于/帮助", WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON, 166, 3, 90, 30, hwnd, HMENU(1002), hi, NULL);
//获取密码
char str[BUFSIZ] = {};
LPCSTR psd;
if (!GetMythwarePasswordFromRegedit(str))
psd = "获取密码失败";
else psd = str;
CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, psd, WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_READONLY, 8, 36, 248, 20, hwnd, HMENU(1003), hi, NULL);
CreateWindow(WC_BUTTON, "杀掉学生机房管理助手", WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_DEFPUSHBUTTON, 8, 64, 248, 50, hwnd, HMENU(1013), hi, NULL);
BtKmw = CreateWindow(WC_BUTTON, "杀掉极域", WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_SPLITBUTTON, 8, 122, 248, 50, hwnd, HMENU(1004), hi, NULL);
TxOut = CreateWindow(STATUSCLASSNAME, "等待操作", WS_CHILD | WS_VISIBLE, 0, 0, 0, 0, hwnd, HMENU(1005), hi, NULL);
int pts[2] = {352, -1};
SendMessage(TxOut, SB_SETPARTS, WPARAM(2), LPARAM(pts));
CreateWindow(WC_BUTTON, "解除禁用工具", WS_CHILD | WS_VISIBLE | BS_GROUPBOX, 264, 8, 248, 98, hwnd, NULL, hi, NULL);
CreateWindow(WC_BUTTON, "一键解禁系统程序", WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON, 272, 28, 112, 30, hwnd, HMENU(1007), hi, NULL);
CreateWindow(WC_BUTTON, "解除网络限制", WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON, 272, 66, 112, 30, hwnd, HMENU(1008), hi, NULL);
CreateWindow(WC_BUTTON, "解除极域U盘限制", WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON, 392, 66, 112, 30, hwnd, HMENU(1009), hi, NULL);
CreateWindow(WC_BUTTON, "重启资源管理器", WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON, 392, 28, 112, 30, hwnd, HMENU(1010), hi, NULL);
CreateWindow(WC_BUTTON, "广播窗口化", WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON | WS_DISABLED, 264, 112, 120, 30, hwnd, HMENU(1014), hi, NULL);
CreateWindow(WC_BUTTON, "重置助手密码(&P)", WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON, 392, 112, 120, 30, hwnd, HMENU(1015), hi, NULL);
CreateWindow(WC_BUTTON, "MeltdownDFC", WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON, 264, 150, 120, 22, hwnd, HMENU(1019), hi, NULL);
CreateWindow(WC_BUTTON, "crdisk", WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON, 392, 150, 120, 22, hwnd, HMENU(1020), hi, NULL);
BtWnd = CreateWindow(WC_BUTTON, "启用鼠标监测弹窗", WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_AUTOCHECKBOX, 385, 176, 130, 18, hwnd, HMENU(1012), hi, NULL);
BtSnp = CreateWindow(WC_BUTTON, "防止截屏", WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_AUTOCHECKBOX | (IsWindows7OrGreater() ? 0 : WS_DISABLED), 309, 176, 65, 18, hwnd, HMENU(1011), hi, NULL);
SendMessage(BtSnp, BM_SETCHECK, BST_CHECKED, 0);
SendMessage(hwnd, WM_COMMAND, 1011, 0);
BtTop = CreateWindow(WC_BUTTON, "置顶此窗口", WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_AUTOCHECKBOX, 8, 176, 77, 18, hwnd, HMENU(1016), hi, NULL);
SendMessage(BtTop, BM_SETCHECK, BST_CHECKED, 0);
BtCur = CreateWindow(WC_BUTTON, "解除鼠标限制(&M)", WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_AUTOCHECKBOX, 95, 176, 107, 18, hwnd, HMENU(1017), hi, NULL);
BtKbh = CreateWindow(WC_BUTTON, "解键盘锁(&C)", WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_AUTOCHECKBOX, 213, 176, 85, 18, hwnd, HMENU(1018), hi, NULL);
HFONT hFont = NULL;
NONCLIENTMETRICS info;
info.cbSize = sizeof(NONCLIENTMETRICS);
if (SystemParametersInfo (SPI_GETNONCLIENTMETRICS, 0, &info, 0)) {
hFont = CreateFontIndirect ((LOGFONT*)&info.lfMessageFont);
}//取系统默认字体
EnumChildWindows(hwnd, SetWindowFont, LPARAM(hFont));
SetupTrayIcon(hwnd, hi);
HMENU sys = GetSystemMenu(hwnd, FALSE);//系统菜单
AppendMenu(sys, MF_STRING, 2, "显示上一个错误(&E)");
AppendMenu(sys, MF_STRING, 4, "显示程序日志(&L)");
AppendMenu(sys, MF_STRING, 3, "启动任务管理器(&T)");
// EnableMenuItem(sys, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
DrawMenuBar(hwnd);
focus = GetDlgItem(hwnd, 1013);
SetFocus(focus);
SendMessage(hwnd, WM_TIMER, WPARAM(2), 0);
//卸载极域进程终止hook
HMODULE hook = NULL;
if (sizeof(PVOID) == 8)hook = GetModuleHandle("LibTDProcHook64.dll");
else hook = GetModuleHandle("LibTDProcHook32.dll");
if (hook)FreeModule(hook);
break;
}
case WM_INITMENU: { //双击图标默认最小化
HMENU sys = GetSystemMenu(hwnd, FALSE);
SetMenuDefaultItem(sys, SC_MINIMIZE, 0);
break;
}
case WM_COMMAND: {
switch (LOWORD(wParam)) {
case 1002: {
MessageBox(NULL, helpText, "关于/帮助", MB_OK | MB_ICONINFORMATION);
break;
}
case 1004: {
if (mwSts != 2) {
if (KillProcess(GetProcessIDFromName(MythwareFilename), KILL_FORCE)) {
SetWindowText(TxOut, "执行成功");
Sleep(30);
SendMessage(hwnd, WM_TIMER, WPARAM(2), 0);
} else {
ge;
SetWindowText(TxOut, "执行失败");
}
} else { //降权启动极域
HKEY retKey;//先读取极域路径
char szPath[MAX_PATH * 2];
LONG ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\TopDomain\\e-Learning Class Standard\\1.00", 0, KEY_QUERY_VALUE | KEY_WOW64_32KEY, &retKey);
if (ret != ERROR_SUCCESS) {
ge;
SetWindowText(TxOut, "读取路径失败");
RegCloseKey(retKey);
break;
}
DWORD dataLong = MAX_PATH * 2, type = REG_SZ;
ret = RegQueryValueEx(retKey, "TargetDirectory", 0, &type, LPBYTE(szPath), &dataLong);
RegCloseKey(retKey);
if (ret != ERROR_SUCCESS) {
ge;
SetWindowText(TxOut, "读取路径失败");
break;
}
HWND hwnd = FindWindow("Shell_TrayWnd", NULL);//有这个类名的窗口一定隶属于explorer.exe
DWORD pid;
GetWindowThreadProcessId(hwnd, &pid);//反查出窗口PID
HANDLE handle = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid);
if (!handle) {
SetWindowText(TxOut, "请先启动资源管理器");
break;
}
HANDLE token;
OpenProcessToken(handle, TOKEN_DUPLICATE, &token);//取得token
DuplicateTokenEx(token, MAXIMUM_ALLOWED, NULL, SecurityIdentification, TokenPrimary, &token);
STARTUPINFO si = {};//必要的一些参数......
PROCESS_INFORMATION pi = {};
si.cb = sizeof(STARTUPINFO);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_SHOW;
BOOL bResult = CreateProcessAsUser(token, strcat(szPath, MythwareFilename), NULL, NULL, NULL,
FALSE, CREATE_NEW_PROCESS_GROUP | NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi); //启动极域
if (bResult) {
SetWindowText(TxOut, "启动成功");
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
} else {
ge;
SetWindowText(TxOut, "启动失败");
}
CloseHandle(handle);
CloseHandle(token);
SendMessage(hwnd, WM_TIMER, WPARAM(2), 0);
}
break;
}
case 1007: {
BYTE cStatus = NO_ERROR;
//HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System:DisableCMD->0
HKEY retKey;
DWORD value = 0;
RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Policies\\Microsoft\\Windows\\System", 0, KEY_SET_VALUE | KEY_WOW64_32KEY, &retKey);
LONG ret = RegSetValueEx(retKey, "DisableCMD", 0, REG_DWORD, (CONST BYTE*)&value, sizeof(DWORD));
if (ret != ERROR_SUCCESS) {
PrtError("解禁cmd失败", ret);
cStatus = 1;
} else Println("解禁cmd成功");
RegCloseKey(retKey);
//HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System:DisableRegistryTools->0
RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", 0, KEY_SET_VALUE | KEY_WOW64_32KEY, &retKey);
ret = RegSetValueEx(retKey, "DisableRegistryTools", 0, REG_DWORD, (CONST BYTE*)&value, sizeof(DWORD));
if (ret != ERROR_SUCCESS) {
PrtError("解禁注册表编辑器失败", ret);
cStatus = 1;
} else Println("解禁注册表编辑器成功");
//HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System:DisableTaskMgr->0
ret = RegSetValueEx(retKey, "DisableTaskMgr", 0, REG_DWORD, (CONST BYTE*)&value, sizeof(DWORD));
if (ret != ERROR_SUCCESS) {
PrtError("解禁任务管理器失败", ret);
cStatus = 1;
} else Println("解禁任务管理器成功");
RegCloseKey(retKey);
//HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer:NoRun->0
RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", 0, KEY_SET_VALUE | KEY_WOW64_32KEY, &retKey);
ret = RegSetValueEx(retKey, "NoRun", 0, REG_DWORD, (CONST BYTE*)&value, sizeof(DWORD));
if (ret != ERROR_SUCCESS) {
PrtError("解禁Win+R运行失败", ret);
cStatus = 1;
} else Println("解禁Win+R运行成功,重启资源管理器即可生效");
//HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer:RestrictRun->0
ret = RegSetValueEx(retKey, "RestrictRun", 0, REG_DWORD, (CONST BYTE*)&value, sizeof(DWORD));//也有作用
if (ret != ERROR_SUCCESS) {
PrtError("解除程序运行限制失败", ret);
cStatus = 1;
} else Println("解除程序运行限制成功,重启资源管理器即可生效");
RegCloseKey(retKey);
//HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\taskkill.exe:debugger:(
RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options\\taskkill.exe", 0, KEY_SET_VALUE | KEY_WOW64_32KEY, &retKey);
ret = RegDeleteValue(retKey, "debugger");
if (ret != ERROR_SUCCESS) {
PrtError("解禁taskkill失败", ret);
//cStatus = 1;
} else Println("解禁taskkill成功");
//HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\ntsd.exe:debugger:(
RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options\\ntsd.exe", 0, KEY_SET_VALUE | KEY_WOW64_32KEY, &retKey);
ret = RegDeleteValue(retKey, "debugger");
if (ret != ERROR_SUCCESS) {
PrtError("解禁ntsd失败", ret);
//cStatus = 1;
} else Println("解禁ntsd成功");
RegCloseKey(retKey);
//HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer:NoLogOff->0
//HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer:StartMenuLogOff->0
//HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System:DisableLockWorkstation->0
RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", 0, KEY_SET_VALUE | KEY_WOW64_32KEY, &retKey);
ret = RegSetValueEx(retKey, "NoLogOff", 0, REG_DWORD, (CONST BYTE*)&value, sizeof(DWORD));
if (ret != ERROR_SUCCESS) {
PrtError("解禁注销栏失败", ret);
cStatus = 1;
} else Println("解禁注销栏成功");
ret = RegSetValueEx(retKey, "StartMenuLogOff", 0, REG_DWORD, (CONST BYTE*)&value, sizeof(DWORD));
if (ret != ERROR_SUCCESS) {
PrtError("解禁开始菜单注销失败", ret);
cStatus = 1;
} else Println("解禁开始菜单注销成功");
RegCloseKey(retKey);
RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", 0, KEY_SET_VALUE | KEY_WOW64_32KEY, &retKey);
ret = RegSetValueEx(retKey, "DisableLockWorkstation", 0, REG_DWORD, (CONST BYTE*)&value, sizeof(DWORD));
if (ret != ERROR_SUCCESS) {
PrtError("解禁锁定失败", ret);
cStatus = 1;
} else Println("解禁锁定成功");
RegCloseKey(retKey);
RegOpenKeyEx(HKEY_CURRENT_USER, "SOFTWARE\\Policies\\Microsoft\\MMC", 0, KEY_SET_VALUE | KEY_WOW64_32KEY, &retKey);
ret = RegSetValueEx(retKey, "RestrictToPermittedSnapins", 0, REG_DWORD, (CONST BYTE*)&value, sizeof(DWORD));
if (ret != ERROR_SUCCESS) {
PrtError("解禁微软管理控制台失败", ret);
cStatus = 1;
} else Println("解禁微软管理控制台成功");
RegCloseKey(retKey);
RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Policies\\Google\\Chrome", 0, KEY_SET_VALUE | KEY_WOW64_32KEY, &retKey);
ret = RegDeleteValue(retKey, "AllowDinosaurEasterEgg");
if (ret != ERROR_SUCCESS) {
PrtError("解禁Chrome恐龙游戏失败", ret);
cStatus = 1;
} else Println("解禁Chrome恐龙游戏成功");
RegCloseKey(retKey);
RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Policies\\Microsoft\\Edge", 0, KEY_SET_VALUE | KEY_WOW64_32KEY, &retKey);
ret = RegDeleteValue(retKey, "AllowSurfGame");
if (ret != ERROR_SUCCESS) {
PrtError("解禁Edge冲浪游戏失败", ret);
cStatus = 1;
} else Println("解禁Edge冲浪游戏成功");
RegCloseKey(retKey);
if (cStatus == NO_ERROR)SetWindowText(TxOut, "设置成功");
else SetWindowText(TxOut, "设置部分失败。。");
break;
}
case 1008: {
//TODO: 检验多种状况
//发送终止指令
HANDLE hNetFilter = CreateFile("\\\\.\\TDNetFilter", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
if(!GetLastError()){
DeviceIoControl(hNetFilter, 0x120014, NULL, 0, NULL, 0, NULL, 0);
PrtError("解除网络限制:发送终止指令", GetLastError());
CloseHandle(hNetFilter);
} else PrtError("解除网络限制:打开网络驱动", GetLastError());
//杀掉网关服务及其守护进程
bool bStateM = KillProcess(GetProcessIDFromName("MasterHelper.exe"),KILL_DEFAULT);
bool bStateG = KillProcess(GetProcessIDFromName("GATESRV.exe"),KILL_DEFAULT);
std::string text = "解除网络限制:停止相关进程";
Println(text + ((bStateM && bStateG) ? "成功" : "失败"));
//停止网络过滤驱动
SC_HANDLE sc = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT);
SC_HANDLE hFilt = OpenService(sc, "TDNetFilter", SERVICE_STOP | DELETE);
SERVICE_STATUS ss = {};
bStateM = ControlService(hFilt, SERVICE_CONTROL_STOP, &ss);
DeleteService(hFilt);
CloseServiceHandle(sc);
CloseServiceHandle(hFilt);
text = "解除网络限制:停止限网驱动";
Println(text + (bStateM ? "成功" : "失败"));
SetWindowText(TxOut, "设置完成");
break;
}
case 1009: {
HHOOK hCBTHook = SetWindowsHookEx(WH_CBT, CBTProc, NULL, GetCurrentThreadId());
int id = MessageBox(hwnd, "请选择关闭USB锁的模式!\n软解禁:向过滤端口发送停止请求\n硬解禁:直接删除过滤驱动,软解禁方案无效时使用!", "USB Setting", MB_YESNOCANCEL | MB_ICONQUESTION | MB_SETFOREGROUND);
UnhookWindowsHookEx(hCBTHook);
if (id == IDYES) {//LibTDUsbHook10.dll
//连接过滤端口(TDUsbFilterInit)
HANDLE hPort = NULL;
HRESULT hResult = FilterConnectCommunicationPort(L"\\TDFileFilterPort", 0, NULL, 0, NULL, &hPort);
if(hResult || hPort <= (HANDLE)0 || GetLastError()){
error = hResult & 0x0000FFFF;
SetWindowText(TxOut, "设置失败");
break;
}
//发送消息(TDUsbFiltFree)
int lpInBuffer[4] = {8, 0, 0, 0}; // [esp+0h] [ebp-10h] BYREF
//memset(&lpInBuffer[1], 0, 12);
//lpInBuffer[0] = 8;
hResult = FilterSendMessage(hPort, lpInBuffer, 16/*0x10u*/, NULL, 0, NULL);
ge;
//关闭句柄(TDUsbFilterDone)
CloseHandle(hPort);
SetWindowText(TxOut, !hResult ? "设置完成" : "设置失败");
} else if (id == IDNO) {
SC_HANDLE sc = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT);
SC_HANDLE hFilt = OpenService(sc, "TDFileFilter", SERVICE_STOP | DELETE);
SERVICE_STATUS ss = {};
if(ControlService(hFilt, SERVICE_CONTROL_STOP, &ss))
SetWindowText(TxOut, "设置成功");
else{
ge;
SetWindowText(TxOut, "设置失败");
}
DeleteService(hFilt);
CloseServiceHandle(sc);
CloseServiceHandle(hFilt);
}
break;
}
case 1010: {
HWND hwnd = FindWindow("Shell_TrayWnd", NULL);//有这个类名的窗口一定隶属于explorer.exe
DWORD pid;
GetWindowThreadProcessId(hwnd, &pid);//反查出窗口PID
if (pid == 0 || hwnd == NULL) { //资源管理器没在运行
WinExec("explorer.exe", SW_SHOW);//先直接运行,系统检测到explorer.exe是系统权限会自动重启它以降权(否则权限被继承,出现奇妙问题)
break;
//pid = GetProcessIDFromName("explorer.exe");
}
HANDLE handle = OpenProcess(PROCESS_TERMINATE, FALSE, pid);
if (TerminateProcess(handle, 2))//退出码为2
SetWindowText(TxOut, "执行成功");
else {
ge;
SetWindowText(TxOut, "执行失败");
}
CloseHandle(handle);
break;
}
case 1013: {
char version[6] = {};//考虑极端值如6.9.5
HKEY retKey;
LONG ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\WOW6432Node\\ZM软件工作室\\学生机房管理助手", 0, KEY_QUERY_VALUE | KEY_WOW64_32KEY, &retKey);
DWORD size = sizeof(version);
RegQueryValueEx(retKey, "Version", NULL, NULL, (LPBYTE)&version, &size);
RegCloseKey(retKey);
if (ret != ERROR_SUCCESS) {
ge;
SetWindowText(TxOut, "执行失败,可能未安装学生机房管理助手");
break;
}
std::string sLog = "机房助手版本:";
sLog += version;
sLog += "\nprozs.exe进程名:";
//取时间用于计算prozs.exe的随机进程名
SYSTEMTIME time;
GetLocalTime(&time);
int n3 = time.wMonth + time.wDay;
int n4, n5, n6;
DWORD prozsPid;
if (version[0] == '9' && version[2] >= '0'){
//以下为9.x版本逻辑(目前可验证版本:9.95)
//新版使用固定算法,但是依然可以确定在[107, 118]范围内
char name[10] = {};
VBMath.Randomize(double(time.wMonth * time.wDay));
long long n = round(double(VBMath.Rnd()) * 300000.f + 1.f);
for(int i = 4; i >= 0; i--){
name[i] = char(n % 10L + 107L);
n /= 10L;
}
prozsPid = GetProcessIDFromName(strcat(name, ".exe"));
if (!prozsPid){
PROCESSENTRY32 pe;
pe.dwSize = sizeof(PROCESSENTRY32);
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (Process32First(hSnapshot, &pe)) {
do {
//筛选长度为大于等于4(9.x)的进程名(不包含末尾“.exe”)
size_t uImageLength = strlen(pe.szExeFile);
if (uImageLength >= 8) {
for (char* n7 = pe.szExeFile; *n7 != '.'; n7++) {
//f-o之间
if (!(*n7 >= 102 && *n7 <= 111))goto IL_13A;
}
sLog += pe.szExeFile;
prozsPid = pe.th32ProcessID;
break;
}
IL_13A:;
} while (Process32Next(hSnapshot, &pe));
}
CloseHandle(hSnapshot);
} else sLog += name;
} else if (version[0] == '7' &&version[2] >= '5') {
//以下为7.5、7.8版本逻辑
PROCESSENTRY32 pe;
pe.dwSize = sizeof(PROCESSENTRY32);
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (Process32First(hSnapshot, &pe)) {
do {
//筛选长度为10(7.5)或大于等于4(7.8)的进程名(不包含末尾“.exe”)
size_t uImageLength = strlen(pe.szExeFile);
if ((version[2] == '5')?(uImageLength == 14):(uImageLength >= 8)) {
//遍历字符
for (char* n7 = pe.szExeFile; *n7 != '.'; n7++) {
//符不符合d-m之间
if (!(*n7 >= 100 && *n7 <= 109))goto IL_226;
}
//就是你!
sLog += pe.szExeFile;
prozsPid = pe.th32ProcessID;
break;
}
IL_226:;
} while (Process32Next(hSnapshot, &pe));
}
CloseHandle(hSnapshot);
} else if (version[0] == '7' && version[2] == '4') {
//以下为7.4版本逻辑
char c1, c2, c3, c4;
n3 = time.wMonth * time.wDay, n4 = n3 % 7, n5 = n3 % 5, n6 = n3 % 3;
int n = n3 % 9;
if (n3 % 2 == 0)
c1 = 108 + n4, c2 = 75 + n, c3 = 98 + n5, c4 = 65 + n6;
else
c1 = 98 + n, c2 = 65 + n4, c3 = 108 + n5, c4 = 75 + n6;
char c[5] = {c1, c2, c3, c4, '\0'};
sLog += c;
prozsPid = GetProcessIDFromName(strcat(c, ".exe"));
} else if (version[0] == '7' && version[2] == '2') {
char c1, c2, c3, c4;
//以下为7.2版本逻辑
n4 = n3 % 7, n5 = n3 % 9, n6 = n3 % 5;
if (n3 % 2 != 0)
c1 = 103 + n5, c2 = 111 + n4, c3 = 107 + n6, c4 = 48 + n4;
else
c1 = 97 + n4, c2 = 109 + n5, c3 = 101 + n6, c4 = 48 + n5;
char c[5] = {c1, c2, c3, c4, '\0'};
sLog += c;
prozsPid = GetProcessIDFromName(strcat(c, ".exe"));
} else {
//以下为7.2版本之前的逻辑
n4 = n3 % 3 + 3, n5 = n3 % 4 + 4;
char c[10] = {'p'};
if (n3 % 2 != 0)
c[1] = n5 + 102, c[2] = n4 + 98;
else
c[1] = n4 + 99, c[2] = n5 + 106;
sLog += c;
sLog += "(使用7.2前的逻辑)";
prozsPid = GetProcessIDFromName(strcat(c, ".exe"));
}
Println(sLog);
KillProcess(prozsPid, KILL_DEFAULT);
KillProcess(GetProcessIDFromName("prozs.exe"), KILL_DEFAULT);
KillProcess(GetProcessIDFromName("przs.exe"), KILL_DEFAULT); //新版prozs的名字
KillProcess(GetProcessIDFromName("jfglzs.exe"), KILL_DEFAULT);
//停止zmserv服务防止关机
SC_HANDLE sc = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT);
SC_HANDLE zm = OpenService(sc, "zmserv", SERVICE_STOP);
SERVICE_STATUS ss = {};
ControlService(zm, SERVICE_CONTROL_STOP, &ss);
CloseServiceHandle(sc);
CloseServiceHandle(zm);
KillProcess(GetProcessIDFromName("zmserv.exe"), KILL_DEFAULT);
SetWindowText(TxOut, "执行成功");
break;
}
case 1011: {
LRESULT check = SendMessage(BtSnp, BM_GETCHECK, 0, 0);
if (check == BST_CHECKED)
SetWindowDisplayAffinity(hwnd, WDA_EXCLUDEFROMCAPTURE);
else
SetWindowDisplayAffinity(hwnd, WDA_NONE);
break;
}
case 1012: {
LRESULT check = SendMessage(BtWnd, BM_GETCHECK, 0, 0);
ask = check == BST_CHECKED;
break;
}
case 1014: {
//找到工具条
HWND menuBar = FindWindowEx(hBdCst, NULL, "AfxWnd80u", NULL);
/*//显示工具条
ShowWindow(menuBar, SW_SHOWDEFAULT);
SetWindowPos(menuBar, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
//隐藏工具条
ShowWindow(menuBar, SW_NORMAL);
SetWindowPos(menuBar, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);*/
//解禁全屏按钮
//EnableWindow(GetDlgItem(menuBar, 1004),FALSE);
//模拟点击
LONG lStyle = GetWindowLong(hBdCst, GWL_STYLE);
BOOL bWindowing = lStyle & (WS_CAPTION | WS_SIZEBOX);
PostMessage(hBdCst, WM_COMMAND, MAKEWPARAM(1004, BM_CLICK), 0);
SetWindowText(TxOut, bWindowing ? "全屏化完成" : "窗口化完成");
SendMessage(hwnd, WM_TIMER, WPARAM(2), 0);
break;
}
case 1015: {
if (MessageBox(hwnd, "你是否要将学生机房管理助手的密码设成12345678?仅7.1-9.9版本有效,该操作不可逆!!(高版本的机房助手可能会蓝屏,慎重)", "警告", MB_YESNO | MB_ICONWARNING) == IDYES) {
std::string c = "8a29cc29f5951530ac69f4";
HKEY retKey;
LONG ret = RegOpenKeyEx(HKEY_CURRENT_USER, "Software", 0, KEY_SET_VALUE, &retKey);
if (ret != ERROR_SUCCESS) {
ge;
SetWindowText(TxOut, "设置失败");
RegCloseKey(retKey);
break;
}
ret = RegSetValueEx(retKey, "n", 0, REG_SZ, (CONST BYTE*)c.c_str(), c.size() + 1);
SetWindowText(TxOut, "设置成功");
RegCloseKey(retKey);
}
break;
}
case 1016: {
LRESULT check = SendMessage(BtTop, BM_GETCHECK, 0, 0);
if (check == BST_CHECKED) {
ResumeThread(thread);
} else {
SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
SuspendThread(thread);
}
break;
}
case 1017: {
LRESULT check = SendMessage(BtCur, BM_GETCHECK, 0, 0);
if (check == BST_CHECKED) {
ResumeThread(mouHook);
} else {
SuspendThread(mouHook);
UnhookWindowsHookEx(mseHook);
}
break;
}
case 1018: {
LRESULT check = SendMessage(BtKbh, BM_GETCHECK, 0, 0);
if (check == BST_CHECKED) {
ResumeThread(keyHook);
//打开符号链接
HANDLE hDevice = CreateFile("\\\\.\\TDKeybd", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
if (GetLastError()) {
PrtError(GetLastError() == ERROR_FILE_NOT_FOUND ? "解驱动键盘锁:驱动未安装" : "解驱动键盘锁:设置失败", GetLastError());
break;
}
BOOL bEnable = TRUE;
//发送控制代码
if (DeviceIoControl(hDevice, 0x220000, &bEnable, 4, NULL, 0, NULL, NULL))
Print("解驱动键盘锁:设置成功");
else
PrtError("解驱动键盘锁:设置失败",GetLastError());
CloseHandle(hDevice);
} else {
SuspendThread(keyHook);
UnhookWindowsHookEx(kbdHook);
}
break;
}
case 1019: {
//判断是否已在运行
DWORD dwPID = GetProcessIDFromName("MeltdownDFC.exe");
if(dwPID) break;
//取缓存路径,创建文件
char szTempPath[MAX_PATH];
GetTempPath(MAX_PATH, szTempPath);
HANDLE hFile = CreateFile(strcat(szTempPath, "\\MeltdownDFC.exe"), GENERIC_ALL, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_TEMPORARY, NULL);
if(hFile != INVALID_HANDLE_VALUE){
//获取资源信息
HRSRC hResInfo = FindResource(NULL, MAKEINTRESOURCE(2), RT_RCDATA);
HGLOBAL hResData = LoadResource(NULL, hResInfo);
DWORD dwSize = SizeofResource(NULL, hResInfo);
LPVOID pData = LockResource(hResData);
if(pData){
//写入文件
if(!WriteFile(hFile, pData, dwSize + 1, NULL, NULL)){
SetWindowText(TxOut, "写入失败");
CloseHandle(hFile);
break;
}
FlushFileBuffers(hFile);
CloseHandle(hFile);
//执行程序
if(WinExec(szTempPath, SW_SHOW) < 32)
SetWindowText(TxOut, "启动失败");
else SetWindowText(TxOut, "启动完成");
} else SetWindowText(TxOut, "写入失败");
} else SetWindowText(TxOut, "启动失败");
break;
}
case 1020: {
//同上
DWORD dwPID = GetProcessIDFromName("crdisk.exe");
if(dwPID) break;
char szTempPath[MAX_PATH];
GetTempPath(MAX_PATH, szTempPath);
HANDLE hFile = CreateFile(strcat(szTempPath, "\\crdisk.exe"), GENERIC_ALL, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_TEMPORARY, NULL);
if(hFile != INVALID_HANDLE_VALUE){
HRSRC hResInfo = FindResource(NULL, MAKEINTRESOURCE(3), RT_RCDATA);
HGLOBAL hResData = LoadResource(NULL, hResInfo);
DWORD dwSize = SizeofResource(NULL, hResInfo);
LPVOID pData = LockResource(hResData);
if(pData){
if(!WriteFile(hFile, pData, dwSize + 1, NULL, NULL)){
SetWindowText(TxOut, "写入失败");
CloseHandle(hFile);
break;
}
FlushFileBuffers(hFile);
CloseHandle(hFile);
if(WinExec(szTempPath, SW_SHOW) < 32)
SetWindowText(TxOut, "启动失败");
else SetWindowText(TxOut, "启动完成");
} else SetWindowText(TxOut, "写入失败");
} else SetWindowText(TxOut, "启动失败");
break;
}
}
return 0;
}
case WM_HOTKEY:
switch (wParam) {
case 0://Alt+C
if (closingProcess) { //第二次
closingProcess = false;
KillTimer(hwnd, 3);
HWND topHwnd = GetForegroundWindow();
DWORD pid;
GetWindowThreadProcessId(topHwnd, &pid);
if(pid != GetCurrentProcessId())//避免焦点在当前程序时,关闭自己
KillProcess(pid, KILL_FORCE);
} else { //第一次
closingProcess = true;
SetTimer(hwnd, 3, GetDoubleClickTime(), NULL); //默认应该是500ms
}
break;
case 1: { //Alt+W
HWND topHwnd = GetForegroundWindow();
if(!IsHungAppWindow(topHwnd))//应用程序无响应时不作处理。防止使自己堵塞,导致无响应。
ShowWindow(topHwnd, SW_MINIMIZE);
break;
}
case 2://Alt+B
ShowWindow(hwnd, SW_SHOWNORMAL);
SetForegroundWindow(hwnd);
}
return 0;
case WM_TIMER:
switch (wParam) {
case 1:
if (!asking && ask) {
//检测鼠标左上角事件
GetCursorPos(&p);
if (p.x == 0 && p.y == 0) {
asking = true;
HWND topHwnd = GetForegroundWindow();
if (MessageBox(hwnd, "检测到了鼠标位置变化!是否最小化焦点窗口?", "实时监测", MB_YESNO | MB_ICONINFORMATION | MB_SETFOREGROUND | MB_TOPMOST) == IDYES) {
if(!IsHungAppWindow(topHwnd))//同上
ShowWindow(topHwnd, SW_MINIMIZE);
}
asking = false;
} else if (p.x == w && p.y == 0) {
asking = true;
HWND topHwnd = GetForegroundWindow();
HHOOK hCBTHook = SetWindowsHookEx(WH_CBT, CBTProc, NULL, GetCurrentThreadId());
int id = MessageBox(hwnd, "检测到了鼠标位置变化!是否关闭焦点窗口?", "实时监测", MB_YESNOCANCEL | MB_ICONINFORMATION | MB_SETFOREGROUND | MB_TOPMOST);
UnhookWindowsHookEx(hCBTHook);
if (id == IDYES) {
PostMessage(topHwnd, WM_CLOSE, 0, 0); //异步
} else if (id == IDNO) {
//创建一个透明零大小的父窗口
HWND hParent = CreateWindowEx(0, WC_STATIC, "", 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
//将目标窗口设为子窗口
SetParent(topHwnd, hParent);
ge;
//关闭父窗口,子窗口也将一并销毁
PostMessage(hParent, WM_CLOSE, 0, 0);
}
asking = false;
}
break;
}
case 2: {
SetWindowText(hwnd, RandomWindowTitle());
DWORD id = GetProcessIDFromName(MythwareFilename);
if (id == 0) {
SendMessage(TxOut, SB_SETTEXT, 1, LPARAM("极域未运行"));
mwSts = 2;
SetWindowText(BtKmw, "启动极域");
} else {
//判断广播状态,顺便判断极域是否无响应
MW_INFO info = {}; info.pid = id;
BOOL bWindowing = FALSE;
EnumWindows(EnumWindowsProc, LPARAM(&info));
hBdCst = info.hwndOfBoardcast;
if (hBdCst) {
LONG lStyle = GetWindowLong(hBdCst, GWL_STYLE);
if (lStyle & WS_SYSMENU)bWindowing = TRUE;
}
EnableWindow(GetDlgItem(hwnd, 1014), hBdCst ? TRUE : FALSE);
SetDlgItemText(hwnd, 1014, bWindowing ? "广播全屏化" : "广播窗口化");
//极域状态
mwSts = GetProcessState(id);
std::string show;
if (mwSts == -1)show = "极域状态未知";
else if (mwSts == 0 && !info.bNotResponding)show = "极域运行中";
else if (mwSts == 0 && info.bNotResponding)show = "极域无响应";
else if (mwSts == 1)show = "极域已挂起";
sprintf(show.data(), "%s[PID:%d]", show.c_str(), int(id));
SendMessage(TxOut, SB_SETTEXT, 1, LPARAM(show.c_str()));
SetWindowText(BtKmw, "杀掉极域");
}
break;
}
case 3: {
closingProcess = false;
KillTimer(hwnd, 3);//立刻解除
}
}
break;
case WM_DESTROY:
UnregisterHotKey(hwnd, 0);
UnregisterHotKey(hwnd, 1);
UnregisterHotKey(hwnd, 2);
CloseHandle(thread);
CloseHandle(keyHook);
CloseHandle(mouHook);
Shell_NotifyIcon(NIM_DELETE, &icon); //删除托盘图标,否则只有鼠标划过图标才消失
UnhookWindowsHookEx(mseHook);
UnhookWindowsHookEx(kbdHook);
PostQuitMessage(0);
break;
case WM_ACTIVATE: { // TODO: 目前可观测到的崩溃问题来自此处,可能存在内存访问隐患,需要排查
if (LOWORD(wParam) == WA_INACTIVE) {
if (GetWindowLong(hwnd, GWL_STYLE) & WS_VISIBLE) {
focus = GetFocus();
char c[7] = {};
if (GetClassName(focus, c, 7) && _stricmp(c, "Button") == 0) {
LONG style = GetWindowLong(focus, GWL_STYLE);
if ((style & BS_AUTOCHECKBOX) != BS_AUTOCHECKBOX)
SendMessage(focus, BM_SETSTYLE, 0, TRUE);
}
}
} else {
SetFocus(focus);
char c[7] = {};
if (GetClassName(focus, c, 7) && _stricmp(c, "Button") == 0) {
LONG style = GetWindowLong(focus, GWL_STYLE);
if ((style & BS_AUTOCHECKBOX) != BS_AUTOCHECKBOX)
SendMessage(focus, BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE);
}
}
return FALSE;
}
case WM_USER + 3:
if (lParam == WM_LBUTTONDBLCLK) { //左键双击
ShowWindow(hwnd, SW_SHOWNORMAL);
SetForegroundWindow(hwnd);
} else if (lParam == WM_RBUTTONUP) { //右键单击
GetCursorPos(&pt);
SetForegroundWindow(hwnd);
HMENU hMenu = CreatePopupMenu();//托盘菜单
AppendMenu(hMenu, MF_STRING, 1, "关闭程序");
AppendMenu(hMenu, MF_STRING, 2, "打开界面");
int i = TrackPopupMenu(hMenu, TPM_RETURNCMD, pt.x, pt.y, 0, hwnd, NULL);
switch (i) {
case 1:
//TODO
PostMessage(hwnd, WM_CLOSE, 0, 0);
break;
case 2:
ShowWindow(hwnd, SW_SHOWNORMAL);
SetForegroundWindow(hwnd);
break;
}
}
return FALSE;
case WM_NOTIFY:
switch (((LPNMHDR)lParam)->code) {
case BCN_DROPDOWN: {
NMBCDROPDOWN* pDropDown = (NMBCDROPDOWN*)lParam;
if (pDropDown->hdr.hwndFrom == BtKmw) {
// Get screen coordinates of the button.
POINT pt;
pt.x = pDropDown->rcButton.left;
pt.y = pDropDown->rcButton.bottom;
ClientToScreen(pDropDown->hdr.hwndFrom, &pt);
// Create a menu and add items.
HMENU hSplitMenu = CreatePopupMenu();
LPCSTR show;
if (mwSts != 1)show = "挂起极域";
else if (mwSts == 1)show = "恢复极域";
AppendMenu(hSplitMenu, MF_BYPOSITION, 1, show);
EnableMenuItem(hSplitMenu, 1, mwSts != 2 ? MF_ENABLED : MF_GRAYED);
// Display the menu.
SuspendThread(thread);
int i = TrackPopupMenu(hSplitMenu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RETURNCMD, pt.x, pt.y, 0, hwnd, NULL);
ResumeThread(thread);
switch (i) {
case 1: {
BOOL sts = SuspendProcess(GetProcessIDFromName(MythwareFilename), !mwSts);
if (sts)SetWindowText(TxOut, "挂起/恢复成功");
else SetWindowText(TxOut, "挂起/恢复失败");
SendMessage(hwnd, WM_TIMER, WPARAM(2), 0);
break;
}
}
return TRUE;
}
break;
}
case NM_CLICK:
if (((LPNMHDR)lParam)->hwndFrom == TxOut) {
focus = GetFocus();
char c[7];
GetClassName(focus, c, 7);
if (_stricmp(c, "Button") == 0) {
LONG style = GetWindowLong(focus, GWL_STYLE);
if ((style & BS_AUTOCHECKBOX) != BS_AUTOCHECKBOX)
SendMessage(focus, BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE);
}
break;//避免点击输出栏发生异常
}
case NM_RETURN: {
PNMLINK pNMLink = (PNMLINK)lParam;
LITEM item = pNMLink->item;
if ((((LPNMHDR)lParam)->hwndFrom == TxLnk) && (item.iLink == 0))
ShellExecuteW(NULL, L"open", item.szUrl, NULL, NULL, SW_SHOW);
break;
}
}
break;
case WM_LBUTTONDOWN:
//实现空白处随意拖动
SendMessage(hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0);
break;
case WM_SYSCOMMAND:
switch (wParam) {
case 2: {
if (error == -1)error = GetLastError();
LPSTR szError = NULL;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
NULL, error, 0, (PTSTR)&szError, 0, NULL);
char s[BUFSIZ] = {};
sprintf(s, "GetLastError上一个错误:\n%u:%s", error, szError);
LocalFree(HLOCAL(szError));
MessageBox(hwnd, s, "上一个错误", MB_OK | MB_ICONINFORMATION);
error = -1;
break;
}
case 3: {//启动任务管理器,win10版本可以置顶
//判断有没有启动
HWND h = FindWindow("TaskManagerWindow", NULL);
BYTE nCount = 0;
if (!h) {
//如果还没有就先启动
WinExec("taskmgr", SW_SHOW);
ge;
do {
//最多等待3秒,否则停止搜寻,防止无响应(5秒)
if (++nCount == 60) {
SetWindowText(TxOut, "启动失败");
return FALSE;
}
//等待窗口创建完成
Sleep(50);
h = FindWindow("TaskManagerWindow", NULL);
} while (!h);
}
//获取菜单,取得勾选状态
HMENU hm = GetMenu(h);
MENUITEMINFO mii = {sizeof(MENUITEMINFO), MIIM_STATE};
GetMenuItemInfo(hm, 0x7704, FALSE, &mii);
//如果未勾选就模拟勾选
if (!(mii.fState & MFS_CHECKED))
PostMessage(h, WM_COMMAND, 0x7704, 0);
SetWindowText(TxOut, "启动完成");