1
0
mirror of https://github.com/veracrypt/VeraCrypt.git synced 2025-11-12 03:18:26 -06:00

Windows: Add tooltip message and help button for new option to disable memory protection

Also a dedicated page in the documentation was added for it.
This commit is contained in:
Mounir IDRASSI
2023-09-24 01:26:02 +02:00
parent 07c827c849
commit 76c64d49ea
56 changed files with 374 additions and 49 deletions

View File

@@ -1759,6 +1759,88 @@ void AccommodateTextField (HWND hwndDlg, UINT ctrlId, BOOL bFirstUpdate, HFONT h
}
}
// Resizes width of a checkbox according to actual width in pixels of its label text (font size is taken into account)
void AccommodateCheckBoxTextWidth (HWND hwndDlg, UINT ctrlId)
{
RECT rec;
HWND hwndCtrl = GetDlgItem (hwndDlg, ctrlId);
int width, origWidth, origHeight;
int horizSubOffset;
wchar_t text [MAX_URL_LENGTH];
HFONT hFont = (HFONT) SendDlgItemMessage (hwndDlg, ctrlId, WM_GETFONT, 0, 0);
// Resize the field according to its length and font size and move if centered or right-aligned
GetWindowTextW (hwndCtrl, text, sizeof (text) / sizeof (wchar_t));
width = GetTextGfxWidth (hwndCtrl, text, hFont);
// add to width variable value the width of the checkbox square. We use SM_CXMENUCHECK which is a little larger than actual width
width += GetSystemMetrics(SM_CXMENUCHECK);
GetClientRect (hwndCtrl, &rec);
origWidth = rec.right;
origHeight = rec.bottom;
if (width >= 0
&& (origWidth > width)) // The original width of the field is the maximum allowed size
{
horizSubOffset = origWidth - width;
// Resize the text field
SetWindowPos (hwndCtrl, 0, 0, 0,
origWidth - horizSubOffset,
origHeight,
SWP_NOMOVE | SWP_NOZORDER);
InvalidateRect (hwndCtrl, NULL, TRUE);
}
}
// makes controls contiguous by moving the second control right next to the first one horizontally
void MakeControlsContiguous(HWND hwndDlg, UINT ctrl1ID, UINT ctrl2ID) {
HWND hwndCtrl1 = GetDlgItem(hwndDlg, ctrl1ID);
HWND hwndCtrl2 = GetDlgItem(hwndDlg, ctrl2ID);
RECT rect1, rect2;
POINT pt1, pt2;
int newLeftPosition;
// Exit silently if one or both controls are missing
if (!hwndCtrl1 || !hwndCtrl2) {
return;
}
GetWindowRect(hwndCtrl1, &rect1);
GetWindowRect(hwndCtrl2, &rect2);
// Convert the top-right point of the first control from screen to client coordinates
pt1.x = rect1.right;
pt1.y = rect1.top;
if (!ScreenToClient(hwndDlg, &pt1)) {
return; // Exit if the conversion fails
}
// Convert the top-left point of the second control from screen to client coordinates
pt2.x = rect2.left;
pt2.y = rect2.top;
if (!ScreenToClient(hwndDlg, &pt2)) {
return; // Exit if the conversion fails
}
// Ensure the second control is always placed to the right of the first one
newLeftPosition = pt1.x + 1;
if (pt2.x < pt1.x) { // if the second control is to the left of the first one
newLeftPosition += (pt1.x - pt2.x);
}
// Move the second control to its new position
SetWindowPos(hwndCtrl2, NULL, newLeftPosition, pt2.y, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
}
// Note that the user can still close the window by right-clicking its taskbar icon and selecting 'Close window', or by pressing Alt-F4, or using the Task Manager.
void DisableCloseButton (HWND hwndDlg)
{
@@ -2129,6 +2211,42 @@ BOOL CALLBACK AboutDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam
return 0;
}
HWND CreateToolTip(int toolID, HWND hDlg, const char* strID)
{
if (!toolID || !hDlg)
{
return FALSE;
}
// Create the tooltip.
HWND hwndTip = CreateWindowExW(NULL, TOOLTIPS_CLASS, NULL,
WS_POPUP | TTS_ALWAYSTIP | TTS_NOPREFIX | TTS_BALLOON,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
hDlg, NULL,
hInst, NULL);
if (!hwndTip)
{
return (HWND)NULL;
}
// Associate the tooltip with the tool.
TOOLINFOW toolInfo = { 0 };
toolInfo.cbSize = sizeof(toolInfo);
toolInfo.hwnd = hDlg;
toolInfo.uFlags = TTF_SUBCLASS | TTF_IDISHWND;
toolInfo.uId = (UINT_PTR) GetDlgItem(hDlg, toolID);
toolInfo.lpszText = GetString(strID);
// set tooltip maximum width
SendMessage(hwndTip, TTM_SETMAXTIPWIDTH, 0, (LPARAM) 300);
SendMessage(hwndTip, TTM_ADDTOOL, 0, (LPARAM)&toolInfo);
return hwndTip;
}
static HWND StaticModelessWaitDlgHandle = NULL;
@@ -11093,6 +11211,10 @@ void Applink (const char *dest)
{
StringCbCopyW (page, sizeof (page),L"Personal%20Iterations%20Multiplier%20%28PIM%29.html");
}
else if (strcmp(dest, "memoryprotection") == 0)
{
StringCbCopyW (page, sizeof (page),L"VeraCrypt%20Memory%20Protection.html");
}
else
{
StringCbCopyW (url, sizeof (url),TC_APPLINK);

View File

@@ -327,6 +327,7 @@ void HandCursor ();
void AddComboPair (HWND hComboBox, const wchar_t *lpszItem, int value);
void SelectAlgo ( HWND hComboBox , int *nCipher );
void PopulateWipeModeCombo (HWND hComboBox, BOOL bNA, BOOL bInPlaceEncryption, BOOL bHeaderWipe);
HWND CreateToolTip(int toolID, HWND hDlg, const char* strID);
wchar_t *GetWipeModeName (WipeAlgorithmId modeId);
wchar_t *GetPathType (const wchar_t *path, BOOL bUpperCase, BOOL *bIsPartition);
LRESULT CALLBACK CustomDlgProc ( HWND hwnd , UINT uMsg , WPARAM wParam , LPARAM lParam );
@@ -532,6 +533,8 @@ void EnableCloseButton (HWND hwndDlg);
void ToBootPwdField (HWND hwndDlg, UINT ctrlId);
void ToNormalPwdField (HWND hwndDlg, UINT ctrlId);
void AccommodateTextField (HWND hwndDlg, UINT ctrlId, BOOL bFirstUpdate, HFONT hFont);
void AccommodateCheckBoxTextWidth (HWND hwndDlg, UINT ctrlId);
void MakeControlsContiguous(HWND hwndDlg, UINT ctrl1ID, UINT ctrl2ID);
BOOL GetDriveLabel (int driveNo, wchar_t *label, int labelSize);
BOOL GetSysDevicePaths (HWND hwndDlg);
BOOL DoDriverInstall (HWND hwndDlg);

View File

@@ -1633,7 +1633,8 @@
<entry lang="en" key="EXPANDER_EXTENDING_FILESYSTEM">Extending file system ...\n</entry>
<entry lang="en" key="PARTIAL_SYSENC_MOUNT_READONLY">Warning: The system partition you attempted to mount was not fully encrypted. As a safety measure to prevent potential corruption or unwanted modifications, volume '%s' was mounted as read-only.</entry>
<entry lang="en" key="IDC_LINK_KEYFILES_EXTENSIONS_WARNING">Important information on using third-party file extensions</entry>
<entry lang="en" key="IDC_DISABLE_MEMORY_PROTECTION">Disable memory protection in VeraCrypt</entry>
<entry lang="en" key="IDC_DISABLE_MEMORY_PROTECTION">Disable memory protection for Accessibility tools compatibility</entry>
<entry lang="en" key="DISABLE_MEMORY_PROTECTION_WARNING">WARNING: Disabling memory protection significantly reduces security. Enable this option ONLY if you rely on Accessibility tools, like Screen Readers, to interact with VeraCrypt's UI.</entry>
</localization>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="VeraCrypt">

View File

@@ -227,6 +227,7 @@
#define IDC_KEYFILES_SIZE_UNIT 5143
#define IDC_LINK_KEYFILES_EXTENSIONS_WARNING 5144
#define IDC_DISABLE_MEMORY_PROTECTION 5145
#define IDC_DISABLE_MEMORY_PROTECTION_HELP 5146
// Next default values for new objects
//
@@ -235,7 +236,7 @@
#define _APS_NO_MFC 1
#define _APS_NEXT_RESOURCE_VALUE 578
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 5146
#define _APS_NEXT_CONTROL_VALUE 5147
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

View File

@@ -11574,6 +11574,7 @@ void NotifyService (DWORD dwNotifyCmd)
static BOOL CALLBACK PerformanceSettingsDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
static HWND hDisableMemProtectionTooltipWnd = NULL;
WORD lw = LOWORD (wParam);
switch (msg)
@@ -11652,9 +11653,24 @@ static BOOL CALLBACK PerformanceSettingsDlgProc (HWND hwndDlg, UINT msg, WPARAM
ToHyperlink (hwndDlg, IDC_MORE_INFO_ON_HW_ACCELERATION);
ToHyperlink (hwndDlg, IDC_MORE_INFO_ON_THREAD_BASED_PARALLELIZATION);
hDisableMemProtectionTooltipWnd = CreateToolTip (IDC_DISABLE_MEMORY_PROTECTION, hwndDlg, "DISABLE_MEMORY_PROTECTION_WARNING");
// make IDC_DISABLE_MEMORY_PROTECTION control fit the text so that the tooltip is shown only when mouse is over the text
AccommodateCheckBoxTextWidth(hwndDlg, IDC_DISABLE_MEMORY_PROTECTION);
// make the help button adjacent to the checkbox
MakeControlsContiguous(hwndDlg, IDC_DISABLE_MEMORY_PROTECTION, IDC_DISABLE_MEMORY_PROTECTION_HELP);
}
return 0;
// handle message to destroy hDisableMemProtectionTooltipWnd when the dialog is closed
case WM_DESTROY:
if (hDisableMemProtectionTooltipWnd)
{
DestroyWindow (hDisableMemProtectionTooltipWnd);
hDisableMemProtectionTooltipWnd = NULL;
}
break;
case WM_COMMAND:
switch (lw)
@@ -11852,10 +11868,18 @@ static BOOL CALLBACK PerformanceSettingsDlgProc (HWND hwndDlg, UINT msg, WPARAM
BOOL originalDisableMemoryProtection = !ReadMemoryProtectionConfig();
if (disableMemoryProtection != originalDisableMemoryProtection)
{
if (disableMemoryProtection)
{
Warning ("DISABLE_MEMORY_PROTECTION_WARNING", hwndDlg);
}
Warning ("SETTING_REQUIRES_REBOOT", hwndDlg);
}
}
return 1;
case IDC_DISABLE_MEMORY_PROTECTION_HELP:
Applink ("memoryprotection");
return 1;
case IDC_BENCHMARK:
Benchmark (hwndDlg);
return 1;

View File

@@ -345,8 +345,9 @@ BEGIN
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,18,237,335,10
CONTROL "Activate encryption of keys and passwords stored in RAM",IDC_ENABLE_RAM_ENCRYPTION,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,18,250,337,10
CONTROL "Disable memory protection in VeraCrypt",IDC_DISABLE_MEMORY_PROTECTION,
CONTROL "Disable memory protection for Accessibility tools compatibility",IDC_DISABLE_MEMORY_PROTECTION,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,18,263,339,10
PUSHBUTTON "?",IDC_DISABLE_MEMORY_PROTECTION_HELP,364,259,7,14
PUSHBUTTON "&Benchmark",IDC_BENCHMARK,7,279,59,14
DEFPUSHBUTTON "OK",IDOK,257,279,50,14
PUSHBUTTON "Cancel",IDCANCEL,314,279,50,14

View File

@@ -198,8 +198,8 @@
#define IDC_FORCE_NEXT_BOOT_VERACRYPT 1176
#define IDC_FORCE_VERACRYPT_BOOT_ENTRY 1177
#define IDC_FORCE_VERACRYPT_FIRST_BOOT_ENTRY 1178
#define IDC_ENABLE_EMV_SUPPORT 1179
#define IDT_EMV_OPTIONS 1180
#define IDC_ENABLE_EMV_SUPPORT 1179
#define IDT_EMV_OPTIONS 1180
#define IDM_HELP 40001
#define IDM_ABOUT 40002
#define IDM_UNMOUNT_VOLUME 40003
@@ -277,7 +277,7 @@
#define _APS_NO_MFC 1
#define _APS_NEXT_RESOURCE_VALUE 120
#define _APS_NEXT_COMMAND_VALUE 40070
#define _APS_NEXT_CONTROL_VALUE 1179
#define _APS_NEXT_CONTROL_VALUE 1181
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

View File

@@ -151,8 +151,9 @@ BEGIN
CONTROL "Add VeraCrypt icon to &desktop",IDC_DESKTOP_ICON,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,92,168,11
CONTROL "Associate the .hc file &extension with VeraCrypt",IDC_FILE_TYPE,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,104,232,11
CONTROL "Disable memory protection in VeraCrypt",IDC_DISABLE_MEMORY_PROTECTION,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,115,218,10
CONTROL "Disable memory protection for Accessibility tools compatibility",IDC_DISABLE_MEMORY_PROTECTION,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,115,315,10
PUSHBUTTON "?",IDC_DISABLE_MEMORY_PROTECTION_HELP,337,111,7,14
CONTROL "Create System &Restore point",IDC_SYSTEM_RESTORE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,125,194,11
LTEXT "Please select or type the location where you want to install the VeraCrypt program files. If the specified folder does not exist, it will be automatically created.",IDT_INSTALL_DESTINATION,11,14,319,25
END

View File

@@ -212,6 +212,7 @@ static int GetDonVal (int minVal, int maxVal)
BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static char PageDebugId[128];
static HWND hDisableMemProtectionTooltipWnd = NULL;
WORD lw = LOWORD (wParam);
WORD hw = HIWORD (wParam);
@@ -439,9 +440,16 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
EnableWindow (GetDlgItem (hwndDlg, IDC_SYSTEM_RESTORE), FALSE);
}
hDisableMemProtectionTooltipWnd = CreateToolTip (IDC_DISABLE_MEMORY_PROTECTION, hwndDlg, "DISABLE_MEMORY_PROTECTION_WARNING");
// make IDC_DISABLE_MEMORY_PROTECTION control fit the text so that the tooltip is shown only when mouse is over the text
AccommodateCheckBoxTextWidth(hwndDlg, IDC_DISABLE_MEMORY_PROTECTION);
// make the help button adjacent to the checkbox
MakeControlsContiguous(hwndDlg, IDC_DISABLE_MEMORY_PROTECTION, IDC_DISABLE_MEMORY_PROTECTION_HELP);
SetCheckBox (hwndDlg, IDC_ALL_USERS, bForAllUsers);
SetCheckBox (hwndDlg, IDC_FILE_TYPE, bRegisterFileExt);
SetCheckBox (hwndDlg, IDC_PROG_GROUP, bAddToStartMenu);
SetCheckBox (hwndDlg, IDC_DISABLE_MEMORY_PROTECTION, bDisableMemoryProtection);
SetCheckBox (hwndDlg, IDC_DESKTOP_ICON, bDesktopIcon);
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString (bUpgrade ? "UPGRADE" : "INSTALL"));
@@ -687,6 +695,14 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
case IDC_DISABLE_MEMORY_PROTECTION:
bDisableMemoryProtection = IsButtonChecked (GetDlgItem (hCurPage, IDC_DISABLE_MEMORY_PROTECTION));
if (bDisableMemoryProtection)
{
Warning ("DISABLE_MEMORY_PROTECTION_WARNING", hwndDlg);
}
return 1;
case IDC_DISABLE_MEMORY_PROTECTION_HELP:
Applink("memoryprotection")
return 1;
case IDC_FILE_TYPE:
@@ -764,6 +780,16 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
}
return 0;
case WM_DESTROY:
if (hDisableMemProtectionTooltipWnd != NULL)
{
DestroyWindow (hDisableMemProtectionTooltipWnd);
hDisableMemProtectionTooltipWnd = NULL;
}
break;
}
return 0;