|
7 | 7 |
|
8 | 8 | constexpr const char* DRIVER_SERVICE_NAME = "debugviewdriver";
|
9 | 9 | constexpr const char* DRIVER_DISPLAY_NAME = "DbgView Kernel Message Driver";
|
10 |
| -const std::string driverPath = "dbgv.sys"; |
| 10 | +const std::string driverPath = "C:\\Windows\\System32\\drivers\\dbgvpp.sys"; |
| 11 | + |
| 12 | +bool FileExists(const std::string& path) { |
| 13 | + DWORD fileAttributes = GetFileAttributesA(path.c_str()); |
| 14 | + return (fileAttributes != INVALID_FILE_ATTRIBUTES && |
| 15 | + !(fileAttributes & FILE_ATTRIBUTE_DIRECTORY)); |
| 16 | +} |
| 17 | + |
| 18 | +bool StartDriverSvc() |
| 19 | +{ |
| 20 | + SC_HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); |
| 21 | + if (!hSCManager) return false; |
| 22 | + |
| 23 | + SC_HANDLE hService = OpenServiceA(hSCManager, DRIVER_SERVICE_NAME, SERVICE_START); |
| 24 | + if (!hService) { |
| 25 | + CloseServiceHandle(hSCManager); |
| 26 | + return false; |
| 27 | + } |
| 28 | + |
| 29 | + if (!StartService(hService, 0, NULL)) { |
| 30 | + if (GetLastError() == ERROR_SERVICE_ALREADY_RUNNING) { |
| 31 | + std::cout << "Service is already running.\n"; |
| 32 | + CloseServiceHandle(hService); |
| 33 | + CloseServiceHandle(hSCManager); |
| 34 | + return true; |
| 35 | + } |
| 36 | + std::cout << "Failed to start service. Error: " << GetLastError() << std::endl; |
| 37 | + CloseServiceHandle(hService); |
| 38 | + CloseServiceHandle(hSCManager); |
| 39 | + return false; |
| 40 | + } |
| 41 | + |
| 42 | + CloseServiceHandle(hService); |
| 43 | + CloseServiceHandle(hSCManager); |
| 44 | + return true; |
| 45 | +} |
| 46 | + |
| 47 | +bool StopDriverSvc() |
| 48 | +{ |
| 49 | + SC_HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); |
| 50 | + if (!hSCManager) return false; |
| 51 | + |
| 52 | + SC_HANDLE hService = OpenServiceA(hSCManager, DRIVER_SERVICE_NAME, SERVICE_STOP); |
| 53 | + if (!hService) { |
| 54 | + CloseServiceHandle(hSCManager); |
| 55 | + return false; |
| 56 | + } |
| 57 | + |
| 58 | + SERVICE_STATUS status; |
| 59 | + if (!ControlService(hService, SERVICE_CONTROL_STOP, &status)) { |
| 60 | + DWORD err = GetLastError(); |
| 61 | + if (err != ERROR_SERVICE_NOT_ACTIVE) { |
| 62 | + std::cout << "Failed to stop service. Error: " << err << std::endl; |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + CloseServiceHandle(hService); |
| 67 | + CloseServiceHandle(hSCManager); |
| 68 | + return true; |
| 69 | +} |
11 | 70 |
|
12 | 71 | void InstallKernelMessagesDriver()
|
13 | 72 | {
|
14 | 73 | // try to uninstall first, in case the driver is somehow still loaded.
|
15 | 74 | UninstallKernelMessagesDriver();
|
16 | 75 |
|
| 76 | + if (!FileExists(driverPath)) { |
| 77 | + std::cout << "Driver file not found at: " << driverPath << std::endl; |
| 78 | + } |
| 79 | + |
17 | 80 | SC_HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
|
18 | 81 | if (!hSCManager) {
|
19 | 82 | std::cout << "Failed to open Service Control Manager. Error: " << GetLastError() << std::endl;
|
@@ -41,10 +104,14 @@ void InstallKernelMessagesDriver()
|
41 | 104 | }
|
42 | 105 | CloseServiceHandle(hService);
|
43 | 106 | CloseServiceHandle(hSCManager);
|
| 107 | + |
| 108 | + StartDriverSvc(); |
44 | 109 | }
|
45 | 110 |
|
46 | 111 | void UninstallKernelMessagesDriver()
|
47 | 112 | {
|
| 113 | + StopDriverSvc(); |
| 114 | + |
48 | 115 | SC_HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
|
49 | 116 | if (!hSCManager)
|
50 | 117 | {
|
|
0 commit comments