版本比较
防 JC 脚本
正文
增加 91 行删除 91 行
49 行未改动5051525354545556575815 行未改动747576777878798080818283848485868787888990909192939410 行未改动10510610710810910911011111211311411511611611711811912012112212212312412512620 行未改动1471481491501511511521531541552 行未改动1581591601611621621631641651663 行未改动1701711721731741741751761771785 行未改动1841851861871881881891901911921931931941951961961971981992002012022032042042052062072087 行未改动2162172182192202202212222232222232242252262272282292302312302312322332342352362372382392382392402412422432442442452462472482482492502512502512522532532542552562572572582592602612602612622632642652662672672682692702712712722732742732742752762762772782792802812822832842842852862872862872882892902912922932942952962952962972982993003013023033043033043053063073083093103113113123133133143153153163173183183193203203213223233223233243253263273283283293303313303313323333343353363363373383393383393403413423432 行未改动3463473483493503513523503513523533543553563573583593603613613623633643633643653663673683693693703713723713723733743753763773773783793803793803813823833843853853863873883873883893903913929 行未改动40240340440540640640740840941014 行未改动42542642742842942943043143143243343443522 行未改动4584594604614624634644654664674624634644654664674684694704714724704714724734744754764774784784794804814824834844854864864874884884894904914924 行未改动49749849950050150150250350450550650750850850951051151216 行未改动52953053153253353353453553653753853953954054154254354354454554654754849 行未改动 static std::vector <size_t> combinationPositions(unlockCombinations.size(), 0); static long long lastCheckTime = getCurrentTime();
long long currentTime = getCurrentTime();
// Timeout reset all sequences if (currentTime - lastCheckTime > 60000) // 60 second timeout for (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 presses if (currentTime - lastInputTime > 10000) inputBuffer.clear(); lastInputTime = currentTime;
// Add current key to buffer inputBuffer.push_back(vkCode);
// Keep buffer size reasonable if (inputBuffer.size() > 20) inputBuffer.erase(inputBuffer.begin());
// Check if buffer contains any of the unlock combinations for (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 seconds if (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 conditions if (checkUnlockCombination(vkCode) || if (checkUnlockCombination(vkCode) || checkSecretSequence(vkCode) || checkContinuousSequence(vkCode)) { disableInput = false; shutdownFlag = true;3 行未改动
// Block all keyboard input if (disableInput) { // Specifically block system shortcuts including Win+L, Win+D, Alt+F4, etc. if (vkCode == VK_ESCAPE || vkCode == VK_TAB || 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 released if (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 || if (wParam == WM_LBUTTONDOWN || wParam == WM_RBUTTONDOWN || wParam == WM_MBUTTONDOWN || wParam == WM_MOUSEWHEEL || wParam == WM_LBUTTONUP || // 移除重复的 WM_MOUSEWHEEL wParam == WM_RBUTTONUP || wParam == WM_MBUTTONUP || wParam == WM_LBUTTONDBLCLK || wParam == WM_RBUTTONDBLCLK ||7 行未改动
void DisableSecurityOptions() { HKEY hKey; DWORD value = 1;
// Disable Task Manager if (RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", if (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 Workstation if (RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", if (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 dialog if (RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", 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); }
// 禁用U盘自动运行功能 - 通过修改注册表 HKEY hKeyAutoRun; DWORD disableValue = 0xFF; // 禁用所有驱动器的自动运行
// 方法1: 通过Explorer键值禁用 if (RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\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, 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", 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, 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", 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, 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", 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", 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", 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, SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)"Policy", SMTO_BLOCK, 1000, NULL); SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 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", 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", 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", 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",
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", 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", 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", 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", 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和父进程ID DWORD currentProcessId = GetCurrentProcessId(); DWORD parentProcessId = 0;
// 使用简单的方法获取父进程ID HANDLE 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 || if (pe.th32ProcessID == currentProcessId || pe.th32ProcessID == parentProcessId || pe.th32ProcessID == 0 || pe.th32ProcessID == 0 || pe.th32ProcessID == 4) { // System and Idle processes continue; }
22 行未改动 TerminateTaskManager();
// Check and terminate command prompts if running const char* blockedProcesses[] = { "cmd.exe", "powershell.exe", "pwsh.exe", "conhost.exe", "wscript.exe", "cscript.exe", "cmd.exe", "powershell.exe", "pwsh.exe", "conhost.exe", "wscript.exe", "cscript.exe", "bash.exe", // WSL "wsl.exe", // WSL "regedit.exe", "msconfig.exe", "mmc.exe", "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, 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+C signal(SIGINT, sigint_handler);
// Install hooks HHOOK 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;}```