Browse Source

Main: Guards against NULL dereferences (#879)

pull/886/head
Valentin Radu 4 years ago
parent
commit
c00de82cd6
  1. 22
      ExplorerPatcher/dllmain.c

22
ExplorerPatcher/dllmain.c

@ -4624,10 +4624,12 @@ BOOL explorer_SetChildWindowNoActivateHook(HWND hWnd) @@ -4624,10 +4624,12 @@ BOOL explorer_SetChildWindowNoActivateHook(HWND hWnd)
if (!wcscmp(className, L"TrayButton"))
{
uintptr_t Instance = *(uintptr_t*)GetWindowLongPtrW(hWnd, 0);
if (Instance)
{
uintptr_t TrayButton_GetComponentName = *(INT_PTR(WINAPI**)())(Instance + 304);
if (!IsBadCodePtr(TrayButton_GetComponentName))
{
wchar_t* wszComponentName = (const WCHAR*)(*(uintptr_t (**)(void))(Instance + 304))();
wchar_t* wszComponentName = (const WCHAR*)(*(uintptr_t(**)(void))(Instance + 304))();
if (!wcscmp(wszComponentName, L"CortanaButton"))
{
DWORD dwOldProtect;
@ -4692,6 +4694,7 @@ BOOL explorer_SetChildWindowNoActivateHook(HWND hWnd) @@ -4692,6 +4694,7 @@ BOOL explorer_SetChildWindowNoActivateHook(HWND hWnd)
}
}
}
}
return SetChildWindowNoActivateFunc(hWnd);
}
#endif
@ -6173,12 +6176,15 @@ void Explorer_RefreshClockHelper(HWND hClockButton) @@ -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
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,11 +6235,16 @@ void Explorer_TogglePeopleButton(int unused) @@ -6229,11 +6235,16 @@ void Explorer_TogglePeopleButton(int unused)
if (hShellTray_Wnd)
{
INT64* CTrayInstance = (BYTE*)(GetWindowLongPtrW(hShellTray_Wnd, 0)); // -> CTray
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);
}
}
}
}
void Explorer_ToggleTouchpad(int unused)
@ -6242,11 +6253,16 @@ void Explorer_ToggleTouchpad(int unused) @@ -6242,11 +6253,16 @@ void Explorer_ToggleTouchpad(int unused)
if (hShellTray_Wnd)
{
INT64* CTrayInstance = (BYTE*)(GetWindowLongPtrW(hShellTray_Wnd, 0)); // -> CTray
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

Loading…
Cancel
Save