From ba20b461d03700b79811c3edeb70c694ec3d49d8 Mon Sep 17 00:00:00 2001 From: Krxk <1246924370@qq.com> Date: Fri, 26 Apr 2024 17:57:02 +0800 Subject: [PATCH] version 1.0.1 --- HelpUploadFiles/CContext.cpp | 12 +++++++++-- HelpUploadFiles/CContext.h | 1 + HelpUploadFiles/CMainDlg.cpp | 23 +++++++++++++++++++++ HelpUploadFiles/CMainDlg.h | 2 ++ HelpUploadFiles/HelpUploadFiles.rc | Bin 9840 -> 11664 bytes IgnoreInfoFormat/CIgnoreInfo.cpp | 5 +++++ IgnoreInfoFormat/CIgnoreInfo.h | 6 ++++++ WorkDll/CAdvice.cpp | 12 ++++++++--- WorkDll/CAdvice.h | 1 + WorkDll/work.cpp | 31 ++++++++++++++++++++++++----- 10 files changed, 83 insertions(+), 10 deletions(-) diff --git a/HelpUploadFiles/CContext.cpp b/HelpUploadFiles/CContext.cpp index cb96b11..44f5690 100644 --- a/HelpUploadFiles/CContext.cpp +++ b/HelpUploadFiles/CContext.cpp @@ -1,8 +1,7 @@ #include "CContext.h" CContext* CContext::singleton = new CContext; -LPCTSTR SharedMemoryName = _T("HelpUploadFileSharedMemory"); -LPCTSTR EventName = _T("HelpUploadEvent"); + CContext::CContext() { @@ -15,6 +14,13 @@ CContext::CContext() throw buffer; } + this->hWaitReadEvent = CreateEvent(0, FALSE, TRUE, EventWaitReadName); // 初始可写 + if (hWaitReadEvent== INVALID_HANDLE_VALUE) { + wchar_t buffer[100]; + std::swprintf(buffer, _countof(buffer), _T("CreateReadEvent failed with %d"), GetLastError()); + throw buffer; + } + this->hSharedMem = CreateFileMapping(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, 4096, SharedMemoryName); if (this->hSharedMem == INVALID_HANDLE_VALUE) { wchar_t buffer[100]; @@ -43,6 +49,8 @@ VOID CContext::DoOperation(CIgnoreInfo* pIgnoreInfo, std::wstring fileName, CIgn _tcscpy_s(pIgnoreInfo->fileName, cbWrite, fileName.c_str()); // 写入共享内存 + WaitForSingleObject(this->hWaitReadEvent, INFINITE); + LPVOID sharedMemory = MapViewOfFile(this->hSharedMem, FILE_MAP_WRITE, 0, 0, sizeof(CIgnoreInfo)); if (sharedMemory != NULL) { pIgnoreInfo->Serialize(sharedMemory); diff --git a/HelpUploadFiles/CContext.h b/HelpUploadFiles/CContext.h index 45399c4..f5da19d 100644 --- a/HelpUploadFiles/CContext.h +++ b/HelpUploadFiles/CContext.h @@ -10,6 +10,7 @@ class CContext private: HANDLE hSharedMem; HANDLE hEvent; + HANDLE hWaitReadEvent; public: static CContext* singleton; CContext(); diff --git a/HelpUploadFiles/CMainDlg.cpp b/HelpUploadFiles/CMainDlg.cpp index 3c88bf3..357d4d6 100644 --- a/HelpUploadFiles/CMainDlg.cpp +++ b/HelpUploadFiles/CMainDlg.cpp @@ -33,6 +33,8 @@ INT_PTR CALLBACK CMainDlg::MainDlg(HWND hDlg, UINT message, WPARAM wParam, LPARA VOID CMainDlg::OnDlgInit() { + this->haveInject = false; + this->hInjectWnd = NULL; SetDlgItemText(this->hDlg, IDC_CAPTUREWND, _T("长按鼠标开启捕获")); @@ -81,6 +83,9 @@ void CMainDlg::SaveParameters(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPa void CMainDlg::OnAdd() { + if (!isHaveInject()) { + return; + } GetInputString(); DoAdd(); } @@ -120,6 +125,8 @@ void CMainDlg::OnInject() } CContext::singleton->InjectWorkDll(this->hInjectWnd); this->hInjectWnd = NULL; + + this->haveInject = true; } @@ -132,6 +139,10 @@ void CMainDlg::OnOpenAbout() void CMainDlg::OnDropFile() { HDROP hDrop = (HDROP)this->wParam; + if (!isHaveInject()) { + DragFinish(hDrop); // 结束此次拖拽 + return; + } if (IDCANCEL == MessageBox(this->hDlg, _T("检测到拖拽文件,是否添加到忽略列表?"), _T("提示"), MB_ICONQUESTION | MB_OKCANCEL | MB_DEFBUTTON1)) { DragFinish(hDrop); // 结束此次拖拽 @@ -208,3 +219,15 @@ void CMainDlg::OnLButtonUp() OnInject(); } } + + +bool CMainDlg::isHaveInject() +{ + bool b = this->haveInject; + if (!b) { + TCHAR sz[MAX_PATH]; + std::swprintf(sz, _countof(sz), _T("尚未注入赋能模块,请先完成注入操作")); + MessageBox(this->hDlg, sz, _T("提示"), MB_ICONWARNING); + } + return b; +} diff --git a/HelpUploadFiles/CMainDlg.h b/HelpUploadFiles/CMainDlg.h index 7f4e247..b2a1862 100644 --- a/HelpUploadFiles/CMainDlg.h +++ b/HelpUploadFiles/CMainDlg.h @@ -24,6 +24,7 @@ class CMainDlg HWND hInjectWnd; TCHAR szTitle[MAX_PATH]; // 注入的窗口标题 / 类 + bool haveInject; public: static INT_PTR CALLBACK MainDlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam); protected: @@ -42,5 +43,6 @@ class CMainDlg void OnMouseMove(); void OnLButtonDown(); void OnLButtonUp(); + bool isHaveInject(); }; diff --git a/HelpUploadFiles/HelpUploadFiles.rc b/HelpUploadFiles/HelpUploadFiles.rc index 3cfb0f95425996ae2a13d80b5ba948321d893790..71ddc016be6d5c5314cd360cbd0d6c0c911650fd 100644 GIT binary patch delta 1233 zcma)5!A=uV6g>-3n8YPfLqdmffy7E?ki;e|2(>LCRHmVI3<1*=oR&$TZQ7bBn|=Z& z?*~}8aYuq%Kf?uburQ#8g7%4y`i`e8XLYs|`hE$iqC z(H)NDM|wRN?{6G4aYs7l&i>96$zM=E7alz~*_S-}oOx8-OZ1P;fileName) + 1; diff --git a/IgnoreInfoFormat/CIgnoreInfo.h b/IgnoreInfoFormat/CIgnoreInfo.h index fff3dac..d3e577e 100644 --- a/IgnoreInfoFormat/CIgnoreInfo.h +++ b/IgnoreInfoFormat/CIgnoreInfo.h @@ -1,6 +1,12 @@ #pragma once #include "pch.h" + +// 进程同步声明 +extern LPCTSTR SharedMemoryName; +extern LPCTSTR EventName; +extern LPCTSTR EventWaitReadName; + class CIgnoreInfo { public: diff --git a/WorkDll/CAdvice.cpp b/WorkDll/CAdvice.cpp index 195794d..ea81b66 100644 --- a/WorkDll/CAdvice.cpp +++ b/WorkDll/CAdvice.cpp @@ -2,9 +2,6 @@ #include "CAdvice.h" #include "CIgnoreInfo.h" -// 命名管道 & 读写结构 -LPCTSTR SharedMemoryName = _T("HelpUploadFileSharedMemory"); -LPCTSTR EventName = _T("HelpUploadEvent"); // 单例初始化 CAdvice* CAdvice::singleton = new CAdvice; @@ -69,6 +66,8 @@ UINT CALLBACK CAdvice::ListenThread(LPVOID pParam) } UnmapViewOfFile(sharedMemory); + + SetEvent(pAdvice->hWaitReadEvent); } } } @@ -87,6 +86,13 @@ CAdvice::CAdvice() MessageBox(NULL, sz, _T("初始化事件"), MB_ICONINFORMATION); } + this->hWaitReadEvent = CreateEvent(0, FALSE, TRUE, EventWaitReadName); + if (this->hWaitReadEvent == INVALID_HANDLE_VALUE) { + wchar_t sz[100]; + std::swprintf(sz, _countof(sz), _T("创建失败 : %d"), GetLastError()); + MessageBox(NULL, sz, _T("初始化读等待事件"), MB_ICONINFORMATION); + } + this->hSharedMem = OpenFileMapping(FILE_MAP_READ, FALSE, SharedMemoryName); if (this->hSharedMem == INVALID_HANDLE_VALUE) { wchar_t sz[100]; diff --git a/WorkDll/CAdvice.h b/WorkDll/CAdvice.h index 58096e7..fd67f17 100644 --- a/WorkDll/CAdvice.h +++ b/WorkDll/CAdvice.h @@ -11,6 +11,7 @@ class CAdvice private: HANDLE hSharedMem; HANDLE hEvent; + HANDLE hWaitReadEvent; std::list interceptTable; public: static UINT CALLBACK ListenThread(LPVOID pParam); diff --git a/WorkDll/work.cpp b/WorkDll/work.cpp index 54531e0..10733b0 100644 --- a/WorkDll/work.cpp +++ b/WorkDll/work.cpp @@ -35,13 +35,13 @@ VOID DllInit() //StringCchPrintf(sz, _countof(sz), _T("DLL琚姞杞斤紒\t搴旂敤绋嬪簭璺緞锛%s"), szPath); //MyOutputDebugStringW(sz); + wchar_t sz[100]; + std::swprintf(sz, _countof(sz), _T("璧嬭兘妯″潡娉ㄥ叆鎴愬姛\n杩涚▼ID: %d"), GetCurrentProcessId()); CAdvice::singleton->startListenThread(); - MessageBox(NULL, _T("璧嬭兘妯″潡娉ㄥ叆鎴愬姛"), _T("HelpUploadFiles"), MB_ICONINFORMATION); + MessageBox(NULL, sz, _T("HelpUploadFiles"), MB_ICONINFORMATION); } // API 鎷︽埅 - - /** * @brief 鐢ㄤ簬鎷︽埅鐧惧害缃戠洏 涓婁紶鏂囦欢锛屾帓闄ゆ寚瀹氭枃浠 * @param hFindFile @@ -53,11 +53,32 @@ BOOL WINAPI MyFindNextFileW(HANDLE hFindFile, LPWIN32_FIND_DATAW lpFindFileData) BOOL res = FindNextFileW(hFindFile, lpFindFileData); CAdvice* pAdvice = CAdvice::singleton; - for (bool b = pAdvice->isMatch(lpFindFileData); b; b = pAdvice->isMatch(lpFindFileData)) { + for (bool b = pAdvice->isMatch(lpFindFileData); b && res; b = pAdvice->isMatch(lpFindFileData)) { + //MessageBox(NULL, lpFindFileData->cFileName, _T("鎻愮ず"), MB_ICONINFORMATION); res = FindNextFileW(hFindFile, lpFindFileData); // 鐩存帴璺冲埌涓嬩竴涓枃浠 } return res; } + +/** + * @brief 鎷︽埅 FindFirstFileW + * @param lpFileName + * @param lpFindFileData + * @return +*/ +HANDLE WINAPI MyFindFirstFileW(LPCWSTR lpFileName, LPWIN32_FIND_DATAW lpFindFileData) +{ + HANDLE h = FindFirstFileW(lpFileName, lpFindFileData); + //MessageBox(NULL, lpFindFileData->cFileName, _T("棣栦釜鏂囦欢"), MB_ICONINFORMATION); + + //CAdvice* pAdvice = CAdvice::singleton; + //for (bool b = pAdvice->isMatch(lpFindFileData); b; b = pAdvice->isMatch(lpFindFileData)) { + // FindNextFileW(h, lpFindFileData); // 鐩存帴璺冲埌涓嬩竴涓枃浠 + //} + + return h; +} // API 鎷︽埅 -CAPIHook g_MyFindNextFile("Kernel32.dll", "FindNextFileW" , (PROC)MyFindNextFileW); \ No newline at end of file +CAPIHook g_MyFindNextFile("Kernel32.dll", "FindNextFileW" , (PROC)MyFindNextFileW); +CAPIHook g_MyFindFirstFile("Kernel32.dll", "FindFirstFileW", (PROC)MyFindFirstFileW); \ No newline at end of file