Created
April 13, 2024 01:09
-
-
Save polkaulfield/9b5c50af9081ba22e8765d40dd54c080 to your computer and use it in GitHub Desktop.
Testing stuff...
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
// ==WindhawkMod== | |
// @id icon-changer-alpha | |
// @name icon-changer-alpha | |
// @description Testing changing icons in memory | |
// @version 0.1 | |
// @author You | |
// @github https://github.com/nat | |
// @twitter https://twitter.com/jack | |
// @homepage https://your-personal-homepage.example.com/ | |
// @include explorer.exe | |
// ==/WindhawkMod== | |
// ==WindhawkModReadme== | |
/* | |
# load-icon-changer-alpha | |
*/ | |
// ==/WindhawkModReadme== | |
constexpr int nDlls = 5; | |
constexpr WCHAR kDllOriginalArr[nDlls][40] = { | |
LR"(C:\Windows\System32\imageres.dll)", | |
LR"(C:\Windows\System32\imagesp1.dll)", | |
LR"(C:\Windows\System32\shell32.dll)", | |
LR"(C:\Windows\System32\themecpl.dll)", | |
LR"(C:\Windows\System32\zipfldr.dll)", | |
}; | |
constexpr WCHAR kDllReplacedArr[nDlls][40] = { | |
LR"(C:\MUNs\imageres.dll.mun)", | |
LR"(C:\MUNs\imagesp1.dll.mun)", | |
LR"(C:\MUNs\shell32.dll.mun)", | |
LR"(C:\MUNs\themecpl.dll.mun)", | |
LR"(C:\MUNs\zipfldr.dll.mun)", | |
}; | |
using LoadLibraryExW_t = decltype(&LoadLibraryExW); | |
LoadLibraryExW_t LoadLibraryExW_Original; | |
HMODULE WINAPI LoadLibraryExW_Hook(LPCWSTR lpLibFileName, | |
HANDLE hFile, | |
DWORD dwFlags) { | |
/* | |
Wh_Log(L"> %s", lpLibFileName); | |
if (dwFlags & | |
(LOAD_LIBRARY_AS_DATAFILE | LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE | | |
LOAD_LIBRARY_AS_IMAGE_RESOURCE) && | |
_wcsicmp(lpLibFileName, kDllOriginal) == 0) { | |
Wh_Log(L"%s -> %s", lpLibFileName, kDllReplaced); | |
lpLibFileName = kDllReplaced; | |
} | |
*/ | |
return LoadLibraryExW_Original(lpLibFileName, hFile, dwFlags); | |
} | |
using PrivateExtractIconsW_t = decltype(&PrivateExtractIconsW); | |
PrivateExtractIconsW_t PrivateExtractIconsW_Original; | |
UINT WINAPI PrivateExtractIconsW_Hook(LPCWSTR szFileName, | |
int nIconIndex, | |
int cxIcon, | |
int cyIcon, | |
HICON* phicon, | |
UINT* piconid, | |
UINT nIcons, | |
UINT flags) { | |
Wh_Log(L"> %s", szFileName); | |
for (int i = 0; i < nDlls; i++) { | |
if (_wcsicmp(szFileName, kDllOriginalArr[i]) == 0) { | |
Wh_Log(L"%s -> %s", szFileName, kDllReplacedArr[i]); | |
szFileName = kDllReplacedArr[i]; | |
} | |
} | |
return PrivateExtractIconsW_Original(szFileName, nIconIndex, cxIcon, cyIcon, | |
phicon, piconid, nIcons, flags); | |
} | |
void LoadSettings() { | |
// ... | |
} | |
BOOL Wh_ModInit() { | |
Wh_Log(L">"); | |
LoadSettings(); | |
auto* pLoadLibraryExW = | |
GetProcAddress(GetModuleHandle(L"kernelbase.dll"), "LoadLibraryExW"); | |
if (!pLoadLibraryExW) { | |
Wh_Log(L"LoadLibraryExW not found"); | |
return FALSE; | |
} | |
Wh_SetFunctionHook((void*)LoadLibraryExW, (void*)LoadLibraryExW_Hook, | |
(void**)&LoadLibraryExW_Original); | |
auto* pPrivateExtractIconsW = | |
GetProcAddress(GetModuleHandle(L"user32.dll"), "PrivateExtractIconsW"); | |
if (!pPrivateExtractIconsW) { | |
Wh_Log(L"PrivateExtractIconsW not found"); | |
return FALSE; | |
} | |
Wh_SetFunctionHook((void*)PrivateExtractIconsW, | |
(void*)PrivateExtractIconsW_Hook, | |
(void**)&PrivateExtractIconsW_Original); | |
return TRUE; | |
} | |
void Wh_ModUninit() { | |
Wh_Log(L">"); | |
} | |
void Wh_ModSettingsChanged() { | |
Wh_Log(L">"); | |
LoadSettings(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment