Skip to content

Commit

Permalink
version 1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
KrxkGit committed Apr 26, 2024
1 parent 2c24fc0 commit ba20b46
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 10 deletions.
12 changes: 10 additions & 2 deletions HelpUploadFiles/CContext.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include "CContext.h"

CContext* CContext::singleton = new CContext;
LPCTSTR SharedMemoryName = _T("HelpUploadFileSharedMemory");
LPCTSTR EventName = _T("HelpUploadEvent");


CContext::CContext()
{
Expand All @@ -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];
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions HelpUploadFiles/CContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class CContext
private:
HANDLE hSharedMem;
HANDLE hEvent;
HANDLE hWaitReadEvent;
public:
static CContext* singleton;
CContext();
Expand Down
23 changes: 23 additions & 0 deletions HelpUploadFiles/CMainDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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("长按鼠标开启捕获"));

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

void CMainDlg::OnAdd()
{
if (!isHaveInject()) {
return;
}
GetInputString();
DoAdd();
}
Expand Down Expand Up @@ -120,6 +125,8 @@ void CMainDlg::OnInject()
}
CContext::singleton->InjectWorkDll(this->hInjectWnd);
this->hInjectWnd = NULL;

this->haveInject = true;
}


Expand All @@ -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); // 结束此次拖拽
Expand Down Expand Up @@ -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;
}
2 changes: 2 additions & 0 deletions HelpUploadFiles/CMainDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -42,5 +43,6 @@ class CMainDlg
void OnMouseMove();
void OnLButtonDown();
void OnLButtonUp();
bool isHaveInject();
};

Binary file modified HelpUploadFiles/HelpUploadFiles.rc
Binary file not shown.
5 changes: 5 additions & 0 deletions IgnoreInfoFormat/CIgnoreInfo.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#include "CIgnoreInfo.h"

// ½ø³Ìͬ²½¶¨Òå
LPCTSTR SharedMemoryName = _T("HelpUploadFileSharedMemory");
LPCTSTR EventName = _T("HelpUploadEvent");
LPCTSTR EventWaitReadName = _T("HelpUploadWaitReadEvent");

VOID CIgnoreInfo::Serialize(LPVOID lpData)
{
size_t endPos = lstrlen(this->fileName) + 1;
Expand Down
6 changes: 6 additions & 0 deletions IgnoreInfoFormat/CIgnoreInfo.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#pragma once
#include "pch.h"


// ½ø³Ìͬ²½ÉùÃ÷
extern LPCTSTR SharedMemoryName;
extern LPCTSTR EventName;
extern LPCTSTR EventWaitReadName;

class CIgnoreInfo
{
public:
Expand Down
12 changes: 9 additions & 3 deletions WorkDll/CAdvice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
#include "CAdvice.h"
#include "CIgnoreInfo.h"

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

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

UnmapViewOfFile(sharedMemory);

SetEvent(pAdvice->hWaitReadEvent);
}
}
}
Expand All @@ -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];
Expand Down
1 change: 1 addition & 0 deletions WorkDll/CAdvice.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class CAdvice
private:
HANDLE hSharedMem;
HANDLE hEvent;
HANDLE hWaitReadEvent;
std::list<std::wstring> interceptTable;
public:
static UINT CALLBACK ListenThread(LPVOID pParam);
Expand Down
31 changes: 26 additions & 5 deletions WorkDll/work.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
CAPIHook g_MyFindNextFile("Kernel32.dll", "FindNextFileW" , (PROC)MyFindNextFileW);
CAPIHook g_MyFindFirstFile("Kernel32.dll", "FindFirstFileW", (PROC)MyFindFirstFileW);

0 comments on commit ba20b46

Please sign in to comment.