Skip to content

Commit 8a80229

Browse files
author
Jan Wilmans
committed
moved driver name to GetDebugviewDriverLocation and silently fail if driver can't be deleted
1 parent c433255 commit 8a80229

File tree

10 files changed

+51
-29
lines changed

10 files changed

+51
-29
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ target_link_options(msvc_gui_link_options INTERFACE /SUBSYSTEM:WINDOWS /NOLOGO /
6161
target_link_options(msvc_console_link_options INTERFACE /SUBSYSTEM:CONSOLE /NOLOGO /RELEASE)
6262

6363
# warnings (the project picked up a bunch of unresolved warnings with migrating to new VS versions and when {fmt} was added, work in progress...)
64-
target_compile_options(project_compile_options INTERFACE /W4 /w14242 /w14254 /w14263 /w14265 /w14287 /w14289 /w14296 /w14311 /w14545 /w14546 /w14547 /w14549 /w14555 /w14640 /w14826 /w14905 /w14906 /w14928)
64+
target_compile_options(project_compile_options INTERFACE /W4 /w14242 /w14254 /w14263 /w14265 /w14287 /w14289 /w14296 /w14311 /w14545 /w14546 /w14547 /w14549 /w14555 /w14640 /w14826 /w14905 /w14906 /w14928 /we4715)
6565

6666
add_library(project::definitions ALIAS project_definitions)
6767
add_library(project::compile_features ALIAS project_compile_features)

application/DebugViewpp/DebugView++.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
#include "crashpad.h"
2323
#endif
2424

25-
//#define CONSOLE_DEBUG
26-
2725
CAppModule _Module;
2826

2927
namespace fusion {

application/DebugViewpp/MainFrame.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <filesystem>
88
#include <optional>
99
#include <iostream>
10+
#include <format>
11+
#include <cstdio>
1012

1113
#include <boost/optional.hpp>
1214
#include <boost/algorithm/string.hpp>
@@ -1474,15 +1476,15 @@ void CMainFrame::Resume()
14741476
{
14751477
m_pKernelReader = m_logSources.AddKernelReader();
14761478
}
1477-
catch (std::exception&)
1479+
catch (std::exception& e)
14781480
{
1479-
MessageBox(L"Unable to capture Kernel Messages.\n"
1480-
L"\n"
1481-
L"Make sure you have appropriate permissions.\n"
1482-
L"\n"
1483-
L"You may need to start this application by right-clicking it and selecting\n"
1484-
L"'Run As Administator' even if you have administrator rights.",
1485-
m_applicationName.c_str(), MB_ICONERROR | MB_OK);
1481+
const auto message = std::format("Unable to capture Kernel Messages.\n"
1482+
"({})\n\n"
1483+
"Make sure you have appropriate permissions.\n"
1484+
"\n"
1485+
"You may need to start this application by right-clicking it and selecting\n"
1486+
"'Run As Administator' even if you have administrator rights.", e.what());
1487+
MessageBox(WStr(message), m_applicationName.c_str(), MB_ICONERROR | MB_OK);
14861488
m_tryKernel = false;
14871489
}
14881490
}
@@ -1517,11 +1519,9 @@ void CMainFrame::OnLogGlobal(UINT /*uNotifyCode*/, int /*nID*/, CWindow /*wndCtl
15171519
UpdateTitle();
15181520
}
15191521

1520-
static const auto driver_name = "C:\\Windows\\System32\\drivers\\dbgvpp.sys";
1521-
1522-
void WriteDriverFromResource()
1522+
void CMainFrame::WriteDriverFromResource()
15231523
{
1524-
if (std::filesystem::exists(driver_name))
1524+
if (std::filesystem::exists(m_driverLocation))
15251525
{
15261526
return;
15271527
}
@@ -1535,18 +1535,18 @@ void WriteDriverFromResource()
15351535
void* pLockedRes = LockResource(hLoadedRes);
15361536
if (pLockedRes)
15371537
{
1538-
std::cout << "write to " << driver_name << "\n";
1539-
std::ofstream outFile(driver_name, std::ios::binary);
1538+
std::ofstream outFile(m_driverLocation.c_str(), std::ios::binary);
15401539
outFile.write(static_cast<const char*>(pLockedRes), dwSize);
15411540
outFile.close();
15421541
}
15431542
}
15441543
}
15451544
}
15461545

1547-
void RemoveDriver()
1546+
void CMainFrame::RemoveDriver()
15481547
{
1549-
std::filesystem::remove(driver_name);
1548+
// can fail silently
1549+
std::remove(m_driverLocation.c_str());
15501550
}
15511551

15521552
void CMainFrame::OnLogKernel(UINT /*uNotifyCode*/, int /*nID*/, CWindow /*wndCtl*/)

application/DebugViewpp/MainFrame.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ class CMainFrame : public CTabbedFrameImpl<CMainFrame, CDotNetTabCtrl<SelectedTa
204204
void AddLogSource(const SourceInfo& info);
205205
void CloseView(int i);
206206

207+
void WriteDriverFromResource();
208+
void RemoveDriver();
209+
207210
CCommandBarCtrl m_cmdBar;
208211
CMultiPaneStatusBarCtrl m_statusBar;
209212

@@ -237,6 +240,7 @@ class CMainFrame : public CTabbedFrameImpl<CMainFrame, CDotNetTabCtrl<SelectedTa
237240
Win32::Handle m_httpMonitorHandle;
238241
std::deque<Lines> m_incomingMessages;
239242
int m_showCmd = SW_SHOWDEFAULT;
243+
std::string m_driverLocation = GetDebugviewDriverLocation();
240244
};
241245

