VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Common/SecurityToken.cpp2
-rw-r--r--src/ExpandVolume/DlgExpandVolume.cpp1400
2 files changed, 698 insertions, 704 deletions
diff --git a/src/Common/SecurityToken.cpp b/src/Common/SecurityToken.cpp
index e8fb275b..1bbad78e 100644
--- a/src/Common/SecurityToken.cpp
+++ b/src/Common/SecurityToken.cpp
@@ -700,7 +700,7 @@ namespace VeraCrypt
}
}
wchar_t err[8192];
- wsprintfW (err, L"%s:\n\n%hs%s", GetString ("SECURITY_TOKEN_ERROR"), errorString.c_str(), subjectErrorCode.str().c_str());
+ StringCbPrintfW (err, sizeof(err),L"%s:\n\n%hs%s", GetString ("SECURITY_TOKEN_ERROR"), errorString.c_str(), subjectErrorCode.str().c_str());
ErrorDirect (err, parent);
}
else
diff --git a/src/ExpandVolume/DlgExpandVolume.cpp b/src/ExpandVolume/DlgExpandVolume.cpp
index db2aa9fd..d6982933 100644
--- a/src/ExpandVolume/DlgExpandVolume.cpp
+++ b/src/ExpandVolume/DlgExpandVolume.cpp
@@ -1,411 +1,405 @@
-/*
-
-Some portions of the source code contained in this file were derived from the
-source code of TrueCrypt 7.0a, which is governed by the TrueCrypt License 3.0
-that can be found in the file 'License.txt' in the folder 'TrueCrypt-License'.
-
-Modifications and additions to the original source code (contained in this file)
-and all other portions of this file are Copyright (c) 2009-2010 by Kih-Oskh or
-Copyright (c) 2012-2013 Josef Schneider <josef@netpage.dk>
-
-
-Some portions of the source code here are derived from 'Mount\Mount.c'
-
--------------------------------------------------------------------------------
-
-Original legal notice of the TrueCrypt source:
-
- Legal Notice: Some portions of the source code contained in this file were
- derived 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'. Modifications and additions to
- the original source code (contained in this file) and all other portions
- of this file are Copyright (c) 2003-2009 TrueCrypt Developers Association
- and are governed by the TrueCrypt License 3.0 the full text of which is
- contained in the file License.txt included in TrueCrypt binary and source
- code distribution packages.
-
-*/
-
-#include "Tcdefs.h"
-
-#include <time.h>
-#include <math.h>
-#include <dbt.h>
-#include <fcntl.h>
-#include <io.h>
-#include <sys/stat.h>
-#include <windowsx.h>
-#include <stdio.h>
-
-#include "Apidrvr.h"
-#include "Volumes.h"
-#include "Crypto.h"
-#include "Dlgcode.h"
-#include "Language.h"
-#include "Pkcs5.h"
-#include "Random.h"
-// #include "../Mount/Mount.h"
-
-#include "../Common/Dictionary.h"
-#include "../Common/Common.h"
-#include "../Common/Resource.h"
-#include "../Common/SecurityToken.h"
-#include "../Common/Progress.h"
-
-#include "ExpandVolume.h"
-#include "Resource.h"
-
-// TO DO: display sector sizes different than 512 bytes
-#define SECTOR_SIZE_MSG 512
-
-#define TIMER_ID_RANDVIEW 0xff
-#define TIMER_INTERVAL_RANDVIEW 50
-
-// see definition of enum EV_FileSystem
-const char * szFileSystemStr[3] = {"RAW","FAT","NTFS"};
-
-// prototypes for internal functions
-BOOL CALLBACK ExpandVolSizeDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
-BOOL CALLBACK ExpandVolProgressDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
-
-namespace VeraCryptExpander
-{
-/* defined in WinMain.c, referenced by ExpandVolumeWizard() */
-int ExtcvAskVolumePassword (HWND hwndDlg, Password *password, int *pkcs5, BOOL* truecryptMode, char *titleStringId, BOOL enableMountOptions);
-}
-
-
-int GetSpaceString(char *dest, size_t maxlen, uint64 size, BOOL bDevice)
-{
- const char * szFmtBytes = "%.0lf %s";
- const char * szFmtOther = "%.2lf %s";
- const char * SuffixStr[] = {"Byte", "kB", "MB", "GB", "TB"};
- const uint64 Muliplier[] = {1, BYTES_PER_KB, BYTES_PER_MB, BYTES_PER_GB, BYTES_PER_TB};
- const int nMaxSuffix = sizeof(Muliplier)/sizeof(uint64) - 1;
- int i;
-
- for (i=1; i<=nMaxSuffix && size>Muliplier[i]; i++) ;
-
- --i;
-
- if (bDevice) {
- char szTemp[512];
-
- if (sprintf_s(szTemp, sizeof(szTemp),i?szFmtOther:szFmtBytes, size/(double)Muliplier[i], SuffixStr[i]) < 0 )
- return -1;
-
- return sprintf_s(dest, maxlen, "%I64u sectors (%s)", size/SECTOR_SIZE_MSG , szTemp);
- }
-
- return sprintf_s(dest, maxlen,i?szFmtOther:szFmtBytes, size/(double)Muliplier[i], SuffixStr[i]);
-}
-
-void SetCurrentVolSize(HWND hwndDlg, uint64 size)
-{
- const uint64 Muliplier[] = {BYTES_PER_KB, BYTES_PER_MB, BYTES_PER_GB};
- const int IdRadioBtn[] = {IDC_KB, IDC_MB, IDC_GB};
- const int nMaxSuffix = sizeof(Muliplier)/sizeof(uint64) - 1;
- int i;
- char szTemp[256];
-
- for (i=1; i<=nMaxSuffix && size>Muliplier[i]; i++) ;
-
- --i;
-
- SendDlgItemMessage (hwndDlg, IdRadioBtn[i], BM_SETCHECK, BST_CHECKED, 0);
- sprintf(szTemp,"%I64u",size/Muliplier[i]);
- SetWindowText (GetDlgItem (hwndDlg, IDC_SIZEBOX), szTemp);
-}
-
-uint64 GetSizeBoxMultiplier(HWND hwndDlg)
-{
- const uint64 Muliplier[] = {BYTES_PER_KB, BYTES_PER_MB, BYTES_PER_GB};
- const int IdRadioBtn[] = {IDC_KB, IDC_MB, IDC_GB};
- const int nMaxSuffix = sizeof(Muliplier)/sizeof(uint64) - 1;
- int i;
-
- for (i=nMaxSuffix; i>0 && !IsButtonChecked (GetDlgItem (hwndDlg, IdRadioBtn[i])); --i) ;
-
- return Muliplier[i];
-}
-
-BOOL CALLBACK ExpandVolSizeDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- static EXPAND_VOL_THREAD_PARAMS *pVolExpandParam;
-
- WORD lw = LOWORD (wParam);
-
- switch (msg)
- {
- case WM_INITDIALOG:
- {
- char szTemp[4096];
-
- pVolExpandParam = (EXPAND_VOL_THREAD_PARAMS*)lParam;
-
- EnableWindow (GetDlgItem (hwndDlg, IDC_SIZEBOX), !pVolExpandParam->bIsDevice);
- EnableWindow (GetDlgItem (hwndDlg, IDC_KB), !pVolExpandParam->bIsDevice);
- EnableWindow (GetDlgItem (hwndDlg, IDC_MB), !pVolExpandParam->bIsDevice);
- EnableWindow (GetDlgItem (hwndDlg, IDC_GB), !pVolExpandParam->bIsDevice);
-
- EnableWindow (GetDlgItem (hwndDlg, IDC_INIT_NEWSPACE),
- !(pVolExpandParam->bIsLegacy && pVolExpandParam->bIsDevice));
- SendDlgItemMessage (hwndDlg, IDC_INIT_NEWSPACE, BM_SETCHECK,
- pVolExpandParam->bInitFreeSpace ? BST_CHECKED : BST_UNCHECKED, 0);
-
- if (!pVolExpandParam->bIsDevice)
- SetCurrentVolSize(hwndDlg,pVolExpandParam->oldSize);
-
- SendMessage (GetDlgItem (hwndDlg, IDC_BOX_HELP), WM_SETFONT, (WPARAM) hBoldFont, (LPARAM) TRUE);
-
- GetSpaceString(szTemp,sizeof(szTemp),pVolExpandParam->oldSize,pVolExpandParam->bIsDevice);
-
- SetWindowText (GetDlgItem (hwndDlg, IDC_EXPAND_VOLUME_OLDSIZE), szTemp);
- SetWindowText (GetDlgItem (hwndDlg, IDC_EXPAND_VOLUME_NAME), pVolExpandParam->szVolumeName);
- SetWindowText (GetDlgItem (hwndDlg, IDC_EXPAND_FILE_SYSTEM), szFileSystemStr[pVolExpandParam->FileSystem]);
-
- if (pVolExpandParam->bIsDevice)
- {
- GetSpaceString(szTemp,sizeof(szTemp),pVolExpandParam->newSize,TRUE);
- }
- else
- {
- char szHostFreeStr[256];
-
- SetWindowText (GetDlgItem (hwndDlg, IDT_NEW_SIZE), "");
- GetSpaceString(szHostFreeStr,sizeof(szHostFreeStr),pVolExpandParam->hostSizeFree,FALSE);
- sprintf (szTemp,"%s available on host drive", szHostFreeStr);
- }
-
- SetWindowText (GetDlgItem (hwndDlg, IDC_EXPAND_VOLUME_NEWSIZE), szTemp);
-
- // set help text
- if (pVolExpandParam->bIsDevice)
- {
- sprintf (szTemp,"This is a device-based VeraCrypt volume.\n\nThe new volume size will be choosen automatically as the size of the host device.");
- if (pVolExpandParam->bIsLegacy)
- strcat(szTemp," Note: filling the new space with random data is not supported for legacy volumes.");
- }
- else
- {
- sprintf (szTemp,"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);
-
- }
- return 0;
-
-
- case WM_COMMAND:
- if (lw == IDCANCEL)
- {
- EndDialog (hwndDlg, lw);
- return 1;
- }
-
- if (lw == IDOK)
- {
- char szTemp[4096];
-
- pVolExpandParam->bInitFreeSpace = IsButtonChecked (GetDlgItem (hwndDlg, IDC_INIT_NEWSPACE));
- if (!pVolExpandParam->bIsDevice) // for devices new size is set by calling function
- {
- GetWindowText (GetDlgItem (hwndDlg, IDC_SIZEBOX), szTemp, sizeof (szTemp));
- pVolExpandParam->newSize = _atoi64(szTemp) * GetSizeBoxMultiplier(hwndDlg);
- }
-
- EndDialog (hwndDlg, lw);
- return 1;
- }
-
- return 0;
- }
-
- return 0;
-}
-
-
-extern "C" void AddProgressDlgStatus(HWND hwndDlg, const char* szText)
-{
- HWND hwndCtrl;
-
- hwndCtrl = GetDlgItem (hwndDlg,IDC_BOX_STATUS);
- SendMessage(hwndCtrl,EM_REPLACESEL,FALSE,(LPARAM)szText);
- SendMessage(hwndCtrl,EM_SCROLLCARET,0,0);
-}
-
-
-extern "C" void SetProgressDlgStatus(HWND hwndDlg, const char* szText)
-{
- HWND hwndCtrl;
-
- hwndCtrl = GetDlgItem (hwndDlg,IDC_BOX_STATUS);
- SendMessage(hwndCtrl,EM_SETSEL,0,-1);
- SendMessage(hwndCtrl,EM_REPLACESEL,FALSE,(LPARAM)szText);
- SendMessage(hwndCtrl,EM_SCROLLCARET,0,0);
-}
-
-
-BOOL CALLBACK ExpandVolProgressDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- static EXPAND_VOL_THREAD_PARAMS *pProgressDlgParam;
- static BOOL bVolTransformStarted = FALSE;
- static BOOL showRandPool = TRUE;
-
- WORD lw = LOWORD (wParam);
-
- switch (msg)
- {
- case WM_INITDIALOG:
- {
- char szOldHostSize[512], szNewHostSize[512];
-
- pProgressDlgParam = (EXPAND_VOL_THREAD_PARAMS*)lParam;
- bVolTransformStarted = FALSE;
- showRandPool = TRUE;
-
- hCurPage = hwndDlg;
- nPbar = IDC_PROGRESS_BAR;
-
- GetSpaceString(szOldHostSize,sizeof(szOldHostSize),pProgressDlgParam->oldSize,pProgressDlgParam->bIsDevice);
- GetSpaceString(szNewHostSize,sizeof(szNewHostSize),pProgressDlgParam->newSize,pProgressDlgParam->bIsDevice);
-
- SetWindowText (GetDlgItem (hwndDlg, IDC_EXPAND_VOLUME_OLDSIZE), szOldHostSize);
- SetWindowText (GetDlgItem (hwndDlg, IDC_EXPAND_VOLUME_NEWSIZE), szNewHostSize);
- SetWindowText (GetDlgItem (hwndDlg, IDC_EXPAND_VOLUME_NAME), pProgressDlgParam->szVolumeName);
- SetWindowText (GetDlgItem (hwndDlg, IDC_EXPAND_FILE_SYSTEM), szFileSystemStr[pProgressDlgParam->FileSystem]);
- SetWindowText (GetDlgItem (hwndDlg, IDC_EXPAND_VOLUME_INITSPACE), pProgressDlgParam->bInitFreeSpace?"Yes":"No");
-
- SendMessage (GetDlgItem (hwndDlg, IDC_BOX_STATUS), WM_SETFONT, (WPARAM) hBoldFont, (LPARAM) TRUE);
-
- SendMessage (GetDlgItem (hwndDlg, IDC_RANDOM_BYTES), WM_SETFONT, (WPARAM) hFixedDigitFont, (LPARAM) TRUE);
-
- // set status text
- if ( !pProgressDlgParam->bInitFreeSpace && pProgressDlgParam->bIsLegacy )
- {
- showRandPool = FALSE;
- EnableWindow (GetDlgItem (hwndDlg, IDC_DISPLAY_POOL_CONTENTS), FALSE);
- EnableWindow (GetDlgItem (hwndDlg, IDC_RANDOM_BYTES), FALSE);
- SetDlgItemText(hwndDlg, IDC_BOX_STATUS, "Click 'Continue' to expand the volume.");
- }
- else
- {
- SetDlgItemText(hwndDlg, IDC_BOX_STATUS, "IMPORTANT: Move your mouse as randomly as possible within this window. The longer you move it, the better. This significantly increases the cryptographic strength of the encryption keys. Then click 'Continue' to expand the volume.");
- }
-
- SendMessage (GetDlgItem (hwndDlg, IDC_DISPLAY_POOL_CONTENTS), BM_SETCHECK, showRandPool ? BST_CHECKED : BST_UNCHECKED, 0);
- SetTimer (hwndDlg, TIMER_ID_RANDVIEW, TIMER_INTERVAL_RANDVIEW, NULL);
- }
- return 0;
- case TC_APPMSG_VOL_TRANSFORM_THREAD_ENDED:
- {
- int nStatus = (int)lParam;
-
- NormalCursor ();
- if (nStatus != 0)
- {
- if ( nStatus != ERR_USER_ABORT )
- AddProgressDlgStatus (hwndDlg, "Error: volume expansion failed.");
- else
- AddProgressDlgStatus (hwndDlg, "Error: operation aborted by user.");
- }
- else
- {
- AddProgressDlgStatus (hwndDlg, "Finished. Volume successfully expanded.");
- }
-
- SetWindowText (GetDlgItem (hwndDlg, IDOK), "Exit");
- EnableWindow (GetDlgItem (hwndDlg, IDOK), TRUE);
- EnableWindow (GetDlgItem (hwndDlg, IDCANCEL), FALSE);
- }
- return 1;
-
- case WM_TIMER:
-
- switch (wParam)
- {
- case TIMER_ID_RANDVIEW:
- {
- unsigned char tmp[16];
- char szRndPool[64], *t;
- DWORD *p;
-
- if (!showRandPool)
- return 1;
-
- RandpeekBytes (hwndDlg, tmp, sizeof (tmp));
-
- for ( p = (DWORD*)(tmp + sizeof(tmp)), t=szRndPool; p > (DWORD*)tmp; )
- {
- int len;
- if ( (len = sprintf ( t, "%08X", *--p)) < 0 )
- return 1;
- t += len;
- }
-
- SetWindowText (GetDlgItem (hwndDlg, IDC_RANDOM_BYTES), szRndPool);
-
- burn (tmp, sizeof(tmp));
- burn (szRndPool, sizeof(szRndPool));
- }
- return 1;
- }
- return 0;
-
- case WM_COMMAND:
- if (lw == IDC_DISPLAY_POOL_CONTENTS)
- {
- showRandPool = IsButtonChecked (GetDlgItem (hwndDlg, IDC_DISPLAY_POOL_CONTENTS));
- return 1;
- }
- if (lw == IDCANCEL)
- {
- if (bVolTransformStarted)
- {
- if (MessageBoxW (hwndDlg, L"Warning: Volume expansion is in progress!\n\nStopping now may result in a damaged volume.\n\nDo you really want to cancel?", lpszTitle, YES_NO|MB_ICONQUESTION|MB_DEFBUTTON2) == IDNO)
- return 1;
-
- // tell the volume transform thread to terminate
- bVolTransformThreadCancel = TRUE;
- }
- EndDialog (hwndDlg, lw);
- return 1;
- }
-
- if (lw == IDOK)
- {
- if (bVolTransformStarted)
- {
- // TransformThreadFunction finished -> OK button is now exit
- EndDialog (hwndDlg, lw);
- }
- else
- {
- showRandPool = FALSE;
- KillTimer (hwndDlg, TIMER_ID_RANDVIEW);
- EnableWindow (GetDlgItem (hwndDlg, IDC_DISPLAY_POOL_CONTENTS), FALSE);
- EnableWindow (GetDlgItem (hwndDlg, IDOK), FALSE);
- SetProgressDlgStatus (hwndDlg, "Starting volume expansion ...\r\n");
- bVolTransformStarted = TRUE;
- pProgressDlgParam->hwndDlg = hwndDlg;
- if ( _beginthread (volTransformThreadFunction, 0, pProgressDlgParam) == -1L )
- {
- handleError (hwndDlg, ERR_OS_ERROR);
- EndDialog (hwndDlg, lw);
- }
- WaitCursor();
- }
- return 1;
- }
-
- return 0;
- }
-
- return 0;
-}
-
-
+/*
+
+Some portions of the source code contained in this file were derived from the
+source code of TrueCrypt 7.0a, which is governed by the TrueCrypt License 3.0
+that can be found in the file 'License.txt' in the folder 'TrueCrypt-License'.
+
+Modifications and additions to the original source code (contained in this file)
+and all other portions of this file are Copyright (c) 2009-2010 by Kih-Oskh or
+Copyright (c) 2012-2013 Josef Schneider <josef@netpage.dk>
+
+
+Some portions of the source code here are derived from 'Mount\Mount.c'
+
+-------------------------------------------------------------------------------
+
+Original legal notice of the TrueCrypt source:
+
+ Legal Notice: Some portions of the source code contained in this file were
+ derived 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'. Modifications and additions to
+ the original source code (contained in this file) and all other portions
+ of this file are Copyright (c) 2003-2009 TrueCrypt Developers Association
+ and are governed by the TrueCrypt License 3.0 the full text of which is
+ contained in the file License.txt included in TrueCrypt binary and source
+ code distribution packages.
+
+*/
+
+#include "Tcdefs.h"
+
+#include <time.h>
+#include <math.h>
+#include <dbt.h>
+#include <fcntl.h>
+#include <io.h>
+#include <sys/stat.h>
+#include <windowsx.h>
+#include <stdio.h>
+
+#include "Apidrvr.h"
+#include "Volumes.h"
+#include "Crypto.h"
+#include "Dlgcode.h"
+#include "Language.h"
+#include "Pkcs5.h"
+#include "Random.h"
+// #include "../Mount/Mount.h"
+
+#include "../Common/Dictionary.h"
+#include "../Common/Common.h"
+#include "../Common/Resource.h"
+#include "../Common/SecurityToken.h"
+#include "../Common/Progress.h"
+
+#include "ExpandVolume.h"
+#include "Resource.h"
+
+// TO DO: display sector sizes different than 512 bytes
+#define SECTOR_SIZE_MSG 512
+
+#define TIMER_ID_RANDVIEW 0xff
+#define TIMER_INTERVAL_RANDVIEW 50
+
+// see definition of enum EV_FileSystem
+const char * szFileSystemStr[3] = {"RAW","FAT","NTFS"};
+
+// prototypes for internal functions
+BOOL CALLBACK ExpandVolSizeDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
+BOOL CALLBACK ExpandVolProgressDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
+
+namespace VeraCryptExpander
+{
+/* defined in WinMain.c, referenced by ExpandVolumeWizard() */
+int ExtcvAskVolumePassword (HWND hwndDlg, Password *password, int *pkcs5, BOOL* truecryptMode, char *titleStringId, BOOL enableMountOptions);
+}
+
+
+int GetSpaceString(char *dest, size_t maxlen, uint64 size, BOOL bDevice)
+{
+ const char * szFmtBytes = "%.0lf %s";
+ const char * szFmtOther = "%.2lf %s";
+ const char * SuffixStr[] = {"Byte", "kB", "MB", "GB", "TB"};
+ const uint64 Muliplier[] = {1, BYTES_PER_KB, BYTES_PER_MB, BYTES_PER_GB, BYTES_PER_TB};
+ const int nMaxSuffix = sizeof(Muliplier)/sizeof(uint64) - 1;
+ int i;
+
+ for (i=1; i<=nMaxSuffix && size>Muliplier[i]; i++) ;
+
+ --i;
+
+ if (bDevice) {
+ char szTemp[512];
+
+ if (sprintf_s(szTemp, sizeof(szTemp),i?szFmtOther:szFmtBytes, size/(double)Muliplier[i], SuffixStr[i]) < 0 )
+ return -1;
+
+ return sprintf_s(dest, maxlen, "%I64u sectors (%s)", size/SECTOR_SIZE_MSG , szTemp);
+ }
+
+ return sprintf_s(dest, maxlen,i?szFmtOther:szFmtBytes, size/(double)Muliplier[i], SuffixStr[i]);
+}
+
+void SetCurrentVolSize(HWND hwndDlg, uint64 size)
+{
+ const uint64 Muliplier[] = {BYTES_PER_KB, BYTES_PER_MB, BYTES_PER_GB};
+ const int IdRadioBtn[] = {IDC_KB, IDC_MB, IDC_GB};
+ const int nMaxSuffix = sizeof(Muliplier)/sizeof(uint64) - 1;
+ int i;
+ char szTemp[256];
+
+ for (i=1; i<=nMaxSuffix && size>Muliplier[i]; i++) ;
+
+ --i;
+
+ SendDlgItemMessage (hwndDlg, IdRadioBtn[i], BM_SETCHECK, BST_CHECKED, 0);
+ StringCbPrintfA(szTemp,sizeof(szTemp),"%I64u",size/Muliplier[i]);
+ SetWindowText (GetDlgItem (hwndDlg, IDC_SIZEBOX), szTemp);
+}
+
+uint64 GetSizeBoxMultiplier(HWND hwndDlg)
+{
+ const uint64 Muliplier[] = {BYTES_PER_KB, BYTES_PER_MB, BYTES_PER_GB};
+ const int IdRadioBtn[] = {IDC_KB, IDC_MB, IDC_GB};
+ const int nMaxSuffix = sizeof(Muliplier)/sizeof(uint64) - 1;
+ int i;
+
+ for (i=nMaxSuffix; i>0 && !IsButtonChecked (GetDlgItem (hwndDlg, IdRadioBtn[i])); --i) ;
+
+ return Muliplier[i];
+}
+
+BOOL CALLBACK ExpandVolSizeDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ static EXPAND_VOL_THREAD_PARAMS *pVolExpandParam;
+
+ WORD lw = LOWORD (wParam);
+
+ switch (msg)
+ {
+ case WM_INITDIALOG:
+ {
+ char szTemp[4096];
+
+ pVolExpandParam = (EXPAND_VOL_THREAD_PARAMS*)lParam;
+
+ EnableWindow (GetDlgItem (hwndDlg, IDC_SIZEBOX), !pVolExpandParam->bIsDevice);
+ EnableWindow (GetDlgItem (hwndDlg, IDC_KB), !pVolExpandParam->bIsDevice);
+ EnableWindow (GetDlgItem (hwndDlg, IDC_MB), !pVolExpandParam->bIsDevice);
+ EnableWindow (GetDlgItem (hwndDlg, IDC_GB), !pVolExpandParam->bIsDevice);
+
+ EnableWindow (GetDlgItem (hwndDlg, IDC_INIT_NEWSPACE),
+ !(pVolExpandParam->bIsLegacy && pVolExpandParam->bIsDevice));
+ SendDlgItemMessage (hwndDlg, IDC_INIT_NEWSPACE, BM_SETCHECK,
+ pVolExpandParam->bInitFreeSpace ? BST_CHECKED : BST_UNCHECKED, 0);
+
+ if (!pVolExpandParam->bIsDevice)
+ SetCurrentVolSize(hwndDlg,pVolExpandParam->oldSize);
+
+ SendMessage (GetDlgItem (hwndDlg, IDC_BOX_HELP), WM_SETFONT, (WPARAM) hBoldFont, (LPARAM) TRUE);
+
+ GetSpaceString(szTemp,sizeof(szTemp),pVolExpandParam->oldSize,pVolExpandParam->bIsDevice);
+
+ SetWindowText (GetDlgItem (hwndDlg, IDC_EXPAND_VOLUME_OLDSIZE), szTemp);
+ SetWindowText (GetDlgItem (hwndDlg, IDC_EXPAND_VOLUME_NAME), pVolExpandParam->szVolumeName);
+ SetWindowText (GetDlgItem (hwndDlg, IDC_EXPAND_FILE_SYSTEM), szFileSystemStr[pVolExpandParam->FileSystem]);
+
+ if (pVolExpandParam->bIsDevice)
+ {
+ GetSpaceString(szTemp,sizeof(szTemp),pVolExpandParam->newSize,TRUE);
+ }
+ else
+ {
+ char szHostFreeStr[256];
+
+ SetWindowText (GetDlgItem (hwndDlg, IDT_NEW_SIZE), "");
+ GetSpaceString(szHostFreeStr,sizeof(szHostFreeStr),pVolExpandParam->hostSizeFree,FALSE);
+ StringCbPrintfA (szTemp,sizeof(szTemp),"%s available on host drive", szHostFreeStr);
+ }
+
+ SetWindowText (GetDlgItem (hwndDlg, IDC_EXPAND_VOLUME_NEWSIZE), szTemp);
+
+ // set help text
+ if (pVolExpandParam->bIsDevice)
+ {
+ StringCbPrintfA (szTemp,sizeof(szTemp),"This is a device-based VeraCrypt volume.\n\nThe new volume size will be choosen automatically as the size of the host device.");
+ if (pVolExpandParam->bIsLegacy)
+ StringCbCatA(szTemp,sizeof(szTemp)," Note: filling the new space with random data is not supported for legacy volumes.");
+ }
+ else
+ {
+ StringCbPrintfA (szTemp, sizeof(szTemp),"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);
+
+ }
+ return 0;
+
+
+ case WM_COMMAND:
+ if (lw == IDCANCEL)
+ {
+ EndDialog (hwndDlg, lw);
+ return 1;
+ }
+
+ if (lw == IDOK)
+ {
+ char szTemp[4096];
+
+ pVolExpandParam->bInitFreeSpace = IsButtonChecked (GetDlgItem (hwndDlg, IDC_INIT_NEWSPACE));
+ if (!pVolExpandParam->bIsDevice) // for devices new size is set by calling function
+ {
+ GetWindowText (GetDlgItem (hwndDlg, IDC_SIZEBOX), szTemp, sizeof (szTemp));
+ pVolExpandParam->newSize = _atoi64(szTemp) * GetSizeBoxMultiplier(hwndDlg);
+ }
+
+ EndDialog (hwndDlg, lw);
+ return 1;
+ }
+
+ return 0;
+ }
+
+ return 0;
+}
+
+
+extern "C" void AddProgressDlgStatus(HWND hwndDlg, const char* szText)
+{
+ HWND hwndCtrl;
+
+ hwndCtrl = GetDlgItem (hwndDlg,IDC_BOX_STATUS);
+ SendMessage(hwndCtrl,EM_REPLACESEL,FALSE,(LPARAM)szText);
+ SendMessage(hwndCtrl,EM_SCROLLCARET,0,0);
+}
+
+
+extern "C" void SetProgressDlgStatus(HWND hwndDlg, const char* szText)
+{
+ HWND hwndCtrl;
+
+ hwndCtrl = GetDlgItem (hwndDlg,IDC_BOX_STATUS);
+ SendMessage(hwndCtrl,EM_SETSEL,0,-1);
+ SendMessage(hwndCtrl,EM_REPLACESEL,FALSE,(LPARAM)szText);
+ SendMessage(hwndCtrl,EM_SCROLLCARET,0,0);
+}
+
+
+BOOL CALLBACK ExpandVolProgressDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ static EXPAND_VOL_THREAD_PARAMS *pProgressDlgParam;
+ static BOOL bVolTransformStarted = FALSE;
+ static BOOL showRandPool = TRUE;
+
+ WORD lw = LOWORD (wParam);
+
+ switch (msg)
+ {
+ case WM_INITDIALOG:
+ {
+ char szOldHostSize[512], szNewHostSize[512];
+
+ pProgressDlgParam = (EXPAND_VOL_THREAD_PARAMS*)lParam;
+ bVolTransformStarted = FALSE;
+ showRandPool = TRUE;
+
+ hCurPage = hwndDlg;
+ nPbar = IDC_PROGRESS_BAR;
+
+ GetSpaceString(szOldHostSize,sizeof(szOldHostSize),pProgressDlgParam->oldSize,pProgressDlgParam->bIsDevice);
+ GetSpaceString(szNewHostSize,sizeof(szNewHostSize),pProgressDlgParam->newSize,pProgressDlgParam->bIsDevice);
+
+ SetWindowText (GetDlgItem (hwndDlg, IDC_EXPAND_VOLUME_OLDSIZE), szOldHostSize);
+ SetWindowText (GetDlgItem (hwndDlg, IDC_EXPAND_VOLUME_NEWSIZE), szNewHostSize);
+ SetWindowText (GetDlgItem (hwndDlg, IDC_EXPAND_VOLUME_NAME), pProgressDlgParam->szVolumeName);
+ SetWindowText (GetDlgItem (hwndDlg, IDC_EXPAND_FILE_SYSTEM), szFileSystemStr[pProgressDlgParam->FileSystem]);
+ SetWindowText (GetDlgItem (hwndDlg, IDC_EXPAND_VOLUME_INITSPACE), pProgressDlgParam->bInitFreeSpace?"Yes":"No");
+
+ SendMessage (GetDlgItem (hwndDlg, IDC_BOX_STATUS), WM_SETFONT, (WPARAM) hBoldFont, (LPARAM) TRUE);
+
+ SendMessage (GetDlgItem (hwndDlg, IDC_RANDOM_BYTES), WM_SETFONT, (WPARAM) hFixedDigitFont, (LPARAM) TRUE);
+
+ // set status text
+ if ( !pProgressDlgParam->bInitFreeSpace && pProgressDlgParam->bIsLegacy )
+ {
+ showRandPool = FALSE;
+ EnableWindow (GetDlgItem (hwndDlg, IDC_DISPLAY_POOL_CONTENTS), FALSE);
+ EnableWindow (GetDlgItem (hwndDlg, IDC_RANDOM_BYTES), FALSE);
+ SetDlgItemText(hwndDlg, IDC_BOX_STATUS, "Click 'Continue' to expand the volume.");
+ }
+ else
+ {
+ SetDlgItemText(hwndDlg, IDC_BOX_STATUS, "IMPORTANT: Move your mouse as randomly as possible within this window. The longer you move it, the better. This significantly increases the cryptographic strength of the encryption keys. Then click 'Continue' to expand the volume.");
+ }
+
+ SendMessage (GetDlgItem (hwndDlg, IDC_DISPLAY_POOL_CONTENTS), BM_SETCHECK, showRandPool ? BST_CHECKED : BST_UNCHECKED, 0);
+ SetTimer (hwndDlg, TIMER_ID_RANDVIEW, TIMER_INTERVAL_RANDVIEW, NULL);
+ }
+ return 0;
+ case TC_APPMSG_VOL_TRANSFORM_THREAD_ENDED:
+ {
+ int nStatus = (int)lParam;
+
+ NormalCursor ();
+ if (nStatus != 0)
+ {
+ if ( nStatus != ERR_USER_ABORT )
+ AddProgressDlgStatus (hwndDlg, "Error: volume expansion failed.");
+ else
+ AddProgressDlgStatus (hwndDlg, "Error: operation aborted by user.");
+ }
+ else
+ {
+ AddProgressDlgStatus (hwndDlg, "Finished. Volume successfully expanded.");
+ }
+
+ SetWindowText (GetDlgItem (hwndDlg, IDOK), "Exit");
+ EnableWindow (GetDlgItem (hwndDlg, IDOK), TRUE);
+ EnableWindow (GetDlgItem (hwndDlg, IDCANCEL), FALSE);
+ }
+ return 1;
+
+ case WM_TIMER:
+
+ switch (wParam)
+ {
+ case TIMER_ID_RANDVIEW:
+ {
+ unsigned char tmp[16] = {0};
+ char szRndPool[64] = {0};
+
+ if (!showRandPool)
+ return 1;
+
+ RandpeekBytes (hwndDlg, tmp, sizeof (tmp));
+
+ StringCbPrintfA (szRndPool, sizeof(szRndPool), "%08X%08X%08X%08X",
+ *((DWORD*) (tmp + 12)), *((DWORD*) (tmp + 8)), *((DWORD*) (tmp + 4)), *((DWORD*) (tmp)));
+
+ SetWindowText (GetDlgItem (hwndDlg, IDC_RANDOM_BYTES), szRndPool);
+
+ burn (tmp, sizeof(tmp));
+ burn (szRndPool, sizeof(szRndPool));
+ }
+ return 1;
+ }
+ return 0;
+
+ case WM_COMMAND:
+ if (lw == IDC_DISPLAY_POOL_CONTENTS)
+ {
+ showRandPool = IsButtonChecked (GetDlgItem (hwndDlg, IDC_DISPLAY_POOL_CONTENTS));
+ return 1;
+ }
+ if (lw == IDCANCEL)
+ {
+ if (bVolTransformStarted)
+ {
+ if (MessageBoxW (hwndDlg, L"Warning: Volume expansion is in progress!\n\nStopping now may result in a damaged volume.\n\nDo you really want to cancel?", lpszTitle, YES_NO|MB_ICONQUESTION|MB_DEFBUTTON2) == IDNO)
+ return 1;
+
+ // tell the volume transform thread to terminate
+ bVolTransformThreadCancel = TRUE;
+ }
+ EndDialog (hwndDlg, lw);
+ return 1;
+ }
+
+ if (lw == IDOK)
+ {
+ if (bVolTransformStarted)
+ {
+ // TransformThreadFunction finished -> OK button is now exit
+ EndDialog (hwndDlg, lw);
+ }
+ else
+ {
+ showRandPool = FALSE;
+ KillTimer (hwndDlg, TIMER_ID_RANDVIEW);
+ EnableWindow (GetDlgItem (hwndDlg, IDC_DISPLAY_POOL_CONTENTS), FALSE);
+ EnableWindow (GetDlgItem (hwndDlg, IDOK), FALSE);
+ SetProgressDlgStatus (hwndDlg, "Starting volume expansion ...\r\n");
+ bVolTransformStarted = TRUE;
+ pProgressDlgParam->hwndDlg = hwndDlg;
+ if ( _beginthread (volTransformThreadFunction, 0, pProgressDlgParam) == -1L )
+ {
+ handleError (hwndDlg, ERR_OS_ERROR);
+ EndDialog (hwndDlg, lw);
+ }
+ WaitCursor();
+ }
+ return 1;
+ }
+
+ return 0;
+ }
+
+ return 0;
+}
+
+
typedef struct
{
OpenVolumeContext *context;
@@ -417,118 +411,118 @@ typedef struct
BOOL preserveTimestamps;
BOOL useBackupHeader;
int* nStatus;
-} OpenVolumeThreadParam;
-
+} OpenVolumeThreadParam;
+
void CALLBACK OpenVolumeWaitThreadProc(void* pArg, HWND hwndDlg)
{
OpenVolumeThreadParam* pThreadParam = (OpenVolumeThreadParam*) pArg;
*(pThreadParam)->nStatus = OpenVolume(pThreadParam->context, pThreadParam->volumePath, pThreadParam->password, pThreadParam->pkcs5_prf,
pThreadParam->truecryptMode, pThreadParam->write, pThreadParam->preserveTimestamps, pThreadParam->useBackupHeader);
-}
-
-/*
- ExpandVolumeWizard
-
- Expands a trucrypt volume (wizard for user interface)
-
- Parameters:
-
- hwndDlg : HWND
- [in] handle to parent window (if any)
-
- szVolume : char *
- [in] Pointer to a string with the volume name (e.g. '\Device\Harddisk0\Partition1' or 'C:\topsecret.tc')
-
- Return value:
-
- none
-
-*/
-void ExpandVolumeWizard (HWND hwndDlg, char *lpszVolume)
-{
- int nStatus = ERR_OS_ERROR;
- wchar_t szTmp[4096];
- Password VolumePassword;
- int VolumePkcs5 = 0;
- uint64 hostSize, volSize, hostSizeFree, maxSizeFS;
- BOOL bIsDevice, bIsLegacy;
- DWORD dwError;
- int driveNo;
- enum EV_FileSystem volFSType;
- char rootPath[] = "A:\\";
-
- switch (IsSystemDevicePath (lpszVolume, hwndDlg, TRUE))
- {
- case 1:
- case 2:
- MessageBoxW (hwndDlg, L"A VeraCrypt system volume can't be expanded.", lpszTitle, MB_OK|MB_ICONEXCLAMATION);
- goto ret;
- }
-
- EnableElevatedCursorChange (hwndDlg);
- WaitCursor();
-
- if (IsMountedVolume (lpszVolume))
- {
- Warning ("DISMOUNT_FIRST", hwndDlg);
- goto ret;
- }
-
- if (Randinit() != ERR_SUCCESS) {
+}
+
+/*
+ ExpandVolumeWizard
+
+ Expands a trucrypt volume (wizard for user interface)
+
+ Parameters:
+
+ hwndDlg : HWND
+ [in] handle to parent window (if any)
+
+ szVolume : char *
+ [in] Pointer to a string with the volume name (e.g. '\Device\Harddisk0\Partition1' or 'C:\topsecret.tc')
+
+ Return value:
+
+ none
+
+*/
+void ExpandVolumeWizard (HWND hwndDlg, char *lpszVolume)
+{
+ int nStatus = ERR_OS_ERROR;
+ wchar_t szTmp[4096];
+ Password VolumePassword;
+ int VolumePkcs5 = 0;
+ uint64 hostSize, volSize, hostSizeFree, maxSizeFS;
+ BOOL bIsDevice, bIsLegacy;
+ DWORD dwError;
+ int driveNo;
+ enum EV_FileSystem volFSType;
+ char rootPath[] = "A:\\";
+
+ switch (IsSystemDevicePath (lpszVolume, hwndDlg, TRUE))
+ {
+ case 1:
+ case 2:
+ MessageBoxW (hwndDlg, L"A VeraCrypt system volume can't be expanded.", lpszTitle, MB_OK|MB_ICONEXCLAMATION);
+ goto ret;
+ }
+
+ EnableElevatedCursorChange (hwndDlg);
+ WaitCursor();
+
+ if (IsMountedVolume (lpszVolume))
+ {
+ Warning ("DISMOUNT_FIRST", hwndDlg);
+ goto ret;
+ }
+
+ if (Randinit() != ERR_SUCCESS) {
if (CryptoAPILastError == ERROR_SUCCESS)
nStatus = ERR_RAND_INIT_FAILED;
else
- nStatus = ERR_CAPI_INIT_FAILED;
- goto error;
- }
-
- NormalCursor();
-
- // Ask the user if there is a hidden volume
- char *volTypeChoices[] = {0, "DOES_VOLUME_CONTAIN_HIDDEN", "VOLUME_CONTAINS_HIDDEN", "VOLUME_DOES_NOT_CONTAIN_HIDDEN", "IDCANCEL", 0};
- switch (AskMultiChoice ((void **) volTypeChoices, FALSE, hwndDlg))
- {
- case 1:
- MessageBoxW (hwndDlg, L"An outer volume containing a hidden volume can't be expanded, because this destroys the hidden volume.", lpszTitle, MB_OK|MB_ICONEXCLAMATION);
- goto ret;
-
- case 2:
- break;
-
- default:
- nStatus = ERR_SUCCESS;
- goto ret;
- }
-
- WaitCursor();
-
- nStatus = QueryVolumeInfo(hwndDlg,lpszVolume,&hostSizeFree,&maxSizeFS);
-
- if (nStatus!=ERR_SUCCESS)
- {
- nStatus = ERR_OS_ERROR;
- goto error;
- }
-
- NormalCursor();
-
- while (TRUE)
- {
- OpenVolumeContext expandVol;
- BOOL truecryptMode = FALSE;
-
- if (!VeraCryptExpander::ExtcvAskVolumePassword (hwndDlg, &VolumePassword, &VolumePkcs5, &truecryptMode, "ENTER_NORMAL_VOL_PASSWORD", FALSE))
- {
- goto ret;
- }
-
- EnableElevatedCursorChange (hwndDlg);
- WaitCursor();
-
- if (KeyFilesEnable && FirstKeyFile)
- KeyFilesApply (hwndDlg, &VolumePassword, FirstKeyFile);
-
+ nStatus = ERR_CAPI_INIT_FAILED;
+ goto error;
+ }
+
+ NormalCursor();
+
+ // Ask the user if there is a hidden volume
+ char *volTypeChoices[] = {0, "DOES_VOLUME_CONTAIN_HIDDEN", "VOLUME_CONTAINS_HIDDEN", "VOLUME_DOES_NOT_CONTAIN_HIDDEN", "IDCANCEL", 0};
+ switch (AskMultiChoice ((void **) volTypeChoices, FALSE, hwndDlg))
+ {
+ case 1:
+ MessageBoxW (hwndDlg, L"An outer volume containing a hidden volume can't be expanded, because this destroys the hidden volume.", lpszTitle, MB_OK|MB_ICONEXCLAMATION);
+ goto ret;
+
+ case 2:
+ break;
+
+ default:
+ nStatus = ERR_SUCCESS;
+ goto ret;
+ }
+
+ WaitCursor();
+
+ nStatus = QueryVolumeInfo(hwndDlg,lpszVolume,&hostSizeFree,&maxSizeFS);
+
+ if (nStatus!=ERR_SUCCESS)
+ {
+ nStatus = ERR_OS_ERROR;
+ goto error;
+ }
+
+ NormalCursor();
+
+ while (TRUE)
+ {
+ OpenVolumeContext expandVol;
+ BOOL truecryptMode = FALSE;
+
+ if (!VeraCryptExpander::ExtcvAskVolumePassword (hwndDlg, &VolumePassword, &VolumePkcs5, &truecryptMode, "ENTER_NORMAL_VOL_PASSWORD", FALSE))
+ {
+ goto ret;
+ }
+
+ EnableElevatedCursorChange (hwndDlg);
+ WaitCursor();
+
+ if (KeyFilesEnable && FirstKeyFile)
+ KeyFilesApply (hwndDlg, &VolumePassword, FirstKeyFile);
+
WaitCursor ();
OpenVolumeThreadParam threadParam;
@@ -544,195 +538,195 @@ void ExpandVolumeWizard (HWND hwndDlg, char *lpszVolume)
ShowWaitDialog (hwndDlg, TRUE, OpenVolumeWaitThreadProc, &threadParam);
- NormalCursor ();
-
- dwError = GetLastError();
-
- if (nStatus == ERR_SUCCESS)
- {
- bIsDevice = expandVol.IsDevice;
- bIsLegacy = expandVol.CryptoInfo->LegacyVolume;
- hostSize = expandVol.HostSize;
- VolumePkcs5 = expandVol.CryptoInfo->pkcs5;
- if ( bIsLegacy )
- {
- if ( bIsDevice )
- volSize = 0; // updated later
- else
- volSize = hostSize;
- }
- else
- {
- volSize = GetVolumeSizeByDataAreaSize (expandVol.CryptoInfo->VolumeSize.Value, bIsLegacy);
- }
- CloseVolume (&expandVol);
- break;
- }
- else if (nStatus != ERR_PASSWORD_WRONG)
- {
- SetLastError (dwError);
- goto error;
- }
-
- NormalCursor();
-
- handleError (hwndDlg, nStatus);
- }
-
- WaitCursor();
-
- // auto mount the volume to check the file system type
- nStatus=MountVolTemp(hwndDlg, lpszVolume, &driveNo, &VolumePassword, VolumePkcs5);
-
- if (nStatus != ERR_SUCCESS)
- goto error;
-
- rootPath[0] += driveNo;
-
- if ( !GetFileSystemType(rootPath,&volFSType) )
- volFSType = EV_FS_TYPE_RAW;
-
- if ( bIsLegacy && bIsDevice && volFSType == EV_FS_TYPE_NTFS )
- {
- uint64 NumberOfSectors;
- DWORD BytesPerSector;
-
- if ( !GetNtfsNumberOfSectors(rootPath, &NumberOfSectors, &BytesPerSector) )
- nStatus = ERR_OS_ERROR;
-
- // NTFS reported size does not include boot sector copy at volume end
- volSize = ( NumberOfSectors + 1 ) * BytesPerSector;
- }
-
- UnmountVolume (hwndDlg, driveNo, TRUE);
-
- NormalCursor();
-
- if (nStatus != ERR_SUCCESS)
- goto error;
-
- if ( bIsDevice && bIsLegacy && volFSType != EV_FS_TYPE_NTFS )
- {
- MessageBoxW (hwndDlg,
- L"Expanding a device hosted legacy volume with no NTFS file system\n"
- L"is unsupported.\n"
- L"Note that expanding the VeraCrypt volume itself is not neccessary\n"
- L"for legacy volumes.\n",
- lpszTitle, MB_OK|MB_ICONEXCLAMATION);
- goto ret;
- }
-
- // check if there is enough free space on host device/drive to expand the volume
- if ( (bIsDevice && hostSize < volSize + TC_MINVAL_FS_EXPAND) || (!bIsDevice && hostSizeFree < TC_MINVAL_FS_EXPAND) )
- {
- MessageBoxW (hwndDlg, L"Not enough free space to expand the volume", lpszTitle, MB_OK|MB_ICONEXCLAMATION);
- goto ret;
- }
-
- if (!bIsDevice && hostSize != volSize ) {
- // there is some junk data at the end of the volume
- if (MessageBoxW (hwndDlg, L"Warning: The container file is larger than the VeraCrypt volume area. The data after the VeraCrypt volume area will be overwritten.\n\nDo you want to continue?", lpszTitle, YES_NO|MB_ICONQUESTION|MB_DEFBUTTON2) == IDNO)
- goto ret;
- }
-
- switch (volFSType)
- {
- case EV_FS_TYPE_NTFS:
- break;
- case EV_FS_TYPE_FAT:
- if (MessageBoxW (hwndDlg,L"Warning: The VeraCrypt volume contains a FAT file system!\n\nOnly the VeraCrypt volume itself will be expanded, but not the file system.\n\nDo you want to continue?",
- lpszTitle, YES_NO|MB_ICONQUESTION|MB_DEFBUTTON2) == IDNO)
- goto ret;
- break;
- default:
- if (MessageBoxW (hwndDlg,L"Warning: The VeraCrypt volume contains an unknown or no file system!\n\nOnly the VeraCrypt volume itself will be expanded, the file system remains unchanged.\n\nDo you want to continue?",
- lpszTitle, YES_NO|MB_ICONQUESTION|MB_DEFBUTTON2) == IDNO)
- goto ret;
- }
-
- EXPAND_VOL_THREAD_PARAMS VolExpandParam;
-
- VolExpandParam.bInitFreeSpace = (bIsLegacy && bIsDevice) ? FALSE:TRUE;
- VolExpandParam.szVolumeName = lpszVolume;
- VolExpandParam.FileSystem = volFSType;
- VolExpandParam.pVolumePassword = &VolumePassword;
- VolExpandParam.VolumePkcs5 = VolumePkcs5;
- VolExpandParam.bIsDevice = bIsDevice;
- VolExpandParam.bIsLegacy = bIsLegacy;
- VolExpandParam.oldSize = bIsDevice ? volSize : hostSize;
- VolExpandParam.newSize = hostSize;
- VolExpandParam.hostSizeFree = hostSizeFree;
-
- while (1)
- {
- uint64 newVolumeSize;
-
- if (IDCANCEL == DialogBoxParamW (hInst,
- MAKEINTRESOURCEW (IDD_SIZE_DIALOG), hwndDlg,
- (DLGPROC) ExpandVolSizeDlgProc, (LPARAM) &VolExpandParam))
- {
- goto ret;
- }
-
- newVolumeSize = VolExpandParam.newSize;
-
- if ( !bIsDevice )
- {
- if ( newVolumeSize < hostSize + TC_MINVAL_FS_EXPAND)
- {
- swprintf(szTmp,L"New volume size too small, must be at least %I64u kB larger than the current size.",TC_MINVAL_FS_EXPAND/BYTES_PER_KB);
- MessageBoxW (hwndDlg, szTmp, lpszTitle, MB_OK | MB_ICONEXCLAMATION );
- continue;
- }
-
- if ( newVolumeSize - hostSize > hostSizeFree )
- {
- swprintf(szTmp,L"New volume size too large, not enough space on host drive.");
- MessageBoxW (hwndDlg, szTmp, lpszTitle, MB_OK | MB_ICONEXCLAMATION );
- continue;
- }
-
- if ( newVolumeSize>maxSizeFS )
- {
- swprintf(szTmp,L"Maximum file size of %I64u MB on host drive exceeded.",maxSizeFS/BYTES_PER_MB);
- MessageBoxW (hwndDlg, L"!\n",lpszTitle, MB_OK | MB_ICONEXCLAMATION );
- continue;
- }
- }
-
- if ( newVolumeSize > TC_MAX_VOLUME_SIZE )
- {
- // note: current limit TC_MAX_VOLUME_SIZE is 1 PetaByte
- swprintf(szTmp,L"Maximum VeraCrypt volume size of %I64u TB exceeded!\n",TC_MAX_VOLUME_SIZE/BYTES_PER_TB);
- MessageBoxW (hwndDlg, szTmp,lpszTitle, MB_OK | MB_ICONEXCLAMATION );
- if (bIsDevice)
- break; // TODO: ask to limit volume size to TC_MAX_VOLUME_SIZE
- continue;
- }
-
- break;
- }
-
- VolExpandParam.oldSize = volSize;
-
- // start progress dialog
- DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_EXPAND_PROGRESS_DLG), hwndDlg,
- (DLGPROC) ExpandVolProgressDlgProc, (LPARAM) &VolExpandParam );
-
-ret:
- nStatus = ERR_SUCCESS;
-
-error:
-
- if (nStatus != 0)
- handleError (hwndDlg, nStatus);
-
- burn (&VolumePassword, sizeof (VolumePassword));
-
- RestoreDefaultKeyFilesParam();
- RandStop (FALSE);
- NormalCursor();
-
- return;
-}
-
+ NormalCursor ();
+
+ dwError = GetLastError();
+
+ if (nStatus == ERR_SUCCESS)
+ {
+ bIsDevice = expandVol.IsDevice;
+ bIsLegacy = expandVol.CryptoInfo->LegacyVolume;
+ hostSize = expandVol.HostSize;
+ VolumePkcs5 = expandVol.CryptoInfo->pkcs5;
+ if ( bIsLegacy )
+ {
+ if ( bIsDevice )
+ volSize = 0; // updated later
+ else
+ volSize = hostSize;
+ }
+ else
+ {
+ volSize = GetVolumeSizeByDataAreaSize (expandVol.CryptoInfo->VolumeSize.Value, bIsLegacy);
+ }
+ CloseVolume (&expandVol);
+ break;
+ }
+ else if (nStatus != ERR_PASSWORD_WRONG)
+ {
+ SetLastError (dwError);
+ goto error;
+ }
+
+ NormalCursor();
+
+ handleError (hwndDlg, nStatus);
+ }
+
+ WaitCursor();
+
+ // auto mount the volume to check the file system type
+ nStatus=MountVolTemp(hwndDlg, lpszVolume, &driveNo, &VolumePassword, VolumePkcs5);
+
+ if (nStatus != ERR_SUCCESS)
+ goto error;
+
+ rootPath[0] += driveNo;
+
+ if ( !GetFileSystemType(rootPath,&volFSType) )
+ volFSType = EV_FS_TYPE_RAW;
+
+ if ( bIsLegacy && bIsDevice && volFSType == EV_FS_TYPE_NTFS )
+ {
+ uint64 NumberOfSectors;
+ DWORD BytesPerSector;
+
+ if ( !GetNtfsNumberOfSectors(rootPath, &NumberOfSectors, &BytesPerSector) )
+ nStatus = ERR_OS_ERROR;
+
+ // NTFS reported size does not include boot sector copy at volume end
+ volSize = ( NumberOfSectors + 1 ) * BytesPerSector;
+ }
+
+ UnmountVolume (hwndDlg, driveNo, TRUE);
+
+ NormalCursor();
+
+ if (nStatus != ERR_SUCCESS)
+ goto error;
+
+ if ( bIsDevice && bIsLegacy && volFSType != EV_FS_TYPE_NTFS )
+ {
+ MessageBoxW (hwndDlg,
+ L"Expanding a device hosted legacy volume with no NTFS file system\n"
+ L"is unsupported.\n"
+ L"Note that expanding the VeraCrypt volume itself is not neccessary\n"
+ L"for legacy volumes.\n",
+ lpszTitle, MB_OK|MB_ICONEXCLAMATION);
+ goto ret;
+ }
+
+ // check if there is enough free space on host device/drive to expand the volume
+ if ( (bIsDevice && hostSize < volSize + TC_MINVAL_FS_EXPAND) || (!bIsDevice && hostSizeFree < TC_MINVAL_FS_EXPAND) )
+ {
+ MessageBoxW (hwndDlg, L"Not enough free space to expand the volume", lpszTitle, MB_OK|MB_ICONEXCLAMATION);
+ goto ret;
+ }
+
+ if (!bIsDevice && hostSize != volSize ) {
+ // there is some junk data at the end of the volume
+ if (MessageBoxW (hwndDlg, L"Warning: The container file is larger than the VeraCrypt volume area. The data after the VeraCrypt volume area will be overwritten.\n\nDo you want to continue?", lpszTitle, YES_NO|MB_ICONQUESTION|MB_DEFBUTTON2) == IDNO)
+ goto ret;
+ }
+
+ switch (volFSType)
+ {
+ case EV_FS_TYPE_NTFS:
+ break;
+ case EV_FS_TYPE_FAT:
+ if (MessageBoxW (hwndDlg,L"Warning: The VeraCrypt volume contains a FAT file system!\n\nOnly the VeraCrypt volume itself will be expanded, but not the file system.\n\nDo you want to continue?",
+ lpszTitle, YES_NO|MB_ICONQUESTION|MB_DEFBUTTON2) == IDNO)
+ goto ret;
+ break;
+ default:
+ if (MessageBoxW (hwndDlg,L"Warning: The VeraCrypt volume contains an unknown or no file system!\n\nOnly the VeraCrypt volume itself will be expanded, the file system remains unchanged.\n\nDo you want to continue?",
+ lpszTitle, YES_NO|MB_ICONQUESTION|MB_DEFBUTTON2) == IDNO)
+ goto ret;
+ }
+
+ EXPAND_VOL_THREAD_PARAMS VolExpandParam;
+
+ VolExpandParam.bInitFreeSpace = (bIsLegacy && bIsDevice) ? FALSE:TRUE;
+ VolExpandParam.szVolumeName = lpszVolume;
+ VolExpandParam.FileSystem = volFSType;
+ VolExpandParam.pVolumePassword = &VolumePassword;
+ VolExpandParam.VolumePkcs5 = VolumePkcs5;
+ VolExpandParam.bIsDevice = bIsDevice;
+ VolExpandParam.bIsLegacy = bIsLegacy;
+ VolExpandParam.oldSize = bIsDevice ? volSize : hostSize;
+ VolExpandParam.newSize = hostSize;
+ VolExpandParam.hostSizeFree = hostSizeFree;
+
+ while (1)
+ {
+ uint64 newVolumeSize;
+
+ if (IDCANCEL == DialogBoxParamW (hInst,
+ MAKEINTRESOURCEW (IDD_SIZE_DIALOG), hwndDlg,
+ (DLGPROC) ExpandVolSizeDlgProc, (LPARAM) &VolExpandParam))
+ {
+ goto ret;
+ }
+
+ newVolumeSize = VolExpandParam.newSize;
+
+ if ( !bIsDevice )
+ {
+ if ( newVolumeSize < hostSize + TC_MINVAL_FS_EXPAND)
+ {
+ StringCbPrintfW(szTmp,sizeof(szTmp),L"New volume size too small, must be at least %I64u kB larger than the current size.",TC_MINVAL_FS_EXPAND/BYTES_PER_KB);
+ MessageBoxW (hwndDlg, szTmp, lpszTitle, MB_OK | MB_ICONEXCLAMATION );
+ continue;
+ }
+
+ if ( newVolumeSize - hostSize > hostSizeFree )
+ {
+ StringCbPrintfW(szTmp,sizeof(szTmp),L"New volume size too large, not enough space on host drive.");
+ MessageBoxW (hwndDlg, szTmp, lpszTitle, MB_OK | MB_ICONEXCLAMATION );
+ continue;
+ }
+
+ if ( newVolumeSize>maxSizeFS )
+ {
+ StringCbPrintfW(szTmp,sizeof(szTmp),L"Maximum file size of %I64u MB on host drive exceeded.",maxSizeFS/BYTES_PER_MB);
+ MessageBoxW (hwndDlg, L"!\n",lpszTitle, MB_OK | MB_ICONEXCLAMATION );
+ continue;
+ }
+ }
+
+ if ( newVolumeSize > TC_MAX_VOLUME_SIZE )
+ {
+ // note: current limit TC_MAX_VOLUME_SIZE is 1 PetaByte
+ StringCbPrintfW(szTmp,sizeof(szTmp),L"Maximum VeraCrypt volume size of %I64u TB exceeded!\n",TC_MAX_VOLUME_SIZE/BYTES_PER_TB);
+ MessageBoxW (hwndDlg, szTmp,lpszTitle, MB_OK | MB_ICONEXCLAMATION );
+ if (bIsDevice)
+ break; // TODO: ask to limit volume size to TC_MAX_VOLUME_SIZE
+ continue;
+ }
+
+ break;
+ }
+
+ VolExpandParam.oldSize = volSize;
+
+ // start progress dialog
+ DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_EXPAND_PROGRESS_DLG), hwndDlg,
+ (DLGPROC) ExpandVolProgressDlgProc, (LPARAM) &VolExpandParam );
+
+ret:
+ nStatus = ERR_SUCCESS;
+
+error:
+
+ if (nStatus != 0)
+ handleError (hwndDlg, nStatus);
+
+ burn (&VolumePassword, sizeof (VolumePassword));
+
+ RestoreDefaultKeyFilesParam();
+ RandStop (FALSE);
+ NormalCursor();
+
+ return;
+}
+