mirror of
https://github.com/pbatard/rufus.git
synced 2024-08-14 23:57:05 +00:00
[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:
parent
8823c0cf9c
commit
db68bcd7f9
6 changed files with 55 additions and 37 deletions
|
@ -343,7 +343,7 @@ t MSG_136 "Release"
|
||||||
t MSG_137 "Edition"
|
t MSG_137 "Edition"
|
||||||
t MSG_138 "Language"
|
t MSG_138 "Language"
|
||||||
t MSG_139 "Architecture"
|
t MSG_139 "Architecture"
|
||||||
t MSG_140 "Confirm"
|
t MSG_140 "Continue"
|
||||||
t MSG_141 "Back"
|
t MSG_141 "Back"
|
||||||
t MSG_142 "Please wait..."
|
t MSG_142 "Please wait..."
|
||||||
t MSG_143 "Download ISO Image"
|
t MSG_143 "Download ISO Image"
|
||||||
|
@ -4285,7 +4285,7 @@ t MSG_133 "Rufus a détecté que vous êtes en train de créer un média 'Window
|
||||||
t MSG_134 "Parce que MBR a été sélectionné pour le schéma de partition, Rufus peut seulement créer une partition sur ce média occupant jusqu’à 2 To, ce qui laissera %s d’espace disque non-disponible.\n\nEtes-vous sûr de vouloir continuer ?"
|
t MSG_134 "Parce que MBR a été sélectionné pour le schéma de partition, Rufus peut seulement créer une partition sur ce média occupant jusqu’à 2 To, ce qui laissera %s d’espace disque non-disponible.\n\nEtes-vous sûr de vouloir continuer ?"
|
||||||
t MSG_137 "Édition"
|
t MSG_137 "Édition"
|
||||||
t MSG_138 "Langue de produit"
|
t MSG_138 "Langue de produit"
|
||||||
t MSG_140 "Confirmer"
|
t MSG_140 "Continuer"
|
||||||
t MSG_141 "Retour"
|
t MSG_141 "Retour"
|
||||||
t MSG_142 "Veuillez patienter..."
|
t MSG_142 "Veuillez patienter..."
|
||||||
t MSG_143 "Télécharger une image ISO"
|
t MSG_143 "Télécharger une image ISO"
|
||||||
|
|
|
@ -49,7 +49,7 @@ BYTE* fido_script = NULL;
|
||||||
|
|
||||||
extern loc_cmd* selected_locale;
|
extern loc_cmd* selected_locale;
|
||||||
extern HANDLE dialog_handle;
|
extern HANDLE dialog_handle;
|
||||||
extern BOOL force_update, is_x86_32;
|
extern BOOL force_update, is_x86_32, close_fido_cookie_prompts;
|
||||||
static DWORD error_code, fido_len = 0;
|
static DWORD error_code, fido_len = 0;
|
||||||
static BOOL update_check_in_progress = FALSE;
|
static BOOL update_check_in_progress = FALSE;
|
||||||
static BOOL force_update_check = FALSE;
|
static BOOL force_update_check = FALSE;
|
||||||
|
@ -385,7 +385,7 @@ static uint64_t DownloadToFileOrBuffer(const char* url, const char* file, BYTE**
|
||||||
uprintf("No buffer pointer provided for download");
|
uprintf("No buffer pointer provided for download");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
*buffer = malloc(total_size);
|
*buffer = malloc((size_t)total_size);
|
||||||
if (*buffer == NULL) {
|
if (*buffer == NULL) {
|
||||||
uprintf("Could not allocate buffer for download");
|
uprintf("Could not allocate buffer for download");
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -897,9 +897,12 @@ static DWORD WINAPI DownloadISOThread(LPVOID param)
|
||||||
}
|
}
|
||||||
|
|
||||||
static_sprintf(cmdline, "%s -NonInteractive -NoProfile –ExecutionPolicy Bypass "
|
static_sprintf(cmdline, "%s -NonInteractive -NoProfile –ExecutionPolicy Bypass "
|
||||||
"-File %s -PipeName %s -LocData \"%s\" -Icon %s -AppTitle \"%s\" -ShowBrowserOption",
|
"-File %s -PipeName %s -LocData \"%s\" -Icon %s -AppTitle \"%s\"",
|
||||||
powershell_path, script_path, &pipe[9], locale_str, icon_path, lmprintf(MSG_143));
|
powershell_path, script_path, &pipe[9], locale_str, icon_path, lmprintf(MSG_143));
|
||||||
|
// Signal our Windows alerts hook that it should close the IE cookie prompts from Fido
|
||||||
|
close_fido_cookie_prompts = TRUE;
|
||||||
FormatStatus = RunCommand(cmdline, app_dir, TRUE);
|
FormatStatus = RunCommand(cmdline, app_dir, TRUE);
|
||||||
|
close_fido_cookie_prompts = FALSE;
|
||||||
if ((FormatStatus == 0) && PeekNamedPipe(hPipe, NULL, dwPipeSize, NULL, &dwAvail, NULL) && (dwAvail != 0)) {
|
if ((FormatStatus == 0) && PeekNamedPipe(hPipe, NULL, dwPipeSize, NULL, &dwAvail, NULL) && (dwAvail != 0)) {
|
||||||
url = malloc(dwAvail + 1);
|
url = malloc(dwAvail + 1);
|
||||||
if ((url != NULL) && ReadFile(hPipe, url, dwAvail, &dwSize, NULL) && (dwSize > 4)) {
|
if ((url != NULL) && ReadFile(hPipe, url, dwAvail, &dwSize, NULL) && (dwSize > 4)) {
|
||||||
|
|
|
@ -3152,7 +3152,7 @@ relaunch:
|
||||||
ChangeWindowMessageFilter(WM_COPYGLOBALDATA, MSGFLT_ADD);
|
ChangeWindowMessageFilter(WM_COPYGLOBALDATA, MSGFLT_ADD);
|
||||||
|
|
||||||
// Set the hook to automatically close Windows' "You need to format the disk in drive..." prompt
|
// Set the hook to automatically close Windows' "You need to format the disk in drive..." prompt
|
||||||
if (!SetFormatPromptHook())
|
if (!SetAlertPromptHook())
|
||||||
uprintf("Warning: Could not set 'Format Disk' prompt auto-close");
|
uprintf("Warning: Could not set 'Format Disk' prompt auto-close");
|
||||||
|
|
||||||
ShowWindow(hDlg, SW_SHOWNORMAL);
|
ShowWindow(hDlg, SW_SHOWNORMAL);
|
||||||
|
@ -3402,7 +3402,7 @@ out:
|
||||||
if ((!external_loc_file) && (loc_file[0] != 0))
|
if ((!external_loc_file) && (loc_file[0] != 0))
|
||||||
DeleteFileU(loc_file);
|
DeleteFileU(loc_file);
|
||||||
DestroyAllTooltips();
|
DestroyAllTooltips();
|
||||||
ClrFormatPromptHook();
|
ClrAlertPromptHook();
|
||||||
exit_localization();
|
exit_localization();
|
||||||
safe_free(image_path);
|
safe_free(image_path);
|
||||||
safe_free(locale_name);
|
safe_free(locale_name);
|
||||||
|
|
|
@ -567,8 +567,8 @@ extern BOOL IsBufferInDB(const unsigned char* buf, const size_t len);
|
||||||
extern char* _printbits(size_t const size, void const * const ptr, int leading_zeroes);
|
extern char* _printbits(size_t const size, void const * const ptr, int leading_zeroes);
|
||||||
extern BOOL IsCurrentProcessElevated(void);
|
extern BOOL IsCurrentProcessElevated(void);
|
||||||
extern char* GetCurrentMUI(void);
|
extern char* GetCurrentMUI(void);
|
||||||
extern BOOL SetFormatPromptHook(void);
|
extern BOOL SetAlertPromptHook(void);
|
||||||
extern void ClrFormatPromptHook(void);
|
extern void ClrAlertPromptHook(void);
|
||||||
extern BYTE SearchProcess(char* HandleName, DWORD dwTimeout, BOOL bPartialMatch, BOOL bIgnoreSelf, BOOL bQuiet);
|
extern BYTE SearchProcess(char* HandleName, DWORD dwTimeout, BOOL bPartialMatch, BOOL bIgnoreSelf, BOOL bQuiet);
|
||||||
extern BOOL EnablePrivileges(void);
|
extern BOOL EnablePrivileges(void);
|
||||||
extern void FlashTaskbar(HANDLE handle);
|
extern void FlashTaskbar(HANDLE handle);
|
||||||
|
|
10
src/rufus.rc
10
src/rufus.rc
|
@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
|
||||||
IDD_DIALOG DIALOGEX 12, 12, 232, 326
|
IDD_DIALOG DIALOGEX 12, 12, 232, 326
|
||||||
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||||
EXSTYLE WS_EX_ACCEPTFILES
|
EXSTYLE WS_EX_ACCEPTFILES
|
||||||
CAPTION "Rufus 3.5.1451"
|
CAPTION "Rufus 3.5.1452"
|
||||||
FONT 9, "Segoe UI Symbol", 400, 0, 0x0
|
FONT 9, "Segoe UI Symbol", 400, 0, 0x0
|
||||||
BEGIN
|
BEGIN
|
||||||
LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP
|
LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP
|
||||||
|
@ -394,8 +394,8 @@ END
|
||||||
//
|
//
|
||||||
|
|
||||||
VS_VERSION_INFO VERSIONINFO
|
VS_VERSION_INFO VERSIONINFO
|
||||||
FILEVERSION 3,5,1451,0
|
FILEVERSION 3,5,1452,0
|
||||||
PRODUCTVERSION 3,5,1451,0
|
PRODUCTVERSION 3,5,1452,0
|
||||||
FILEFLAGSMASK 0x3fL
|
FILEFLAGSMASK 0x3fL
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
FILEFLAGS 0x1L
|
FILEFLAGS 0x1L
|
||||||
|
@ -413,13 +413,13 @@ BEGIN
|
||||||
VALUE "Comments", "https://akeo.ie"
|
VALUE "Comments", "https://akeo.ie"
|
||||||
VALUE "CompanyName", "Akeo Consulting"
|
VALUE "CompanyName", "Akeo Consulting"
|
||||||
VALUE "FileDescription", "Rufus"
|
VALUE "FileDescription", "Rufus"
|
||||||
VALUE "FileVersion", "3.5.1451"
|
VALUE "FileVersion", "3.5.1452"
|
||||||
VALUE "InternalName", "Rufus"
|
VALUE "InternalName", "Rufus"
|
||||||
VALUE "LegalCopyright", "© 2011-2019 Pete Batard (GPL v3)"
|
VALUE "LegalCopyright", "© 2011-2019 Pete Batard (GPL v3)"
|
||||||
VALUE "LegalTrademarks", "https://www.gnu.org/copyleft/gpl.html"
|
VALUE "LegalTrademarks", "https://www.gnu.org/copyleft/gpl.html"
|
||||||
VALUE "OriginalFilename", "rufus-3.5.exe"
|
VALUE "OriginalFilename", "rufus-3.5.exe"
|
||||||
VALUE "ProductName", "Rufus"
|
VALUE "ProductName", "Rufus"
|
||||||
VALUE "ProductVersion", "3.5.1451"
|
VALUE "ProductVersion", "3.5.1452"
|
||||||
END
|
END
|
||||||
END
|
END
|
||||||
BLOCK "VarFileInfo"
|
BLOCK "VarFileInfo"
|
||||||
|
|
63
src/stdlg.c
63
src/stdlg.c
|
@ -59,8 +59,10 @@ static BOOL notification_is_question;
|
||||||
static const notification_info* notification_more_info;
|
static const notification_info* notification_more_info;
|
||||||
static const char* notification_dont_display_setting;
|
static const char* notification_dont_display_setting;
|
||||||
static WNDPROC update_original_proc = NULL;
|
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 *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[] = {
|
static int update_settings_reposition_ids[] = {
|
||||||
IDC_POLICY,
|
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
|
* 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
|
* Windows format prompt "You must format the disk in drive X:" as well as the cookies
|
||||||
* event hook that gets triggered whenever a window is placed in the foreground.
|
* 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
|
* 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
|
* title. However, in case of the Format prompt, because the title in itself is too
|
||||||
* it will be "Microsoft Windows") we also enumerate all the child controls from that
|
* generic (the expectation is that it will be "Microsoft Windows") we also enumerate
|
||||||
* prompt, using another callback, until we find one that contains the text we expect
|
* all the child controls from that prompt, using another callback, until we find one
|
||||||
* for the "Format disk" button.
|
* 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
|
* 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];
|
char str[128];
|
||||||
BOOL *found = (BOOL*)lParam;
|
BOOL *found = (BOOL*)lParam;
|
||||||
|
@ -1951,7 +1954,7 @@ static BOOL CALLBACK FormatPromptCallback(HWND hWnd, LPARAM lParam)
|
||||||
return TRUE;
|
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];
|
char str[128];
|
||||||
BOOL found;
|
BOOL found;
|
||||||
|
@ -1960,25 +1963,27 @@ static void CALLBACK FormatPromptHook(HWINEVENTHOOK hWinEventHook, DWORD Event,
|
||||||
if (GetWindowLongPtr(hWnd, GWL_STYLE) & WS_POPUPWINDOW) {
|
if (GetWindowLongPtr(hWnd, GWL_STYLE) & WS_POPUPWINDOW) {
|
||||||
str[0] = 0;
|
str[0] = 0;
|
||||||
GetWindowTextU(hWnd, str, sizeof(str));
|
GetWindowTextU(hWnd, str, sizeof(str));
|
||||||
if (safe_strcmp(str, fp_title_str) == 0) {
|
if (strcmp(str, fp_title_str) == 0) {
|
||||||
found = FALSE;
|
found = FALSE;
|
||||||
EnumChildWindows(hWnd, FormatPromptCallback, (LPARAM)&found);
|
EnumChildWindows(hWnd, AlertPromptCallback, (LPARAM)&found);
|
||||||
if (found) {
|
if (found) {
|
||||||
SendMessage(hWnd, WM_COMMAND, (WPARAM)IDCANCEL, (LPARAM)0);
|
SendMessage(hWnd, WM_COMMAND, (WPARAM)IDCANCEL, (LPARAM)0);
|
||||||
uprintf("Closed Windows format prompt");
|
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;
|
HMODULE mui_lib;
|
||||||
char mui_path[MAX_PATH];
|
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
|
return TRUE; // No need to set again if active
|
||||||
|
|
||||||
// Fetch the localized strings in the relevant MUI
|
// 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)
|
// 4097 = "You need to format the disk in drive %c: before you can use it." (dialog text)
|
||||||
// 4125 = "Microsoft Windows" (dialog title)
|
// 4125 = "Microsoft Windows" (dialog title)
|
||||||
// 4126 = "Format disk" (button)
|
// 4126 = "Format disk" (button)
|
||||||
if (LoadStringU(mui_lib, 4125, title_str, sizeof(title_str)) > 0)
|
if (LoadStringU(mui_lib, 4125, title_str[0], sizeof(title_str[0])) > 0)
|
||||||
fp_title_str = title_str;
|
fp_title_str = title_str[0];
|
||||||
else
|
else
|
||||||
uprintf("Warning: Could not locate localized format prompt title string in '%s': %s", mui_path, WindowsErrorString());
|
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)
|
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());
|
uprintf("Warning: Could not locate localized format prompt button string in '%s': %s", mui_path, WindowsErrorString());
|
||||||
FreeLibrary(mui_lib);
|
FreeLibrary(mui_lib);
|
||||||
}
|
}
|
||||||
|
static_sprintf(mui_path, "%s\\%s\\urlmon.dll.mui", system_dir, GetCurrentMUI());
|
||||||
fp_weh = SetWinEventHook(EVENT_SYSTEM_FOREGROUND, EVENT_SYSTEM_FOREGROUND, NULL,
|
mui_lib = LoadLibraryU(mui_path);
|
||||||
FormatPromptHook, 0, 0, WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS);
|
if (mui_lib != NULL) {
|
||||||
return (fp_weh != 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClrFormatPromptHook(void) {
|
ap_weh = SetWinEventHook(EVENT_SYSTEM_FOREGROUND, EVENT_SYSTEM_FOREGROUND, NULL,
|
||||||
UnhookWinEvent(fp_weh);
|
AlertPromptHook, 0, 0, WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS);
|
||||||
fp_weh = NULL;
|
return (ap_weh != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClrAlertPromptHook(void) {
|
||||||
|
UnhookWinEvent(ap_weh);
|
||||||
|
ap_weh = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FlashTaskbar(HANDLE handle)
|
void FlashTaskbar(HANDLE handle)
|
||||||
|
|
Loading…
Reference in a new issue