diff --git a/ExplorerPatcher/dllmain.c b/ExplorerPatcher/dllmain.c index 2f4d1f9..fd8f5a7 100644 --- a/ExplorerPatcher/dllmain.c +++ b/ExplorerPatcher/dllmain.c @@ -4624,71 +4624,74 @@ BOOL explorer_SetChildWindowNoActivateHook(HWND hWnd) if (!wcscmp(className, L"TrayButton")) { uintptr_t Instance = *(uintptr_t*)GetWindowLongPtrW(hWnd, 0); - uintptr_t TrayButton_GetComponentName = *(INT_PTR(WINAPI**)())(Instance + 304); - if (!IsBadCodePtr(TrayButton_GetComponentName)) + if (Instance) { - wchar_t* wszComponentName = (const WCHAR*)(*(uintptr_t (**)(void))(Instance + 304))(); - if (!wcscmp(wszComponentName, L"CortanaButton")) + uintptr_t TrayButton_GetComponentName = *(INT_PTR(WINAPI**)())(Instance + 304); + if (!IsBadCodePtr(TrayButton_GetComponentName)) { - DWORD dwOldProtect; - VirtualProtect(Instance + 160, sizeof(uintptr_t), PAGE_READWRITE, &dwOldProtect); - if (!Widgets_OnClickFunc) Widgets_OnClickFunc = *(uintptr_t*)(Instance + 160); - *(uintptr_t*)(Instance + 160) = Widgets_OnClickHook; // OnClick - VirtualProtect(Instance + 160, sizeof(uintptr_t), dwOldProtect, &dwOldProtect); - VirtualProtect(Instance + 216, sizeof(uintptr_t), PAGE_READWRITE, &dwOldProtect); - if (!Widgets_GetTooltipTextFunc) Widgets_GetTooltipTextFunc = *(uintptr_t*)(Instance + 216); - *(uintptr_t*)(Instance + 216) = Widgets_GetTooltipTextHook; // OnTooltipShow - VirtualProtect(Instance + 216, sizeof(uintptr_t), dwOldProtect, &dwOldProtect); - } - else if (!wcscmp(wszComponentName, L"MultitaskingButton")) - { - DWORD dwOldProtect; - VirtualProtect(Instance + 160, sizeof(uintptr_t), PAGE_READWRITE, &dwOldProtect); - *(uintptr_t*)(Instance + 160) = ToggleTaskView; // OnClick - VirtualProtect(Instance + 160, sizeof(uintptr_t), dwOldProtect, &dwOldProtect); - } - else if (!wcscmp(wszComponentName, L"PeopleButton")) - { - DWORD dwOldProtect; + wchar_t* wszComponentName = (const WCHAR*)(*(uintptr_t(**)(void))(Instance + 304))(); + if (!wcscmp(wszComponentName, L"CortanaButton")) + { + DWORD dwOldProtect; + VirtualProtect(Instance + 160, sizeof(uintptr_t), PAGE_READWRITE, &dwOldProtect); + if (!Widgets_OnClickFunc) Widgets_OnClickFunc = *(uintptr_t*)(Instance + 160); + *(uintptr_t*)(Instance + 160) = Widgets_OnClickHook; // OnClick + VirtualProtect(Instance + 160, sizeof(uintptr_t), dwOldProtect, &dwOldProtect); + VirtualProtect(Instance + 216, sizeof(uintptr_t), PAGE_READWRITE, &dwOldProtect); + if (!Widgets_GetTooltipTextFunc) Widgets_GetTooltipTextFunc = *(uintptr_t*)(Instance + 216); + *(uintptr_t*)(Instance + 216) = Widgets_GetTooltipTextHook; // OnTooltipShow + VirtualProtect(Instance + 216, sizeof(uintptr_t), dwOldProtect, &dwOldProtect); + } + else if (!wcscmp(wszComponentName, L"MultitaskingButton")) + { + DWORD dwOldProtect; + VirtualProtect(Instance + 160, sizeof(uintptr_t), PAGE_READWRITE, &dwOldProtect); + *(uintptr_t*)(Instance + 160) = ToggleTaskView; // OnClick + VirtualProtect(Instance + 160, sizeof(uintptr_t), dwOldProtect, &dwOldProtect); + } + else if (!wcscmp(wszComponentName, L"PeopleButton")) + { + DWORD dwOldProtect; - uintptr_t PeopleButton_Instance = *((uintptr_t*)GetWindowLongPtrW(hWnd, 0) + 17); + uintptr_t PeopleButton_Instance = *((uintptr_t*)GetWindowLongPtrW(hWnd, 0) + 17); - VirtualProtect(PeopleButton_Instance + 32, sizeof(uintptr_t), PAGE_READWRITE, &dwOldProtect); - if (!PeopleButton_CalculateMinimumSizeFunc) PeopleButton_CalculateMinimumSizeFunc = *(uintptr_t*)(PeopleButton_Instance + 32); - *(uintptr_t*)(PeopleButton_Instance + 32) = PeopleButton_CalculateMinimumSizeHook; // CalculateMinimumSize - VirtualProtect(PeopleButton_Instance + 32, sizeof(uintptr_t), dwOldProtect, &dwOldProtect); + VirtualProtect(PeopleButton_Instance + 32, sizeof(uintptr_t), PAGE_READWRITE, &dwOldProtect); + if (!PeopleButton_CalculateMinimumSizeFunc) PeopleButton_CalculateMinimumSizeFunc = *(uintptr_t*)(PeopleButton_Instance + 32); + *(uintptr_t*)(PeopleButton_Instance + 32) = PeopleButton_CalculateMinimumSizeHook; // CalculateMinimumSize + VirtualProtect(PeopleButton_Instance + 32, sizeof(uintptr_t), dwOldProtect, &dwOldProtect); - VirtualProtect(Instance + 224, sizeof(uintptr_t), PAGE_READWRITE, &dwOldProtect); - if (!PeopleButton_ShowTooltipFunc) PeopleButton_ShowTooltipFunc = *(uintptr_t*)(Instance + 224); - *(uintptr_t*)(Instance + 224) = PeopleButton_ShowTooltipHook; // OnTooltipShow - VirtualProtect(Instance + 224, sizeof(uintptr_t), dwOldProtect, &dwOldProtect); + VirtualProtect(Instance + 224, sizeof(uintptr_t), PAGE_READWRITE, &dwOldProtect); + if (!PeopleButton_ShowTooltipFunc) PeopleButton_ShowTooltipFunc = *(uintptr_t*)(Instance + 224); + *(uintptr_t*)(Instance + 224) = PeopleButton_ShowTooltipHook; // OnTooltipShow + VirtualProtect(Instance + 224, sizeof(uintptr_t), dwOldProtect, &dwOldProtect); - VirtualProtect(Instance + 160, sizeof(uintptr_t), PAGE_READWRITE, &dwOldProtect); - if (!PeopleButton_OnClickFunc) PeopleButton_OnClickFunc = *(uintptr_t*)(Instance + 160); - *(uintptr_t*)(Instance + 160) = PeopleButton_OnClickHook; // OnClick - VirtualProtect(Instance + 160, sizeof(uintptr_t), dwOldProtect, &dwOldProtect); + VirtualProtect(Instance + 160, sizeof(uintptr_t), PAGE_READWRITE, &dwOldProtect); + if (!PeopleButton_OnClickFunc) PeopleButton_OnClickFunc = *(uintptr_t*)(Instance + 160); + *(uintptr_t*)(Instance + 160) = PeopleButton_OnClickHook; // OnClick + VirtualProtect(Instance + 160, sizeof(uintptr_t), dwOldProtect, &dwOldProtect); - PeopleButton_LastHWND = hWnd; - SetWindowSubclass(hWnd, PeopleButton_SubclassProc, PeopleButton_SubclassProc, 0); + PeopleButton_LastHWND = hWnd; + SetWindowSubclass(hWnd, PeopleButton_SubclassProc, PeopleButton_SubclassProc, 0); - AcquireSRWLockExclusive(&lock_epw); - if (!epw) - { - if (SUCCEEDED(CoCreateInstance(&CLSID_EPWeather, NULL, CLSCTX_LOCAL_SERVER, &IID_IEPWeather, &epw)) && epw) + AcquireSRWLockExclusive(&lock_epw); + if (!epw) { - epw->lpVtbl->SetNotifyWindow(epw, hWnd); - - WCHAR wszBuffer[MAX_PATH]; - ZeroMemory(wszBuffer, sizeof(WCHAR) * MAX_PATH); - HMODULE hModule = GetModuleHandleW(L"pnidui.dll"); - if (hModule) + if (SUCCEEDED(CoCreateInstance(&CLSID_EPWeather, NULL, CLSCTX_LOCAL_SERVER, &IID_IEPWeather, &epw)) && epw) { - LoadStringW(hModule, 35, wszBuffer, MAX_PATH); + epw->lpVtbl->SetNotifyWindow(epw, hWnd); + + WCHAR wszBuffer[MAX_PATH]; + ZeroMemory(wszBuffer, sizeof(WCHAR) * MAX_PATH); + HMODULE hModule = GetModuleHandleW(L"pnidui.dll"); + if (hModule) + { + LoadStringW(hModule, 35, wszBuffer, MAX_PATH); + } + SetWindowTextW(hWnd, wszBuffer); } - SetWindowTextW(hWnd, wszBuffer); } + ReleaseSRWLockExclusive(&lock_epw); } - ReleaseSRWLockExclusive(&lock_epw); } } } @@ -6173,12 +6176,15 @@ void Explorer_RefreshClockHelper(HWND hClockButton) // we call v_Initialize because all it does is to query the // registry and update the internal state to display seconds or not // to get the offset, simply inspect the vtable of ClockButton - ((void(*)(void*))(*(INT64*)((*(INT64*)ClockButtonInstance) + 6 * sizeof(uintptr_t))))(ClockButtonInstance); // v_Initialize - // we need to refresh the button; for the text to actually change, we need to set this: - // inspect ClockButton::v_OnTimer - *((BYTE*)ClockButtonInstance + 547) = 1; - // then, we simply invalidate the area - InvalidateRect(hClockButton, NULL, TRUE); + if (ClockButtonInstance) + { + ((void(*)(void*))(*(INT64*)((*(INT64*)ClockButtonInstance) + 6 * sizeof(uintptr_t))))(ClockButtonInstance); // v_Initialize + // we need to refresh the button; for the text to actually change, we need to set this: + // inspect ClockButton::v_OnTimer + *((BYTE*)ClockButtonInstance + 547) = 1; + // then, we simply invalidate the area + InvalidateRect(hClockButton, NULL, TRUE); + } } void Explorer_RefreshClock(int unused) @@ -6229,10 +6235,15 @@ void Explorer_TogglePeopleButton(int unused) if (hShellTray_Wnd) { INT64* CTrayInstance = (BYTE*)(GetWindowLongPtrW(hShellTray_Wnd, 0)); // -> CTray - const unsigned int TRAYUI_OFFSET_IN_CTRAY = 110; - INT64* TrayUIInstance = *((INT64*)CTrayInstance + TRAYUI_OFFSET_IN_CTRAY); - - ((void(*)(void*))(*(INT64*)((*(INT64*)TrayUIInstance) + 57 * sizeof(uintptr_t))))(TrayUIInstance); + if (CTrayInstance) + { + const unsigned int TRAYUI_OFFSET_IN_CTRAY = 110; + INT64* TrayUIInstance = *((INT64*)CTrayInstance + TRAYUI_OFFSET_IN_CTRAY); + if (TrayUIInstance) + { + ((void(*)(void*))(*(INT64*)((*(INT64*)TrayUIInstance) + 57 * sizeof(uintptr_t))))(TrayUIInstance); + } + } } } @@ -6242,10 +6253,15 @@ void Explorer_ToggleTouchpad(int unused) if (hShellTray_Wnd) { INT64* CTrayInstance = (BYTE*)(GetWindowLongPtrW(hShellTray_Wnd, 0)); // -> CTray - const unsigned int TRAYUI_OFFSET_IN_CTRAY = 110; - INT64* TrayUIInstance = *((INT64*)CTrayInstance + TRAYUI_OFFSET_IN_CTRAY); - - ((void(*)(void*))(*(INT64*)((*(INT64*)TrayUIInstance) + 60 * sizeof(uintptr_t))))(TrayUIInstance); + if (CTrayInstance) + { + const unsigned int TRAYUI_OFFSET_IN_CTRAY = 110; + INT64* TrayUIInstance = *((INT64*)CTrayInstance + TRAYUI_OFFSET_IN_CTRAY); + if (TrayUIInstance) + { + ((void(*)(void*))(*(INT64*)((*(INT64*)TrayUIInstance) + 60 * sizeof(uintptr_t))))(TrayUIInstance); + } + } } } #pragma endregion