Last active
November 10, 2024 22:57
-
-
Save m417z/a3d01ec23bda410dea0354306525beb5 to your computer and use it in GitHub Desktop.
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 everything-hang-fix | |
// @name Everything hang fix | |
// @description A test fix for hanging explorer when opened via Everything | |
// @version 0.1 | |
// @author m417z | |
// @github https://github.com/m417z | |
// @twitter https://twitter.com/m417z | |
// @homepage https://m417z.com/ | |
// @include everything.exe | |
// @include everything64.exe | |
// @compilerOptions -lole32 | |
// ==/WindhawkMod== | |
// ==WindhawkModReadme== | |
/* | |
# Everything hang fix | |
*/ | |
// ==/WindhawkModReadme== | |
#include <shlobj.h> | |
#include <winscard.h> | |
#include <functional> | |
#include <memory> | |
using SHOpenFolderAndSelectItems_t = decltype(&SHOpenFolderAndSelectItems); | |
SHOpenFolderAndSelectItems_t SHOpenFolderAndSelectItems_Original; | |
HRESULT WINAPI SHOpenFolderAndSelectItems_Hook(LPCITEMIDLIST pidlFolder, | |
UINT cidl, | |
LPCITEMIDLIST* apidl, | |
DWORD dwFlags) { | |
Wh_Log(L"SHOpenFolderAndSelectItems_Hook"); | |
LPITEMIDLIST pidlFolderCopy = ILClone(pidlFolder); | |
LPITEMIDLIST* apidlCopy = nullptr; | |
if (cidl) { | |
apidlCopy = new LPITEMIDLIST[cidl]; | |
for (UINT i = 0; i < cidl; i++) { | |
apidlCopy[i] = ILClone(apidl[i]); | |
} | |
} | |
auto threadProc = std::make_unique<std::function<DWORD()>>([=]() -> DWORD { | |
CoInitialize(nullptr); | |
SHOpenFolderAndSelectItems_Original(pidlFolderCopy, cidl, | |
(LPCITEMIDLIST*)apidlCopy, dwFlags); | |
ILFree(pidlFolderCopy); | |
for (UINT i = 0; i < cidl; i++) { | |
ILFree(apidlCopy[i]); | |
} | |
if (apidlCopy) { | |
delete[] apidlCopy; | |
} | |
CoUninitialize(); | |
return 0; | |
}); | |
HANDLE thread = CreateThread( | |
nullptr, 0, | |
[](LPVOID lpParam) WINAPI -> DWORD { | |
decltype(threadProc) proc{ | |
reinterpret_cast<decltype(threadProc.get())>(lpParam)}; | |
return (*proc)(); | |
}, | |
threadProc.release(), 0, nullptr); | |
if (thread) { | |
CloseHandle(thread); | |
} | |
return S_OK; | |
} | |
BOOL Wh_ModInit() { | |
Wh_Log(L"Init"); | |
Wh_SetFunctionHook((void*)SHOpenFolderAndSelectItems, | |
(void*)SHOpenFolderAndSelectItems_Hook, | |
(void**)&SHOpenFolderAndSelectItems_Original); | |
return TRUE; | |
} | |
void Wh_ModUninit() { | |
Wh_Log(L"Uninit"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment