/* Legal Notice: Some portions of the source code contained in this file were derived from the source code of TrueCrypt 7.1a, which is Copyright (c) 2003-2012 TrueCrypt Developers Association and which is governed by the TrueCrypt License 3.0, also from the source code of Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux and which is governed by the 'License Agreement for Encryption for the Masses' and also from the source code of extcv, which is Copyright (c) 2009-2010 Kih-Oskh or Copyright (c) 2012-2013 Josef Schneider Modifications and additions to the original source code (contained in this file) and all other portions of this file are Copyright (c) 2013-2016 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ #include "Tcdefs.h" #include "cpu.h" #include #include #include #include #include #include #include #include "Apidrvr.h" #include "BootEncryption.h" #include "Cmdline.h" #include "Crypto.h" #include "Dlgcode.h" #include "Combo.h" #include "Keyfiles.h" #include "Language.h" #include "../Mount/MainCom.h" #include "../Mount/Mount.h" #include "Pkcs5.h" #include "Random.h" #include "Registry.h" #include "Resource.h" #include "Password.h" #include "Xml.h" #include "../Boot/Windows/BootCommon.h" #include "../Common/Dictionary.h" #include "../Common/Common.h" #include "../Common/Resource.h" #include "../Common/SecurityToken.h" #include "../Platform/Finally.h" #include "../Platform/ForEach.h" #include #include "ExpandVolume.h" using namespace VeraCrypt; const wchar_t szExpandVolumeInfo[] = L":: VeraCrypt Expander ::\n\nExpand a VeraCrypt volume on the fly without reformatting\n\n\n\ All kind of volumes (container files, disks and partitions) formatted with \ NTFS are supported. The only condition is that there must be enough free \ space on the host drive or host device of the VeraCrypt volume.\n\n\ Do not use this software to expand an outer volume containing a hidden \ volume, because this destroys the hidden volume!\n\ "; enum timer_ids { TIMER_ID_MAIN = 0xff, TIMER_ID_KEYB_LAYOUT_GUARD }; enum hidden_os_read_only_notif_mode { TC_HIDDEN_OS_READ_ONLY_NOTIF_MODE_NONE = 0, TC_HIDDEN_OS_READ_ONLY_NOTIF_MODE_COMPACT, TC_HIDDEN_OS_READ_ONLY_NOTIF_MODE_DISABLED }; #define TIMER_INTERVAL_MAIN 500 #define TIMER_INTERVAL_KEYB_LAYOUT_GUARD 10 namespace VeraCryptExpander { BOOL bExplore = FALSE; /* Display explorer window after mount */ BOOL bBeep = FALSE; /* Donot beep after mount */ wchar_t szFileName[TC_MAX_PATH+1]; /* Volume to mount */ wchar_t szDriveLetter[3]; /* Drive Letter to mount */ wchar_t commandLineDrive = 0; BOOL bCacheInDriver = FALSE; /* Cache any passwords we see */ BOOL bCacheInDriverDefault = FALSE; BOOL bHistoryCmdLine = FALSE; /* History control is always disabled */ BOOL bCloseDismountedWindows=TRUE; /* Close all open explorer windows of dismounted volume */ BOOL bWipeCacheOnExit = FALSE; /* Wipe password from chace on exit */ BOOL bWipeCacheOnAutoDismount = TRUE; BOOL bEnableBkgTask = FALSE; BOOL bCloseBkgTaskWhenNoVolumes = FALSE; BOOL bDismountOnLogOff = TRUE; BOOL bDismountOnScreenSaver = TRUE; BOOL bDismountOnPowerSaving = FALSE; BOOL bForceAutoDismount = TRUE; BOOL bForceMount = FALSE; /* Mount volume even if host file/device already in use */ BOOL bForceUnmount = FALSE; /* Unmount volume even if it cannot be locked */ BOOL bWipe = FALSE; /* Wipe driver passwords */ BOOL bAuto = FALSE; /* Do everything without user input */ BOOL bAutoMountDevices = FALSE; /* Auto-mount devices */ BOOL bAutoMountFavorites = FALSE; BOOL bPlaySoundOnHotkeyMountDismount = TRUE; BOOL bDisplayMsgBoxOnHotkeyDismount = FALSE; BOOL bHibernationPreventionNotified = FALSE; /* TRUE if the user has been notified that hibernation was prevented (system encryption) during the session. */ BOOL bHiddenSysLeakProtNotifiedDuringSession = FALSE; /* TRUE if the user has been notified during the session that unencrypted filesystems and non-hidden VeraCrypt volumes are mounted as read-only under hidden OS. */ BOOL CloseSecurityTokenSessionsAfterMount = FALSE; BOOL MultipleMountOperationInProgress = FALSE; BOOL Quit = FALSE; /* Exit after processing command line */ BOOL ComServerMode = FALSE; BOOL UsePreferences = TRUE; int HiddenSysLeakProtectionNotificationStatus = TC_HIDDEN_OS_READ_ONLY_NOTIF_MODE_NONE; int MaxVolumeIdleTime = -120; int nCurrentShowType = 0; /* current display mode, mount, unmount etc */ int nSelectedDriveIndex = -1; /* Item number of selected drive */ int cmdUnmountDrive = -2; /* Volume drive letter to unmount (-1 = all) */ Password VolumePassword; /* Password used for mounting volumes */ Password CmdVolumePassword; /* Password passed from command line */ BOOL CmdVolumePasswordValid = FALSE; MountOptions mountOptions; MountOptions defaultMountOptions; KeyFile *FirstCmdKeyFile; HBITMAP hbmLogoBitmapRescaled = NULL; wchar_t OrigKeyboardLayout [8+1] = L"00000409"; BOOL bKeyboardLayoutChanged = FALSE; /* TRUE if the keyboard layout was changed to the standard US keyboard layout (from any other layout). */ BOOL bKeybLayoutAltKeyWarningShown = FALSE; /* TRUE if the user has been informed that it is not possible to type characters by pressing keys while the right Alt key is held down. */ static KeyFilesDlgParam hidVolProtKeyFilesParam; VOLUME_NOTIFICATIONS_LIST VolumeNotificationsList; static int bPrebootPasswordDlgMode = FALSE; static void localcleanup (void) { // Wipe command line char *c = GetCommandLineA (); wchar_t *wc = GetCommandLineW (); burn(c, strlen (c)); burn(wc, wcslen (wc) * sizeof (wchar_t)); /* Delete buffered bitmaps (if any) */ if (hbmLogoBitmapRescaled != NULL) { DeleteObject ((HGDIOBJ) hbmLogoBitmapRescaled); hbmLogoBitmapRescaled = NULL; } /* These items should have already been cleared by the functions that used them, but we're going to clear them for extra security. */ burn (&VolumePassword, sizeof (VolumePassword)); burn (&CmdVolumePassword, sizeof (CmdVolumePassword)); burn (&mountOptions, sizeof (mountOptions)); burn (&defaultMountOptions, sizeof (defaultMountOptions)); burn (&szFileName, sizeof(szFileName)); /* Cleanup common code resources */ cleanup (); RandStop (TRUE); } void EndMainDlg (HWND hwndDlg) { if (!bHistory) { SetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), L""); } EndDialog (hwndDlg, 0); } BOOL CALLBACK MountOptionsDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { // dummy (referenced by PasswordDlgProc() ) return FALSE; } BOOL TCBootLoaderOnInactiveSysEncDrive (void) { // dummy (referenced by Dlgcode.c) return FALSE; } BOOL CheckSysEncMountWithoutPBA (const char *devicePath, BOOL quiet) { // dummy (referenced by Dlgcode.c) return FALSE; } static void InitMainDialog (HWND hwndDlg) { /* Call the common dialog init code */ InitDialog (hwndDlg); LocalizeDialog (hwndDlg, NULL); SendMessage (GetDlgItem (hwndDlg, IDC_VOLUME), CB_LIMITTEXT, TC_MAX_PATH, 0); SetWindowTextW (hwndDlg, lpszTitle); SendMessage (GetDlgItem (hwndDlg, IDC_INFOEXPAND), WM_SETFONT, (WPARAM) hBoldFont, (LPARAM) TRUE); SetWindowText (GetDlgItem (hwndDlg, IDC_INFOEXPAND), szExpandVolumeInfo); // Resize the logo bitmap if the user has a non-default DPI if (ScreenDPI != USER_DEFAULT_SCREEN_DPI && hbmLogoBitmapRescaled == NULL) // If not re-called (e.g. after language pack change) { hbmLogoBitmapRescaled = RenderBitmap (MAKEINTRESOURCE (IDB_LOGO_288DPI), GetDlgItem (hwndDlg, IDC_LOGO), 0, 0, 0, 0, FALSE, TRUE); } EnableDisableButtons (hwndDlg); } void EnableDisableButtons (HWND hwndDlg) { HWND hOKButton = GetDlgItem (hwndDlg, IDOK); WORD x; x = LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))); EnableWindow (hOKButton, TRUE); } BOOL VolumeSelected (HWND hwndDlg) { return (GetWindowTextLength (GetDlgItem (hwndDlg, IDC_VOLUME)) > 0); } void LoadSettings (HWND hwndDlg) { WipeAlgorithmId savedWipeAlgorithm = TC_WIPE_NONE; LoadSysEncSettings (); if (LoadNonSysInPlaceEncSettings (&savedWipeAlgorithm) != 0) bInPlaceEncNonSysPending = TRUE; // If the config file has already been loaded during this session if (ConfigBuffer != NULL) { free (ConfigBuffer); ConfigBuffer = NULL; } // Options bExplore = ConfigReadInt ("OpenExplorerWindowAfterMount", FALSE); bCloseDismountedWindows = ConfigReadInt ("CloseExplorerWindowsOnDismount", TRUE); bHistory = ConfigReadInt ("SaveVolumeHistory", FALSE); bCacheInDriverDefault = bCacheInDriver = ConfigReadInt ("CachePasswords", FALSE); bWipeCacheOnExit = ConfigReadInt ("WipePasswordCacheOnExit", FALSE); bWipeCacheOnAutoDismount = ConfigReadInt ("WipeCacheOnAutoDismount", TRUE); bStartOnLogon = ConfigReadInt ("StartOnLogon", FALSE); bMountDevicesOnLogon = ConfigReadInt ("MountDevicesOnLogon", FALSE); bMountFavoritesOnLogon = ConfigReadInt ("MountFavoritesOnLogon", FALSE); bEnableBkgTask = ConfigReadInt ("EnableBackgroundTask", TRUE); bCloseBkgTaskWhenNoVolumes = ConfigReadInt ("CloseBackgroundTaskOnNoVolumes", FALSE); bDismountOnLogOff = ConfigReadInt ("DismountOnLogOff", TRUE); bDismountOnPowerSaving = ConfigReadInt ("DismountOnPowerSaving", FALSE); bDismountOnScreenSaver = ConfigReadInt ("DismountOnScreenSaver", FALSE); bForceAutoDismount = ConfigReadInt ("ForceAutoDismount", TRUE); MaxVolumeIdleTime = ConfigReadInt ("MaxVolumeIdleTime", -60); HiddenSectorDetectionStatus = ConfigReadInt ("HiddenSectorDetectionStatus", 0); defaultKeyFilesParam.EnableKeyFiles = ConfigReadInt ("UseKeyfiles", FALSE); bPreserveTimestamp = defaultMountOptions.PreserveTimestamp = ConfigReadInt ("PreserveTimestamps", TRUE); bShowDisconnectedNetworkDrives = ConfigReadInt ("ShowDisconnectedNetworkDrives", FALSE); bHideWaitingDialog = ConfigReadInt ("HideWaitingDialog", FALSE); defaultMountOptions.Removable = ConfigReadInt ("MountVolumesRemovable", FALSE); defaultMountOptions.ReadOnly = ConfigReadInt ("MountVolumesReadOnly", FALSE); defaultMountOptions.ProtectHiddenVolume = FALSE; defaultMountOptions.PartitionInInactiveSysEncScope = FALSE; defaultMountOptions.RecoveryMode = FALSE; defaultMountOptions.UseBackupHeader = FALSE; mountOptions = defaultMountOptions; CloseSecurityTokenSessionsAfterMount = ConfigReadInt ("CloseSecurityTokenSessionsAfterMount", 0); { char szTmp[TC_MAX_PATH] = {0}; WideCharToMultiByte (CP_UTF8, 0, SecurityTokenLibraryPath, -1, szTmp, sizeof (szTmp), NULL, NULL); ConfigReadString ("SecurityTokenLibrary", "", szTmp, sizeof (szTmp) - 1); MultiByteToWideChar (CP_UTF8, 0, szTmp, -1, SecurityTokenLibraryPath, ARRAYSIZE (SecurityTokenLibraryPath)); if (SecurityTokenLibraryPath[0]) InitSecurityTokenLibrary(hwndDlg); } /* we don't load the history */ } BOOL SelectItem (HWND hTree, wchar_t nLetter) { int i; LVITEM item; for (i = 0; i < ListView_GetItemCount(hTree); i++) { memset(&item, 0, sizeof(LVITEM)); item.mask = LVIF_PARAM; item.iItem = i; if (ListView_GetItem (hTree, &item) == FALSE) return FALSE; else { if (HIWORD (item.lParam) == nLetter) { memset(&item, 0, sizeof(LVITEM)); item.state = LVIS_FOCUSED|LVIS_SELECTED; item.stateMask = LVIS_FOCUSED|LVIS_SELECTED; item.mask = LVIF_STATE; item.iItem = i; SendMessage(hTree, LVM_SETITEMSTATE, i, (LPARAM) &item); return TRUE; } } } return TRUE; } LPARAM GetSelectedLong (HWND hTree) { int hItem = ListView_GetSelectionMark (hTree); LVITEM item; if (nSelectedDriveIndex >= 0) hItem = nSelectedDriveIndex; memset(&item, 0, sizeof(LVITEM)); item.mask = LVIF_PARAM; item.iItem = hItem; if (ListView_GetItem (hTree, &item) == FALSE) return MAKELONG (0xffff, 0xffff); else return item.lParam; } LPARAM GetItemLong (HWND hTree, int itemNo) { LVITEM item; memset(&item, 0, sizeof(LVITEM)); item.mask = LVIF_PARAM; item.iItem = itemNo; if (ListView_GetItem (hTree, &item) == FALSE) return MAKELONG (0xffff, 0xffff); else return item.lParam; } static wchar_t PasswordDlgVolume[MAX_PATH + 1] = {0}; static BOOL PasswordDialogDisableMountOptions; static char *PasswordDialogTitleStringId; /* Except in response to the WM_INITDIALOG message, the dialog box procedure should return nonzero if it processes the message, and zero if it does not. - see DialogProc */ BOOL CALLBACK ExtcvPasswordDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { WORD lw = LOWORD (wParam); static Password *szXPwd; static int *pkcs5; static int *pim; static BOOL* truecryptMode; switch (msg) { case WM_INITDIALOG: { int i, nIndex; szXPwd = ((PasswordDlgParam *) lParam) -> password; pkcs5 = ((PasswordDlgParam *) lParam) -> pkcs5; pim = ((PasswordDlgParam *) lParam) -> pim; truecryptMode = ((PasswordDlgParam *) lParam) -> truecryptMode; LocalizeDialog (hwndDlg, "IDD_PASSWORD_DLG"); DragAcceptFiles (hwndDlg, TRUE); if (PasswordDialogTitleStringId) { SetWindowTextW (hwndDlg, GetString (PasswordDialogTitleStringId)); } else if (wcslen (PasswordDlgVolume) > 0) { wchar_t s[1024]; const int maxVisibleLen = 40; if (wcslen (PasswordDlgVolume) > maxVisibleLen) { wstring volStr = PasswordDlgVolume; StringCbPrintfW (s, sizeof(s), GetString ("ENTER_PASSWORD_FOR"), (L"..." + volStr.substr (volStr.size() - maxVisibleLen - 1)).c_str()); } else StringCbPrintfW (s, sizeof(s), GetString ("ENTER_PASSWORD_FOR"), PasswordDlgVolume); SetWindowTextW (hwndDlg, s); } /* Populate the PRF algorithms list */ HWND hComboBox = GetDlgItem (hwndDlg, IDC_PKCS5_PRF_ID); SendMessage (hComboBox, CB_RESETCONTENT, 0, 0); nIndex = SendMessageW (hComboBox, CB_ADDSTRING, 0, (LPARAM) GetString ("AUTODETECTION")); SendMessage (hComboBox, CB_SETITEMDATA, nIndex, (LPARAM) 0); for (i = FIRST_PRF_ID; i <= LAST_PRF_ID; i++) { nIndex = SendMessage (hComboBox, CB_ADDSTRING, 0, (LPARAM) get_pkcs5_prf_name(i)); SendMessage (hComboBox, CB_SETITEMDATA, nIndex, (LPARAM) i); } /* make autodetection the default */ SendMessage (hComboBox, CB_SETCURSEL, 0, 0); SendMessage (GetDlgItem (hwndDlg, IDC_PASSWORD), EM_LIMITTEXT, MAX_PASSWORD, 0); SendMessage (GetDlgItem (hwndDlg, IDC_CACHE), BM_SETCHECK, bCacheInDriver ? BST_CHECKED:BST_UNCHECKED, 0); SendMessage (GetDlgItem (hwndDlg, IDC_PIM), EM_LIMITTEXT, MAX_PIM, 0); SetPim (hwndDlg, IDC_PIM, *pim); /* make PIM field visible if a PIM value has been explicitely specified */ if (*pim > 0) { ShowWindow (GetDlgItem (hwndDlg, IDC_PIM_ENABLE), SW_HIDE); ShowWindow (GetDlgItem( hwndDlg, IDT_PIM), SW_SHOW); ShowWindow (GetDlgItem( hwndDlg, IDC_PIM), SW_SHOW); ShowWindow (GetDlgItem( hwndDlg, IDC_PIM_HELP), SW_SHOW); } SetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE, KeyFilesEnable); mountOptions.PartitionInInactiveSysEncScope = bPrebootPasswordDlgMode; if (bPrebootPasswordDlgMode) { SendMessage (hwndDlg, TC_APPMSG_PREBOOT_PASSWORD_MODE, 0, 0); } if (PasswordDialogDisableMountOptions) { EnableWindow (GetDlgItem (hwndDlg, IDC_CACHE), FALSE); EnableWindow (GetDlgItem (hwndDlg, IDC_MOUNT_OPTIONS), FALSE); } /* No support for mounting TrueCrypt volumes */ SetCheckBox (hwndDlg, IDC_TRUECRYPT_MODE, FALSE); EnableWindow (GetDlgItem (hwndDlg, IDC_TRUECRYPT_MODE), FALSE); if (!SetForegroundWindow (hwndDlg) && (FavoriteMountOnArrivalInProgress)) { SetWindowPos (hwndDlg, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); FLASHWINFO flash; flash.cbSize = sizeof (flash); flash.dwFlags = FLASHW_ALL | FLASHW_TIMERNOFG; flash.dwTimeout = 0; flash.hwnd = hwndDlg; flash.uCount = 0; FlashWindowEx (&flash); SetWindowPos (hwndDlg, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); } } return 0; case TC_APPMSG_PREBOOT_PASSWORD_MODE: { /* No support for mounting TrueCrypt system partition */ SetCheckBox (hwndDlg, IDC_TRUECRYPT_MODE, FALSE); EnableWindow (GetDlgItem (hwndDlg, IDC_TRUECRYPT_MODE), FALSE); /* Repopulate the PRF algorithms list with algorithms that support system encryption */ HWND hComboBox = GetDlgItem (hwndDlg, IDC_PKCS5_PRF_ID); SendMessage (hComboBox, CB_RESETCONTENT, 0, 0); int i, nIndex = SendMessageW (hComboBox, CB_ADDSTRING, 0, (LPARAM) GetString ("AUTODETECTION")); SendMessage (hComboBox, CB_SETITEMDATA, nIndex, (LPARAM) 0); BOOL bIsGPT = FALSE; try { BootEncryption BootEncObj (hwndDlg); bIsGPT = BootEncObj.GetSystemDriveConfiguration().SystemPartition.IsGPT; } catch (...) {} for (i = FIRST_PRF_ID; i <= LAST_PRF_ID; i++) { if (bIsGPT || HashForSystemEncryption(i)) { nIndex = SendMessage (hComboBox, CB_ADDSTRING, 0, (LPARAM) get_pkcs5_prf_name(i)); SendMessage (hComboBox, CB_SETITEMDATA, nIndex, (LPARAM) i); } } /* make autodetection the default */ SendMessage (hComboBox, CB_SETCURSEL, 0, 0); ToBootPwdField (hwndDlg, IDC_PASSWORD); // Attempt to wipe the password stored in the input field buffer wchar_t tmp[MAX_PASSWORD+1]; wmemset (tmp, L'X', MAX_PASSWORD); tmp [MAX_PASSWORD] = 0; SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), tmp); SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), L""); StringCbPrintfW (OrigKeyboardLayout, sizeof(OrigKeyboardLayout),L"%08X", (DWORD) GetKeyboardLayout (NULL) & 0xFFFF); DWORD keybLayout = (DWORD) LoadKeyboardLayout (L"00000409", KLF_ACTIVATE); if (keybLayout != 0x00000409 && keybLayout != 0x04090409) { Error ("CANT_CHANGE_KEYB_LAYOUT_FOR_SYS_ENCRYPTION", hwndDlg); EndDialog (hwndDlg, IDCANCEL); return 1; } if (SetTimer (hwndDlg, TIMER_ID_KEYB_LAYOUT_GUARD, TIMER_INTERVAL_KEYB_LAYOUT_GUARD, NULL) == 0) { Error ("CANNOT_SET_TIMER", hwndDlg); EndDialog (hwndDlg, IDCANCEL); return 1; } if (GetCheckBox (hwndDlg, IDC_SHOW_PASSWORD)) { // simulate hiding password SetCheckBox (hwndDlg, IDC_SHOW_PASSWORD, FALSE); HandleShowPasswordFieldAction (hwndDlg, IDC_SHOW_PASSWORD, IDC_PASSWORD, IDC_PIM); } SetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE, FALSE); EnableWindow (GetDlgItem (hwndDlg, IDC_KEYFILES_ENABLE), FALSE); EnableWindow (GetDlgItem (hwndDlg, IDC_KEY_FILES), FALSE); SetPim (hwndDlg, IDC_PIM, *pim); bPrebootPasswordDlgMode = TRUE; } return 1; case WM_TIMER: switch (wParam) { case TIMER_ID_KEYB_LAYOUT_GUARD: if (bPrebootPasswordDlgMode) { DWORD keybLayout = (DWORD) GetKeyboardLayout (NULL); if (keybLayout != 0x00000409 && keybLayout != 0x04090409) { // Keyboard layout is not standard US // Attempt to wipe the password stored in the input field buffer wchar_t tmp[MAX_PASSWORD+1]; wmemset (tmp, L'X', MAX_PASSWORD); tmp [MAX_PASSWORD] = 0; SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), tmp); SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), L""); keybLayout = (DWORD) LoadKeyboardLayout (L"00000409", KLF_ACTIVATE); if (keybLayout != 0x00000409 && keybLayout != 0x04090409) { KillTimer (hwndDlg, TIMER_ID_KEYB_LAYOUT_GUARD); Error ("CANT_CHANGE_KEYB_LAYOUT_FOR_SYS_ENCRYPTION", hwndDlg); EndDialog (hwndDlg, IDCANCEL); return 1; } wchar_t szTmp [4096]; StringCbCopyW (szTmp, sizeof(szTmp), GetString ("KEYB_LAYOUT_CHANGE_PREVENTED")); StringCbCatW (szTmp, sizeof(szTmp), L"\n\n"); StringCbCatW (szTmp, sizeof(szTmp), GetString ("KEYB_LAYOUT_SYS_ENC_EXPLANATION")); MessageBoxW (MainDlg, szTmp, lpszTitle, MB_ICONWARNING | MB_SETFOREGROUND | MB_TOPMOST); } } return 1; } return 0; case WM_COMMAND: if (lw == IDC_MOUNT_OPTIONS) { DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_MOUNT_OPTIONS), hwndDlg, (DLGPROC) MountOptionsDlgProc, (LPARAM) &mountOptions); if (!bPrebootPasswordDlgMode && mountOptions.PartitionInInactiveSysEncScope) SendMessage (hwndDlg, TC_APPMSG_PREBOOT_PASSWORD_MODE, 0, 0); return 1; } if (lw == IDC_PIM_ENABLE) { ShowWindow (GetDlgItem (hwndDlg, IDC_PIM_ENABLE), SW_HIDE); ShowWindow (GetDlgItem( hwndDlg, IDT_PIM), SW_SHOW); ShowWindow (GetDlgItem( hwndDlg, IDC_PIM), SW_SHOW); ShowWindow (GetDlgItem( hwndDlg, IDC_PIM_HELP), SW_SHOW); SetFocus (GetDlgItem (hwndDlg, IDC_PIM)); return 1; } if (lw == IDC_SHOW_PASSWORD) { HandleShowPasswordFieldAction (hwndDlg, IDC_SHOW_PASSWORD, IDC_PASSWORD, IDC_PIM); return 1; } if (lw == IDC_KEY_FILES) { KeyFilesDlgParam param; param.EnableKeyFiles = KeyFilesEnable; param.FirstKeyFile = FirstKeyFile; if (IDOK == DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_KEYFILES), hwndDlg, (DLGPROC) KeyFilesDlgProc, (LPARAM) ¶m)) { KeyFilesEnable = param.EnableKeyFiles; FirstKeyFile = param.FirstKeyFile; SetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE, KeyFilesEnable); } return 1; } if (lw == IDC_KEYFILES_ENABLE) { KeyFilesEnable = GetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE); return 1; } if (lw == IDCANCEL || lw == IDOK) { wchar_t tmp[MAX_PASSWORD+1]; if (lw == IDOK) { if (mountOptions.ProtectHiddenVolume && hidVolProtKeyFilesParam.EnableKeyFiles) KeyFilesApply (hwndDlg, &mountOptions.ProtectedHidVolPassword, hidVolProtKeyFilesParam.FirstKeyFile, PasswordDlgVolume); if (GetPassword (hwndDlg, IDC_PASSWORD, (LPSTR) szXPwd->Text, MAX_PASSWORD + 1, TRUE)) szXPwd->Length = strlen ((char *) szXPwd->Text); else return 1; bCacheInDriver = IsButtonChecked (GetDlgItem (hwndDlg, IDC_CACHE)); *pkcs5 = (int) SendMessage (GetDlgItem (hwndDlg, IDC_PKCS5_PRF_ID), CB_GETITEMDATA, SendMessage (GetDlgItem (hwndDlg, IDC_PKCS5_PRF_ID), CB_GETCURSEL, 0, 0), 0); *truecryptMode = GetCheckBox (hwndDlg, IDC_TRUECRYPT_MODE); *pim = GetPim (hwndDlg, IDC_PIM); /* SHA-256 is not supported by TrueCrypt */ if ( (*truecryptMode) && ((*pkcs5 == SHA256) || (mountOptions.ProtectHiddenVolume && mountOptions.ProtectedHidVolPkcs5Prf == SHA256)) ) { Error ("ALGO_NOT_SUPPORTED_FOR_TRUECRYPT_MODE", hwndDlg); return 1; } if ( (*truecryptMode) && (*pim != 0) ) { Error ("PIM_NOT_SUPPORTED_FOR_TRUECRYPT_MODE", hwndDlg); return 1; } } // Attempt to wipe password stored in the input field buffer wmemset (tmp, L'X', MAX_PASSWORD); tmp[MAX_PASSWORD] = 0; SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), tmp); SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD_PROT_HIDVOL), tmp); if (hidVolProtKeyFilesParam.FirstKeyFile != NULL) { KeyFileRemoveAll (&hidVolProtKeyFilesParam.FirstKeyFile); hidVolProtKeyFilesParam.EnableKeyFiles = FALSE; } if (bPrebootPasswordDlgMode) { KillTimer (hwndDlg, TIMER_ID_KEYB_LAYOUT_GUARD); // Restore the original keyboard layout if (LoadKeyboardLayout (OrigKeyboardLayout, KLF_ACTIVATE | KLF_SUBSTITUTE_OK) == NULL) Warning ("CANNOT_RESTORE_KEYBOARD_LAYOUT", hwndDlg); } EndDialog (hwndDlg, lw); return 1; } return 0; case WM_CONTEXTMENU: { RECT buttonRect; GetWindowRect (GetDlgItem (hwndDlg, IDC_KEY_FILES), &buttonRect); if (LOWORD (lParam) >= buttonRect.left && LOWORD (lParam) <= buttonRect.right && HIWORD (lParam) >= buttonRect.top && HIWORD (lParam) <= buttonRect.bottom) { // The "Keyfiles" button has been right-clicked KeyFilesDlgParam param; param.EnableKeyFiles = KeyFilesEnable; param.FirstKeyFile = FirstKeyFile; POINT popupPos; popupPos.x = buttonRect.left + 2; popupPos.y = buttonRect.top + 2; if (KeyfilesPopupMenu (hwndDlg, popupPos, ¶m)) { KeyFilesEnable = param.EnableKeyFiles; FirstKeyFile = param.FirstKeyFile; SetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE, KeyFilesEnable); } } } break; case WM_DROPFILES: { HDROP hdrop = (HDROP) wParam; int i = 0, count = DragQueryFile (hdrop, 0xFFFFFFFF, NULL, 0); while (count-- > 0) { KeyFile *kf = (KeyFile *) malloc (sizeof (KeyFile)); if (kf) { DragQueryFile (hdrop, i++, kf->FileName, ARRAYSIZE (kf->FileName)); FirstKeyFile = KeyFileAdd (FirstKeyFile, kf); KeyFilesEnable = TRUE; } } SetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE, KeyFilesEnable); DragFinish (hdrop); } return 1; } return 0; } void SaveSettings (HWND hwndDlg) { // dummy } int BackupVolumeHeader (HWND hwndDlg, BOOL bRequireConfirmation, char *lpszVolume) { // dummy return 0; } int RestoreVolumeHeader (HWND hwndDlg, char *lpszVolume) { // dummy return 0; } int ExtcvAskVolumePassword (HWND hwndDlg, const wchar_t* fileName, Password *password, int *pkcs5, int *pim, BOOL* truecryptMode, char *titleStringId, BOOL enableMountOptions) { int result; PasswordDlgParam dlgParam; PasswordDialogTitleStringId = titleStringId; PasswordDialogDisableMountOptions = !enableMountOptions; dlgParam.password = password; dlgParam.pkcs5 = pkcs5; dlgParam.pim = pim; dlgParam.truecryptMode = truecryptMode; StringCbCopyW (PasswordDlgVolume, sizeof(PasswordDlgVolume), fileName); result = DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_PASSWORD_DLG), hwndDlg, (DLGPROC) ExtcvPasswordDlgProc, (LPARAM) &dlgParam); if (result != IDOK) { password->Length = 0; *pkcs5 = 0; *pim = 0; *truecryptMode = FALSE; burn (&mountOptions.ProtectedHidVolPassword, sizeof (mountOptions.ProtectedHidVolPassword)); burn (&mountOptions.ProtectedHidVolPkcs5Prf, sizeof (mountOptions.ProtectedHidVolPkcs5Prf)); } return result == IDOK; } // GUI actions static BOOL SelectContainer (HWND hwndDlg) { if (BrowseFiles (hwndDlg, "OPEN_VOL_TITLE", szFileName, bHistory, FALSE, NULL) == FALSE) return FALSE; AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, bHistory); VeraCryptExpander::EnableDisableButtons (hwndDlg); SetFocus (GetDlgItem (hwndDlg, IDC_DRIVELIST)); return TRUE; } static BOOL SelectPartition (HWND hwndDlg) { RawDevicesDlgParam param; param.pszFileName = szFileName; int nResult = DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_RAWDEVICES_DLG), hwndDlg, (DLGPROC) RawDevicesDlgProc, (LPARAM) & param); if (nResult == IDOK) { AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, bHistory); VeraCryptExpander::EnableDisableButtons (hwndDlg); SetFocus (GetDlgItem (hwndDlg, IDC_DRIVELIST)); return TRUE; } return FALSE; } /* 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. */ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { static UINT taskBarCreatedMsg; WORD lw = LOWORD (wParam); switch (uMsg) { case WM_INITDIALOG: { int exitCode = 0; MainDlg = hwndDlg; // Set critical default options in case UsePreferences is false bPreserveTimestamp = defaultMountOptions.PreserveTimestamp = TRUE; bShowDisconnectedNetworkDrives = FALSE; bHideWaitingDialog = FALSE; if (UsePreferences) { // General preferences VeraCryptExpander::LoadSettings (hwndDlg); // Keyfiles LoadDefaultKeyFilesParam (); RestoreDefaultKeyFilesParam (); } InitMainDialog (hwndDlg); // Quit if (Quit) { exit (exitCode); } Silent = FALSE; } return 0; case WM_SYSCOMMAND: if (lw == IDC_ABOUT) { DialogBoxW (hInst, MAKEINTRESOURCEW (IDD_ABOUT_DLG), hwndDlg, (DLGPROC) AboutDlgProc); return 1; } return 0; case WM_ENDSESSION: VeraCryptExpander::EndMainDlg (hwndDlg); localcleanup (); return 0; case WM_COMMAND: if (lw == IDCANCEL || lw == IDC_EXIT) { VeraCryptExpander::EndMainDlg (hwndDlg); return 1; } if ( lw == IDOK ) { if (!VeraCryptExpander::VolumeSelected(hwndDlg)) { Warning ("NO_VOLUME_SELECTED", hwndDlg); } else { wchar_t fileName[MAX_PATH]; GetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), fileName, ARRAYSIZE (fileName)); ExpandVolumeWizard(hwndDlg, fileName); } return 1; } if (lw == IDM_ABOUT ) { DialogBoxW (hInst, MAKEINTRESOURCEW (IDD_ABOUT_DLG), hwndDlg, (DLGPROC) AboutDlgProc); return 1; } if (lw == IDM_HOMEPAGE ) { ArrowWaitCursor (); ShellExecute (NULL, L"open", L"https://veracrypt.codeplex.com", NULL, NULL, SW_SHOWNORMAL); Sleep (200); NormalCursor (); return 1; } if (lw == IDC_SELECT_FILE) { SelectContainer (hwndDlg); return 1; } if (lw == IDC_SELECT_DEVICE) { SelectPartition (hwndDlg); return 1; } return 0; case WM_CLOSE: VeraCryptExpander::EndMainDlg (hwndDlg); return 1; default: ; } return 0; } } int WINAPI wWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, wchar_t *lpszCommandLine, int nCmdShow) { int status; atexit (VeraCryptExpander::localcleanup); SetProcessShutdownParameters (0x100, 0); VirtualLock (&VeraCryptExpander::VolumePassword, sizeof (VeraCryptExpander::VolumePassword)); VirtualLock (&VeraCryptExpander::CmdVolumePassword, sizeof (VeraCryptExpander::CmdVolumePassword)); VirtualLock (&VeraCryptExpander::mountOptions, sizeof (VeraCryptExpander::mountOptions)); VirtualLock (&VeraCryptExpander::defaultMountOptions, sizeof (VeraCryptExpander::defaultMountOptions)); VirtualLock (&VeraCryptExpander::szFileName, sizeof(VeraCryptExpander::szFileName)); InitApp (hInstance, lpszCommandLine); /* application title */ lpszTitle = L"VeraCrypt Expander"; DetectX86Features (); status = DriverAttach (); if (status != 0) { if (status == ERR_OS_ERROR) handleWin32Error (NULL, SRC_POS); else handleError (NULL, status, SRC_POS); AbortProcess ("NODRIVER"); } /* Create the main dialog box */ DialogBoxParamW (hInstance, MAKEINTRESOURCEW (IDD_MOUNT_DLG), NULL, (DLGPROC) VeraCryptExpander::MainDialogProc, (LPARAM) lpszCommandLine); /* Terminate */ return 0; } '#n809'>809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678