diff options
Diffstat (limited to 'src/Common/Dlgcode.c')
-rw-r--r-- | src/Common/Dlgcode.c | 71 |
1 files changed, 61 insertions, 10 deletions
diff --git a/src/Common/Dlgcode.c b/src/Common/Dlgcode.c index 2c707f5d..c3430525 100644 --- a/src/Common/Dlgcode.c +++ b/src/Common/Dlgcode.c @@ -2036,106 +2036,113 @@ void HandlePasswordEditWmChar (HWND hwnd, WPARAM wParam) short vk = VkKeyScanW ((WCHAR) wParam); BYTE vkCode = LOBYTE (vk); BYTE vkState = HIBYTE (vk); bool ctrlPressed = (vkState & 2) && !(vkState & 4); int dwMaxPassLen = (int) SendMessage (hwnd, EM_GETLIMITTEXT, 0, 0); // check if there is a selected text SendMessage (hwnd, EM_GETSEL, (WPARAM) &dwStartPos, (LPARAM) &dwEndPos); if ((dwStartPos == dwEndPos) && (vkCode != VK_DELETE) && (vkCode != VK_BACK) && !ctrlPressed && (GetWindowTextLength (hwnd) == dwMaxPassLen)) { EDITBALLOONTIP ebt; DWORD dwTextSize = (DWORD) wcslen (GetString ("PASSWORD_MAXLENGTH_REACHED")) + 16; WCHAR* szErrorText = (WCHAR*) malloc (dwTextSize * sizeof (WCHAR)); StringCchPrintf (szErrorText, dwTextSize, GetString ("PASSWORD_MAXLENGTH_REACHED"), dwMaxPassLen); ebt.cbStruct = sizeof( EDITBALLOONTIP ); ebt.pszText = szErrorText; ebt.pszTitle = lpszTitle; ebt.ttiIcon = TTI_ERROR_LARGE; // tooltip warning icon SendMessage(hwnd, EM_SHOWBALLOONTIP, 0, (LPARAM)&ebt); MessageBeep (0xFFFFFFFF); free (szErrorText); } else SendMessage(hwnd, EM_HIDEBALLOONTIP, 0, 0); } -// Protects an input field from having its content updated by a Paste action (call ToBootPwdField() to use this). + +/* Protects an input field from having its content updated by a paste action */ static LRESULT CALLBACK BootPwdFieldProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { WNDPROC wp = (WNDPROC) GetWindowLongPtrW (hwnd, GWLP_USERDATA); - + switch (message) { case WM_PASTE: + Error ("ERROR_PASTE_ACTION", GetParent(hwnd)); return 1; + case WM_CHAR: HandlePasswordEditWmChar (hwnd, wParam); break; } - return CallWindowProcW (wp, hwnd, message, wParam, lParam); } - // Protects an input field from having its content updated by a Paste action. Used for pre-boot password // input fields (only the US keyboard layout is supported in pre-boot environment so we must prevent the // user from pasting a password typed using a non-US keyboard layout). void ToBootPwdField (HWND hwndDlg, UINT ctrlId) { HWND hwndCtrl = GetDlgItem (hwndDlg, ctrlId); WNDPROC originalwp = (WNDPROC) GetWindowLongPtrW (hwndCtrl, GWLP_USERDATA); SendMessage (hwndCtrl, EM_LIMITTEXT, MAX_LEGACY_PASSWORD, 0); // if ToNormalPwdField has been called before, GWLP_USERDATA already contains original WNDPROC if (!originalwp) { SetWindowLongPtrW (hwndCtrl, GWLP_USERDATA, (LONG_PTR) GetWindowLongPtrW (hwndCtrl, GWLP_WNDPROC)); } SetWindowLongPtrW (hwndCtrl, GWLP_WNDPROC, (LONG_PTR) BootPwdFieldProc); } +BOOL CheckIsIMESupported () +{ + if (himm32dll == NULL) + return FALSE; + return TRUE; +} // Ensures that a warning is displayed when user is pasting a password longer than the maximum // length which is set to 64 characters static LRESULT CALLBACK NormalPwdFieldProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { WNDPROC wp = (WNDPROC) GetWindowLongPtrW (hwnd, GWLP_USERDATA); switch (message) { case WM_PASTE: { bool bBlock = false; if (OpenClipboard (NULL)) { HANDLE h = GetClipboardData (CF_UNICODETEXT); if (h) { wchar_t *pchData = (wchar_t*)GlobalLock(h); int txtlen = 0; int dwMaxPassLen = bUseLegacyMaxPasswordLength? MAX_LEGACY_PASSWORD : MAX_PASSWORD; while (*pchData) { if (*pchData == '\r' || *pchData == '\n') break; else { txtlen++; pchData++; } } if (txtlen) { int curLen = GetWindowTextLength (hwnd); if (curLen == dwMaxPassLen) { @@ -2902,71 +2909,71 @@ void HandCursor () { static HCURSOR hcHand = NULL; if (hcHand == NULL) hcHand = LoadCursor (NULL, IDC_HAND); SetCursor (hcHand); hCursor = hcHand; } void AddComboPair (HWND hComboBox, const wchar_t *lpszItem, int value) { LPARAM nIndex; nIndex = SendMessage (hComboBox, CB_ADDSTRING, 0, (LPARAM) lpszItem); nIndex = SendMessage (hComboBox, CB_SETITEMDATA, nIndex, (LPARAM) value); } void SelectAlgo (HWND hComboBox, int *algo_id) { LPARAM nCount = SendMessage (hComboBox, CB_GETCOUNT, 0, 0); LPARAM x, i; for (i = 0; i < nCount; i++) { x = SendMessage (hComboBox, CB_GETITEMDATA, i, 0); if (x == (LPARAM) *algo_id) { SendMessage (hComboBox, CB_SETCURSEL, i, 0); return; } } /* Something went wrong ; couldn't find the requested algo id so we drop back to a default */ - + *algo_id = (int) SendMessage (hComboBox, CB_GETITEMDATA, 0, 0); SendMessage (hComboBox, CB_SETCURSEL, 0, 0); } void PopulateWipeModeCombo (HWND hComboBox, BOOL bNA, BOOL bInPlaceEncryption, BOOL bHeaderWipe) { if (bNA) { AddComboPair (hComboBox, GetString ("NOT_APPLICABLE_OR_NOT_AVAILABLE"), TC_WIPE_NONE); } else { if (!bHeaderWipe) { AddComboPair (hComboBox, GetString ("WIPE_MODE_NONE"), TC_WIPE_NONE); } AddComboPair (hComboBox, GetString ("WIPE_MODE_1_RAND"), TC_WIPE_1_RAND); AddComboPair (hComboBox, GetString ("WIPE_MODE_3_DOD_5220"), TC_WIPE_3_DOD_5220); AddComboPair (hComboBox, GetString ("WIPE_MODE_7_DOD_5220"), TC_WIPE_7_DOD_5220); AddComboPair (hComboBox, GetString ("WIPE_MODE_35_GUTMANN"), TC_WIPE_35_GUTMANN); if (bHeaderWipe) AddComboPair (hComboBox, GetString ("WIPE_MODE_256"), TC_WIPE_256); // paranoid wipe for volume header } } wchar_t *GetWipeModeName (WipeAlgorithmId modeId) { switch (modeId) { case TC_WIPE_NONE: return GetString ("WIPE_MODE_NONE"); @@ -5429,70 +5436,117 @@ load: CloseHandle (hDriver); hDriver = INVALID_HANDLE_VALUE; return ERR_DRIVER_VERSION; } } #else if (!bResult) DriverVersion = 0; #endif } return 0; } void ResetCurrentDirectory () { wchar_t p[MAX_PATH]; if (!IsNonInstallMode () && SHGetFolderPath (NULL, CSIDL_PROFILE, NULL, 0, p) == ERROR_SUCCESS) { SetCurrentDirectory (p); } else { GetModPath (p, ARRAYSIZE (p)); SetCurrentDirectory (p); } } BOOL BrowseFiles (HWND hwndDlg, char *stringId, wchar_t *lpszFileName, BOOL keepHistory, BOOL saveMode, wchar_t *browseFilter) { return BrowseFilesInDir (hwndDlg, stringId, NULL, lpszFileName, keepHistory, saveMode, browseFilter); } +BOOL BrowseFile (HWND hwndDlg, char *stringId, wchar_t *initialDir) +{ + OPENFILENAMEW ofn; + wchar_t file[TC_MAX_PATH] = { 0 }; + wchar_t filter[1024]; + BOOL status = FALSE; + + CoInitialize (NULL); + + ZeroMemory (&ofn, sizeof (ofn)); + + if (initialDir) + { + ofn.lpstrInitialDir = initialDir; + } + + ofn.lStructSize = sizeof (ofn); + ofn.hwndOwner = hwndDlg; + StringCbPrintfW (filter, sizeof(filter), L"%ls (*.*)%c*.*%c", + GetString ("ALL_FILES"), 0, 0); + ofn.lpstrFilter = filter; + ofn.nFilterIndex = 1; + ofn.lpstrFile = NULL; + ofn.nMaxFile = sizeof (file) / sizeof (file[0]); + ofn.lpstrTitle = GetString (stringId); + ofn.lpstrDefExt = NULL; + ofn.Flags = OFN_HIDEREADONLY + | OFN_PATHMUSTEXIST + | OFN_DONTADDTORECENT; + + SystemFileSelectorCallerThreadId = GetCurrentThreadId(); + SystemFileSelectorCallPending = TRUE; + + if (!GetOpenFileNameW (&ofn)) + goto ret; + + SystemFileSelectorCallPending = FALSE; + + status = TRUE; + +ret: + SystemFileSelectorCallPending = FALSE; + ResetCurrentDirectory(); + CoUninitialize(); + + return status; +} BOOL BrowseFilesInDir (HWND hwndDlg, char *stringId, wchar_t *initialDir, wchar_t *lpszFileName, BOOL keepHistory, BOOL saveMode, wchar_t *browseFilter, const wchar_t *initialFileName, const wchar_t *defaultExtension) { OPENFILENAMEW ofn; wchar_t file[TC_MAX_PATH] = { 0 }; wchar_t filter[1024]; BOOL status = FALSE; CoInitialize (NULL); ZeroMemory (&ofn, sizeof (ofn)); *lpszFileName = 0; if (initialDir) { ofn.lpstrInitialDir = initialDir; } if (initialFileName) StringCchCopyW (file, array_capacity (file), initialFileName); ofn.lStructSize = sizeof (ofn); ofn.hwndOwner = hwndDlg; StringCbPrintfW (filter, sizeof(filter), L"%ls (*.*)%c*.*%c%ls (*.hc)%c*.hc%c%c", GetString ("ALL_FILES"), 0, 0, GetString ("TC_VOLUMES"), 0, 0, 0); ofn.lpstrFilter = browseFilter ? browseFilter : filter; ofn.nFilterIndex = 1; ofn.lpstrFile = file; ofn.nMaxFile = sizeof (file) / sizeof (file[0]); ofn.lpstrTitle = GetString (stringId); ofn.lpstrDefExt = defaultExtension; ofn.Flags = OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | (keepHistory ? 0 : OFN_DONTADDTORECENT) @@ -9950,72 +10004,70 @@ BOOL PrintHardCopyTextUTF16 (wchar_t *text, wchar_t *title, size_t textByteLen) if (!SaveBufferToFile ("\xFF\xFE", path, 2, FALSE, FALSE)) { _wremove (path); return FALSE; } // Write the actual text if (!SaveBufferToFile ((char *) text, path, (DWORD) textByteLen, TRUE, FALSE)) { _wremove (path); return FALSE; } StringCbCatW (cl, sizeof(cl), path); StringCbCatW (cl, sizeof(cl), L"\""); // Get the absolute path for notepad if (GetWindowsDirectory(filename, MAX_PATH)) { if (filename[wcslen (filename) - 1] != L'\\') StringCbCatW (filename, sizeof(filename), L"\\"); StringCbCatW(filename, sizeof(filename), PRINT_TOOL); } else StringCbCopyW(filename, sizeof(filename), L"C:\\Windows\\" PRINT_TOOL); WaitCursor (); ShellExecute (NULL, L"open", filename, cl, NULL, SW_HIDE); Sleep (6000); NormalCursor(); _wremove (path); return TRUE; } - - BOOL IsNonInstallMode () { HKEY hkey, hkeybis; DWORD dw; WCHAR szBuffer[512]; DWORD dwBufferSize = sizeof(szBuffer); std::wstring msiProductGUID; if (bPortableModeConfirmed) return TRUE; if (hDriver != INVALID_HANDLE_VALUE) { // The driver is running if (DeviceIoControl (hDriver, TC_IOCTL_GET_PORTABLE_MODE_STATUS, NULL, 0, NULL, 0, &dw, 0)) { bPortableModeConfirmed = TRUE; return TRUE; } else { // This is also returned if we fail to determine the status (it does not mean that portable mode is disproved). return FALSE; } } else { // The tests in this block are necessary because this function is in some cases called before DriverAttach(). HANDLE hDriverTmp = CreateFile (WIN32_ROOT_PREFIX, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); if (hDriverTmp == INVALID_HANDLE_VALUE) { // The driver was not found in the system path @@ -10050,71 +10102,70 @@ BOOL IsNonInstallMode () // The following test checks whether the MSI is installed, which means we're not in portable mode. // The ProductGUID is read from registry. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"Software\\VeraCrypt_MSI", 0, KEY_QUERY_VALUE | KEY_WOW64_32KEY, &hkey) == ERROR_SUCCESS || RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"Software\\VeraCrypt_MSI", 0, KEY_QUERY_VALUE, &hkey) == ERROR_SUCCESS) { if (ERROR_SUCCESS == RegQueryValueExW(hkey, L"ProductGuid", 0, NULL, (LPBYTE)szBuffer, &dwBufferSize)) { msiProductGUID = szBuffer; std::wstring regKey = L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\"; regKey += msiProductGUID; if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, regKey.c_str(), 0, KEY_READ | KEY_WOW64_32KEY, &hkeybis) == ERROR_SUCCESS || RegOpenKeyEx(HKEY_LOCAL_MACHINE, regKey.c_str(), 0, KEY_READ, &hkeybis) == ERROR_SUCCESS) { RegCloseKey(hkeybis); return FALSE; } } RegCloseKey(hkey); } // The following test may be unreliable in some cases (e.g. after the user selects restore "Last Known Good // Configuration" from the Windows boot menu). if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\VeraCrypt", 0, KEY_READ | KEY_WOW64_32KEY, &hkey) == ERROR_SUCCESS) { RegCloseKey (hkey); return FALSE; } else return TRUE; } - LRESULT SetCheckBox (HWND hwndDlg, int dlgItem, BOOL state) { return SendDlgItemMessage (hwndDlg, dlgItem, BM_SETCHECK, state ? BST_CHECKED : BST_UNCHECKED, 0); } BOOL GetCheckBox (HWND hwndDlg, int dlgItem) { return IsButtonChecked (GetDlgItem (hwndDlg, dlgItem)); } // Scroll the listview vertically so that the item with index of topMostVisibleItem is the topmost visible item. void SetListScrollHPos (HWND hList, int topMostVisibleItem) { int testedPos = 0; do { SendMessage (hList, LVM_SCROLL, 0, testedPos); } while (ListView_GetTopIndex (hList) < topMostVisibleItem && ++testedPos < 10000); } // Adds or removes TrueCrypt.exe to/from the system startup sequence (with appropriate command line arguments) void ManageStartupSeq (void) { if (!IsNonInstallMode ()) { wchar_t regk [64]; GetStartupRegKeyName (regk, sizeof(regk)); if (bStartOnLogon || bMountDevicesOnLogon || bMountFavoritesOnLogon) @@ -11591,83 +11642,83 @@ BOOL CALLBACK CloseTCWindowsEnum (HWND hwnd, LPARAM lParam) PostMessage (hwnd, TC_APPMSG_CLOSE_BKG_TASK, 0, 0); PostMessage (hwnd, WM_CLOSE, 0, 0); if (lParam != 0) *((BOOL *)lParam) = TRUE; } } return TRUE; } BOOL CALLBACK FindTCWindowEnum (HWND hwnd, LPARAM lParam) { if (*(HWND *)lParam == hwnd) return TRUE; LONG_PTR userDataVal = GetWindowLongPtrW (hwnd, GWLP_USERDATA); if ((userDataVal == (LONG_PTR) 'VERA') || (userDataVal == (LONG_PTR) 'TRUE')) // Prior to 1.0e, 'TRUE' was used for VeraCrypt dialogs { wchar_t name[32] = { 0 }; GetWindowText (hwnd, name, ARRAYSIZE (name) - 1); if (hwnd != MainDlg && wcscmp (name, L"VeraCrypt") == 0) { if (lParam != 0) *((HWND *)lParam) = hwnd; } } return TRUE; } BYTE *MapResource (wchar_t *resourceType, int resourceId, PDWORD size) { HGLOBAL hResL; HRSRC hRes; - HINSTANCE hResInst = NULL; + HINSTANCE hResInst = NULL; #ifdef SETUP_DLL // In case we're being called from the SetupDLL project, FindResource() // and LoadResource() with NULL will fail since we're in a DLL. We need // to call them with the HINSTANCE of the DLL instead, which we set in // Setup.c of SetupDLL, DllMain() function. hResInst = hInst; #endif hRes = FindResource (hResInst, MAKEINTRESOURCE(resourceId), resourceType); hResL = LoadResource (hResInst, hRes); - + if (size != NULL) *size = SizeofResource (hResInst, hRes); return (BYTE *) LockResource (hResL); } void InconsistencyResolved (char *techInfo) { wchar_t finalMsg[8024]; StringCbPrintfW (finalMsg, sizeof(finalMsg), GetString ("INCONSISTENCY_RESOLVED"), techInfo); MessageBoxW (MainDlg, finalMsg, lpszTitle, MB_ICONWARNING | MB_SETFOREGROUND | MB_TOPMOST); } void ReportUnexpectedState (const char *techInfo) { wchar_t finalMsg[8024]; StringCbPrintfW (finalMsg, sizeof(finalMsg), GetString ("UNEXPECTED_STATE"), techInfo); MessageBoxW (MainDlg, finalMsg, lpszTitle, MB_ICONERROR | MB_SETFOREGROUND | MB_TOPMOST); } #ifndef SETUP int OpenVolume (OpenVolumeContext *context, const wchar_t *volumePath, Password *password, int pkcs5_prf, int pim, BOOL truecryptMode, BOOL write, BOOL preserveTimestamps, BOOL useBackupHeader) { int status = ERR_PARAMETER_INCORRECT; int volumeType; wchar_t szDiskFile[TC_MAX_PATH], szCFDevice[TC_MAX_PATH]; wchar_t szDosDevice[TC_MAX_PATH]; char buffer[TC_VOLUME_HEADER_EFFECTIVE_SIZE]; LARGE_INTEGER headerOffset; |