[fido] use Rufus existing alert handler to close Fido's cookie prompts

* Addresses pbatard/Fido#1 while being much more effective than an all-script solution
This commit is contained in:
Pete Batard 2019-03-05 12:41:10 +00:00
parent 8823c0cf9c
commit db68bcd7f9
No known key found for this signature in database
GPG key ID: 38E0CF5E69EDD671
6 changed files with 55 additions and 37 deletions

View file

@ -59,8 +59,10 @@ static BOOL notification_is_question;
static const notification_info* notification_more_info;
static const char* notification_dont_display_setting;
static WNDPROC update_original_proc = NULL;
static HWINEVENTHOOK fp_weh = NULL;
static HWINEVENTHOOK ap_weh = NULL;
static char *fp_title_str = "Microsoft Windows", *fp_button_str = "Format disk";
static char *cp_title_str = "Windows Security Warning";
BOOL close_fido_cookie_prompts = FALSE;
static int update_settings_reposition_ids[] = {
IDC_POLICY,
@ -1929,17 +1931,18 @@ INT_PTR MyDialogBox(HINSTANCE hInstance, int Dialog_ID, HWND hWndParent, DLGPROC
/*
* The following function calls are used to automatically detect and close the native
* Windows format prompt "You must format the disk in drive X:". To do that, we use an
* event hook that gets triggered whenever a window is placed in the foreground.
* Windows format prompt "You must format the disk in drive X:" as well as the cookies
* alert being popped by Windows when running our Download script. To do that, we use
* an event hook that gets triggered whenever a window is placed in the foreground.
* In that hook, we look for a dialog that has style WS_POPUPWINDOW and has the relevant
* title. However, because the title in itself is too generic (the expectation is that
* it will be "Microsoft Windows") we also enumerate all the child controls from that
* prompt, using another callback, until we find one that contains the text we expect
* for the "Format disk" button.
* title. However, in case of the Format prompt, because the title in itself is too
* generic (the expectation is that it will be "Microsoft Windows") we also enumerate
* all the child controls from that prompt, using another callback, until we find one
* that contains the text we expect for the "Format disk" button.
* Oh, and since all of these strings are localized, we must first pick them up from
* the relevant mui (something like "C:\Windows\System32\en-GB\shell32.dll.mui")
* the relevant mui's.
*/
static BOOL CALLBACK FormatPromptCallback(HWND hWnd, LPARAM lParam)
static BOOL CALLBACK AlertPromptCallback(HWND hWnd, LPARAM lParam)
{
char str[128];
BOOL *found = (BOOL*)lParam;
@ -1951,7 +1954,7 @@ static BOOL CALLBACK FormatPromptCallback(HWND hWnd, LPARAM lParam)
return TRUE;
}
static void CALLBACK FormatPromptHook(HWINEVENTHOOK hWinEventHook, DWORD Event, HWND hWnd, LONG idObject, LONG idChild, DWORD dwEventThread, DWORD dwmsEventTime)
static void CALLBACK AlertPromptHook(HWINEVENTHOOK hWinEventHook, DWORD Event, HWND hWnd, LONG idObject, LONG idChild, DWORD dwEventThread, DWORD dwmsEventTime)
{
char str[128];
BOOL found;
@ -1960,25 +1963,27 @@ static void CALLBACK FormatPromptHook(HWINEVENTHOOK hWinEventHook, DWORD Event,
if (GetWindowLongPtr(hWnd, GWL_STYLE) & WS_POPUPWINDOW) {
str[0] = 0;
GetWindowTextU(hWnd, str, sizeof(str));
if (safe_strcmp(str, fp_title_str) == 0) {
if (strcmp(str, fp_title_str) == 0) {
found = FALSE;
EnumChildWindows(hWnd, FormatPromptCallback, (LPARAM)&found);
EnumChildWindows(hWnd, AlertPromptCallback, (LPARAM)&found);
if (found) {
SendMessage(hWnd, WM_COMMAND, (WPARAM)IDCANCEL, (LPARAM)0);
uprintf("Closed Windows format prompt");
}
} else if (close_fido_cookie_prompts && strcmp(str, cp_title_str) == 0) {
SendMessage(hWnd, WM_COMMAND, (WPARAM)IDCANCEL, (LPARAM)0);
}
}
}
}
BOOL SetFormatPromptHook(void)
BOOL SetAlertPromptHook(void)
{
HMODULE mui_lib;
char mui_path[MAX_PATH];
static char title_str[128], button_str[128];
static char title_str[2][128], button_str[128];
if (fp_weh != NULL)
if (ap_weh != NULL)
return TRUE; // No need to set again if active
// Fetch the localized strings in the relevant MUI
@ -1988,8 +1993,8 @@ BOOL SetFormatPromptHook(void)
// 4097 = "You need to format the disk in drive %c: before you can use it." (dialog text)
// 4125 = "Microsoft Windows" (dialog title)
// 4126 = "Format disk" (button)
if (LoadStringU(mui_lib, 4125, title_str, sizeof(title_str)) > 0)
fp_title_str = title_str;
if (LoadStringU(mui_lib, 4125, title_str[0], sizeof(title_str[0])) > 0)
fp_title_str = title_str[0];
else
uprintf("Warning: Could not locate localized format prompt title string in '%s': %s", mui_path, WindowsErrorString());
if (LoadStringU(mui_lib, 4126, button_str, sizeof(button_str)) > 0)
@ -1998,15 +2003,25 @@ BOOL SetFormatPromptHook(void)
uprintf("Warning: Could not locate localized format prompt button string in '%s': %s", mui_path, WindowsErrorString());
FreeLibrary(mui_lib);
}
static_sprintf(mui_path, "%s\\%s\\urlmon.dll.mui", system_dir, GetCurrentMUI());
mui_lib = LoadLibraryU(mui_path);
if (mui_lib != NULL) {
// 2070 = "Windows Security Warning" (yes, that's what MS uses for a stupid cookie!)
if (LoadStringU(mui_lib, 2070, title_str[1], sizeof(title_str[1])) > 0)
cp_title_str = title_str[1];
else
uprintf("Warning: Could not locate localized cookie prompt title string in '%s': %s", mui_path, WindowsErrorString());
FreeLibrary(mui_lib);
}
fp_weh = SetWinEventHook(EVENT_SYSTEM_FOREGROUND, EVENT_SYSTEM_FOREGROUND, NULL,
FormatPromptHook, 0, 0, WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS);
return (fp_weh != NULL);
ap_weh = SetWinEventHook(EVENT_SYSTEM_FOREGROUND, EVENT_SYSTEM_FOREGROUND, NULL,
AlertPromptHook, 0, 0, WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS);
return (ap_weh != NULL);
}
void ClrFormatPromptHook(void) {
UnhookWinEvent(fp_weh);
fp_weh = NULL;
void ClrAlertPromptHook(void) {
UnhookWinEvent(ap_weh);
ap_weh = NULL;
}
void FlashTaskbar(HANDLE handle)