-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create fake-explorer-path.wh.cpp (#915)
* Create fake-explorer-path.wh.cpp * Update fake-explorer-path.wh.cpp
- Loading branch information
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <windhawk_api.h> | ||
#include <windows.h> | ||
|
||
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"); | ||
} |