1 /* 2 * PROJECT: ReactOS Task Manager 3 * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later) 4 * PURPOSE: Process Debugging 5 * COPYRIGHT: Copyright 1999-2001 Brian Palmer <brianp@reactos.org> 6 * Copyright 2005 Klemens Friedl <frik85@reactos.at> 7 */ 8 9 #include "precomp.h" 10 11 void ProcessPage_OnDebug(void) 12 { 13 DWORD dwProcessId; 14 WCHAR strErrorText[260]; 15 HKEY hKey; 16 WCHAR strDebugPath[260]; 17 WCHAR strDebugger[260]; 18 DWORD dwDebuggerSize; 19 PROCESS_INFORMATION pi; 20 STARTUPINFOW si; 21 HANDLE hDebugEvent; 22 WCHAR szTemp[256]; 23 WCHAR szTempA[256]; 24 25 dwProcessId = GetSelectedProcessId(); 26 27 if (dwProcessId == 0) 28 return; 29 30 LoadStringW(hInst, IDS_MSG_WARNINGDEBUG, szTemp, _countof(szTemp)); 31 LoadStringW(hInst, IDS_MSG_TASKMGRWARNING, szTempA, _countof(szTempA)); 32 33 if (!ConfirmMessageBox(hMainWnd, szTemp, szTempA, MB_YESNO | MB_ICONWARNING)) 34 { 35 GetLastErrorText(strErrorText, _countof(strErrorText)); 36 LoadStringW(hInst, IDS_MSG_UNABLEDEBUGPROCESS, szTemp, _countof(szTemp)); 37 MessageBoxW(hMainWnd, strErrorText, szTemp, MB_OK | MB_ICONSTOP); 38 return; 39 } 40 41 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug", 0, KEY_QUERY_VALUE, &hKey) != ERROR_SUCCESS) 42 { 43 GetLastErrorText(strErrorText, _countof(strErrorText)); 44 LoadStringW(hInst, IDS_MSG_UNABLEDEBUGPROCESS, szTemp, _countof(szTemp)); 45 MessageBoxW(hMainWnd, strErrorText, szTemp, MB_OK | MB_ICONSTOP); 46 return; 47 } 48 49 dwDebuggerSize = sizeof(strDebugger); 50 if (RegQueryValueExW(hKey, L"Debugger", NULL, NULL, (LPBYTE)strDebugger, &dwDebuggerSize) != ERROR_SUCCESS) 51 { 52 GetLastErrorText(strErrorText, _countof(strErrorText)); 53 LoadStringW(hInst, IDS_MSG_UNABLEDEBUGPROCESS, szTemp, _countof(szTemp)); 54 MessageBoxW(hMainWnd, strErrorText, szTemp, MB_OK | MB_ICONSTOP); 55 RegCloseKey(hKey); 56 return; 57 } 58 59 RegCloseKey(hKey); 60 61 hDebugEvent = CreateEventW(NULL, FALSE, FALSE, NULL); 62 if (!hDebugEvent) 63 { 64 GetLastErrorText(strErrorText, _countof(strErrorText)); 65 LoadStringW(hInst, IDS_MSG_UNABLEDEBUGPROCESS, szTemp, _countof(szTemp)); 66 MessageBoxW(hMainWnd, strErrorText, szTemp, MB_OK | MB_ICONSTOP); 67 return; 68 } 69 70 wsprintfW(strDebugPath, strDebugger, dwProcessId, hDebugEvent); 71 72 ZeroMemory(&pi, sizeof(pi)); 73 ZeroMemory(&si, sizeof(si)); 74 si.cb = sizeof(si); 75 if (!CreateProcessW(NULL, strDebugPath, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) 76 { 77 GetLastErrorText(strErrorText, _countof(strErrorText)); 78 LoadStringW(hInst, IDS_MSG_UNABLEDEBUGPROCESS, szTemp, _countof(szTemp)); 79 MessageBoxW(hMainWnd, strErrorText, szTemp, MB_OK | MB_ICONSTOP); 80 } 81 else 82 { 83 CloseHandle(pi.hThread); 84 CloseHandle(pi.hProcess); 85 } 86 87 CloseHandle(hDebugEvent); 88 } 89