@@ -9,25 +9,30 @@ constexpr const char* DRIVER_SERVICE_NAME = "debugviewdriver";
99constexpr const char * DRIVER_DISPLAY_NAME = " DbgView Kernel Message Driver" ;
1010const std::string driverPath = " C:\\ Windows\\ System32\\ drivers\\ dbgvpp.sys" ;
1111
12- bool FileExists (const std::string& path) {
12+ bool FileExists (const std::string& path)
13+ {
1314 DWORD fileAttributes = GetFileAttributesA (path.c_str ());
1415 return (fileAttributes != INVALID_FILE_ATTRIBUTES &&
15- !(fileAttributes & FILE_ATTRIBUTE_DIRECTORY));
16+ !(fileAttributes & FILE_ATTRIBUTE_DIRECTORY));
1617}
1718
1819bool StartDriverSvc ()
1920{
2021 SC_HANDLE hSCManager = OpenSCManager (NULL , NULL , SC_MANAGER_ALL_ACCESS);
21- if (!hSCManager) return false ;
22+ if (!hSCManager)
23+ return false ;
2224
2325 SC_HANDLE hService = OpenServiceA (hSCManager, DRIVER_SERVICE_NAME, SERVICE_START);
24- if (!hService) {
26+ if (!hService)
27+ {
2528 CloseServiceHandle (hSCManager);
2629 return false ;
2730 }
2831
29- if (!StartService (hService, 0 , NULL )) {
30- if (GetLastError () == ERROR_SERVICE_ALREADY_RUNNING) {
32+ if (!StartService (hService, 0 , NULL ))
33+ {
34+ if (GetLastError () == ERROR_SERVICE_ALREADY_RUNNING)
35+ {
3136 std::cout << " Service is already running.\n " ;
3237 CloseServiceHandle (hService);
3338 CloseServiceHandle (hSCManager);
@@ -47,18 +52,22 @@ bool StartDriverSvc()
4752bool StopDriverSvc ()
4853{
4954 SC_HANDLE hSCManager = OpenSCManager (NULL , NULL , SC_MANAGER_ALL_ACCESS);
50- if (!hSCManager) return false ;
55+ if (!hSCManager)
56+ return false ;
5157
5258 SC_HANDLE hService = OpenServiceA (hSCManager, DRIVER_SERVICE_NAME, SERVICE_STOP);
53- if (!hService) {
59+ if (!hService)
60+ {
5461 CloseServiceHandle (hSCManager);
5562 return false ;
5663 }
5764
5865 SERVICE_STATUS status;
59- if (!ControlService (hService, SERVICE_CONTROL_STOP, &status)) {
66+ if (!ControlService (hService, SERVICE_CONTROL_STOP, &status))
67+ {
6068 DWORD err = GetLastError ();
61- if (err != ERROR_SERVICE_NOT_ACTIVE) {
69+ if (err != ERROR_SERVICE_NOT_ACTIVE)
70+ {
6271 std::cout << " Failed to stop service. Error: " << err << std::endl;
6372 }
6473 }
@@ -73,12 +82,14 @@ void InstallKernelMessagesDriver(const std::string& driverLocation)
7382 // try to uninstall first, in case the driver is somehow still loaded.
7483 UninstallKernelMessagesDriver ();
7584
76- if (!FileExists (driverPath)) {
85+ if (!FileExists (driverPath))
86+ {
7787 std::cout << " Driver file not found at: " << driverPath << std::endl;
7888 }
7989
8090 SC_HANDLE hSCManager = OpenSCManager (NULL , NULL , SC_MANAGER_ALL_ACCESS);
81- if (!hSCManager) {
91+ if (!hSCManager)
92+ {
8293 std::cout << " Failed to open Service Control Manager. Error: " << GetLastError () << std::endl;
8394 }
8495
@@ -91,11 +102,12 @@ void InstallKernelMessagesDriver(const std::string& driverLocation)
91102 SERVICE_DEMAND_START,
92103 SERVICE_ERROR_NORMAL,
93104 driverLocation.c_str (),
94- NULL , NULL , NULL , NULL , NULL
95- );
105+ NULL , NULL , NULL , NULL , NULL );
96106
97- if (!hService) {
98- if (GetLastError () == ERROR_SERVICE_EXISTS) {
107+ if (!hService)
108+ {
109+ if (GetLastError () == ERROR_SERVICE_EXISTS)
110+ {
99111 std::cout << " Service already exists.\n " ;
100112 CloseServiceHandle (hSCManager);
101113 }
0 commit comments