diff options
Diffstat (limited to 'src/Common/Dlgcode.c')
-rw-r--r-- | src/Common/Dlgcode.c | 128 |
1 files changed, 101 insertions, 27 deletions
diff --git a/src/Common/Dlgcode.c b/src/Common/Dlgcode.c index e7103d0d..b91167d4 100644 --- a/src/Common/Dlgcode.c +++ b/src/Common/Dlgcode.c @@ -2156,7 +2156,7 @@ BOOL CALLBACK AboutDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam L"Based on TrueCrypt 7.1a, freely available at http://www.truecrypt.org/ .\r\n\r\n" L"Portions of this software:\r\n" - L"Copyright \xA9 2013-2023 IDRIX. All rights reserved.\r\n" + L"Copyright \xA9 2013-2024 IDRIX. All rights reserved.\r\n" L"Copyright \xA9 2003-2012 TrueCrypt Developers Association. All Rights Reserved.\r\n" L"Copyright \xA9 1998-2000 Paul Le Roux. All Rights Reserved.\r\n" L"Copyright \xA9 1998-2008 Brian Gladman. All Rights Reserved.\r\n" @@ -2169,7 +2169,7 @@ BOOL CALLBACK AboutDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam L"Copyright \xA9 1999-2023 Igor Pavlov\r\n\r\n" L"This software as a whole:\r\n" - L"Copyright \xA9 2013-2023 IDRIX. All rights reserved.\r\n\r\n" + L"Copyright \xA9 2013-2024 IDRIX. All rights reserved.\r\n\r\n" L"An IDRIX Release"); @@ -4165,6 +4165,7 @@ BOOL CALLBACK TextEditDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa case WM_INITDIALOG: { prm = (TEXT_INFO_DIALOG_PARAM_PTR)lParam; + LocalizeDialog (hwndDlg, NULL); // increase size limit of rich edit control SendMessage(GetDlgItem (hwndDlg, IDC_INFO_BOX_TEXT), EM_EXLIMITTEXT, 0, -1); @@ -4175,9 +4176,43 @@ BOOL CALLBACK TextEditDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa if (prm->ReadOnly) { // switch rich edit control to ReadOnly - SendMessage(GetDlgItem (hwndDlg, IDC_INFO_BOX_TEXT), ES_READONLY, TRUE, 0); + SendMessage(GetDlgItem (hwndDlg, IDC_INFO_BOX_TEXT), EM_SETREADONLY , TRUE, 0); // hide cancel button - ShowWindow(GetDlgItem(hwndDlg, IDCANCEL), SW_HIDE); + HWND hwndCancel = GetDlgItem(hwndDlg, IDCANCEL); + ShowWindow(hwndCancel, SW_HIDE); + + // Reposition OK button to Cancel button's position + HWND hwndOK = GetDlgItem(hwndDlg, IDOK); + if (hwndOK && hwndCancel) + { + // Get Cancel button's position in screen coordinates + RECT rectCancel; + if (GetWindowRect(hwndCancel, &rectCancel)) + { + // Convert Cancel button's position to dialog's client coordinates + POINT ptCancel = { rectCancel.left, rectCancel.top }; + ScreenToClient(hwndDlg, &ptCancel); + + // Get OK button's current size + RECT rectOK; + if (GetWindowRect(hwndOK, &rectOK)) + { + int width = rectOK.right - rectOK.left; + int height = rectOK.bottom - rectOK.top; + + // Move OK button to Cancel button's position + SetWindowPos( + hwndOK, + NULL, + ptCancel.x, + ptCancel.y, + width, + height, + SWP_NOZORDER | SWP_NOACTIVATE + ); + } + } + } } SendMessage (hwndDlg, TC_APPMSG_LOAD_TEXT_BOX_CONTENT, 0, 0); @@ -4189,8 +4224,12 @@ BOOL CALLBACK TextEditDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa { if (!prm->ReadOnly) { - prm->Text.resize(GetWindowTextLengthA (GetDlgItem (hwndDlg, IDC_INFO_BOX_TEXT)) + 1); - GetWindowTextA (GetDlgItem (hwndDlg, IDC_INFO_BOX_TEXT), &(prm->Text)[0], (int) prm->Text.size()); + // read content of the text box as UTF16 and then convert it to UTF8 + HWND hEdit = GetDlgItem(hwndDlg, IDC_INFO_BOX_TEXT); + int size = GetWindowTextLengthW(hEdit); + std::vector<WCHAR> buffer(size + 1); + GetWindowTextW(hEdit, buffer.data(), size + 1); + prm->Text = WideToUtf8String(buffer.data()); } NormalCursor (); EndDialog (hwndDlg, IDOK); @@ -4207,7 +4246,8 @@ BOOL CALLBACK TextEditDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa case TC_APPMSG_LOAD_TEXT_BOX_CONTENT: { - SetWindowTextA (GetDlgItem (hwndDlg, IDC_INFO_BOX_TEXT), prm->Text.c_str()); + // convert prm->Text to UTF16 using Utf8StringToWide + SetWindowTextW(GetDlgItem(hwndDlg, IDC_INFO_BOX_TEXT), Utf8StringToWide(prm->Text).c_str()); } return 0; @@ -5577,6 +5617,14 @@ void handleError (HWND hwndDlg, int code, const char* srcPos) break; #endif + case ERR_XTS_MASTERKEY_VULNERABLE: + MessageBoxW (hwndDlg, AppendSrcPos (GetString ("ERR_XTS_MASTERKEY_VULNERABLE"), srcPos).c_str(), lpszTitle, ICON_HAND); + break; + + case ERR_SYSENC_XTS_MASTERKEY_VULNERABLE: + MessageBoxW (hwndDlg, AppendSrcPos (GetString ("ERR_SYSENC_XTS_MASTERKEY_VULNERABLE"), srcPos).c_str(), lpszTitle, ICON_HAND); + break; + default: StringCbPrintfW (szTmp, sizeof(szTmp), GetString ("ERR_UNKNOWN"), code); MessageBoxW (hwndDlg, AppendSrcPos (szTmp, srcPos).c_str(), lpszTitle, ICON_HAND); @@ -8953,6 +9001,12 @@ retry: LastMountedVolumeDirty = mount.FilesystemDirty; + if (mount.VolumeMasterKeyVulnerable + && !Silent) + { + Warning ("ERR_XTS_MASTERKEY_VULNERABLE", hwndDlg); + } + if (mount.FilesystemDirty) { wchar_t msg[1024]; @@ -13692,11 +13746,11 @@ BOOL SetPrivilege(LPTSTR szPrivilegeName, BOOL bEnable) &tkp.Privileges[0].Luid)) { tkp.PrivilegeCount = 1; - tkp.Privileges[0].Attributes = bEnable? SE_PRIVILEGE_ENABLED : SE_PRIVILEGE_REMOVED; + tkp.Privileges[0].Attributes = bEnable? SE_PRIVILEGE_ENABLED : 0; bRet = AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, NULL, NULL); dwLastError = GetLastError (); - if ( ERROR_SUCCESS != dwLastError) + if (bRet && (ERROR_NOT_ALL_ASSIGNED == dwLastError)) { bRet = FALSE; } @@ -13907,20 +13961,33 @@ static unsigned int __stdcall SecureDesktopThread( LPVOID lpThreadParameter ) StringCbCopy(SecureDesktopName, sizeof (SecureDesktopName), pParam->szDesktopName); pParam->hDesk = hSecureDesk; - // wait for SwitchDesktop to succeed before using it for current thread - while (true) + bNewDesktopSet = SetThreadDesktop (hSecureDesk); + + if (bNewDesktopSet) { - if (SwitchDesktop (hSecureDesk)) + // call ImmDisableIME from imm32.dll to disable IME since it can create issue with secure desktop + // cf: https://keepass.info/help/kb/sec_desk.html#ime + HMODULE hImmDll = LoadLibraryEx (L"imm32.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32); + if (hImmDll) { - break; + typedef BOOL (WINAPI *ImmDisableIME_t)(DWORD); + ImmDisableIME_t ImmDisableIME = (ImmDisableIME_t) GetProcAddress (hImmDll, "ImmDisableIME"); + if (ImmDisableIME) + { + ImmDisableIME (0); + } } - Sleep (SECUREDESKTOP_MONOTIR_PERIOD); - } - bNewDesktopSet = SetThreadDesktop (hSecureDesk); + // wait for SwitchDesktop to succeed before using it for current thread + while (true) + { + if (SwitchDesktop (hSecureDesk)) + { + break; + } + Sleep (SECUREDESKTOP_MONOTIR_PERIOD); + } - if (bNewDesktopSet) - { // create the thread that will ensure that VeraCrypt secure desktop has always user input // this is done only if the stop event is created successfully HANDLE hStopEvent = CreateEvent(NULL, TRUE, FALSE, NULL); @@ -13950,6 +14017,12 @@ static unsigned int __stdcall SecureDesktopThread( LPVOID lpThreadParameter ) } pParam->bDlgDisplayed = TRUE; + + // free imm32.dll handle + if (hImmDll) + { + FreeLibrary (hImmDll); + } } else { @@ -14070,19 +14143,20 @@ INT_PTR SecureDesktopDialogBoxParam( // dialog box was indeed displayed in Secure Desktop retValue = param.retValue; bSuccess = TRUE; + + // switch back to the original desktop + while (!SwitchDesktop (hOriginalDesk)) + { + Sleep (SECUREDESKTOP_MONOTIR_PERIOD); + } + + SetThreadDesktop (hOriginalDesk); } - } - if (param.hDesk) - { - while (!SwitchDesktop (hOriginalDesk)) + if (param.hDesk) { - Sleep (SECUREDESKTOP_MONOTIR_PERIOD); + CloseDesktop (param.hDesk); } - - SetThreadDesktop (hOriginalDesk); - - CloseDesktop (param.hDesk); } // get the new list of ctfmon.exe processes in order to find the ID of the |