From 7dda12912bb919a82a2aa382d9ad2c19de3aa6e1 Mon Sep 17 00:00:00 2001 From: Hell Date: Mon, 4 Jun 2018 22:56:48 +0800 Subject: [PATCH] Update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 当设置驱动自动启动的时候,自动将文件复制到System32\Drivers目录下 --- .../DriverToolFrame.cpp" | 97 +++++++++++++++++++ .../DriverToolFrame.h" | 1 + 2 files changed, 98 insertions(+) diff --git "a/\351\251\261\345\212\250\345\267\245\345\205\267/DriverToolFrame.cpp" "b/\351\251\261\345\212\250\345\267\245\345\205\267/DriverToolFrame.cpp" index ba00e77..171498c 100644 --- "a/\351\251\261\345\212\250\345\267\245\345\205\267/DriverToolFrame.cpp" +++ "b/\351\251\261\345\212\250\345\267\245\345\205\267/DriverToolFrame.cpp" @@ -376,6 +376,9 @@ void CDriverToolFrame::OnStartChange(wxCommandEvent & event) HKEY hMainKey = NULL; ULONG ulRet = 0; + + wchar_t* pwszFullPath = nullptr; + do { if (m_szServiceName == wxT("")) @@ -398,12 +401,56 @@ void CDriverToolFrame::OnStartChange(wxCommandEvent & event) { break; } + + if (nSelect <= 2) + { + pwszFullPath = new wchar_t[32767]; + if (pwszFullPath == nullptr) + { + break; + } + + //˵õԶûѸļdriverȥ + if (wxMessageBox(wxString("ҪΪԶ齫ļSystem32\\DriverĿ¼СǷã"), wxString("ʾ"), wxYES_NO, this) == wxNO) + { + break; + } + + if (FileCopyToDriverFolder(m_pEdtDriverPath->GetLabelText()) == false) + { + break; + } + + size_t pos = m_pEdtDriverPath->GetLabelText().find_last_of('\\'); + if (pos == wxString::npos) + { + break; + } + + wxString strFileName(m_pEdtDriverPath->GetLabelText().c_str() + pos + 1); + + wcscpy_s(pwszFullPath, 32767, L"\\SystemRoot\\System\\Drivers\\"); + wcscat_s(pwszFullPath, 32767, strFileName.c_str()); + + ulRet = RegSetValueEx(hMainKey, TEXT("ImagePath"), 0, REG_EXPAND_SZ, (const PBYTE)pwszFullPath, (wcslen(pwszFullPath) + 1)*sizeof(wchar_t)); + if (ulRet != ERROR_SUCCESS) + { + break; + } + } + } while (0); if (hMainKey != NULL) { RegCloseKey(hMainKey); } + + if (pwszFullPath != nullptr) + { + delete[]pwszFullPath; + pwszFullPath = nullptr; + } } void CDriverToolFrame::OnFilterDriverNotify(wxCommandEvent & event) @@ -1225,3 +1272,53 @@ void CDriverToolFrame::ClearCheckBox() m_ppCheckBoxArray[i]->SetValue(false); } } + +bool CDriverToolFrame::FileCopyToDriverFolder(wxString & strFileName) +{ + bool bRet = false; + wchar_t *pwszFullPath = nullptr; + + do + { + pwszFullPath = new wchar_t[32767]; + if (pwszFullPath == nullptr) + { + break; + } + memset(pwszFullPath, 0, 32767); + + size_t pos = strFileName.find_last_of('\\'); + if (pos == wxString::npos) + { + break; + } + + wxString strFile(strFileName.c_str() + pos + 1); + DWORD dwRet = 0; + dwRet = ExpandEnvironmentStringsW(L"%SystemRoot%", pwszFullPath, 32767); + if (dwRet == 0) + { + break; + } + + wcscat_s(pwszFullPath, 32767, L"\\System32\\Drivers\\"); + wcscat_s(pwszFullPath, 32767, strFile.c_str()); + + if (CopyFileW(strFileName.c_str(), pwszFullPath, FALSE) == FALSE) + { + wxMessageBox(wxString("ļʧ"), wxString("ʧ"), wxOK, this); + break; + } + + bRet = true; + + } while (0); + + if (pwszFullPath != nullptr) + { + delete[]pwszFullPath; + pwszFullPath = nullptr; + } + + return bRet; +} diff --git "a/\351\251\261\345\212\250\345\267\245\345\205\267/DriverToolFrame.h" "b/\351\251\261\345\212\250\345\267\245\345\205\267/DriverToolFrame.h" index f481cc5..4470638 100644 --- "a/\351\251\261\345\212\250\345\267\245\345\205\267/DriverToolFrame.h" +++ "b/\351\251\261\345\212\250\345\267\245\345\205\267/DriverToolFrame.h" @@ -175,6 +175,7 @@ class CDriverToolFrame : void UpdateIoctlInfo(IOCTL_INFO& ioctlInfo); void NotifyExtFrame(); void ClearCheckBox(); + bool FileCopyToDriverFolder(wxString &strFileName); private: wxDECLARE_EVENT_TABLE(); };