Skip to content

Commit

Permalink
Extend frame after successful hooking.
Browse files Browse the repository at this point in the history
  • Loading branch information
dongle-the-gadget committed Nov 17, 2022
1 parent 019fa24 commit dbeec07
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 10 deletions.
67 changes: 58 additions & 9 deletions ExplorerFrame/ExplorerFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
}
catch (...) {}
}

PostQuitMessage(0);
break;
}
Expand Down Expand Up @@ -185,6 +186,36 @@ void WinEventProc(
HandleWindow(hwnd);
}

bool IsWindowOfInterest(HWND hWnd)
{
if (!IsWindow(hWnd) || !IsWindowVisible(hWnd))
return false;

WCHAR lpClassName[MAX_PATH];

GetClassName(hWnd, lpClassName, MAX_PATH);

auto styleEx = GetWindowLongPtrW(hWnd, GWL_EXSTYLE);

if (styleEx & WS_EX_NOACTIVATE || styleEx & WS_EX_LAYERED)
return false;

if (styleEx & WS_EX_APPWINDOW)
return true;

auto style = GetWindowLongPtrW(hWnd, GWL_STYLE);

if (!style)
return false;

auto hasTitleBar = style & WS_BORDER && style & WS_DLGFRAME;

if ((styleEx & WS_EX_TOOLWINDOW || style & WS_POPUP) && !hasTitleBar)
return false;

return true;
}

void HandleWindow(HWND hwnd)
{
DWORD processId;
Expand All @@ -196,15 +227,33 @@ void HandleWindow(HWND hwnd)
CloseHandle(processHandle);

// Check if the process is the Windows Explorer
if (_wcsicmp(processName, L"C:\\Windows\\explorer.exe") == 0 && hookingMap.find(tid) == hookingMap.end())
if (_wcsicmp(processName, L"C:\\Windows\\explorer.exe") == 0)
{
HMODULE dll = LoadLibrary(L"Injector.dll");
if (!dll)
return;
auto procAddr = GetProcAddress(dll, "InjectExplorerHook");
auto method = reinterpret_cast<PFN_INJECT_EXPLORER_HOOK>(procAddr);
HHOOK hook = method(hwnd);
hookingMap.insert(std::pair<DWORD, HHOOK>(tid, hook));
FreeLibrary(dll);
bool isInjectionSuccessful = true;
if (hookingMap.find(tid) == hookingMap.end())
{
HMODULE dll = LoadLibrary(L"Injector.dll");
if (!dll)
return;
auto procAddr = GetProcAddress(dll, "InjectExplorerHook");
auto method = reinterpret_cast<PFN_INJECT_EXPLORER_HOOK>(procAddr);
HHOOK hook = method(hwnd);
if (hook != NULL)
hookingMap.insert(std::pair<DWORD, HHOOK>(tid, hook));
else
isInjectionSuccessful = false;
FreeLibrary(dll);
}

if (IsWindowOfInterest(hwnd) && isInjectionSuccessful)
{
MARGINS margins = MARGINS {
.cxLeftWidth = -1,
.cxRightWidth = -1,
.cyTopHeight = -1,
.cyBottomHeight = -1
};
DwmExtendFrameIntoClientArea(hwnd, &margins);
}
}
}
2 changes: 2 additions & 0 deletions ExplorerFrame/ExplorerFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ void WinEventProc(
DWORD dwmsEventTime);
void HandleWindow(HWND hwnd);

bool IsWindowOfInterest(HWND);

// Define SetPreferredAppMode
typedef enum PREFERRED_APP_MODE
{
Expand Down
3 changes: 3 additions & 0 deletions ExplorerFrame/ExplorerFrame.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@
<ClCompile>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
<Link>
<AdditionalDependencies>dwmapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
Expand Down
3 changes: 2 additions & 1 deletion ExplorerFrame/framework.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
#include <tchar.h>
#include <psapi.h>
#include <shellapi.h>
#include <windowsx.h>
#include <windowsx.h>
#include <dwmapi.h>

0 comments on commit dbeec07

Please sign in to comment.