Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Commit

Permalink
修复重启HOOK失败问题 添加ESC不加载扩展
Browse files Browse the repository at this point in the history
修复了重启可能导致HOOK失败的问题 添加了开启文件夹时按住ESC键不加载设置和不初始化HOOK的功能
  • Loading branch information
Maplespe authored Feb 1, 2022
1 parent 8ab6c56 commit 6e895de
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions ExplorerBgTool/dllmain.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* 文件资源管理器背景工具扩展
*
* Author: Maple
Expand Down Expand Up @@ -39,6 +39,7 @@ struct MyData
#pragma region GlobalVariable

HMODULE g_hModule = NULL; // 全局模块句柄 Global module handle
bool m_isInitHook = false;

ULONG_PTR m_gdiplusToken; // GDI初始化标志 GDI Init flag

Expand Down Expand Up @@ -89,26 +90,6 @@ bool InjectionEntryPoint()
//设置随机数种子
srand((int)time(0));

//创建钩子 CreateHook
if (MH_Initialize() == MH_OK)
{
CreateMHook(CreateWindowExW, MyCreateWindowExW, _CreateWindowExW_, 1);
CreateMHook(DestroyWindow, MyDestroyWindow, _DestroyWindow_, 2);
CreateMHook(BeginPaint, MyBeginPaint, _BeginPaint_, 3);
CreateMHook(FillRect, MyFillRect, _FillRect_, 4);
CreateMHook(CreateCompatibleDC, MyCreateCompatibleDC, _CreateCompatibleDC_, 5);
/*MH_EnableHook(&CreateWindowExW);
MH_EnableHook(&DestroyWindow);
MH_EnableHook(&BeginPaint);
MH_EnableHook(&FillRect);
MH_EnableHook(&CreateCompatibleDC);*/
MH_EnableHook(MH_ALL_HOOKS);
}
else
{
MessageBoxW(0, L"Failed to initialize disassembly!\nSuspected duplicate load extension", L"MTweaker Error", MB_ICONERROR | MB_OK);
FreeLibraryAndExitThread(g_hModule, 0);
}
return true;
}

Expand Down Expand Up @@ -183,6 +164,29 @@ void LoadSettings(bool loadimg)
*/
void OnWindowLoad()
{
//如果按住ESC键则不加载扩展
if (GetKeyState(VK_ESCAPE) < 0)
return;
//在开机的时候系统就会加载此动态库 那时候启用HOOK是会失败的 等创建窗口的时候再初始化HOOK
if (!m_isInitHook)
{
//创建钩子 CreateHook
if (MH_Initialize() == MH_OK)
{
CreateMHook(CreateWindowExW, MyCreateWindowExW, _CreateWindowExW_, 1);
CreateMHook(DestroyWindow, MyDestroyWindow, _DestroyWindow_, 2);
CreateMHook(BeginPaint, MyBeginPaint, _BeginPaint_, 3);
CreateMHook(FillRect, MyFillRect, _FillRect_, 4);
CreateMHook(CreateCompatibleDC, MyCreateCompatibleDC, _CreateCompatibleDC_, 5);
MH_EnableHook(MH_ALL_HOOKS);
}
else
{
MessageBoxW(0, L"Failed to initialize disassembly!\nSuspected duplicate load extension", L"MTweaker Error", MB_ICONERROR | MB_OK);
FreeLibraryAndExitThread(g_hModule, 0);
}
m_isInitHook = true;
}
LoadSettings(true);
}

Expand Down Expand Up @@ -344,4 +348,4 @@ HDC MyCreateCompatibleDC(HDC hDC)
}
}
return retDC;
}
}

0 comments on commit 6e895de

Please sign in to comment.