Skip to content

Commit ba20b46

Browse files
committed
version 1.0.1
1 parent 2c24fc0 commit ba20b46

10 files changed

Lines changed: 83 additions & 10 deletions

File tree

HelpUploadFiles/CContext.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#include "CContext.h"
22

33
CContext* CContext::singleton = new CContext;
4-
LPCTSTR SharedMemoryName = _T("HelpUploadFileSharedMemory");
5-
LPCTSTR EventName = _T("HelpUploadEvent");
4+
65

76
CContext::CContext()
87
{
@@ -15,6 +14,13 @@ CContext::CContext()
1514
throw buffer;
1615
}
1716

17+
this->hWaitReadEvent = CreateEvent(0, FALSE, TRUE, EventWaitReadName); // 初始可写
18+
if (hWaitReadEvent== INVALID_HANDLE_VALUE) {
19+
wchar_t buffer[100];
20+
std::swprintf(buffer, _countof(buffer), _T("CreateReadEvent failed with %d"), GetLastError());
21+
throw buffer;
22+
}
23+
1824
this->hSharedMem = CreateFileMapping(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, 4096, SharedMemoryName);
1925
if (this->hSharedMem == INVALID_HANDLE_VALUE) {
2026
wchar_t buffer[100];
@@ -43,6 +49,8 @@ VOID CContext::DoOperation(CIgnoreInfo* pIgnoreInfo, std::wstring fileName, CIgn
4349
_tcscpy_s(pIgnoreInfo->fileName, cbWrite, fileName.c_str());
4450

4551
// 写入共享内存
52+
WaitForSingleObject(this->hWaitReadEvent, INFINITE);
53+
4654
LPVOID sharedMemory = MapViewOfFile(this->hSharedMem, FILE_MAP_WRITE, 0, 0, sizeof(CIgnoreInfo));
4755
if (sharedMemory != NULL) {
4856
pIgnoreInfo->Serialize(sharedMemory);

HelpUploadFiles/CContext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class CContext
1010
private:
1111
HANDLE hSharedMem;
1212
HANDLE hEvent;
13+
HANDLE hWaitReadEvent;
1314
public:
1415
static CContext* singleton;
1516
CContext();

HelpUploadFiles/CMainDlg.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ INT_PTR CALLBACK CMainDlg::MainDlg(HWND hDlg, UINT message, WPARAM wParam, LPARA
3333

3434
VOID CMainDlg::OnDlgInit()
3535
{
36+
this->haveInject = false;
37+
3638
this->hInjectWnd = NULL;
3739
SetDlgItemText(this->hDlg, IDC_CAPTUREWND, _T("长按鼠标开启捕获"));
3840

@@ -81,6 +83,9 @@ void CMainDlg::SaveParameters(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPa
8183

8284
void CMainDlg::OnAdd()
8385
{
86+
if (!isHaveInject()) {
87+
return;
88+
}
8489
GetInputString();
8590
DoAdd();
8691
}
@@ -120,6 +125,8 @@ void CMainDlg::OnInject()
120125
}
121126
CContext::singleton->InjectWorkDll(this->hInjectWnd);
122127
this->hInjectWnd = NULL;
128+
129+
this->haveInject = true;
123130
}
124131

125132

@@ -132,6 +139,10 @@ void CMainDlg::OnOpenAbout()
132139
void CMainDlg::OnDropFile()
133140
{
134141
HDROP hDrop = (HDROP)this->wParam;
142+
if (!isHaveInject()) {
143+
DragFinish(hDrop); // 结束此次拖拽
144+
return;
145+
}
135146

136147
if (IDCANCEL == MessageBox(this->hDlg, _T("检测到拖拽文件,是否添加到忽略列表?"), _T("提示"), MB_ICONQUESTION | MB_OKCANCEL | MB_DEFBUTTON1)) {
137148
DragFinish(hDrop); // 结束此次拖拽
@@ -208,3 +219,15 @@ void CMainDlg::OnLButtonUp()
208219
OnInject();
209220
}
210221
}
222+
223+
224+
bool CMainDlg::isHaveInject()
225+
{
226+
bool b = this->haveInject;
227+
if (!b) {
228+
TCHAR sz[MAX_PATH];
229+
std::swprintf(sz, _countof(sz), _T("尚未注入赋能模块,请先完成注入操作"));
230+
MessageBox(this->hDlg, sz, _T("提示"), MB_ICONWARNING);
231+
}
232+
return b;
233+
}

HelpUploadFiles/CMainDlg.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class CMainDlg
2424

2525
HWND hInjectWnd;
2626
TCHAR szTitle[MAX_PATH]; // ×¢ÈëµÄ´°¿Ú±êÌâ / Àà
27+
bool haveInject;
2728
public:
2829
static INT_PTR CALLBACK MainDlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
2930
protected:
@@ -42,5 +43,6 @@ class CMainDlg
4243
void OnMouseMove();
4344
void OnLButtonDown();
4445
void OnLButtonUp();
46+
bool isHaveInject();
4547
};
4648

HelpUploadFiles/HelpUploadFiles.rc

1.78 KB
Binary file not shown.

IgnoreInfoFormat/CIgnoreInfo.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#include "CIgnoreInfo.h"
22

3+
// ½ø³Ìͬ²½¶¨Òå
4+
LPCTSTR SharedMemoryName = _T("HelpUploadFileSharedMemory");
5+
LPCTSTR EventName = _T("HelpUploadEvent");
6+
LPCTSTR EventWaitReadName = _T("HelpUploadWaitReadEvent");
7+
38
VOID CIgnoreInfo::Serialize(LPVOID lpData)
49
{
510
size_t endPos = lstrlen(this->fileName) + 1;

IgnoreInfoFormat/CIgnoreInfo.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
#pragma once
22
#include "pch.h"
33

4+
5+
// ½ø³Ìͬ²½ÉùÃ÷
6+
extern LPCTSTR SharedMemoryName;
7+
extern LPCTSTR EventName;
8+
extern LPCTSTR EventWaitReadName;
9+
410
class CIgnoreInfo
511
{
612
public:

WorkDll/CAdvice.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
#include "CAdvice.h"
33
#include "CIgnoreInfo.h"
44

5-
// 命名管道 & 读写结构
6-
LPCTSTR SharedMemoryName = _T("HelpUploadFileSharedMemory");
7-
LPCTSTR EventName = _T("HelpUploadEvent");
85

96
// 单例初始化
107
CAdvice* CAdvice::singleton = new CAdvice;
@@ -69,6 +66,8 @@ UINT CALLBACK CAdvice::ListenThread(LPVOID pParam)
6966
}
7067

7168
UnmapViewOfFile(sharedMemory);
69+
70+
SetEvent(pAdvice->hWaitReadEvent);
7271
}
7372
}
7473
}
@@ -87,6 +86,13 @@ CAdvice::CAdvice()
8786
MessageBox(NULL, sz, _T("初始化事件"), MB_ICONINFORMATION);
8887
}
8988

