From a8bd2909775ef6b37aef4302695b865b3add7fbe Mon Sep 17 00:00:00 2001 From: Amrsatrio Date: Sun, 1 Sep 2024 01:30:30 +0700 Subject: [PATCH] Taskbar10: Add support for loading ep_taskbar on Windows 10 1904x --- ExplorerPatcher/dllmain.c | 73 +++++++++++++++++++++++++++------------ ExplorerPatcher/utility.c | 8 ++--- ExplorerPatcher/utility.h | 21 ++++++++--- ep_setup/ep_setup.c | 1 + ep_startmenu/ep_sm_main.c | 2 +- 5 files changed, 72 insertions(+), 33 deletions(-) diff --git a/ExplorerPatcher/dllmain.c b/ExplorerPatcher/dllmain.c index 0e7e8e3..c4b6076 100644 --- a/ExplorerPatcher/dllmain.c +++ b/ExplorerPatcher/dllmain.c @@ -9944,10 +9944,6 @@ BOOL CheckExplorerSymbols(symbols_addr* symbols_PTRS) const WCHAR* GetTaskbarDllChecked(symbols_addr* symbols_PTRS) { - if (!IsWindows11Version22H2OrHigher()) - { - return NULL; - } const WCHAR* pszTaskbarDll = PickTaskbarDll(); if (!pszTaskbarDll) { @@ -10001,7 +9997,25 @@ HMODULE PrepareAlternateTaskbarImplementation(symbols_addr* symbols_PTRS, const return NULL; } - explorer_TrayUI_CreateInstanceFunc = GetProcAddress(hMyTaskbar, "EP_TrayUI_CreateInstance"); + TrayUI_CreateInstance_t pfnMyTrayUICreateInstance = (TrayUI_CreateInstance_t)GetProcAddress(hMyTaskbar, "EP_TrayUI_CreateInstance"); + if (IsWindows11()) + { + explorer_TrayUI_CreateInstanceFunc = pfnMyTrayUICreateInstance; + } + else if (explorer_TrayUI_CreateInstanceFunc) + { + funchook_prepare( + funchook, + (void**)&explorer_TrayUI_CreateInstanceFunc, + pfnMyTrayUICreateInstance + ); + } + else + { + printf("[TB] Failed to hook TrayUI_CreateInstance()\n"); + FreeLibrary(hMyTaskbar); + return NULL; + } typedef void (*CopyExplorerSymbols_t)(symbols_addr* symbols); CopyExplorerSymbols_t CopyExplorerSymbols = (CopyExplorerSymbols_t)GetProcAddress(hMyTaskbar, "CopyExplorerSymbols"); @@ -10603,8 +10617,8 @@ DWORD Inject(BOOL bIsExplorer) { // Find pointers to various stuff needed to have a working Windows 10 taskbar and Windows 10 taskbar context menu on Windows 11 taskbar #if defined(_M_X64) - // 4C 8D 05 ? ? ? ? 48 8D 0D ? ? ? ? E8 ? ? ? ? 48 8B - // ^^^^^^^ ^^^^^^^ + // 4C 8D 05 ?? ?? ?? ?? 48 8D 0D ?? ?? ?? ?? E8 ?? ?? ?? ?? 48 8B + // ^^^^^^^^^^^ ^^^^^^^^^^^ // Ref: CTray::Init() PBYTE match = FindPattern( hExplorer, @@ -10615,29 +10629,42 @@ DWORD Inject(BOOL bIsExplorer) if (match) { match += 7; // Point to 48 - g_pTrayUIHost = match + 7 + *(int*)(match + 3); + g_pTrayUIHost = (ITrayUIHost*)(match + 7 + *(int*)(match + 3)); match += 7; // Point to E8 - explorer_TrayUI_CreateInstanceFunc = match + 5 + *(int*)(match + 1); + explorer_TrayUI_CreateInstanceFunc = (TrayUI_CreateInstance_t)(match + 5 + *(int*)(match + 1)); } #elif defined(_M_ARM64) // TODO Add support for ARM64 #endif - if (g_pTrayUIHost) + } + else + { +#if defined(_M_X64) + // 4C 8D 05 ?? ?? ?? ?? 48 8D 0D ?? ?? ?? ?? E8 ?? ?? ?? ?? 85 C0 + // ^^^^^^^^^^^ ^^^^^^^^^^^ + // Ref: CTray::Init() + PBYTE match = FindPattern( + hExplorer, + miExplorer.SizeOfImage, + "\x4C\x8D\x05\x00\x00\x00\x00\x48\x8D\x0D\x00\x00\x00\x00\xE8\x00\x00\x00\x00\x85\xC0", + "xxx????xxx????x????xx" + ); + if (match) { - printf("ITrayUIHost = %llX\n", (PBYTE)g_pTrayUIHost - (PBYTE)hExplorer); - } - else - { - printf("Failed to find ITrayUIHost\n"); - } - if (explorer_TrayUI_CreateInstanceFunc) // TODO This does not exist anymore in 26244+ - { - printf("explorer.exe!TrayUI_CreateInstance() = %llX\n", (PBYTE)explorer_TrayUI_CreateInstanceFunc - (PBYTE)hExplorer); - } - else - { - printf("Failed to find explorer.exe!TrayUI_CreateInstance()\n"); + match += 7; // Point to 48 + g_pTrayUIHost = (ITrayUIHost*)(match + 7 + *(int*)(match + 3)); + match += 7; // Point to E8 + explorer_TrayUI_CreateInstanceFunc = (TrayUI_CreateInstance_t)(match + 5 + *(int*)(match + 1)); } +#endif + } + if (g_pTrayUIHost) + { + printf("ITrayUIHost = %llX\n", (PBYTE)g_pTrayUIHost - (PBYTE)hExplorer); + } + if (explorer_TrayUI_CreateInstanceFunc) + { + printf("explorer.exe!TrayUI_CreateInstance() = %llX\n", (PBYTE)explorer_TrayUI_CreateInstanceFunc - (PBYTE)hExplorer); } // Enable Windows 10 taskbar search box on 22621+ diff --git a/ExplorerPatcher/utility.c b/ExplorerPatcher/utility.c index 2fc0491..e247350 100644 --- a/ExplorerPatcher/utility.c +++ b/ExplorerPatcher/utility.c @@ -13,6 +13,7 @@ void printf_guid(GUID guid) guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]); } +#ifdef _DEBUG LRESULT CALLBACK BalloonWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { if (msg == WM_CREATE) @@ -82,7 +83,6 @@ __declspec(dllexport) int CALLBACK ZZTestBalloon(HWND hWnd, HINSTANCE hInstance, return 0; } -#ifdef _DEBUG const wchar_t TestToastXML[] = L"\r\n" @@ -138,7 +138,7 @@ __declspec(dllexport) int CALLBACK ZZTestToast(HWND hWnd, HINSTANCE hInstance, L } #endif -__declspec(dllexport) int CALLBACK ZZLaunchExplorer(HWND hWnd, HINSTANCE hInstance, LPSTR lpszCmdLine, int nCmdShow) +/*__declspec(dllexport)*/ int CALLBACK ZZLaunchExplorer(HWND hWnd, HINSTANCE hInstance, LPSTR lpszCmdLine, int nCmdShow) { Sleep(100); TCHAR wszExplorerPath[MAX_PATH + 1]; @@ -170,14 +170,14 @@ __declspec(dllexport) int CALLBACK ZZLaunchExplorer(HWND hWnd, HINSTANCE hInstan return 0; } -__declspec(dllexport) int CALLBACK ZZLaunchExplorerDelayed(HWND hWnd, HINSTANCE hInstance, LPSTR lpszCmdLine, int nCmdShow) +/*__declspec(dllexport)*/ int CALLBACK ZZLaunchExplorerDelayed(HWND hWnd, HINSTANCE hInstance, LPSTR lpszCmdLine, int nCmdShow) { Sleep(2000); ZZLaunchExplorer(hWnd, hInstance, lpszCmdLine, nCmdShow); return 0; } -__declspec(dllexport) int CALLBACK ZZRestartExplorer(HWND hWnd, HINSTANCE hInstance, LPSTR lpszCmdLine, int nCmdShow) +/*__declspec(dllexport)*/ int CALLBACK ZZRestartExplorer(HWND hWnd, HINSTANCE hInstance, LPSTR lpszCmdLine, int nCmdShow) { BeginExplorerRestart(NULL); FinishExplorerRestart(); diff --git a/ExplorerPatcher/utility.h b/ExplorerPatcher/utility.h index d868402..9314cda 100644 --- a/ExplorerPatcher/utility.h +++ b/ExplorerPatcher/utility.h @@ -104,7 +104,8 @@ DEFINE_GUID(IID_ITrayUIComponent, 0x64, 0xb4, 0xc0, 0x9b, 0x21, 0x1b ); -EP_INLINE HRESULT(*explorer_TrayUI_CreateInstanceFunc)(ITrayUIHost* host, REFIID riid, void** ppv); +typedef HRESULT(*TrayUI_CreateInstance_t)(ITrayUIHost* host, REFIID riid, void** ppv); +EP_INLINE TrayUI_CreateInstance_t explorer_TrayUI_CreateInstanceFunc; #pragma endregion inline int FileExistsW(wchar_t* file) @@ -122,19 +123,19 @@ inline int FileExistsW(wchar_t* file) // https://stackoverflow.com/questions/1672677/print-a-guid-variable void printf_guid(GUID guid); +#ifdef _DEBUG LRESULT CALLBACK BalloonWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); __declspec(dllexport) int CALLBACK ZZTestBalloon(HWND hWnd, HINSTANCE hInstance, LPSTR lpszCmdLine, int nCmdShow); -#ifdef _DEBUG __declspec(dllexport) int CALLBACK ZZTestToast(HWND hWnd, HINSTANCE hInstance, LPSTR lpszCmdLine, int nCmdShow); #endif -__declspec(dllexport) int CALLBACK ZZLaunchExplorer(HWND hWnd, HINSTANCE hInstance, LPSTR lpszCmdLine, int nCmdShow); +/*__declspec(dllexport)*/ int CALLBACK ZZLaunchExplorer(HWND hWnd, HINSTANCE hInstance, LPSTR lpszCmdLine, int nCmdShow); -__declspec(dllexport) int CALLBACK ZZLaunchExplorerDelayed(HWND hWnd, HINSTANCE hInstance, LPSTR lpszCmdLine, int nCmdShow); +/*__declspec(dllexport)*/ int CALLBACK ZZLaunchExplorerDelayed(HWND hWnd, HINSTANCE hInstance, LPSTR lpszCmdLine, int nCmdShow); -__declspec(dllexport) int CALLBACK ZZRestartExplorer(HWND hWnd, HINSTANCE hInstance, LPSTR lpszCmdLine, int nCmdShow); +/*__declspec(dllexport)*/ int CALLBACK ZZRestartExplorer(HWND hWnd, HINSTANCE hInstance, LPSTR lpszCmdLine, int nCmdShow); #define MIN(X, Y) (((X) < (Y)) ? (X) : (Y)) #define MAX(X, Y) (((X) > (Y)) ? (X) : (Y)) @@ -941,6 +942,16 @@ inline const WCHAR* PickTaskbarDll() { DWORD b = global_rovi.dwBuildNumber; + if (b >= 19041 && b <= 19045) // Windows 10 20H2, 21H2, 22H2 + { + return L"ep_taskbar.0.dll"; + } + + if (b >= 21343 && b <= 22000) // Windows 11 21H2 + { + return L"ep_taskbar.1.dll"; + } + if ((b >= 22621 && b <= 22635) // 22H2-23H2 Release, Release Preview, and Beta channels || (b >= 23403 && b <= 25197)) // Early pre-reboot Dev channel until post-reboot Dev channel { diff --git a/ep_setup/ep_setup.c b/ep_setup/ep_setup.c index cd1da49..ce49087 100644 --- a/ep_setup/ep_setup.c +++ b/ep_setup/ep_setup.c @@ -825,6 +825,7 @@ BOOL DownloadResource(BOOL bInstall, LPCWSTR pwszURL, DWORD dwSize, LPCSTR chash void ProcessTaskbarDlls(BOOL* bInOutOk, BOOL bInstall, BOOL bExtractMode, HINSTANCE hInstance, unzFile zipFile, WCHAR wszPath[260]) { LPCWSTR pwszTaskbarDllName = bExtractMode ? NULL : PickTaskbarDll(); + if (*bInOutOk) *bInOutOk = InstallResource(bInstall && (bExtractMode || pwszTaskbarDllName && !wcscmp(pwszTaskbarDllName, L"ep_taskbar.0.dll")), hInstance, zipFile, "ep_taskbar.0.dll", wszPath, L"ep_taskbar.0.dll"); if (*bInOutOk) *bInOutOk = InstallResource(bInstall && (bExtractMode || pwszTaskbarDllName && !wcscmp(pwszTaskbarDllName, L"ep_taskbar.2.dll")), hInstance, zipFile, "ep_taskbar.2.dll", wszPath, L"ep_taskbar.2.dll"); if (*bInOutOk) *bInOutOk = InstallResource(bInstall && (bExtractMode || pwszTaskbarDllName && !wcscmp(pwszTaskbarDllName, L"ep_taskbar.3.dll")), hInstance, zipFile, "ep_taskbar.3.dll", wszPath, L"ep_taskbar.3.dll"); if (*bInOutOk) *bInOutOk = InstallResource(bInstall && (bExtractMode || pwszTaskbarDllName && !wcscmp(pwszTaskbarDllName, L"ep_taskbar.4.dll")), hInstance, zipFile, "ep_taskbar.4.dll", wszPath, L"ep_taskbar.4.dll"); diff --git a/ep_startmenu/ep_sm_main.c b/ep_startmenu/ep_sm_main.c index 811dca5..90389d2 100644 --- a/ep_startmenu/ep_sm_main.c +++ b/ep_startmenu/ep_sm_main.c @@ -82,7 +82,7 @@ void PatchXamlMetaDataProviderGuid() PIMAGE_NT_HEADERS64 ntHeader = (PIMAGE_NT_HEADERS64)((u_char*)dosHeader + dosHeader->e_lfanew); if (ntHeader->Signature == IMAGE_NT_SIGNATURE) { - PIMAGE_SECTION_HEADER firstSection = IMAGE_FIRST_SECTION(ntHeader); + PIMAGE_SECTION_HEADER firstSection = IMAGE_FIRST_SECTION(ntHeader); for (unsigned int i = 0; i < ntHeader->FileHeader.NumberOfSections; ++i) { PIMAGE_SECTION_HEADER section = firstSection + i;