1
0
mirror of https://github.com/veracrypt/VeraCrypt.git synced 2025-11-11 02:58:02 -06:00

Windows: Fix failure of Screen Readers (Accessibility support) to reader UI by disabling newly introduced memory protection by default and adding a CLI switch (/protectMemory) to enable it when needed. This fixes issue https://github.com/veracrypt/VeraCrypt/issues/536

This commit is contained in:
Mounir IDRASSI
2020-01-21 00:53:32 +01:00
parent 8fe3eb0136
commit b6c290e4fd
5 changed files with 97 additions and 3 deletions

View File

@@ -190,6 +190,7 @@ BOOL MultipleMountOperationInProgress = FALSE;
volatile BOOL NeedPeriodicDeviceListUpdate = FALSE; volatile BOOL NeedPeriodicDeviceListUpdate = FALSE;
BOOL DisablePeriodicDeviceListUpdate = FALSE; BOOL DisablePeriodicDeviceListUpdate = FALSE;
BOOL EnableMemoryProtection = FALSE;
BOOL WaitDialogDisplaying = FALSE; BOOL WaitDialogDisplaying = FALSE;
@@ -2919,9 +2920,6 @@ void InitApp (HINSTANCE hInstance, wchar_t *lpszCommandLine)
char langId[6]; char langId[6];
InitCommonControlsPtr InitCommonControlsFn = NULL; InitCommonControlsPtr InitCommonControlsFn = NULL;
wchar_t modPath[MAX_PATH]; wchar_t modPath[MAX_PATH];
/* Protect this process memory from being accessed by non-admin users */
EnableProcessProtection ();
GetModuleFileNameW (NULL, modPath, ARRAYSIZE (modPath)); GetModuleFileNameW (NULL, modPath, ARRAYSIZE (modPath));

View File

@@ -167,6 +167,7 @@ extern BOOL MultipleMountOperationInProgress;
extern volatile BOOL NeedPeriodicDeviceListUpdate; extern volatile BOOL NeedPeriodicDeviceListUpdate;
extern BOOL DisablePeriodicDeviceListUpdate; extern BOOL DisablePeriodicDeviceListUpdate;
extern BOOL EnableMemoryProtection;
#ifndef SETUP #ifndef SETUP
extern BOOL bLanguageSetInSetup; extern BOOL bLanguageSetInSetup;

View File

@@ -866,6 +866,67 @@ static BOOL SelectPartition (HWND hwndDlg)
return FALSE; return FALSE;
} }
void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine)
{
wchar_t **lpszCommandLineArgs = NULL; /* Array of command line arguments */
int nNoCommandLineArgs; /* The number of arguments in the array */
/* Extract command line arguments */
nNoCommandLineArgs = Win32CommandLine (&lpszCommandLineArgs);
if (nNoCommandLineArgs > 0)
{
int i;
for (i = 0; i < nNoCommandLineArgs; i++)
{
enum
{
OptionEnableMemoryProtection,
};
argument args[]=
{
{ OptionEnableMemoryProtection, L"/protectMemory", NULL, FALSE },
};
argumentspec as;
int x;
if (lpszCommandLineArgs[i] == NULL)
continue;
as.args = args;
as.arg_cnt = sizeof(args)/ sizeof(args[0]);
x = GetArgumentID (&as, lpszCommandLineArgs[i]);
switch (x)
{
case OptionEnableMemoryProtection:
EnableMemoryProtection = TRUE;
break;
default:
DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_COMMANDHELP_DLG), hwndDlg, (DLGPROC)
CommandHelpDlgProc, (LPARAM) &as);
exit(0);
}
}
}
/* Free up the command line arguments */
while (--nNoCommandLineArgs >= 0)
{
free (lpszCommandLineArgs[nNoCommandLineArgs]);
}
if (lpszCommandLineArgs)
free (lpszCommandLineArgs);
}
/* Except in response to the WM_INITDIALOG and WM_ENDSESSION messages, the dialog box procedure /* Except in response to the WM_INITDIALOG and WM_ENDSESSION messages, the dialog box procedure
should return nonzero if it processes a message, and zero if it does not. */ should return nonzero if it processes a message, and zero if it does not. */
@@ -890,6 +951,8 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
bUseSecureDesktop = FALSE; bUseSecureDesktop = FALSE;
bUseLegacyMaxPasswordLength = FALSE; bUseLegacyMaxPasswordLength = FALSE;
VeraCryptExpander::ExtractCommandLine (hwndDlg, (wchar_t *) lParam);
if (UsePreferences) if (UsePreferences)
{ {
// General preferences // General preferences
@@ -900,6 +963,12 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
RestoreDefaultKeyFilesParam (); RestoreDefaultKeyFilesParam ();
} }
if (EnableMemoryProtection)
{
/* Protect this process memory from being accessed by non-admin users */
EnableProcessProtection ();
}
InitMainDialog (hwndDlg); InitMainDialog (hwndDlg);
// Quit // Quit