242246
} // namespace debugviewpp

application/DebugViewpp/version.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
#define VERSION 1,9,0,64
2-
#define VERSION_STR "1.9.0.64"
1+
#define VERSION 1,9,0,65
2+
#define VERSION_STR "1.9.0.65"

application/DebugViewpp/version.wxi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
<?define ProductVersion.Major="1" ?>
44
<?define ProductVersion.Minor="9" ?>
55
<?define ProductVersion.Revision="0" ?>
6-
<?define ProductVersion.Build="64" ?>
7-
<?define ProductVersion="1.9.0.64" ?>
6+
<?define ProductVersion.Build="65" ?>
7+
<?define ProductVersion="1.9.0.65" ?>
88
</Include>

application/DebugViewppLib/Debugview_kernel_client.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ bool StopDriverSvc()
6868
return true;
6969
}
7070

71-
void InstallKernelMessagesDriver()
71+
void InstallKernelMessagesDriver(const std::string& driverLocation)
7272
{
7373
// try to uninstall first, in case the driver is somehow still loaded.
7474
UninstallKernelMessagesDriver();
@@ -90,7 +90,7 @@ void InstallKernelMessagesDriver()
9090
SERVICE_KERNEL_DRIVER,
9191
SERVICE_DEMAND_START,
9292
SERVICE_ERROR_NORMAL,
93-
driverPath.c_str(),
93+
driverLocation.c_str(),
9494
NULL, NULL, NULL, NULL, NULL
9595
);
9696

application/DebugViewppLib/KernelReader.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,28 @@
99
#include "DebugViewppLib/LineBuffer.h"
1010
#include "DebugViewppLib/Debugview_kernel_client.h"
1111

12+
#include <filesystem>
13+
#include <format>
1214
namespace fusion {
1315
namespace debugviewpp {
1416

17+
std::string GetDebugviewDriverLocation()
18+
{
19+
const auto driver_name = "dbgvpp.sys";
20+
// this has issues, because there could already be an existing file
21+
// in that case we would load a possibly different driver verion?
22+
// an we also do not seem to be able to (always?) remove it ?
23+
// windows something reports it is 'in-use' even through we unloaded it.
24+
25+
std::filesystem::path driverLocation = driver_name;
26+
const auto systemRoot = std::getenv("SystemRoot");
27+
if (systemRoot != nullptr)
28+
{
29+
driverLocation = std::format("{}\\System32\\driver\\{}", systemRoot, driver_name);
30+
}
31+
return driverLocation.string();
32+
}
33+
1534
void KernelReader::StartListening()
1635
{
1736
Win32::Handle handle(::CreateFile(strDbgviewKernelDriverDeviceName,
@@ -56,7 +75,7 @@ KernelReader::KernelReader(Timer& timer, ILineBuffer& linebuffer) :
5675
PolledLogSource(timer, SourceType::Pipe, linebuffer, 1)
5776
{
5877
SetDescription(L"Kernel Message Reader");
59-
InstallKernelMessagesDriver();
78+
InstallKernelMessagesDriver(GetDebugviewDriverLocation());
6079
Signal();
6180
StartListening();
6281
StartThread();

application/include/DebugViewppLib/Debugview_kernel_client.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55

66
#pragma once
77

8-
void InstallKernelMessagesDriver();
9-
void UninstallKernelMessagesDriver();
10-
118
#include <windows.h>
129
#include <tchar.h>
1310
#include <winioctl.h>
@@ -69,3 +66,5 @@ typedef struct
6966
constexpr const wchar_t * strDbgviewKernelDriverDeviceName = L"\\\\.\\dbgv";
7067
constexpr const DWORD kernelMessageBufferSize = 0x10000;
7168

69+
void InstallKernelMessagesDriver(const std::string& driverLocation);
70+
void UninstallKernelMessagesDriver();

application/include/DebugViewppLib/KernelReader.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
namespace fusion {
1616
namespace debugviewpp {
1717

18+
std::string GetDebugviewDriverLocation();
19+
1820
class ILineBuffer;
1921

2022
class KernelReader : public PolledLogSource

0 commit comments

Comments
 (0)