@@ -192,7 +192,10 @@ CMainFrame::CMainFrame() :
192192 m_notifyIconData.cbSize = 0 ;
193193}
194194
195- CMainFrame::~CMainFrame () = default ;
195+ CMainFrame::~CMainFrame ()
196+ {
197+ RemoveDriver ();
198+ }
196199
197200void CMainFrame::SetLogging ()
198201{
@@ -284,11 +287,6 @@ void CMainFrame::OnClose()
284287 Shell_NotifyIcon (NIM_DELETE, &m_notifyIconData);
285288 m_notifyIconData.cbSize = 0 ;
286289 }
287-
288- #ifdef CONSOLE_DEBUG
289- fclose (stdout);
290- FreeConsole ();
291- #endif
292290}
293291
294292LRESULT CMainFrame::OnQueryEndSession (WPARAM /* unused*/ , LPARAM /* unused*/ )
@@ -1519,18 +1517,51 @@ void CMainFrame::OnLogGlobal(UINT /*uNotifyCode*/, int /*nID*/, CWindow /*wndCtl
15191517 UpdateTitle ();
15201518}
15211519
1520+ static const auto driver_name = " dbgv.sys" ;
1521+
1522+ void WriteDriverFromResource ()
1523+ {
1524+ if (std::filesystem::exists (driver_name))
1525+ {
1526+ return ;
1527+ }
1528+ HRSRC hRes = FindResource (NULL , MAKEINTRESOURCE (IDR_DBGV_DRIVER), RT_RCDATA);
1529+ if (hRes)
1530+ {
1531+ HGLOBAL hLoadedRes = LoadResource (NULL , hRes);
1532+ if (hLoadedRes)
1533+ {
1534+ DWORD dwSize = SizeofResource (NULL , hRes);
1535+ void * pLockedRes = LockResource (hLoadedRes);
1536+ if (pLockedRes)
1537+ {
1538+ std::ofstream outFile (driver_name, std::ios::binary);
1539+ outFile.write (static_cast <const char *>(pLockedRes), dwSize);
1540+ outFile.close ();
1541+ }
1542+ }
1543+ }
1544+ }
1545+
1546+ void RemoveDriver ()
1547+ {
1548+ std::filesystem::remove (driver_name);
1549+ }
1550+
15221551void CMainFrame::OnLogKernel (UINT /* uNotifyCode*/ , int /* nID*/ , CWindow /* wndCtl*/ )
15231552{
15241553 m_tryKernel = (m_pKernelReader == nullptr );
15251554
15261555 if (m_tryKernel)
15271556 {
1557+ WriteDriverFromResource ();
15281558 Resume ();
15291559 }
15301560 else
15311561 {
15321562 m_logSources.Remove (m_pKernelReader);
15331563 m_pKernelReader = nullptr ;
1564+ RemoveDriver ();
15341565 }
15351566 UpdateTitle ();
15361567}
0 commit comments