View File

@@ -6145,6 +6145,12 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
ExtractCommandLine (hwndDlg, (wchar_t *) lParam); ExtractCommandLine (hwndDlg, (wchar_t *) lParam);
if (EnableMemoryProtection)
{
/* Protect this process memory from being accessed by non-admin users */
EnableProcessProtection ();
}
if (ComServerMode) if (ComServerMode)
{ {
InitDialog (hwndDlg); InitDialog (hwndDlg);
@@ -9001,6 +9007,7 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine)
OptionNoSizeCheck, OptionNoSizeCheck,
OptionQuickFormat, OptionQuickFormat,
OptionFastCreateFile, OptionFastCreateFile,
OptionEnableMemoryProtection,
}; };
argument args[]= argument args[]=
@@ -9024,6 +9031,7 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine)
{ OptionNoSizeCheck, L"/nosizecheck", NULL, FALSE }, { OptionNoSizeCheck, L"/nosizecheck", NULL, FALSE },
{ OptionQuickFormat, L"/quick", NULL, FALSE }, { OptionQuickFormat, L"/quick", NULL, FALSE },
{ OptionFastCreateFile, L"/fastcreatefile", NULL, FALSE }, { OptionFastCreateFile, L"/fastcreatefile", NULL, FALSE },
{ OptionEnableMemoryProtection, L"/protectMemory", NULL, FALSE },
// Internal // Internal
{ CommandResumeSysEncLogOn, L"/acsysenc", L"/a", TRUE }, { CommandResumeSysEncLogOn, L"/acsysenc", L"/a", TRUE },
@@ -9384,6 +9392,10 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine)
CmdFastCreateFile = TRUE; CmdFastCreateFile = TRUE;
break; break;
case OptionEnableMemoryProtection:
EnableMemoryProtection = TRUE;
break;
case OptionHistory: case OptionHistory:
{ {
wchar_t szTmp[8] = {0}; wchar_t szTmp[8] = {0};

View File

@@ -6859,6 +6859,12 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
AbortProcess ("COMMAND_LINE_ERROR"); AbortProcess ("COMMAND_LINE_ERROR");
} }
if (EnableMemoryProtection)
{
/* Protect this process memory from being accessed by non-admin users */
EnableProcessProtection ();
}
if (ComServerMode) if (ComServerMode)
{ {
InitDialog (hwndDlg); InitDialog (hwndDlg);
@@ -8883,6 +8889,7 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine)
OptionNoWaitDlg, OptionNoWaitDlg,
OptionSecureDesktop, OptionSecureDesktop,
OptionDisableDeviceUpdate, OptionDisableDeviceUpdate,
OptionEnableMemoryProtection,
}; };
argument args[]= argument args[]=
@@ -8912,6 +8919,7 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine)
{ OptionNoWaitDlg, L"/nowaitdlg", NULL, FALSE }, { OptionNoWaitDlg, L"/nowaitdlg", NULL, FALSE },
{ OptionSecureDesktop, L"/secureDesktop", NULL, FALSE }, { OptionSecureDesktop, L"/secureDesktop", NULL, FALSE },
{ OptionDisableDeviceUpdate, L"/disableDeviceUpdate", NULL, FALSE }, { OptionDisableDeviceUpdate, L"/disableDeviceUpdate", NULL, FALSE },
{ OptionEnableMemoryProtection, L"/protectMemory", NULL, FALSE },
}; };
argumentspec as; argumentspec as;
@@ -9008,6 +9016,12 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine)
} }
break; break;
case OptionEnableMemoryProtection:
{
EnableMemoryProtection = TRUE;
}
break;
case OptionCache: case OptionCache:
{ {
wchar_t szTmp[16] = {0}; wchar_t szTmp[16] = {0};