From 33f5a6e22ac4c2ac74ed28bbd5ecb9bcef0d7492 Mon Sep 17 00:00:00 2001 From: Anixx Date: Sun, 1 Sep 2024 14:55:08 +0300 Subject: [PATCH] Create fake-explorer-path.wh.cpp (#915) * Create fake-explorer-path.wh.cpp * Update fake-explorer-path.wh.cpp --- mods/fake-explorer-path.wh.cpp | 55 ++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 mods/fake-explorer-path.wh.cpp diff --git a/mods/fake-explorer-path.wh.cpp b/mods/fake-explorer-path.wh.cpp new file mode 100644 index 000000000..fe1e469b4 --- /dev/null +++ b/mods/fake-explorer-path.wh.cpp @@ -0,0 +1,55 @@ +// ==WindhawkMod== +// @id fake-explorer-path +// @name Fake Explorer path +// @description Allows to run explorer.exe in taskbar mode from any location +// @version 1.0 +// @author Anixx +// @github https://github.com/Anixx +// @include explorer.exe +// ==/WindhawkMod== + +// ==WindhawkModReadme== +/* +Allows to run explorer.exe in taskbar mode from any location. This can be used to run another version of Explorer +without replacing system files. The path to explorer.exe can be specified in the registry key +HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\Shell. +For running taskbar in Windows 10 mode, the localization folder should be available +at the location of explorer.exe. For Windows 11 taskbar mode, this is not required. + +The mod makes explorer.exe think that it has been launched from %Systemroot%\Windows. +*/ +// ==/WindhawkModReadme== + +#include +#include + +typedef DWORD (WINAPI* GetModuleFileNameW_t)(HMODULE, LPWSTR, DWORD); +GetModuleFileNameW_t pOriginalGetModuleFileNameW = NULL; + +DWORD WINAPI HookedGetModuleFileNameW(HMODULE hModule, LPWSTR lpFilename, DWORD nSize) { + // If the call is for the main executable, return the fake path + if (hModule == NULL) { + WCHAR systemRoot[MAX_PATH]; + GetEnvironmentVariableW(L"SystemRoot", systemRoot, MAX_PATH); + wsprintfW(lpFilename, L"%s\\explorer.exe", systemRoot); + return lstrlenW(lpFilename); + } + // Otherwise, call the original function + return pOriginalGetModuleFileNameW(hModule, lpFilename, nSize); +} + +// The mod is being initialized, load settings, hook functions, and do other +// initialization stuff if required. +BOOL Wh_ModInit(void) +{ + Wh_Log(L"Init"); + + Wh_SetFunctionHook((void*)GetProcAddress(LoadLibrary(L"kernelbase.dll"), "GetModuleFileNameW"), (void*)HookedGetModuleFileNameW, (void**)&pOriginalGetModuleFileNameW); + + return TRUE; +} + +// The mod is being unloaded, free all allocated resources. +void Wh_ModUninit() { + Wh_Log(L"Uninit"); +}