VeraCrypt
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ExpandVolume/DlgExpandVolume.cpp70
-rw-r--r--src/ExpandVolume/ExpandVolume.c21
-rw-r--r--src/ExpandVolume/ExpandVolume.h2
-rw-r--r--src/ExpandVolume/ExpandVolume.rc9
-rw-r--r--src/ExpandVolume/resource.h5
5 files changed, 95 insertions, 12 deletions
diff --git a/src/ExpandVolume/DlgExpandVolume.cpp b/src/ExpandVolume/DlgExpandVolume.cpp
index adc8fa0d..ab76d1ba 100644
--- a/src/ExpandVolume/DlgExpandVolume.cpp
+++ b/src/ExpandVolume/DlgExpandVolume.cpp
@@ -49,6 +49,8 @@
#define TIMER_ID_RANDVIEW 0xff
#define TIMER_INTERVAL_RANDVIEW 50
+BOOL bSeManageVolumeNameSet = FALSE;
+
// see definition of enum EV_FileSystem
const wchar_t * szFileSystemStr[4] = {L"RAW",L"FAT",L"NTFS",L"EXFAT"};
@@ -117,6 +119,20 @@ uint64 GetSizeBoxMultiplier(HWND hwndDlg)
return Muliplier[i];
}
+void HandleQuickExpanddCheckBox (HWND hwndDlg)
+{
+ if (IsButtonChecked (GetDlgItem (hwndDlg, IDC_INIT_NEWSPACE)))
+ {
+ EnableWindow (GetDlgItem (hwndDlg, IDC_QUICKEXPAND), FALSE);
+ SendDlgItemMessage (hwndDlg, IDC_QUICKEXPAND, BM_SETCHECK, BST_UNCHECKED, 0);
+ }
+ else
+ {
+ EnableWindow (GetDlgItem (hwndDlg, IDC_QUICKEXPAND), TRUE);
+ }
+}
+
+
BOOL CALLBACK ExpandVolSizeDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
static EXPAND_VOL_THREAD_PARAMS *pVolExpandParam;
@@ -164,6 +180,12 @@ BOOL CALLBACK ExpandVolSizeDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARA
SetWindowText (GetDlgItem (hwndDlg, IDT_NEW_SIZE), L"");
GetSpaceString(szHostFreeStr,sizeof(szHostFreeStr),pVolExpandParam->hostSizeFree,FALSE);
StringCbPrintfW (szTemp,sizeof(szTemp),L"%s available on host drive", szHostFreeStr);
+
+ if (!pVolExpandParam->bDisableQuickExpand)
+ {
+ ShowWindow (GetDlgItem (hwndDlg, IDC_QUICKEXPAND), SW_SHOW);
+ HandleQuickExpanddCheckBox (hwndDlg);
+ }
}
SetWindowText (GetDlgItem (hwndDlg, IDC_EXPAND_VOLUME_NEWSIZE), szTemp);
@@ -179,7 +201,7 @@ BOOL CALLBACK ExpandVolSizeDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARA
{
StringCbPrintfW (szTemp, sizeof(szTemp),L"Please specify the new size of the VeraCrypt volume (must be at least %I64u KB larger than the current size).",TC_MINVAL_FS_EXPAND/1024);
}
- SetWindowText (GetDlgItem (hwndDlg, IDC_BOX_HELP), szTemp);
+ SetWindowText (GetDlgItem (hwndDlg, IDC_BOX_HELP), szTemp);
}
return 0;
@@ -197,6 +219,7 @@ BOOL CALLBACK ExpandVolSizeDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARA
wchar_t szTemp[4096];
pVolExpandParam->bInitFreeSpace = IsButtonChecked (GetDlgItem (hwndDlg, IDC_INIT_NEWSPACE));
+ pVolExpandParam->bQuickExpand = IsButtonChecked (GetDlgItem (hwndDlg, IDC_QUICKEXPAND));
if (!pVolExpandParam->bIsDevice) // for devices new size is set by calling function
{
GetWindowText (GetDlgItem (hwndDlg, IDC_SIZEBOX), szTemp, ARRAYSIZE (szTemp));
@@ -207,6 +230,23 @@ BOOL CALLBACK ExpandVolSizeDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARA
return 1;
}
+ if (lw == IDC_INIT_NEWSPACE && !pVolExpandParam->bDisableQuickExpand)
+ {
+ HandleQuickExpanddCheckBox (hwndDlg);
+ return 1;
+ }
+
+ if (lw == IDC_QUICKEXPAND && IsButtonChecked (GetDlgItem (hwndDlg, IDC_QUICKEXPAND)))
+ {
+ // If quick expand selected, then we warn about security issue
+ if (MessageBoxW (hwndDlg, L"WARNING: You should use Quick Expand only in the following cases:\n\n1) The device where the file container is located contains no sensitive data and you do not need plausible deniability.\n2) The device where the file container is located has already been securely and fully encrypted.\n\nAre you sure you want to use Quick Expand?",
+ lpszTitle, YES_NO|MB_ICONWARNING|MB_DEFBUTTON2) == IDNO)
+ {
+ SendDlgItemMessage (hwndDlg, IDC_QUICKEXPAND, BM_SETCHECK, BST_UNCHECKED, 0);
+ return 1;
+ }
+ }
+
return 0;
}
@@ -393,6 +433,7 @@ BOOL CALLBACK ExpandVolProgressDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, L
// tell the volume transform thread to terminate
bVolTransformThreadCancel = TRUE;
}
+ NormalCursor ();
EndDialog (hwndDlg, lw);
return 1;
}
@@ -402,6 +443,7 @@ BOOL CALLBACK ExpandVolProgressDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, L
if (bVolTransformStarted)
{
// TransformThreadFunction finished -> OK button is now exit
+ NormalCursor ();
EndDialog (hwndDlg, lw);
}
else
@@ -561,7 +603,6 @@ void ExpandVolumeWizard (HWND hwndDlg, wchar_t *lpszVolume)
if (KeyFilesEnable && FirstKeyFile)
KeyFilesApply (hwndDlg, &VolumePassword, FirstKeyFile, lpszVolume);
- WaitCursor ();
OpenVolumeThreadParam threadParam;
threadParam.context = &expandVol;
@@ -691,6 +732,8 @@ void ExpandVolumeWizard (HWND hwndDlg, wchar_t *lpszVolume)
EXPAND_VOL_THREAD_PARAMS VolExpandParam;
VolExpandParam.bInitFreeSpace = (bIsLegacy && bIsDevice) ? FALSE:TRUE;
+ VolExpandParam.bQuickExpand = FALSE;
+ VolExpandParam.bDisableQuickExpand = bIsDevice;
VolExpandParam.szVolumeName = lpszVolume;
VolExpandParam.FileSystem = volFSType;
VolExpandParam.pVolumePassword = &VolumePassword;
@@ -702,6 +745,17 @@ void ExpandVolumeWizard (HWND hwndDlg, wchar_t *lpszVolume)
VolExpandParam.newSize = hostSize;
VolExpandParam.hostSizeFree = hostSizeFree;
+ // disable Quick Expand if the file is sparse or compressed
+ if (!bIsDevice)
+ {
+ DWORD dwFileAttrib = GetFileAttributesW (lpszVolume);
+ if (INVALID_FILE_ATTRIBUTES != dwFileAttrib)
+ {
+ if (dwFileAttrib & (FILE_ATTRIBUTE_COMPRESSED | FILE_ATTRIBUTE_SPARSE_FILE))
+ VolExpandParam.bDisableQuickExpand = TRUE;
+ }
+ }
+
while (1)
{
uint64 newVolumeSize;
@@ -737,6 +791,18 @@ void ExpandVolumeWizard (HWND hwndDlg, wchar_t *lpszVolume)
MessageBoxW (hwndDlg, L"!\n",lpszTitle, MB_OK | MB_ICONEXCLAMATION );
continue;
}
+
+ if (VolExpandParam.bQuickExpand && !bSeManageVolumeNameSet)
+ {
+ if (!SetPrivilege (SE_MANAGE_VOLUME_NAME, TRUE))
+ {
+ MessageBoxW (hwndDlg, L"Error: Failed to get necessary privileges to enable Quick Expand!\nPlease uncheck Quick Expand option and try again.",lpszTitle, MB_OK | MB_ICONEXCLAMATION );
+ VolExpandParam.bQuickExpand = FALSE;
+ continue;
+ }
+
+ bSeManageVolumeNameSet = TRUE;
+ }
}
if ( newVolumeSize > TC_MAX_VOLUME_SIZE )
diff --git a/src/ExpandVolume/ExpandVolume.c b/src/ExpandVolume/ExpandVolume.c
index 588e7688..ec78a36f 100644
--- a/src/ExpandVolume/ExpandVolume.c
+++ b/src/ExpandVolume/ExpandVolume.c
@@ -492,7 +492,7 @@ error:
Remarks: a lot of code is from TrueCrypt 'Common\Password.c' :: ChangePwd()
*/
-static int ExpandVolume (HWND hwndDlg, wchar_t *lpszVolume, Password *pVolumePassword, int VolumePkcs5, int VolumePim, uint64 newHostSize, BOOL initFreeSpace)
+static int ExpandVolume (HWND hwndDlg, wchar_t *lpszVolume, Password *pVolumePassword, int VolumePkcs5, int VolumePim, uint64 newHostSize, BOOL initFreeSpace, BOOL bQuickExpand)
{
int nDosLinkCreated = 1, nStatus = ERR_OS_ERROR;
wchar_t szDiskFile[TC_MAX_PATH], szCFDevice[TC_MAX_PATH];
@@ -754,8 +754,21 @@ static int ExpandVolume (HWND hwndDlg, wchar_t *lpszVolume, Password *pVolumePas
{
// Preallocate the file
if (!SetFilePointerEx (dev, liNewSize, NULL, FILE_BEGIN)
- || !SetEndOfFile (dev)
- || SetFilePointer (dev, 0, NULL, FILE_BEGIN) != 0)
+ || !SetEndOfFile (dev))
+ {
+ nStatus = ERR_OS_ERROR;
+ goto error;
+ }
+
+ if (bQuickExpand)
+ {
+ if (!SetFileValidData (dev, liNewSize.QuadPart))
+ {
+ DebugAddProgressDlgStatus(hwndDlg, L"Warning: Failed to perform Quick Expand. Continuing with standard expanding...\r\n");
+ }
+ }
+
+ if (SetFilePointer (dev, 0, NULL, FILE_BEGIN) != 0)
{
nStatus = ERR_OS_ERROR;
goto error;
@@ -1061,7 +1074,7 @@ void __cdecl volTransformThreadFunction (void *pExpandDlgParam)
HWND hwndDlg = (HWND) pParam->hwndDlg;
nStatus = ExpandVolume (hwndDlg, (wchar_t*)pParam->szVolumeName, pParam->pVolumePassword,
- pParam->VolumePkcs5, pParam->VolumePim, pParam->newSize, pParam->bInitFreeSpace );
+ pParam->VolumePkcs5, pParam->VolumePim, pParam->newSize, pParam->bInitFreeSpace, pParam->bQuickExpand );
if (nStatus!=ERR_SUCCESS && nStatus!=ERR_USER_ABORT)
handleError (hwndDlg, nStatus, SRC_POS);
diff --git a/src/ExpandVolume/ExpandVolume.h b/src/ExpandVolume/ExpandVolume.h
index 5f4eb7f1..668eb79d 100644
--- a/src/ExpandVolume/ExpandVolume.h
+++ b/src/ExpandVolume/ExpandVolume.h
@@ -40,6 +40,8 @@ typedef struct
BOOL bIsDevice;
BOOL bIsLegacy;
BOOL bInitFreeSpace;
+ BOOL bQuickExpand;
+ BOOL bDisableQuickExpand;
Password *pVolumePassword;
int VolumePkcs5;
int VolumePim;
diff --git a/src/ExpandVolume/ExpandVolume.rc b/src/ExpandVolume/ExpandVolume.rc
index 5efa6790..833411a7 100644
--- a/src/ExpandVolume/ExpandVolume.rc
+++ b/src/ExpandVolume/ExpandVolume.rc
@@ -38,7 +38,8 @@ BEGIN
CONTROL "&GB",IDC_GB,"Button",BS_AUTORADIOBUTTON,248,105,38,10
CONTROL "&TB",IDC_TB,"Button",BS_AUTORADIOBUTTON,288,105,38,10
CONTROL "Fill new space with random data",IDC_INIT_NEWSPACE,
- "Button",BS_AUTOCHECKBOX | WS_TABSTOP,30,127,118,10
+ "Button",BS_AUTOCHECKBOX | WS_TABSTOP,30,120,276,10
+ CONTROL "Quick Expand",IDC_QUICKEXPAND,"Button",BS_AUTOCHECKBOX | NOT WS_VISIBLE | WS_DISABLED | WS_TABSTOP,30,132,276,10
DEFPUSHBUTTON "Continue",IDOK,15,238,84,18
PUSHBUTTON "Cancel",IDCANCEL,277,238,84,18
LTEXT "Help Text",IDC_BOX_HELP,15,165,346,58,0,WS_EX_CLIENTEDGE
@@ -141,7 +142,7 @@ END
//
#ifdef APSTUDIO_INVOKED
-GUIDELINES DESIGNINFO
+GUIDELINES DESIGNINFO
BEGIN
IDD_SIZE_DIALOG, DIALOG
BEGIN
@@ -264,7 +265,7 @@ IDB_LOGO_288DPI BITMAP "Logo_288dpi.bmp"
// Menu
//
-IDR_MENU MENUEX
+IDR_MENU MENUEX
BEGIN
MENUITEM "About", IDM_ABOUT,MFT_STRING,MFS_ENABLED
MENUITEM "Homepage", IDM_HOMEPAGE,MFT_STRING | MFT_RIGHTJUSTIFY,MFS_ENABLED
@@ -276,7 +277,7 @@ END
// String Table
//
-STRINGTABLE
+STRINGTABLE
BEGIN
IDS_UACSTRING "VeraCrypt Expander"
END
diff --git a/src/ExpandVolume/resource.h b/src/ExpandVolume/resource.h
index 993c414f..99d89dda 100644
--- a/src/ExpandVolume/resource.h
+++ b/src/ExpandVolume/resource.h
@@ -71,6 +71,7 @@
#define IDC_OLD_PIM 1143
#define IDC_OLD_PIM_HELP 1144
#define ID_HOMEPAGE 1145
+#define IDC_QUICKEXPAND 1146
#define IDM_HELP 40001
#define IDM_ABOUT 40002
#define IDM_UNMOUNT_VOLUME 40003
@@ -135,13 +136,13 @@
#define IDM_MANAGE_TOKEN_KEYFILES 40062
// Next default values for new objects
-//
+//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NO_MFC 1
#define _APS_NEXT_RESOURCE_VALUE 120
#define _APS_NEXT_COMMAND_VALUE 40064
-#define _APS_NEXT_CONTROL_VALUE 1146
+#define _APS_NEXT_CONTROL_VALUE 1147
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif