From dca0b3ae44269f4174cb5869a84057035867bfc3 Mon Sep 17 00:00:00 2001 From: Amrsatrio Date: Tue, 10 Oct 2023 20:15:59 +0700 Subject: [PATCH 1/5] Taskbar10: Made the Control Center and Toast Center positioning patch work with build 25951 (Canary) --- ExplorerPatcher/ImmersiveFlyouts.c | 23 +++++++++--------- ExplorerPatcher/ImmersiveFlyouts.h | 14 ++++++++--- ExplorerPatcher/dllmain.c | 39 +++++++++++++++++++----------- 3 files changed, 47 insertions(+), 29 deletions(-) diff --git a/ExplorerPatcher/ImmersiveFlyouts.c b/ExplorerPatcher/ImmersiveFlyouts.c index d66c4a194..dbbe1cc9b 100644 --- a/ExplorerPatcher/ImmersiveFlyouts.c +++ b/ExplorerPatcher/ImmersiveFlyouts.c @@ -56,7 +56,7 @@ void InvokeActionCenter() } } -void InvokeFlyout(BOOL bAction, DWORD dwWhich) +HRESULT InvokeFlyoutRect(BOOL bAction, DWORD dwWhich, __x_ABI_CWindows_CFoundation_CRect* pRc) { HRESULT hr = S_OK; IUnknown* pImmersiveShell = NULL; @@ -70,13 +70,13 @@ void InvokeFlyout(BOOL bAction, DWORD dwWhich) if (SUCCEEDED(hr)) { IShellExperienceManagerFactory* pShellExperienceManagerFactory = NULL; - IUnknown_QueryService( + hr = IUnknown_QueryService( pImmersiveShell, &CLSID_ShellExperienceManagerFactory, &CLSID_ShellExperienceManagerFactory, &pShellExperienceManagerFactory ); - if (pShellExperienceManagerFactory) + if (SUCCEEDED(hr)) { HSTRING_HEADER hstringHeader; HSTRING hstring = NULL; @@ -102,18 +102,18 @@ void InvokeFlyout(BOOL bAction, DWORD dwWhich) &hstringHeader, &hstring ); - if (hstring) + if (SUCCEEDED(hr)) { IUnknown* pIntf = NULL; - pShellExperienceManagerFactory->lpVtbl->GetExperienceManager( + hr = pShellExperienceManagerFactory->lpVtbl->GetExperienceManager( pShellExperienceManagerFactory, hstring, &pIntf ); - if (pIntf) + if (SUCCEEDED(hr)) { IExperienceManager* pExperienceManager = NULL; - pIntf->lpVtbl->QueryInterface( + hr = pIntf->lpVtbl->QueryInterface( pIntf, dwWhich == INVOKE_FLYOUT_NETWORK ? &IID_NetworkFlyoutExperienceManager : (dwWhich == INVOKE_FLYOUT_CLOCK ? &IID_TrayClockFlyoutExperienceManager : @@ -121,17 +121,15 @@ void InvokeFlyout(BOOL bAction, DWORD dwWhich) (dwWhich == INVOKE_FLYOUT_SOUND ? &IID_TrayMtcUvcFlyoutExperienceManager : &IID_IUnknown))), &pExperienceManager ); - if (pExperienceManager) + if (SUCCEEDED(hr)) { - RECT rc; - SetRect(&rc, 0, 0, 0, 0); if (bAction == INVOKE_FLYOUT_SHOW) { - pExperienceManager->lpVtbl->ShowFlyout(pExperienceManager, &rc, NULL); + hr = pExperienceManager->lpVtbl->ShowFlyout(pExperienceManager, pRc); } else if (bAction == INVOKE_FLYOUT_HIDE) { - pExperienceManager->lpVtbl->HideFlyout(pExperienceManager); + hr = pExperienceManager->lpVtbl->HideFlyout(pExperienceManager); } pExperienceManager->lpVtbl->Release(pExperienceManager); } @@ -143,4 +141,5 @@ void InvokeFlyout(BOOL bAction, DWORD dwWhich) } pImmersiveShell->lpVtbl->Release(pImmersiveShell); } + return hr; } diff --git a/ExplorerPatcher/ImmersiveFlyouts.h b/ExplorerPatcher/ImmersiveFlyouts.h index 947320f16..d36d6358a 100644 --- a/ExplorerPatcher/ImmersiveFlyouts.h +++ b/ExplorerPatcher/ImmersiveFlyouts.h @@ -57,8 +57,7 @@ typedef struct IExperienceManagerVtbl // : IInspectable HRESULT(STDMETHODCALLTYPE* ShowFlyout)( IExperienceManager* This, - /* [in] */ RECT* rect, - /* [in] */ HWND hWnd); + /* [in] */ __x_ABI_CWindows_CFoundation_CRect* rect); HRESULT(STDMETHODCALLTYPE* HideFlyout)( IExperienceManager* This); @@ -192,5 +191,14 @@ void InvokeActionCenter(); #define INVOKE_FLYOUT_CLOCK 2 #define INVOKE_FLYOUT_BATTERY 3 #define INVOKE_FLYOUT_SOUND 4 -void InvokeFlyout(BOOL bAction, DWORD dwWhich); + +HRESULT InvokeFlyoutRect(BOOL bAction, DWORD dwWhich, __x_ABI_CWindows_CFoundation_CRect* pRc); + +inline HRESULT InvokeFlyout(BOOL bAction, DWORD dwWhich) +{ + __x_ABI_CWindows_CFoundation_CRect rc; + ZeroMemory(&rc, sizeof(rc)); + return InvokeFlyoutRect(bAction, dwWhich, &rc); +} + #endif \ No newline at end of file diff --git a/ExplorerPatcher/dllmain.c b/ExplorerPatcher/dllmain.c index 4115891c7..23e062c44 100644 --- a/ExplorerPatcher/dllmain.c +++ b/ExplorerPatcher/dllmain.c @@ -10009,10 +10009,10 @@ BOOL Moment2PatchControlCenter(LPMODULEINFO mi) { // Step 1: // Scan within the DLL for `rcMonitor = mi.rcMonitor`. - // ```0F 10 44 24 ?? F3 0F 7F 44 24 ?? 80 BF // movups - movdqu - cmp``` + // ```0F 10 44 24 ?? F3 0F 7F 44 24 ?? 80 // movups - movdqu - cmp``` // 22621.1992: 4B35B // 22621.2283: 65C5C - PBYTE rcMonitorAssignment = FindPattern(mi->lpBaseOfDll, mi->SizeOfImage, "\x0F\x10\x44\x24\x00\xF3\x0F\x7F\x44\x24\x00\x80\xBF", "xxxx?xxxxx?xx"); + PBYTE rcMonitorAssignment = FindPattern(mi->lpBaseOfDll, mi->SizeOfImage, "\x0F\x10\x44\x24\x00\xF3\x0F\x7F\x44\x24\x00\x80", "xxxx?xxxxx?x"); if (!rcMonitorAssignment) return FALSE; printf("[CC] rcMonitorAssignment = %llX\n", rcMonitorAssignment - (PBYTE)mi->lpBaseOfDll); @@ -10066,11 +10066,23 @@ BOOL Moment2PatchToastCenter(LPMODULEINFO mi) { // Step 1: // Scan within the DLL for `rcMonitor = mi.rcMonitor`. - // ```0F 10 45 84 ?? 0F 7F 44 24 ?? 48 8B CF // movups - movdqu - mov``` + // + // Pattern 1: + // Will have a match if CToastCenterExperienceManager::ShouldShowWithinWorkArea() is present. + // ```0F 10 45 ?? ?? 0F 7F 44 24 ?? 48 8B CF // movups - movdqu - mov``` // 22621.1992: 40CE8 // 22621.2283: 501DB - PBYTE rcMonitorAssignment = FindPattern(mi->lpBaseOfDll, mi->SizeOfImage, "\x0F\x10\x45\x84\x00\x0F\x7F\x44\x24\x00\x48\x8B\xCF", "xxxx?xxxx?xxx"); - if (!rcMonitorAssignment) return FALSE; + // + // Pattern 2: + // Will have a match if CToastCenterExperienceManager::ShouldShowWithinWorkArea() is inlined. + // ```0F 10 45 ?? ?? 0F 7F 44 24 ?? 44 // movups - movdqu - cmp``` + // 25951.1000: 36B2C4 + PBYTE rcMonitorAssignment = FindPattern(mi->lpBaseOfDll, mi->SizeOfImage, "\x0F\x10\x45\x00\x00\x0F\x7F\x44\x24\x00\x48\x8B\xCF", "xxx??xxxx?xxx"); + if (!rcMonitorAssignment) + { + rcMonitorAssignment = FindPattern(mi->lpBaseOfDll, mi->SizeOfImage, "\x0F\x10\x45\x00\x00\x0F\x7F\x44\x24\x00\x44", "xxx??xxxx?x"); + if (!rcMonitorAssignment) return FALSE; + } printf("[TC] rcMonitorAssignment = %llX\n", rcMonitorAssignment - (PBYTE)mi->lpBaseOfDll); // Step 2: @@ -10266,12 +10278,11 @@ void WINAPI HardwareConfirmatorShellcode(PBYTE pCoroInstance) hr = pTheFunc(pEdgeUiManager, &rc); } - typedef struct { float x, y, width, height; } Windows_Foundation_Rect; - Windows_Foundation_Rect* out = pCoroInstance + g_Moment2PatchOffsets.coroInstance_rcOut; - out->x = (float)rc.left; - out->y = (float)rc.top; - out->width = (float)(rc.right - rc.left); - out->height = (float)(rc.bottom - rc.top); + __x_ABI_CWindows_CFoundation_CRect* out = pCoroInstance + g_Moment2PatchOffsets.coroInstance_rcOut; + out->X = (float)rc.left; + out->Y = (float)rc.top; + out->Width = (float)(rc.right - rc.left); + out->Height = (float)(rc.bottom - rc.top); pEdgeUiManager->lpVtbl->Release(pEdgeUiManager); } @@ -11057,13 +11068,13 @@ DWORD Inject(BOOL bIsExplorer) { // Find a pointer to ITrayUIHost needed to have a working Windows 10 taskbar context menu on Windows 11 taskbar // Ref: CTray::Init() - // 4C 8D 05 ? ? ? ? 48 8D 0D ? ? ? ? E8 ? ? ? ? 48 8B 8D + // 4C 8D 05 ? ? ? ? 48 8D 0D ? ? ? ? E8 ? ? ? ? 48 8B // ^^^^^^^ 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\x48\x8B\x8D", - "xxx????xxx????x????xxx" + "\x4C\x8D\x05\x00\x00\x00\x00\x48\x8D\x0D\x00\x00\x00\x00\xE8\x00\x00\x00\x00\x48\x8B", + "xxx????xxx????x????xx" ); if (match) { From b52bd790ed36a337b8b11109eae58ce079a0e4dd Mon Sep 17 00:00:00 2001 From: Amrsatrio Date: Tue, 10 Oct 2023 21:52:15 +0700 Subject: [PATCH 2/5] Taskbar10: Fixed `PatchExplorer_UpdateWindowAccentProperties` to not crash anymore with build 25951 (Canary) --- ExplorerPatcher/dllmain.c | 58 +++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/ExplorerPatcher/dllmain.c b/ExplorerPatcher/dllmain.c index 23e062c44..957440128 100644 --- a/ExplorerPatcher/dllmain.c +++ b/ExplorerPatcher/dllmain.c @@ -9345,11 +9345,11 @@ void PatchExplorer_UpdateWindowAccentProperties() PIMAGE_NT_HEADERS64 ntHeader = (PIMAGE_NT_HEADERS64)((u_char*)dosHeader + dosHeader->e_lfanew); if (ntHeader->Signature == IMAGE_NT_SIGNATURE) { - char* pPatchArea = NULL; + PBYTE pPatchArea = NULL; // test al, al; jz rip+0x11; and ... - char p1[] = { 0x84, 0xC0, 0x74, 0x11, 0x83, 0x65 }; - char p2[] = { 0xF3, 0xF3, 0xF3, 0xFF }; - char* pattern1 = p1; + BYTE p1[] = { 0x84, 0xC0, 0x74, 0x11, 0x83, 0x65 }; + BYTE p2[] = { 0xF3, 0xF3, 0xF3, 0xFF }; + PBYTE pattern1 = p1; int sizeof_pattern1 = 6; if (global_rovi.dwBuildNumber >= 22581) { @@ -9364,12 +9364,13 @@ void PatchExplorer_UpdateWindowAccentProperties() { if (section->SizeOfRawData && !bTwice) { - char* pCandidate = NULL; + PBYTE pSectionBegin = (PBYTE)hExplorer + section->VirtualAddress; + PBYTE pCandidate = NULL; while (TRUE) { pCandidate = memmem( - !pCandidate ? hExplorer + section->VirtualAddress : pCandidate, - !pCandidate ? section->SizeOfRawData : (uintptr_t)section->SizeOfRawData - (uintptr_t)(pCandidate - (hExplorer + section->VirtualAddress)), + !pCandidate ? pSectionBegin : pCandidate, + !pCandidate ? section->SizeOfRawData : (uintptr_t)section->SizeOfRawData - (uintptr_t)(pCandidate - pSectionBegin), pattern1, sizeof_pattern1 ); @@ -9399,8 +9400,9 @@ void PatchExplorer_UpdateWindowAccentProperties() _DecodedInst* decodedInstructions = calloc(110, sizeof(_DecodedInst)); if (decodedInstructions) { + PBYTE diasmBegin = pPatchArea - dec_size; unsigned int decodedInstructionsCount = 0; - _DecodeResult res = distorm_decode(0, (const unsigned char*)(pPatchArea - dec_size), dec_size + 20, Decode64Bits, decodedInstructions, 100, &decodedInstructionsCount); + _DecodeResult res = distorm_decode(0, diasmBegin, dec_size + 20, Decode64Bits, decodedInstructions, 100, &decodedInstructionsCount); int status = 0; for (int i = decodedInstructionsCount - 1; i >= 0; i--) { @@ -9414,7 +9416,7 @@ void PatchExplorer_UpdateWindowAccentProperties() } else if (status == 2 && strcmp(decodedInstructions[i].instructionHex.p, "cc")) { - GetTaskbarColor = pPatchArea - dec_size + decodedInstructions[i].offset; + GetTaskbarColor = diasmBegin + decodedInstructions[i].offset; status = 3; } else if (status == 3 && !strncmp(decodedInstructions[i].instructionHex.p, "e8", 2)) @@ -9423,8 +9425,8 @@ void PatchExplorer_UpdateWindowAccentProperties() } else if (status == 4 && !strncmp(decodedInstructions[i].instructionHex.p, "e8", 2)) { - uint32_t* off = pPatchArea - dec_size + decodedInstructions[i].offset + 1; - GetTaskbarTheme = pPatchArea - dec_size + decodedInstructions[i].offset + decodedInstructions[i].size + (*off); + uint32_t* off = diasmBegin + decodedInstructions[i].offset + 1; + GetTaskbarTheme = diasmBegin + decodedInstructions[i].offset + decodedInstructions[i].size + (*off); break; } if (status >= 2) @@ -11059,10 +11061,7 @@ DWORD Inject(BOOL bIsExplorer) if (bOldTaskbar && global_rovi.dwBuildNumber >= 22572) { VnPatchIAT(hExplorer, "dwmapi.dll", "DwmUpdateThumbnailProperties", explorer_DwmUpdateThumbnailPropertiesHook); - if (global_rovi.dwBuildNumber < 25000) // TODO Needs fixing in Canary - { - PatchExplorer_UpdateWindowAccentProperties(); - } + PatchExplorer_UpdateWindowAccentProperties(); } if (IsWindows11()) { @@ -11280,12 +11279,12 @@ DWORD Inject(BOOL bIsExplorer) Moment2PatchHardwareConfirmator(&miHardwareConfirmator); // Fix pen menu - // 48 89 5C 24 ? 48 89 74 24 ? 57 48 83 EC 50 49 8B F0 48 81 C1 + // 48 89 5C 24 ? 48 89 74 24 ? 57 48 83 EC 50 49 8B ? 48 81 C1 twinui_pcshell_PenMenuSystemTrayManager__GetDynamicSystemTrayHeightForMonitorFunc = FindPattern( hTwinuiPcshell, miTwinuiPcshell.SizeOfImage, - "\x48\x89\x5C\x24\x00\x48\x89\x74\x24\x00\x57\x48\x83\xEC\x50\x49\x8B\xF0\x48\x81\xC1", - "xxxx?xxxx?xxxxxxxxxxx" + "\x48\x89\x5C\x24\x00\x48\x89\x74\x24\x00\x57\x48\x83\xEC\x50\x49\x8B\x00\x48\x81\xC1", + "xxxx?xxxx?xxxxxxx?xxx" ); rv = -1; if (twinui_pcshell_PenMenuSystemTrayManager__GetDynamicSystemTrayHeightForMonitorFunc) @@ -12992,8 +12991,8 @@ void InjectShellExperienceHost() PIMAGE_NT_HEADERS64 ntHeader = (PIMAGE_NT_HEADERS64)((u_char*)dosHeader + dosHeader->e_lfanew); if (ntHeader->Signature == IMAGE_NT_SIGNATURE) { - char* pSEHPatchArea = NULL; - char seh_pattern1[14] = + PBYTE pSEHPatchArea = NULL; + BYTE seh_pattern1[14] = { // mov al, 1 0xB0, 0x01, @@ -13012,8 +13011,8 @@ void InjectShellExperienceHost() // ret 0xC3 }; - char seh_off = 12; - char seh_pattern2[5] = + BYTE seh_off = 12; + BYTE seh_pattern2[5] = { // mov r8b, 3 0x41, 0xB0, 0x03, @@ -13028,14 +13027,15 @@ void InjectShellExperienceHost() { if (section->SizeOfRawData && !bTwice) { - DWORD dwOldProtect; - //VirtualProtect(hQA + section->VirtualAddress, section->SizeOfRawData, PAGE_EXECUTE_READWRITE, &dwOldProtect); - char* pCandidate = NULL; + PBYTE pSectionBegin = (PBYTE)hQA + section->VirtualAddress; + //DWORD dwOldProtect; + //VirtualProtect(pSectionBegin, section->SizeOfRawData, PAGE_EXECUTE_READWRITE, &dwOldProtect); + PBYTE pCandidate = NULL; while (TRUE) { pCandidate = memmem( - !pCandidate ? hQA + section->VirtualAddress : pCandidate, - !pCandidate ? section->SizeOfRawData : (uintptr_t)section->SizeOfRawData - (uintptr_t)(pCandidate - (hQA + section->VirtualAddress)), + !pCandidate ? pSectionBegin : pCandidate, + !pCandidate ? section->SizeOfRawData : (uintptr_t)section->SizeOfRawData - (uintptr_t)(pCandidate - pSectionBegin), seh_pattern1, sizeof(seh_pattern1) ); @@ -13043,7 +13043,7 @@ void InjectShellExperienceHost() { break; } - char* pCandidate2 = pCandidate - seh_off - sizeof(seh_pattern2); + PBYTE pCandidate2 = pCandidate - seh_off - sizeof(seh_pattern2); if (pCandidate2 > section->VirtualAddress) { if (memmem(pCandidate2, sizeof(seh_pattern2), seh_pattern2, sizeof(seh_pattern2))) @@ -13060,7 +13060,7 @@ void InjectShellExperienceHost() } pCandidate += sizeof(seh_pattern1); } - //VirtualProtect(hQA + section->VirtualAddress, section->SizeOfRawData, dwOldProtect, &dwOldProtect); + //VirtualProtect(pSectionBegin, section->SizeOfRawData, dwOldProtect, &dwOldProtect); } } section++; From 8412bd64d9ee5aaf4246a16364b0b6571c867697 Mon Sep 17 00:00:00 2001 From: Amrsatrio Date: Wed, 11 Oct 2023 15:10:02 +0700 Subject: [PATCH 3/5] Symbols: Reworked the symbol manager so that symbols don't need to be successfully downloaded in succession - This should fix start menu not working (at all!) on users who upgraded into 22621.2428 not through 22621.2361 with EP installed. Updating into this version will redownload symbols due to changes in the way they are managed. - 22621.2428 was just released to the general public, but symbols for twinui.pcshell.dll are not available at the time of writing. Despite that, StartDocked.dll and StartUI.dll are still the same as 22621.2361. - I've also removed hardcoded and stuffed-together offsets of really old DLL versions to make the code more concise. --- ExplorerPatcher/StartMenu.c | 4 +- ExplorerPatcher/dllmain.c | 226 +++--- ExplorerPatcher/symbols.c | 1513 +++++++++++------------------------ ExplorerPatcher/symbols.h | 16 +- ExplorerPatcher/utility.h | 10 +- 5 files changed, 615 insertions(+), 1154 deletions(-) diff --git a/ExplorerPatcher/StartMenu.c b/ExplorerPatcher/StartMenu.c index 981a721d0..a0f16912a 100644 --- a/ExplorerPatcher/StartMenu.c +++ b/ExplorerPatcher/StartMenu.c @@ -765,7 +765,7 @@ BOOL NeedsRo_PositionStartMenuForMonitor( return TRUE; } -DWORD GetStartMenuPosition(FARPROC SHRegGetValueFromHKCUHKLMFunc) +DWORD GetStartMenuPosition(t_SHRegGetValueFromHKCUHKLM SHRegGetValueFromHKCUHKLMFunc) { DWORD dwSize = sizeof(DWORD); @@ -776,7 +776,7 @@ DWORD GetStartMenuPosition(FARPROC SHRegGetValueFromHKCUHKLMFunc) SRRF_RT_REG_DWORD, NULL, &dwTaskbarAl, - (LPDWORD)(&dwSize) + &dwSize ) != ERROR_SUCCESS) { dwTaskbarAl = 1; diff --git a/ExplorerPatcher/dllmain.c b/ExplorerPatcher/dllmain.c index 957440128..81c3ceea7 100644 --- a/ExplorerPatcher/dllmain.c +++ b/ExplorerPatcher/dllmain.c @@ -164,7 +164,7 @@ DWORD dwSpotlightDesktopMenuMask = 0; DWORD dwSpotlightUpdateSchedule = 0; int Code = 0; HRESULT InjectStartFromExplorer(); -void InvokeClockFlyout(); +BOOL InvokeClockFlyout(); void WINAPI Explorer_RefreshUI(int unused); int (*SHWindowsPolicy)(REFIID); @@ -911,79 +911,79 @@ BOOL CALLBACK ToggleImmersiveCallback(HWND hWnd, LPARAM lParam) return TRUE; } -void ToggleHelp() +BOOL ToggleHelp() { - PostMessageW(FindWindowExW(NULL, NULL, L"Shell_TrayWnd", NULL), WM_HOTKEY, 505, 0); + return PostMessageW(FindWindowExW(NULL, NULL, L"Shell_TrayWnd", NULL), WM_HOTKEY, 505, 0); } -void ToggleRunDialog() +BOOL ToggleRunDialog() { - PostMessageW(FindWindowExW(NULL, NULL, L"Shell_TrayWnd", NULL), WM_HOTKEY, 502, MAKELPARAM(MOD_WIN, 0x52)); + return PostMessageW(FindWindowExW(NULL, NULL, L"Shell_TrayWnd", NULL), WM_HOTKEY, 502, MAKELPARAM(MOD_WIN, 0x52)); } -void ToggleSystemProperties() +BOOL ToggleSystemProperties() { - PostMessageW(FindWindowExW(NULL, NULL, L"Shell_TrayWnd", NULL), WM_HOTKEY, 512, 0); + return PostMessageW(FindWindowExW(NULL, NULL, L"Shell_TrayWnd", NULL), WM_HOTKEY, 512, 0); } -void FocusSystray() +BOOL FocusSystray() { - PostMessageW(FindWindowExW(NULL, NULL, L"Shell_TrayWnd", NULL), WM_HOTKEY, 514, 0); + return PostMessageW(FindWindowExW(NULL, NULL, L"Shell_TrayWnd", NULL), WM_HOTKEY, 514, 0); } -void TriggerAeroShake() +BOOL TriggerAeroShake() { - PostMessageW(FindWindowExW(NULL, NULL, L"Shell_TrayWnd", NULL), WM_HOTKEY, 515, 0); + return PostMessageW(FindWindowExW(NULL, NULL, L"Shell_TrayWnd", NULL), WM_HOTKEY, 515, 0); } -void PeekDesktop() +BOOL PeekDesktop() { - PostMessageW(FindWindowExW(NULL, NULL, L"Shell_TrayWnd", NULL), WM_HOTKEY, 516, 0); + return PostMessageW(FindWindowExW(NULL, NULL, L"Shell_TrayWnd", NULL), WM_HOTKEY, 516, 0); } -void ToggleEmojiPanel() +BOOL ToggleEmojiPanel() { - PostMessageW(FindWindowExW(NULL, NULL, L"Shell_TrayWnd", NULL), WM_HOTKEY, 579, 0); + return PostMessageW(FindWindowExW(NULL, NULL, L"Shell_TrayWnd", NULL), WM_HOTKEY, 579, 0); } -void ShowDictationPanel() +BOOL ShowDictationPanel() { - PostMessageW(FindWindowExW(NULL, NULL, L"Shell_TrayWnd", NULL), WM_HOTKEY, 577, 0); + return PostMessageW(FindWindowExW(NULL, NULL, L"Shell_TrayWnd", NULL), WM_HOTKEY, 577, 0); } -void ToggleClipboardViewer() +BOOL ToggleClipboardViewer() { - PostMessageW(FindWindowExW(NULL, NULL, L"Shell_TrayWnd", NULL), WM_HOTKEY, 578, 0); + return PostMessageW(FindWindowExW(NULL, NULL, L"Shell_TrayWnd", NULL), WM_HOTKEY, 578, 0); } -void ToggleSearch() +BOOL ToggleSearch() { - PostMessageW(FindWindowExW(NULL, NULL, L"Shell_TrayWnd", NULL), WM_HOTKEY, 507, MAKELPARAM(MOD_WIN, 0x53)); + return PostMessageW(FindWindowExW(NULL, NULL, L"Shell_TrayWnd", NULL), WM_HOTKEY, 507, MAKELPARAM(MOD_WIN, 0x53)); } -void ToggleTaskView() +BOOL ToggleTaskView() { - EnumThreadWindows(GetWindowThreadProcessId(FindWindowExW(NULL, NULL, L"ApplicationManager_ImmersiveShellWindow", NULL), NULL), ToggleImmersiveCallback, 11); + return EnumThreadWindows(GetWindowThreadProcessId(FindWindowExW(NULL, NULL, L"ApplicationManager_ImmersiveShellWindow", NULL), NULL), ToggleImmersiveCallback, 11); } -void ToggleWidgetsPanel() +BOOL ToggleWidgetsPanel() { - EnumThreadWindows(GetWindowThreadProcessId(FindWindowExW(NULL, NULL, L"ApplicationManager_ImmersiveShellWindow", NULL), NULL), ToggleImmersiveCallback, 0x66); + return EnumThreadWindows(GetWindowThreadProcessId(FindWindowExW(NULL, NULL, L"ApplicationManager_ImmersiveShellWindow", NULL), NULL), ToggleImmersiveCallback, 0x66); } -void ToggleMainClockFlyout() +BOOL ToggleMainClockFlyout() { - EnumThreadWindows(GetWindowThreadProcessId(FindWindowExW(NULL, NULL, L"ApplicationManager_ImmersiveShellWindow", NULL), NULL), ToggleImmersiveCallback, 0x6B); + return EnumThreadWindows(GetWindowThreadProcessId(FindWindowExW(NULL, NULL, L"ApplicationManager_ImmersiveShellWindow", NULL), NULL), ToggleImmersiveCallback, 0x6B); } -void ToggleNotificationsFlyout() +BOOL ToggleNotificationsFlyout() { - PostMessageW(FindWindowExW(NULL, NULL, L"Shell_TrayWnd", NULL), WM_HOTKEY, 591, 0); + return PostMessageW(FindWindowExW(NULL, NULL, L"Shell_TrayWnd", NULL), WM_HOTKEY, 591, 0); } -void ToggleActionCenter() +BOOL ToggleActionCenter() { - PostMessageW(FindWindowExW(NULL, NULL, L"Shell_TrayWnd", NULL), WM_HOTKEY, 500, MAKELPARAM(MOD_WIN, 0x41)); + return PostMessageW(FindWindowExW(NULL, NULL, L"Shell_TrayWnd", NULL), WM_HOTKEY, 500, MAKELPARAM(MOD_WIN, 0x41)); } #ifdef _WIN64 @@ -1734,7 +1734,7 @@ LONG_PTR __stdcall CTaskBtnGroup_GetIdealSpanHook(ITaskBtnGroup* _this, LONG_PTR return ret; } -void explorer_QISearch(void* that, LPCQITAB pqit, REFIID riid, void** ppv) +HRESULT explorer_QISearch(void* that, LPCQITAB pqit, REFIID riid, void** ppv) { HRESULT hr = QISearch(that, pqit, riid, ppv); if (SUCCEEDED(hr) && IsEqualGUID(pqit[0].piid, &IID_ITaskGroup) && bPinnedItemsActAsQuickLaunch) @@ -1907,6 +1907,8 @@ DWORD FixTaskbarAutohide(DWORD unused) } } SetEvent(hCanStartSws); + + return 0; } #endif #pragma endregion @@ -2871,7 +2873,7 @@ BOOL CheckIfMenuContainsOwnPropertiesItem(HMENU hMenu) mii.cbSize = sizeof(MENUITEMINFO); mii.fMask = MIIM_DATA | MIIM_ID; BOOL b = GetMenuItemInfoW(hMenu, i, TRUE, &mii); - if (b && (mii.wID >= 12000 && mii.wID <= 12200) && mii.dwItemData == CheckForUpdatesThread) + if (b && (mii.wID >= 12000 && mii.wID <= 12200) && mii.dwItemData == (ULONG_PTR)CheckForUpdatesThread) { return TRUE; } @@ -3064,33 +3066,6 @@ BOOL TrackPopupMenuHook( #define TB_POS_TOP 2 #define TB_POS_LEFT 3 #define TB_POS_RIGHT 4 -void PopupMenuAdjustCoordinatesAndFlags(int* x, int* y, UINT* uFlags) -{ - POINT pt; - GetCursorPos(&pt); - RECT rc; - UINT tbPos = GetTaskbarLocationAndSize(pt, &rc); - if (tbPos == TB_POS_BOTTOM) - { - *y = MIN(*y, rc.top); - *uFlags |= TPM_CENTERALIGN | TPM_BOTTOMALIGN; - } - else if (tbPos == TB_POS_TOP) - { - *y = MAX(*y, rc.bottom); - *uFlags |= TPM_CENTERALIGN | TPM_TOPALIGN; - } - else if (tbPos == TB_POS_LEFT) - { - *x = MAX(*x, rc.right); - *uFlags |= TPM_VCENTERALIGN | TPM_LEFTALIGN; - } - if (tbPos == TB_POS_RIGHT) - { - *x = MIN(*x, rc.left); - *uFlags |= TPM_VCENTERALIGN | TPM_RIGHTALIGN; - } -} UINT GetTaskbarLocationAndSize(POINT ptCursor, RECT* rc) { MONITORINFO mi; @@ -3127,6 +3102,33 @@ UINT GetTaskbarLocationAndSize(POINT ptCursor, RECT* rc) } return TB_POS_NOWHERE; } +void PopupMenuAdjustCoordinatesAndFlags(int* x, int* y, UINT* uFlags) +{ + POINT pt; + GetCursorPos(&pt); + RECT rc; + UINT tbPos = GetTaskbarLocationAndSize(pt, &rc); + if (tbPos == TB_POS_BOTTOM) + { + *y = MIN(*y, rc.top); + *uFlags |= TPM_CENTERALIGN | TPM_BOTTOMALIGN; + } + else if (tbPos == TB_POS_TOP) + { + *y = MAX(*y, rc.bottom); + *uFlags |= TPM_CENTERALIGN | TPM_TOPALIGN; + } + else if (tbPos == TB_POS_LEFT) + { + *x = MAX(*x, rc.right); + *uFlags |= TPM_VCENTERALIGN | TPM_LEFTALIGN; + } + if (tbPos == TB_POS_RIGHT) + { + *x = MIN(*x, rc.left); + *uFlags |= TPM_VCENTERALIGN | TPM_RIGHTALIGN; + } +} INT64 OwnerDrawSubclassProc( _In_ HWND hWnd, _In_ UINT uMsg, @@ -4131,7 +4133,7 @@ void ClockButton_ToggleFlyoutCallback( *((INT64*)params->TrayUIInstance + params->CLOCKBUTTON_OFFSET_IN_TRAYUI) = params->oldClockButtonInstance; free(params); } -void InvokeClockFlyout() +BOOL InvokeClockFlyout() { POINT ptCursor; GetCursorPos(&ptCursor); @@ -4174,14 +4176,13 @@ void InvokeClockFlyout() } else if (ShouldShowLegacyClockExperience() == 2) { - ToggleNotificationsFlyout(); - return 0; + return ToggleNotificationsFlyout(); } // On the main monitor, the TrayUI component of CTray handles this // message and basically does a `ClockButton::ToggleFlyout`; that's // the only place in code where that is used, otherwise, clicking and // dismissing the clock flyout probably involves 2 separate methods - PostMessageW(hShellTray_Wnd, WM_TOGGLE_CLOCK_FLYOUT, 0, 0); + return PostMessageW(hShellTray_Wnd, WM_TOGGLE_CLOCK_FLYOUT, 0, 0); } else { @@ -4227,8 +4228,7 @@ void InvokeClockFlyout() } else if (ShouldShowLegacyClockExperience() == 2) { - ToggleNotificationsFlyout(); - return 0; + return ToggleNotificationsFlyout(); } if (bOldTaskbar) { @@ -4259,15 +4259,16 @@ void InvokeClockFlyout() params->TrayUIInstance = TrayUIInstance; params->CLOCKBUTTON_OFFSET_IN_TRAYUI = CLOCKBUTTON_OFFSET_IN_TRAYUI; params->oldClockButtonInstance = oldClockButtonInstance; - SendMessageCallbackW(hShellTray_Wnd, WM_TOGGLE_CLOCK_FLYOUT, 0, 0, ClockButton_ToggleFlyoutCallback, params); + return SendMessageCallbackW(hShellTray_Wnd, WM_TOGGLE_CLOCK_FLYOUT, 0, 0, ClockButton_ToggleFlyoutCallback, params); } } else { - PostMessageW(hShellTray_Wnd, WM_TOGGLE_CLOCK_FLYOUT, 0, 0); + return PostMessageW(hShellTray_Wnd, WM_TOGGLE_CLOCK_FLYOUT, 0, 0); } } } + return FALSE; } INT64 winrt_Windows_Internal_Shell_implementation_MeetAndChatManager_OnMessageHook( void* _this, @@ -9844,21 +9845,26 @@ DWORD InjectBasicFunctions(BOOL bIsExplorer, BOOL bInstall) #ifdef _WIN64 // As of writing, this function is never invoked with bInstall=TRUE, so we don't handle the case if it's false for now - RtlQueryFeatureConfigurationFunc = GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "RtlQueryFeatureConfiguration"); - int rv = -1; - if (RtlQueryFeatureConfigurationFunc) - { - rv = funchook_prepare( - funchook, - (void**)&RtlQueryFeatureConfigurationFunc, - RtlQueryFeatureConfigurationHook - ); - } - if (rv != 0) + if (bIsExplorerProcess) { - printf("Failed to hook RtlQueryFeatureConfiguration(). rv = %d\n", rv); + RtlQueryFeatureConfigurationFunc = GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "RtlQueryFeatureConfiguration"); + int rv = -1; + if (RtlQueryFeatureConfigurationFunc) + { + rv = funchook_prepare( + funchook, + (void**)&RtlQueryFeatureConfigurationFunc, + RtlQueryFeatureConfigurationHook + ); + } + if (rv != 0) + { + printf("Failed to hook RtlQueryFeatureConfiguration(). rv = %d\n", rv); + } } #endif + + return 0; } @@ -10959,20 +10965,25 @@ DWORD Inject(BOOL bIsExplorer) &symbols_PTRS, sizeof(symbols_addr) ); - if (LoadSymbols(&symbols_PTRS, hModule)) + LoadSymbolsResult loadSymbolsResult = LoadSymbols(&symbols_PTRS); + if (loadSymbolsResult.bSuccess) { - if (bEnableSymbolDownload) + if (NeedToDownloadSymbols(&loadSymbolsResult)) { - printf("Attempting to download symbol data; for now, the program may have limited functionality.\n"); - DownloadSymbolsParams* params = malloc(sizeof(DownloadSymbolsParams)); - params->hModule = hModule; - params->bVerbose = FALSE; - CreateThread(0, 0, DownloadSymbols, params, 0, 0); + if (bEnableSymbolDownload) + { + printf("Attempting to download symbol data; for now, the program may have limited functionality.\n"); + DownloadSymbolsParams* params = malloc(sizeof(DownloadSymbolsParams)); + params->hModule = hModule; + params->bVerbose = FALSE; + params->loadResult = loadSymbolsResult; + CreateThread(0, 0, DownloadSymbols, params, 0, 0); + } + } + else + { + printf("Loaded symbols\n"); } - } - else - { - printf("Loaded symbols\n"); } @@ -12052,14 +12063,14 @@ INT64 StartDocked_StartSizingFrame_StartSizingFrameHook(void* _this) if (hModule) { DWORD dwStatus = 0, dwSize = sizeof(DWORD); - FARPROC SHRegGetValueFromHKCUHKLMFunc = GetProcAddress(hModule, "SHRegGetValueFromHKCUHKLM"); + t_SHRegGetValueFromHKCUHKLM SHRegGetValueFromHKCUHKLMFunc = GetProcAddress(hModule, "SHRegGetValueFromHKCUHKLM"); if (!SHRegGetValueFromHKCUHKLMFunc || SHRegGetValueFromHKCUHKLMFunc( TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced"), TEXT("TaskbarAl"), SRRF_RT_REG_DWORD, NULL, &dwStatus, - (LPDWORD)(&dwSize) + &dwSize ) != ERROR_SUCCESS) { dwStatus = 0; @@ -12757,7 +12768,7 @@ HRESULT WINAPI _DllCanUnloadNow() return S_FALSE; } -void InjectStartMenu() +DWORD InjectStartMenu() { #ifdef _WIN64 funchook = funchook_create(); @@ -12858,56 +12869,56 @@ void InjectStartMenu() ); int rv; - DWORD dwVal0 = 0x62254, dwVal1 = 0x188EBC, dwVal2 = 0x187120, dwVal3 = 0x3C10, dwVal4 = 0; + DWORD dwVal0 = 0, dwVal1 = 0, dwVal2 = 0, dwVal3 = 0, dwVal4 = 0; HMODULE hModule = LoadLibraryW(L"Shlwapi.dll"); if (hModule) { DWORD dwStatus = 0, dwSize = sizeof(DWORD); - FARPROC SHRegGetValueFromHKCUHKLMFunc = GetProcAddress(hModule, "SHRegGetValueFromHKCUHKLM"); + t_SHRegGetValueFromHKCUHKLM SHRegGetValueFromHKCUHKLM = GetProcAddress(hModule, "SHRegGetValueFromHKCUHKLM"); - if (SHRegGetValueFromHKCUHKLMFunc) + if (SHRegGetValueFromHKCUHKLM) { dwSize = sizeof(DWORD); - SHRegGetValueFromHKCUHKLMFunc( + SHRegGetValueFromHKCUHKLM( TEXT(REGPATH_STARTMENU) TEXT("\\") TEXT(STARTDOCKED_SB_NAME), TEXT(STARTDOCKED_SB_0), SRRF_RT_REG_DWORD, NULL, &dwVal0, - (LPDWORD)(&dwSize) + &dwSize ); - SHRegGetValueFromHKCUHKLMFunc( + SHRegGetValueFromHKCUHKLM( TEXT(REGPATH_STARTMENU) TEXT("\\") TEXT(STARTDOCKED_SB_NAME), TEXT(STARTDOCKED_SB_1), SRRF_RT_REG_DWORD, NULL, &dwVal1, - (LPDWORD)(&dwSize) + &dwSize ); - SHRegGetValueFromHKCUHKLMFunc( + SHRegGetValueFromHKCUHKLM( TEXT(REGPATH_STARTMENU) TEXT("\\") TEXT(STARTDOCKED_SB_NAME), TEXT(STARTDOCKED_SB_2), SRRF_RT_REG_DWORD, NULL, &dwVal2, - (LPDWORD)(&dwSize) + &dwSize ); - SHRegGetValueFromHKCUHKLMFunc( + SHRegGetValueFromHKCUHKLM( TEXT(REGPATH_STARTMENU) TEXT("\\") TEXT(STARTDOCKED_SB_NAME), TEXT(STARTDOCKED_SB_3), SRRF_RT_REG_DWORD, NULL, &dwVal3, - (LPDWORD)(&dwSize) + &dwSize ); - SHRegGetValueFromHKCUHKLMFunc( + SHRegGetValueFromHKCUHKLM( TEXT(REGPATH_STARTMENU) TEXT("\\") TEXT(STARTUI_SB_NAME), TEXT(STARTUI_SB_0), SRRF_RT_REG_DWORD, NULL, &dwVal4, - (LPDWORD)(&dwSize) + &dwSize ); } FreeLibrary(hModule); @@ -12971,6 +12982,7 @@ void InjectStartMenu() return rv; } #endif + return 0; } void InjectShellExperienceHost() diff --git a/ExplorerPatcher/symbols.c b/ExplorerPatcher/symbols.c index 03146d99b..7389af54d 100644 --- a/ExplorerPatcher/symbols.c +++ b/ExplorerPatcher/symbols.c @@ -61,15 +61,293 @@ L" \r\n" L"