89+
this->hWaitReadEvent = CreateEvent(0, FALSE, TRUE, EventWaitReadName);
90+
if (this->hWaitReadEvent == INVALID_HANDLE_VALUE) {
91+
wchar_t sz[100];
92+
std::swprintf(sz, _countof(sz), _T("创建失败 : %d"), GetLastError());
93+
MessageBox(NULL, sz, _T("初始化读等待事件"), MB_ICONINFORMATION);
94+
}
95+
9096
this->hSharedMem = OpenFileMapping(FILE_MAP_READ, FALSE, SharedMemoryName);
9197
if (this->hSharedMem == INVALID_HANDLE_VALUE) {
9298
wchar_t sz[100];

WorkDll/CAdvice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class CAdvice
1111
private:
1212
HANDLE hSharedMem;
1313
HANDLE hEvent;
14+
HANDLE hWaitReadEvent;
1415
std::list<std::wstring> interceptTable;
1516
public:
1617
static UINT CALLBACK ListenThread(LPVOID pParam);

WorkDll/work.cpp

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ VOID DllInit()
3535
//StringCchPrintf(sz, _countof(sz), _T("DLL被加载!\t应用程序路径:%s"), szPath);
3636
//MyOutputDebugStringW(sz);
3737

38+
wchar_t sz[100];
39+
std::swprintf(sz, _countof(sz), _T("赋能模块注入成功\n进程ID: %d"), GetCurrentProcessId());
3840
CAdvice::singleton->startListenThread();
39-
MessageBox(NULL, _T("赋能模块注入成功"), _T("HelpUploadFiles"), MB_ICONINFORMATION);
41+
MessageBox(NULL, sz, _T("HelpUploadFiles"), MB_ICONINFORMATION);
4042
}
4143

4244
// API 拦截
43-
44-
4545
/**
4646
* @brief 用于拦截百度网盘 上传文件,排除指定文件
4747
* @param hFindFile
@@ -53,11 +53,32 @@ BOOL WINAPI MyFindNextFileW(HANDLE hFindFile, LPWIN32_FIND_DATAW lpFindFileData)
5353
BOOL res = FindNextFileW(hFindFile, lpFindFileData);
5454

5555
CAdvice* pAdvice = CAdvice::singleton;
56-
for (bool b = pAdvice->isMatch(lpFindFileData); b; b = pAdvice->isMatch(lpFindFileData)) {
56+
for (bool b = pAdvice->isMatch(lpFindFileData); b && res; b = pAdvice->isMatch(lpFindFileData)) {
57+
//MessageBox(NULL, lpFindFileData->cFileName, _T("提示"), MB_ICONINFORMATION);
5758
res = FindNextFileW(hFindFile, lpFindFileData); // 直接跳到下一个文件
5859
}
5960
return res;
6061
}
62+
63+
/**
64+
* @brief 拦截 FindFirstFileW
65+
* @param lpFileName
66+
* @param lpFindFileData
67+
* @return
68+
*/
69+
HANDLE WINAPI MyFindFirstFileW(LPCWSTR lpFileName, LPWIN32_FIND_DATAW lpFindFileData)
70+
{
71+
HANDLE h = FindFirstFileW(lpFileName, lpFindFileData);
72+
//MessageBox(NULL, lpFindFileData->cFileName, _T("首个文件"), MB_ICONINFORMATION);
73+
74+
//CAdvice* pAdvice = CAdvice::singleton;
75+
//for (bool b = pAdvice->isMatch(lpFindFileData); b; b = pAdvice->isMatch(lpFindFileData)) {
76+
// FindNextFileW(h, lpFindFileData); // 直接跳到下一个文件
77+
//}
78+
79+
return h;
80+
}
6181
// API 拦截
6282

63-
CAPIHook g_MyFindNextFile("Kernel32.dll", "FindNextFileW" , (PROC)MyFindNextFileW);
83+
CAPIHook g_MyFindNextFile("Kernel32.dll", "FindNextFileW" , (PROC)MyFindNextFileW);
84+
CAPIHook g_MyFindFirstFile("Kernel32.dll", "FindFirstFileW", (PROC)MyFindFirstFileW);

0 commit comments

Comments
 (0)