VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Format
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2014-07-14 17:41:09 +0200
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2014-11-08 23:21:27 +0100
commitc220db01281564bf5b50575ee7e24b38e45f5050 (patch)
tree5e66aa935ec029ca2bac6fa282f4c18710fc2d0d /src/Format
parentc01f392a7ba1d5cdd4aa182eeb273cf41717d94f (diff)
downloadVeraCrypt-c220db01281564bf5b50575ee7e24b38e45f5050.tar.gz
VeraCrypt-c220db01281564bf5b50575ee7e24b38e45f5050.zip
Static Code Analysis : Generalize the use of Safe String functions. Add some NULL pointer checks. Avoid false-positive detection in AppendMenu (MF_SEPARATOR) calls by setting the last parameter to "" instead of NULL.
Diffstat (limited to 'src/Format')
-rw-r--r--src/Format/InPlace.c34
-rw-r--r--src/Format/Tcformat.c188
2 files changed, 113 insertions, 109 deletions
diff --git a/src/Format/InPlace.c b/src/Format/InPlace.c
index c3d09fb3..228e2e5f 100644
--- a/src/Format/InPlace.c
+++ b/src/Format/InPlace.c
@@ -17,40 +17,42 @@ IMPORTANT: Due to this issue, functions in this file must not directly interact
# define _WIN32_WINNT 0x0600
#endif
#include <stdlib.h>
#include <string.h>
#include <string>
#include "Tcdefs.h"
#include "Platform/Finally.h"
#include "Common.h"
#include "Crc.h"
#include "Dlgcode.h"
#include "Language.h"
#include "Tcformat.h"
#include "Volumes.h"
#include "InPlace.h"
+#include <Strsafe.h>
+
using namespace std;
using namespace VeraCrypt;
#define TC_MAX_NONSYS_INPLACE_ENC_WORK_CHUNK_SIZE (2048 * BYTES_PER_KB)
#define TC_INITIAL_NTFS_CONCEAL_PORTION_SIZE (2 * TC_MAX_VOLUME_SECTOR_SIZE)
#define TC_NTFS_CONCEAL_CONSTANT 0xFF
#define TC_NONSYS_INPLACE_ENC_HEADER_UPDATE_INTERVAL (64 * BYTES_PER_MB)
#define TC_NONSYS_INPLACE_ENC_MIN_VOL_SIZE (TC_TOTAL_VOLUME_HEADERS_SIZE + TC_MIN_NTFS_FS_SIZE * 2)
// If the returned value is greater than 0, it is the desired volume size in NTFS sectors (not in bytes)
// after shrinking has been performed. If there's any error, returns -1.
static __int64 NewFileSysSizeAfterShrink (HANDLE dev, const char *devicePath, int64 *totalClusterCount, DWORD *bytesPerCluster, BOOL silent)
{
NTFS_VOLUME_DATA_BUFFER ntfsVolData;
DWORD nBytesReturned;
__int64 fileSysSize, desiredNbrSectors;
// Filesystem size and sector size
@@ -134,49 +136,49 @@ BOOL CheckRequirementsForNonSysInPlaceEnc (const char *devicePath, BOOL silent)
}
/* Admin rights */
if (!IsAdmin())
{
// We rely on the wizard process to call us only when the whole wizard process has been elevated (so UAC
// status can be ignored). In case the IsAdmin() detection somehow fails, we allow the user to continue.
if (!silent)
Warning ("ADMIN_PRIVILEGES_WARN_DEVICES");
}
/* ---------- Checks that may require admin rights ----------- */
/* Access to the partition */
- strcpy ((char *) devPath, devicePath);
- ToUNICODE ((char *) devPath);
+ StringCbCopyA ((char *) devPath, sizeof(devPath), devicePath);
+ ToUNICODE ((char *) devPath, sizeof(devPath));
driveLetterNo = GetDiskDeviceDriveLetter (devPath);
if (driveLetterNo >= 0)
szRootPath[0] = (char) driveLetterNo + 'A';
- if (FakeDosNameForDevice (devicePath, dosDev, devName, FALSE) != 0)
+ if (FakeDosNameForDevice (devicePath, dosDev, sizeof(dosDev), devName, sizeof(devName),FALSE) != 0)
{
if (!silent)
{
handleWin32Error (MainDlg);
Error ("INPLACE_ENC_CANT_ACCESS_OR_GET_INFO_ON_VOL");
}
return FALSE;
}
dev = OpenPartitionVolume (devName,
FALSE, // Do not require exclusive access
TRUE, // Require shared access (must be TRUE; otherwise, volume properties will not be possible to obtain)
FALSE, // Do not ask the user to confirm shared access (if exclusive fails)
FALSE, // Do not append alternative instructions how to encrypt the data (to applicable error messages)
silent); // Silent mode
if (dev == INVALID_HANDLE_VALUE)
return FALSE;
@@ -331,47 +333,47 @@ int EncryptPartitionInPlaceBegin (volatile FORMAT_VOL_PARAMETERS *volParams, vol
VirtualLock (header, TC_VOLUME_HEADER_EFFECTIVE_SIZE);
deviceSize = GetDeviceSize (volParams->volumePath);
if (deviceSize < 0)
{
// Cannot determine the size of the partition
nStatus = ERR_PARAMETER_INCORRECT;
goto closing_seq;
}
if (deviceSize < TC_NONSYS_INPLACE_ENC_MIN_VOL_SIZE)
{
ShowInPlaceEncErrMsgWAltSteps ("PARTITION_TOO_SMALL_FOR_NONSYS_INPLACE_ENC", TRUE);
nStatus = ERR_DONT_REPORT;
goto closing_seq;
}
dataAreaSize = GetVolumeDataAreaSize (volParams->hiddenVol, deviceSize);
- strcpy ((char *)deviceName, volParams->volumePath);
- ToUNICODE ((char *)deviceName);
+ StringCbCopyA ((char *)deviceName, sizeof(deviceName), volParams->volumePath);
+ ToUNICODE ((char *)deviceName, sizeof(deviceName));
driveLetter = GetDiskDeviceDriveLetter (deviceName);
- if (FakeDosNameForDevice (volParams->volumePath, dosDev, devName, FALSE) != 0)
+ if (FakeDosNameForDevice (volParams->volumePath, dosDev, sizeof(dosDev),devName, sizeof(devName),FALSE) != 0)
{
nStatus = ERR_OS_ERROR;
goto closing_seq;
}
if (IsDeviceMounted (devName))
{
dev = OpenPartitionVolume (devName,
FALSE, // Do not require exclusive access (must be FALSE; otherwise, it will not be possible to dismount the volume or obtain its properties and FSCTL_ALLOW_EXTENDED_DASD_IO will fail too)
TRUE, // Require shared access (must be TRUE; otherwise, it will not be possible to dismount the volume or obtain its properties and FSCTL_ALLOW_EXTENDED_DASD_IO will fail too)
FALSE, // Do not ask the user to confirm shared access (if exclusive fails)
FALSE, // Do not append alternative instructions how to encrypt the data (to applicable error messages)
FALSE); // Non-silent mode
if (dev == INVALID_HANDLE_VALUE)
{
nStatus = ERR_DONT_REPORT;
goto closing_seq;
}
}
@@ -693,44 +695,44 @@ int EncryptPartitionInPlaceResume (HANDLE dev,
}
headerCryptoInfo = crypto_open();
if (headerCryptoInfo == NULL)
{
nStatus = ERR_OUTOFMEMORY;
goto closing_seq;
}
deviceSize = GetDeviceSize (devicePath);
if (deviceSize < 0)
{
// Cannot determine the size of the partition
nStatus = ERR_OS_ERROR;
goto closing_seq;
}
if (dev == INVALID_HANDLE_VALUE)
{
- strcpy ((char *)deviceName, devicePath);
- ToUNICODE ((char *)deviceName);
+ StringCbCopyA ((char *)deviceName, sizeof(deviceName), devicePath);
+ ToUNICODE ((char *)deviceName, sizeof(deviceName));
- if (FakeDosNameForDevice (devicePath, dosDev, devName, FALSE) != 0)
+ if (FakeDosNameForDevice (devicePath, dosDev, sizeof(dosDev),devName, sizeof(devName),FALSE) != 0)
{
nStatus = ERR_OS_ERROR;
goto closing_seq;
}
dev = OpenPartitionVolume (devName,
FALSE, // Do not require exclusive access
FALSE, // Do not require shared access
TRUE, // Ask the user to confirm shared access (if exclusive fails)
FALSE, // Do not append alternative instructions how to encrypt the data (to applicable error messages)
FALSE); // Non-silent mode
if (dev == INVALID_HANDLE_VALUE)
{
nStatus = ERR_DONT_REPORT;
goto closing_seq;
}
}
// This should never be needed, but is still performed for extra safety (without checking the result)
@@ -1068,43 +1070,43 @@ closing_seq:
}
if (buf != NULL)
TCfree (buf);
if (header != NULL)
{
burn (header, TC_VOLUME_HEADER_EFFECTIVE_SIZE);
VirtualUnlock (header, TC_VOLUME_HEADER_EFFECTIVE_SIZE);
TCfree (header);
}
if (wipeBuffer != NULL)
TCfree (wipeBuffer);
if (zeroedSectorCount > 0)
{
wchar_t msg[30000] = {0};
wchar_t sizeStr[500] = {0};
- GetSizeString (zeroedSectorCount * sectorSize, sizeStr);
+ GetSizeString (zeroedSectorCount * sectorSize, sizeStr, sizeof(sizeStr));
- wsprintfW (msg,
+ StringCbPrintfW (msg, sizeof(msg),
GetString ("ZEROED_BAD_SECTOR_COUNT"),
zeroedSectorCount,
sizeStr);
WarningDirect (msg);
}
if (nStatus != ERR_SUCCESS && nStatus != ERR_USER_ABORT)
SetLastError (dwError);
return nStatus;
}
int FastVolumeHeaderUpdate (HANDLE dev, CRYPTO_INFO *headerCryptoInfo, CRYPTO_INFO *masterCryptoInfo, __int64 deviceSize)
{
LARGE_INTEGER offset;
DWORD n;
int nStatus = ERR_SUCCESS;
byte *header;
@@ -1352,44 +1354,44 @@ static int ConcealNTFS (HANDLE dev)
do
{
Sleep (1);
}
while (SetFilePointerEx (dev, offset, NULL, FILE_BEGIN) == 0
|| WriteFile (dev, buf, TC_INITIAL_NTFS_CONCEAL_PORTION_SIZE, &nbrBytesProcessed2, NULL) == 0);
SetLastError (dwError);
return ERR_OS_ERROR;
}
return ERR_SUCCESS;
}
void ShowInPlaceEncErrMsgWAltSteps (char *iniStrId, BOOL bErr)
{
wchar_t msg[30000];
- wcscpy (msg, GetString (iniStrId));
+ StringCbCopyW (msg, sizeof(msg), GetString (iniStrId));
- wcscat (msg, L"\n\n\n");
- wcscat (msg, GetString ("INPLACE_ENC_ALTERNATIVE_STEPS"));
+ StringCbCatW (msg, sizeof(msg), L"\n\n\n");
+ StringCbCatW (msg, sizeof(msg), GetString ("INPLACE_ENC_ALTERNATIVE_STEPS"));
if (bErr)
ErrorDirect (msg);
else
WarningDirect (msg);
}
static void ExportProgressStats (__int64 bytesDone, __int64 totalSize)
{
NonSysInplaceEncBytesDone = bytesDone;
NonSysInplaceEncTotalSize = totalSize;
}
void SetNonSysInplaceEncUIStatus (int nonSysInplaceEncStatus)
{
NonSysInplaceEncStatus = nonSysInplaceEncStatus;
}
@@ -1397,50 +1399,50 @@ void SetNonSysInplaceEncUIStatus (int nonSysInplaceEncStatus)
BOOL SaveNonSysInPlaceEncSettings (int delta, WipeAlgorithmId newWipeAlgorithm)
{
int count;
char str[32];
WipeAlgorithmId savedWipeAlgorithm = TC_WIPE_NONE;
if (delta == 0)
return TRUE;
count = LoadNonSysInPlaceEncSettings (&savedWipeAlgorithm) + delta;
if (count < 1)
{
RemoveNonSysInPlaceEncNotifications();
return TRUE;
}
else
{
if (newWipeAlgorithm != TC_WIPE_NONE)
{
- sprintf (str, "%d", (int) newWipeAlgorithm);
+ StringCbPrintfA (str, sizeof(str), "%d", (int) newWipeAlgorithm);
SaveBufferToFile (str, GetConfigPath (TC_APPD_FILENAME_NONSYS_INPLACE_ENC_WIPE), strlen(str), FALSE);
}
else if (FileExists (GetConfigPath (TC_APPD_FILENAME_NONSYS_INPLACE_ENC_WIPE)))
{
remove (GetConfigPath (TC_APPD_FILENAME_NONSYS_INPLACE_ENC_WIPE));
}
- sprintf (str, "%d", count);
+ StringCbPrintfA (str, sizeof(str), "%d", count);
return SaveBufferToFile (str, GetConfigPath (TC_APPD_FILENAME_NONSYS_INPLACE_ENC), strlen(str), FALSE);
}
}
// Repairs damaged sectors (i.e. those with read errors) by zeroing them.
// Note that this operating fails if there are any write errors.
int ZeroUnreadableSectors (HANDLE dev, LARGE_INTEGER startOffset, int64 size, int sectorSize, uint64 *zeroedSectorCount)
{
int nStatus;
DWORD n;
int64 sectorCount;
LARGE_INTEGER workOffset;
byte *sectorBuffer = NULL;
DWORD dwError;
workOffset.QuadPart = startOffset.QuadPart;
sectorBuffer = (byte *) TCalloc (sectorSize);
diff --git a/src/Format/Tcformat.c b/src/Format/Tcformat.c
index 0074a169..d0b247fa 100644
--- a/src/Format/Tcformat.c
+++ b/src/Format/Tcformat.c
@@ -31,40 +31,42 @@
#include "Common/Dictionary.h"
#include "Common/Endian.h"
#include "Common/resource.h"
#include "Platform/Finally.h"
#include "Platform/ForEach.h"
#include "Random.h"
#include "Fat.h"
#include "InPlace.h"
#include "Resource.h"
#include "TcFormat.h"
#include "Format.h"
#include "FormatCom.h"
#include "Password.h"
#include "Progress.h"
#include "Tests.h"
#include "Cmdline.h"
#include "Volumes.h"
#include "Wipe.h"
#include "Xml.h"
+#include <Strsafe.h>
+
using namespace VeraCrypt;
enum wizard_pages
{
/* IMPORTANT: IF YOU ADD/REMOVE/MOVE ANY PAGES THAT ARE RELATED TO SYSTEM ENCRYPTION,
REVISE THE 'DECOY_OS_INSTRUCTIONS_PORTION_??' STRINGS! */
INTRO_PAGE,
SYSENC_TYPE_PAGE,
SYSENC_HIDDEN_OS_REQ_CHECK_PAGE,
SYSENC_SPAN_PAGE,
SYSENC_PRE_DRIVE_ANALYSIS_PAGE,
SYSENC_DRIVE_ANALYSIS_PAGE,
SYSENC_MULTI_BOOT_MODE_PAGE,
SYSENC_MULTI_BOOT_SYS_EQ_BOOT_PAGE,
SYSENC_MULTI_BOOT_NBR_SYS_DRIVES_PAGE,
SYSENC_MULTI_BOOT_ADJACENT_SYS_PAGE,
SYSENC_MULTI_BOOT_NONWIN_BOOT_LOADER_PAGE,
SYSENC_MULTI_BOOT_OUTCOME_PAGE,
VOLUME_TYPE_PAGE,
@@ -1200,59 +1202,59 @@ void ComboSelChangeEA (HWND hwndDlg)
}
else if (strcmp (name, "Twofish") == 0)
{
swprintf_s (hyperLink, sizeof(hyperLink) / 2, GetString ("MORE_INFO_ABOUT"), name);
SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString ("TWOFISH_HELP"));
}
else if (EAGetCipherCount (nIndex) > 1)
{
// Cascade
cipherIDs[cnt++] = i = EAGetLastCipher(nIndex);
while (i = EAGetPreviousCipher(nIndex, i))
{
cipherIDs[cnt] = i;
cnt++;
}
switch (cnt) // Number of ciphers in the cascade
{
case 2:
- swprintf (auxLine, GetString ("TWO_LAYER_CASCADE_HELP"),
+ StringCbPrintfW (auxLine, sizeof(auxLine), GetString ("TWO_LAYER_CASCADE_HELP"),
CipherGetName (cipherIDs[1]),
CipherGetKeySize (cipherIDs[1])*8,
CipherGetName (cipherIDs[0]),
CipherGetKeySize (cipherIDs[0])*8);
break;
case 3:
- swprintf (auxLine, GetString ("THREE_LAYER_CASCADE_HELP"),
+ StringCbPrintfW (auxLine, sizeof(auxLine), GetString ("THREE_LAYER_CASCADE_HELP"),
CipherGetName (cipherIDs[2]),
CipherGetKeySize (cipherIDs[2])*8,
CipherGetName (cipherIDs[1]),
CipherGetKeySize (cipherIDs[1])*8,
CipherGetName (cipherIDs[0]),
CipherGetKeySize (cipherIDs[0])*8);
break;
}
- wcscpy_s (hyperLink, sizeof(hyperLink) / 2, GetString ("IDC_LINK_MORE_INFO_ABOUT_CIPHER"));
+ StringCbCopyW (hyperLink, sizeof(hyperLink), GetString ("IDC_LINK_MORE_INFO_ABOUT_CIPHER"));
SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), auxLine);
}
else
{
// No info available for this encryption algorithm
SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), L"");
}
// Update hyperlink
SetWindowTextW (GetDlgItem (hwndDlg, IDC_LINK_MORE_INFO_ABOUT_CIPHER), hyperLink);
AccommodateTextField (hwndDlg, IDC_LINK_MORE_INFO_ABOUT_CIPHER, FALSE, hUserUnderlineFont);
}
}
static void VerifySizeAndUpdate (HWND hwndDlg, BOOL bUpdate)
{
BOOL bEnable = TRUE;
char szTmp[50];
@@ -1437,45 +1439,45 @@ static void UpdateSysEncProgressBar (void)
{
return;
}
if (locBootEncStatus.EncryptedAreaEnd == -1
|| locBootEncStatus.EncryptedAreaStart == -1)
{
UpdateProgressBarProc (0);
}
else
{
UpdateProgressBarProc (locBootEncStatus.EncryptedAreaEnd - locBootEncStatus.EncryptedAreaStart + 1);
if (locBootEncStatus.SetupInProgress)
{
wchar_t tmpStr[100];
// Status
if (locBootEncStatus.TransformWaitingForIdle)
- wcscpy (tmpStr, GetString ("PROGRESS_STATUS_WAITING"));
+ StringCbCopyW (tmpStr, sizeof(tmpStr), GetString ("PROGRESS_STATUS_WAITING"));
else
- wcscpy (tmpStr, GetString (SystemEncryptionStatus == SYSENC_STATUS_DECRYPTING ? "PROGRESS_STATUS_DECRYPTING" : "PROGRESS_STATUS_ENCRYPTING"));
+ StringCbCopyW (tmpStr, sizeof(tmpStr), GetString (SystemEncryptionStatus == SYSENC_STATUS_DECRYPTING ? "PROGRESS_STATUS_DECRYPTING" : "PROGRESS_STATUS_ENCRYPTING"));
- wcscat (tmpStr, L" ");
+ StringCbCatW (tmpStr, sizeof(tmpStr), L" ");
SetWindowTextW (GetDlgItem (hCurPage, IDC_WRITESPEED), tmpStr);
}
}
}
static void InitSysEncProgressBar (void)
{
BootEncryptionStatus locBootEncStatus;
try
{
locBootEncStatus = BootEncObj->GetStatus();
}
catch (...)
{
return;
}
if (locBootEncStatus.ConfiguredEncryptedAreaEnd == -1
@@ -1501,51 +1503,51 @@ static void UpdateSysEncControls (void)
locBootEncStatus = BootEncObj->GetStatus();
}
catch (...)
{
return;
}
EnableWindow (GetDlgItem (hCurPage, IDC_WIPE_MODE),
!locBootEncStatus.SetupInProgress
&& SystemEncryptionStatus == SYSENC_STATUS_ENCRYPTING);
SetWindowTextW (GetDlgItem (hCurPage, IDC_PAUSE),
GetString (locBootEncStatus.SetupInProgress ? "IDC_PAUSE" : "RESUME"));
EnableWindow (GetDlgItem (MainDlg, IDC_NEXT), !locBootEncStatus.SetupInProgress && !bFirstSysEncResumeDone);
if (!locBootEncStatus.SetupInProgress)
{
wchar_t tmpStr[100];
- wcscpy (tmpStr, GetString ((SysDriveOrPartitionFullyEncrypted (TRUE) || !locBootEncStatus.DriveMounted) ?
+ StringCbCopyW (tmpStr, sizeof(tmpStr), GetString ((SysDriveOrPartitionFullyEncrypted (TRUE) || !locBootEncStatus.DriveMounted) ?
"PROGRESS_STATUS_FINISHED" : "PROGRESS_STATUS_PAUSED"));
- wcscat (tmpStr, L" ");
+ StringCbCatW (tmpStr, sizeof(tmpStr), L" ");
// Status
SetWindowTextW (GetDlgItem (hCurPage, IDC_WRITESPEED), tmpStr);
if (SysDriveOrPartitionFullyEncrypted (TRUE) || SystemEncryptionStatus == SYSENC_STATUS_NONE)
{
- wcscpy (tmpStr, GetString ("PROCESSED_PORTION_100_PERCENT"));
- wcscat (tmpStr, L" ");
+ StringCbCopyW (tmpStr, sizeof(tmpStr), GetString ("PROCESSED_PORTION_100_PERCENT"));
+ StringCbCatW (tmpStr, sizeof(tmpStr), L" ");
SetWindowTextW (GetDlgItem (hCurPage, IDC_BYTESWRITTEN), tmpStr);
}
SetWindowText (GetDlgItem (hCurPage, IDC_TIMEREMAIN), " ");
}
}
static void SysEncPause (void)
{
BootEncryptionStatus locBootEncStatus;
if (CreateSysEncMutex ())
{
EnableWindow (GetDlgItem (hCurPage, IDC_PAUSE), FALSE);
try
{
locBootEncStatus = BootEncObj->GetStatus();
}
@@ -1682,43 +1684,43 @@ static void SysEncResume (void)
SetThreadExecutionState (ES_CONTINUOUS | ES_SYSTEM_REQUIRED);
bFirstSysEncResumeDone = TRUE;
InitSysEncProgressBar ();
UpdateSysEncProgressBar ();
UpdateSysEncControls ();
EnableWindow (GetDlgItem (hCurPage, IDC_PAUSE), TRUE);
SetTimer (MainDlg, TIMER_ID_SYSENC_PROGRESS, TIMER_INTERVAL_SYSENC_PROGRESS, NULL);
}
else
Error ("SYSTEM_ENCRYPTION_IN_PROGRESS_ELSEWHERE");
}
static BOOL GetDevicePathForHiddenOS (void)
{
BOOL tmpbDevice = FALSE;
try
{
- strncpy (szFileName, BootEncObj->GetPartitionForHiddenOS().DevicePath.c_str(), sizeof(szFileName) - 1);
+ StringCbCopyA (szFileName, sizeof(szFileName), BootEncObj->GetPartitionForHiddenOS().DevicePath.c_str());
- CreateFullVolumePath (szDiskFile, szFileName, &tmpbDevice);
+ CreateFullVolumePath (szDiskFile, sizeof(szDiskFile), szFileName, &tmpbDevice);
}
catch (Exception &e)
{
e.Show (MainDlg);
return FALSE;
}
return (szFileName[0] != 0
&& szDiskFile[0] != 0
&& tmpbDevice);
}
// Returns TRUE if there is unallocated space greater than 64 MB (max possible slack space size) between the
// boot partition and the first partition behind it. If there's none or if an error occurs, returns FALSE.
static BOOL CheckGapBetweenSysAndHiddenOS (void)
{
try
{
SystemDriveConfiguration sysDriveCfg = BootEncObj->GetSystemDriveConfiguration();
@@ -1787,63 +1789,63 @@ static void NonSysInplaceEncResume (void)
bVolTransformThreadCancel = FALSE;
bVolTransformThreadToRun = TRUE;
UpdateNonSysInPlaceEncControls ();
LastDialogId = "NONSYS_INPLACE_ENC_IN_PROGRESS";
_beginthread (volTransformThreadFunction, 0, MainDlg);
return;
}
void ShowNonSysInPlaceEncUIStatus (void)
{
wchar_t nonSysInplaceEncUIStatus [300] = {0};
switch (NonSysInplaceEncStatus)
{
case NONSYS_INPLACE_ENC_STATUS_PAUSED:
- wcscpy (nonSysInplaceEncUIStatus, GetString ("PROGRESS_STATUS_PAUSED"));
+ StringCbCopyW (nonSysInplaceEncUIStatus, sizeof(nonSysInplaceEncUIStatus), GetString ("PROGRESS_STATUS_PAUSED"));
break;
case NONSYS_INPLACE_ENC_STATUS_PREPARING:
- wcscpy (nonSysInplaceEncUIStatus, GetString ("PROGRESS_STATUS_PREPARING"));
+ StringCbCopyW (nonSysInplaceEncUIStatus, sizeof(nonSysInplaceEncUIStatus), GetString ("PROGRESS_STATUS_PREPARING"));
break;
case NONSYS_INPLACE_ENC_STATUS_RESIZING:
- wcscpy (nonSysInplaceEncUIStatus, GetString ("PROGRESS_STATUS_RESIZING"));
+ StringCbCopyW (nonSysInplaceEncUIStatus, sizeof(nonSysInplaceEncUIStatus), GetString ("PROGRESS_STATUS_RESIZING"));
break;
case NONSYS_INPLACE_ENC_STATUS_ENCRYPTING:
- wcscpy (nonSysInplaceEncUIStatus, GetString ("PROGRESS_STATUS_ENCRYPTING"));
+ StringCbCopyW (nonSysInplaceEncUIStatus, sizeof(nonSysInplaceEncUIStatus), GetString ("PROGRESS_STATUS_ENCRYPTING"));
break;
case NONSYS_INPLACE_ENC_STATUS_FINALIZING:
- wcscpy (nonSysInplaceEncUIStatus, GetString ("PROGRESS_STATUS_FINALIZING"));
+ StringCbCopyW (nonSysInplaceEncUIStatus, sizeof(nonSysInplaceEncUIStatus), GetString ("PROGRESS_STATUS_FINALIZING"));
break;
case NONSYS_INPLACE_ENC_STATUS_FINISHED:
- wcscpy (nonSysInplaceEncUIStatus, GetString ("PROGRESS_STATUS_FINISHED"));
+ StringCbCopyW (nonSysInplaceEncUIStatus, sizeof(nonSysInplaceEncUIStatus), GetString ("PROGRESS_STATUS_FINISHED"));
break;
case NONSYS_INPLACE_ENC_STATUS_ERROR:
- wcscpy (nonSysInplaceEncUIStatus, GetString ("PROGRESS_STATUS_ERROR"));
+ StringCbCopyW (nonSysInplaceEncUIStatus, sizeof(nonSysInplaceEncUIStatus), GetString ("PROGRESS_STATUS_ERROR"));
break;
}
- wcscat (nonSysInplaceEncUIStatus, L" ");
+ StringCbCatW (nonSysInplaceEncUIStatus, sizeof(nonSysInplaceEncUIStatus), L" ");
SetWindowTextW (GetDlgItem (hCurPage, IDC_WRITESPEED), nonSysInplaceEncUIStatus);
}
void UpdateNonSysInPlaceEncControls (void)
{
EnableWindow (GetDlgItem (hCurPage, IDC_WIPE_MODE), !(bVolTransformThreadRunning || bVolTransformThreadToRun));
SetWindowTextW (GetDlgItem (hCurPage, IDC_PAUSE),
GetString ((bVolTransformThreadRunning || bVolTransformThreadToRun) ? "IDC_PAUSE" : "RESUME"));
SetWindowTextW (GetDlgItem (MainDlg, IDCANCEL), GetString (bInPlaceEncNonSysResumed ? "DEFER" : "CANCEL"));
EnableWindow (GetDlgItem (hCurPage, IDC_PAUSE), bFirstNonSysInPlaceEncResumeDone
&& NonSysInplaceEncStatus != NONSYS_INPLACE_ENC_STATUS_FINALIZING
&& NonSysInplaceEncStatus != NONSYS_INPLACE_ENC_STATUS_FINISHED);
EnableWindow (GetDlgItem (MainDlg, IDC_NEXT), !(bVolTransformThreadRunning || bVolTransformThreadToRun) && !bFirstNonSysInPlaceEncResumeDone);
EnableWindow (GetDlgItem (MainDlg, IDC_PREV), !(bVolTransformThreadRunning || bVolTransformThreadToRun) && !bInPlaceEncNonSysResumed);
@@ -1957,44 +1959,44 @@ void DisplayRandPool (HWND hPoolDisplay, BOOL bShow)
static BOOL bRandPoolDispAscii = FALSE;
if (!bShow)
{
SetWindowText (hPoolDisplay, "");
return;
}
RandpeekBytes (randPool, sizeof (randPool));
if (memcmp (lastRandPool, randPool, sizeof(lastRandPool)) != 0)
{
outRandPoolDispBuffer[0] = 0;
for (row = 0; row < RANDPOOL_DISPLAY_ROWS; row++)
{
for (col = 0; col < RANDPOOL_DISPLAY_COLUMNS; col++)
{
tmpByte = randPool[row * RANDPOOL_DISPLAY_COLUMNS + col];
- sprintf ((char *) tmp, bRandPoolDispAscii ? ((tmpByte >= 32 && tmpByte < 255 && tmpByte != '&') ? " %c " : " . ") : "%02X ", tmpByte);
- strcat ((char *) outRandPoolDispBuffer, (char *) tmp);
+ StringCbPrintfA ((char *) tmp, sizeof(tmp), bRandPoolDispAscii ? ((tmpByte >= 32 && tmpByte < 255 && tmpByte != '&') ? " %c " : " . ") : "%02X ", tmpByte);
+ StringCbCatA ((char *) outRandPoolDispBuffer, sizeof(outRandPoolDispBuffer), (char *) tmp);
}
- strcat ((char *) outRandPoolDispBuffer, "\n");
+ StringCbCatA ((char *) outRandPoolDispBuffer, sizeof(outRandPoolDispBuffer), "\n");
}
SetWindowText (hPoolDisplay, (char *) outRandPoolDispBuffer);
memcpy (lastRandPool, randPool, sizeof(lastRandPool));
}
}
void DisplayPortionsOfKeys (HWND headerKeyHandle, HWND masterKeyHandle, char *headerKeyStr, char *masterKeyStr, BOOL hideKeys)
{
const wchar_t *hiddenKey = L"******************************** ";
SetWindowTextW (headerKeyHandle, hideKeys ? hiddenKey : (SingleStringToWide (headerKeyStr) + GetString ("TRIPLE_DOT_GLYPH_ELLIPSIS")).c_str());
SetWindowTextW (masterKeyHandle, hideKeys ? hiddenKey : (SingleStringToWide (masterKeyStr) + GetString ("TRIPLE_DOT_GLYPH_ELLIPSIS")).c_str());
}
static void WipeAbort (void)
{
EnableWindow (GetDlgItem (hCurPage, IDC_ABORT_BUTTON), FALSE);
@@ -2283,41 +2285,41 @@ static void __cdecl volTransformThreadFunction (void *hwndDlgArg)
goto cancel;
}
if (bDevice)
{
if (MessageBoxW (hwndDlg, GetString ("ADMIN_PRIVILEGES_WARN_DEVICES"), lpszTitle, MB_OKCANCEL|MB_ICONWARNING|MB_DEFBUTTON2) == IDCANCEL)
goto cancel;
}
}
if (!bInPlaceEncNonSys)
{
if (!bDevice)
{
int x = _access (szDiskFile, 06);
if (x == 0 || errno != ENOENT)
{
wchar_t szTmp[512];
if (! ((bHiddenVol && !bHiddenVolHost) && errno != EACCES)) // Only ask ask for permission to overwrite an existing volume if we're not creating a hidden volume
{
- _snwprintf (szTmp, sizeof szTmp / 2,
+ StringCbPrintfW (szTmp, sizeof szTmp,
GetString (errno == EACCES ? "READONLYPROMPT" : "OVERWRITEPROMPT"),
szDiskFile);
x = MessageBoxW (hwndDlg, szTmp, lpszTitle, YES_NO|MB_ICONWARNING|MB_DEFBUTTON2);
if (x != IDYES)
goto cancel;
}
}
if (_access (szDiskFile, 06) != 0)
{
if (errno == EACCES)
{
if (_chmod (szDiskFile, _S_IREAD | _S_IWRITE) != 0)
{
MessageBoxW (hwndDlg, GetString ("ACCESSMODEFAIL"), lpszTitle, ICON_HAND);
goto cancel;
}
}
@@ -2446,41 +2448,41 @@ static void __cdecl volTransformThreadFunction (void *hwndDlgArg)
wchar_t szMsg[8192];
handleError (hwndDlg, nStatus);
if (bInPlaceEncNonSys)
{
if (bInPlaceEncNonSysResumed)
{
SetNonSysInplaceEncUIStatus (NONSYS_INPLACE_ENC_STATUS_PAUSED);
Error ("INPLACE_ENC_GENERIC_ERR_RESUME");
}
else
{
SetNonSysInplaceEncUIStatus (NONSYS_INPLACE_ENC_STATUS_ERROR);
ShowInPlaceEncErrMsgWAltSteps ("INPLACE_ENC_GENERIC_ERR_ALT_STEPS", TRUE);
}
}
else if (!(bHiddenVolHost && hiddenVolHostDriveNo < 0)) // If the error was not that the hidden volume host could not be mounted (this error has already been reported to the user)
{
- swprintf (szMsg, GetString ("CREATE_FAILED"), szDiskFile);
+ StringCbPrintfW (szMsg, sizeof(szMsg), GetString ("CREATE_FAILED"), szDiskFile);
MessageBoxW (hwndDlg, szMsg, lpszTitle, ICON_HAND);
}
if (!bDevice && !(bHiddenVol && !bHiddenVolHost)) // If we're not creating a hidden volume and if it's a file container
{
remove (szDiskFile); // Delete the container
}
goto cancel;
}
else
{
/* Volume successfully created */
RestoreDefaultKeyFilesParam ();
if (bDevice && !bInPlaceEncNonSys)
{
// Handle assigned drive letter (if any)
@@ -2887,62 +2889,62 @@ int PrintFreeSpace (HWND hwndTextBox, char *lpszDrive, PLARGE_INTEGER lDiskFree)
{
if (bHiddenVol && !bHiddenVolHost) // If it's a hidden volume
nResourceString = "MAX_HIDVOL_SIZE_MB";
else if (bDevice)
nResourceString = "DEVICE_FREE_MB";
else
nResourceString = "DISK_FREE_MB";
}
else
{
if (bHiddenVol && !bHiddenVolHost) // If it's a hidden volume
nResourceString = "MAX_HIDVOL_SIZE_GB";
else if (bDevice)
nResourceString = "DEVICE_FREE_GB";
else
nResourceString = "DISK_FREE_GB";
}
if (bHiddenVol && !bHiddenVolHost) // If it's a hidden volume
{
- _snwprintf (szTmp2, sizeof szTmp2 / 2, GetString (nResourceString), ((double) lDiskFree->QuadPart) / nMultiplier);
+ StringCbPrintfW (szTmp2, sizeof szTmp2, GetString (nResourceString), ((double) lDiskFree->QuadPart) / nMultiplier);
SetWindowTextW (GetDlgItem (hwndTextBox, IDC_SIZEBOX), szTmp2);
}
else
- _snwprintf (szTmp2, sizeof szTmp2 / 2, GetString (nResourceString), lpszDrive, ((double) lDiskFree->QuadPart) / nMultiplier);
+ StringCbPrintfW (szTmp2, sizeof szTmp2, GetString (nResourceString), lpszDrive, ((double) lDiskFree->QuadPart) / nMultiplier);
SetWindowTextW (hwndTextBox, szTmp2);
if (lDiskFree->QuadPart % (__int64) BYTES_PER_MB != 0)
nMultiplier = BYTES_PER_KB;
return nMultiplier;
}
void DisplaySizingErrorText (HWND hwndTextBox)
{
wchar_t szTmp[1024];
if (translateWin32Error (szTmp, sizeof (szTmp) / sizeof(szTmp[0])))
{
wchar_t szTmp2[1024];
- wsprintfW (szTmp2, L"%s\n%s", GetString ("CANNOT_CALC_SPACE"), szTmp);
+ StringCbPrintfW (szTmp2, sizeof(szTmp2), L"%s\n%s", GetString ("CANNOT_CALC_SPACE"), szTmp);
SetWindowTextW (hwndTextBox, szTmp2);
}
else
{
SetWindowText (hwndTextBox, "");
}
}
void EnableDisableFileNext (HWND hComboBox, HWND hMainButton)
{
LPARAM nIndex = SendMessage (hComboBox, CB_GETCURSEL, 0, 0);
if (bHistory && nIndex == CB_ERR)
{
EnableWindow (hMainButton, FALSE);
SetFocus (hComboBox);
}
else
{
EnableWindow (hMainButton, TRUE);
SetFocus (hMainButton);
@@ -3135,191 +3137,191 @@ BOOL QueryFreeSpace (HWND hwndDlg, HWND hwndTextBox, BOOL display)
nVolumeSize = lDiskFree.QuadPart;
if (display)
nMultiplier = PrintFreeSpace (hwndTextBox, szDiskFile, &lDiskFree);
nUIVolumeSize = lDiskFree.QuadPart / nMultiplier;
}
return TRUE;
}
}
static BOOL FinalPreTransformPrompts (void)
{
int x;
wchar_t szTmp[4096];
int driveNo;
WCHAR deviceName[MAX_PATH];
- strcpy ((char *)deviceName, szFileName);
- ToUNICODE ((char *)deviceName);
+ StringCbCopyA ((char *)deviceName, sizeof(deviceName), szFileName);
+ ToUNICODE ((char *)deviceName, sizeof(deviceName));
driveNo = GetDiskDeviceDriveLetter (deviceName);
if (!(bHiddenVol && !bHiddenVolHost)) // Do not ask for permission to overwrite an existing volume if we're creating a hidden volume within it
{
wchar_t drive[128];
wchar_t volumeLabel[128];
wchar_t *type;
BOOL bTmpIsPartition = FALSE;
type = GetPathType (szFileName, !bInPlaceEncNonSys, &bTmpIsPartition);
if (driveNo != -1)
{
if (!GetDriveLabel (driveNo, volumeLabel, sizeof (volumeLabel)))
volumeLabel[0] = 0;
- swprintf_s (drive, sizeof (drive)/2, volumeLabel[0] ? L" (%hc: '%s')" : L" (%hc:%s)", 'A' + driveNo, volumeLabel[0] ? volumeLabel : L"");
+ StringCbPrintfW (drive, sizeof (drive), volumeLabel[0] ? L" (%hc: '%s')" : L" (%hc:%s)", 'A' + driveNo, volumeLabel[0] ? volumeLabel : L"");
}
else
{
drive[0] = 0;
volumeLabel[0] = 0;
}
if (bHiddenOS && bHiddenVolHost)
- swprintf (szTmp, GetString ("OVERWRITEPROMPT_DEVICE_HIDDEN_OS_PARTITION"), szFileName, drive);
+ StringCbPrintfW (szTmp, sizeof(szTmp), GetString ("OVERWRITEPROMPT_DEVICE_HIDDEN_OS_PARTITION"), szFileName, drive);
else
- swprintf (szTmp, GetString (bInPlaceEncNonSys ? "NONSYS_INPLACE_ENC_CONFIRM" : "OVERWRITEPROMPT_DEVICE"), type, szFileName, drive);
+ StringCbPrintfW (szTmp, sizeof(szTmp), GetString (bInPlaceEncNonSys ? "NONSYS_INPLACE_ENC_CONFIRM" : "OVERWRITEPROMPT_DEVICE"), type, szFileName, drive);
x = MessageBoxW (MainDlg, szTmp, lpszTitle, YES_NO | MB_ICONWARNING | (bInPlaceEncNonSys ? MB_DEFBUTTON1 : MB_DEFBUTTON2));
if (x != IDYES)
return FALSE;
if (driveNo != -1 && bTmpIsPartition && !bInPlaceEncNonSys)
{
float percentFreeSpace = 100.0;
__int64 occupiedBytes = 0;
// Do a second check. If we find that the partition contains more than 1GB of data or more than 12%
// of its space is occupied, we will display an extra warning, however, this time it won't be a Yes/No
// dialog box (because users often ignore such dialog boxes).
if (GetStatsFreeSpaceOnPartition (szFileName, &percentFreeSpace, &occupiedBytes, TRUE) != -1)
{
if (occupiedBytes > BYTES_PER_GB && percentFreeSpace < 99.99 // "percentFreeSpace < 99.99" is needed because an NTFS filesystem larger than several terabytes can have more than 1GB of data in use, even if there are no files stored on it.
|| percentFreeSpace < 88) // A 24-MB NTFS filesystem has 11.5% of space in use even if there are no files stored on it.
{
wchar_t tmpMcMsg [8000];
wchar_t tmpMcOption1 [500];
wchar_t tmpMcOptionCancel [50];
- wcscpy (tmpMcMsg, GetString("OVERWRITEPROMPT_DEVICE_SECOND_WARNING_LOTS_OF_DATA"));
- wcscpy (tmpMcOption1, GetString("ERASE_FILES_BY_CREATING_VOLUME"));
- wcscpy (tmpMcOptionCancel, GetString("CANCEL"));
+ StringCbCopyW (tmpMcMsg, sizeof(tmpMcMsg), GetString("OVERWRITEPROMPT_DEVICE_SECOND_WARNING_LOTS_OF_DATA"));
+ StringCbCopyW (tmpMcOption1, sizeof(tmpMcOption1), GetString("ERASE_FILES_BY_CREATING_VOLUME"));
+ StringCbCopyW (tmpMcOptionCancel, sizeof(tmpMcOptionCancel), GetString("CANCEL"));
- wcscat (tmpMcMsg, L"\n\n");
- wcscat (tmpMcMsg, GetString("DRIVE_LETTER_ITEM"));
- swprintf_s (szTmp, sizeof (szTmp)/2, L"%hc:", 'A' + driveNo);
- wcscat (tmpMcMsg, szTmp);
+ StringCbCatW (tmpMcMsg, sizeof(tmpMcMsg), L"\n\n");
+ StringCbCatW (tmpMcMsg, sizeof(tmpMcMsg), GetString("DRIVE_LETTER_ITEM"));
+ StringCbPrintfW (szTmp, sizeof (szTmp), L"%hc:", 'A' + driveNo);
+ StringCbCatW (tmpMcMsg, sizeof(tmpMcMsg), szTmp);
- wcscat (tmpMcMsg, L"\n");
- wcscat (tmpMcMsg, GetString("LABEL_ITEM"));
- wcscat (tmpMcMsg, volumeLabel[0] != 0 ? volumeLabel : GetString("NOT_APPLICABLE_OR_NOT_AVAILABLE"));
+ StringCbCatW (tmpMcMsg, sizeof(tmpMcMsg), L"\n");
+ StringCbCatW (tmpMcMsg, sizeof(tmpMcMsg), GetString("LABEL_ITEM"));
+ StringCbCatW (tmpMcMsg, sizeof(tmpMcMsg), volumeLabel[0] != 0 ? volumeLabel : GetString("NOT_APPLICABLE_OR_NOT_AVAILABLE"));
- wcscat (tmpMcMsg, L"\n");
- wcscat (tmpMcMsg, GetString("SIZE_ITEM"));
- GetSizeString (nVolumeSize, szTmp);
- wcscat (tmpMcMsg, szTmp);
+ StringCbCatW (tmpMcMsg, sizeof(tmpMcMsg), L"\n");
+ StringCbCatW (tmpMcMsg, sizeof(tmpMcMsg), GetString("SIZE_ITEM"));
+ GetSizeString (nVolumeSize, szTmp, sizeof(szTmp));
+ StringCbCatW (tmpMcMsg, sizeof(tmpMcMsg), szTmp);
- wcscat (tmpMcMsg, L"\n");
- wcscat (tmpMcMsg, GetString("PATH_ITEM"));
- wcscat (tmpMcMsg, deviceName);
+ StringCbCatW (tmpMcMsg, sizeof(tmpMcMsg), L"\n");
+ StringCbCatW (tmpMcMsg, sizeof(tmpMcMsg), GetString("PATH_ITEM"));
+ StringCbCatW (tmpMcMsg, sizeof(tmpMcMsg), deviceName);
wchar_t *tmpStr[] = {L"", tmpMcMsg, tmpMcOption1, tmpMcOptionCancel, 0};
switch (AskMultiChoice ((void **) tmpStr, TRUE))
{
case 1:
// Proceed
// NOP
break;
default:
return FALSE;
}
}
}
}
}
return TRUE;
}
void HandleOldAssignedDriveLetter (void)
{
if (bDevice)
{
// Handle assigned drive letter (if any)
WCHAR deviceName[MAX_PATH];
int driveLetter = -1;
- strcpy ((char *)deviceName, szDiskFile);
- ToUNICODE ((char *)deviceName);
+ StringCbCopyA ((char *)deviceName, sizeof(deviceName), szDiskFile);
+ ToUNICODE ((char *)deviceName, sizeof(deviceName));
driveLetter = GetDiskDeviceDriveLetter (deviceName);
if (!bHiddenVolHost
&& !bHiddenOS
&& driveLetter > 1) // If a drive letter is assigned to the device, but not A: or B:
{
char rootPath[] = { (char) driveLetter + 'A', ':', '\\', 0 };
wchar_t szTmp[8192];
- swprintf (szTmp, GetString ("AFTER_FORMAT_DRIVE_LETTER_WARN"), rootPath[0], rootPath[0], rootPath[0], rootPath[0]);
+ StringCbPrintfW (szTmp, sizeof(szTmp), GetString ("AFTER_FORMAT_DRIVE_LETTER_WARN"), rootPath[0], rootPath[0], rootPath[0], rootPath[0]);
MessageBoxW (MainDlg, szTmp, lpszTitle, MB_ICONWARNING);
}
}
}
// Returns TRUE if it makes sense to ask the user whether he wants to store files larger than 4GB in the volume.
static BOOL FileSize4GBLimitQuestionNeeded (void)
{
uint64 dataAreaSize = GetVolumeDataAreaSize (bHiddenVol && !bHiddenVolHost, nVolumeSize);
return (dataAreaSize > 4 * BYTES_PER_GB + TC_MIN_FAT_FS_SIZE
&& dataAreaSize <= TC_MAX_FAT_SECTOR_COUNT * GetFormatSectorSize());
}
/* 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 PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static char PageDebugId[128];
WORD lw = LOWORD (wParam);
WORD hw = HIWORD (wParam);
hCurPage = hwndDlg;
switch (uMsg)
{
case WM_INITDIALOG:
LocalizeDialog (hwndDlg, "IDD_VOL_CREATION_WIZARD_DLG");
- sprintf (PageDebugId, "FORMAT_PAGE_%d", nCurPageNo);
+ StringCbPrintfA (PageDebugId, sizeof(PageDebugId), "FORMAT_PAGE_%d", nCurPageNo);
LastDialogId = PageDebugId;
switch (nCurPageNo)
{
case INTRO_PAGE:
SendMessage (GetDlgItem (hwndDlg, IDC_FILE_CONTAINER), WM_SETFONT, (WPARAM) hUserBoldFont, (LPARAM) TRUE);
SendMessage (GetDlgItem (hwndDlg, IDC_NONSYS_DEVICE), WM_SETFONT, (WPARAM) hUserBoldFont, (LPARAM) TRUE);
SendMessage (GetDlgItem (hwndDlg, IDC_SYS_DEVICE), WM_SETFONT, (WPARAM) hUserBoldFont, (LPARAM) TRUE);
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("INTRO_TITLE"));
ToHyperlink (hwndDlg, IDC_MORE_INFO_ON_CONTAINERS);
ToHyperlink (hwndDlg, IDC_MORE_INFO_ON_SYS_ENCRYPTION);
EnableWindow (GetDlgItem (hwndDlg, IDC_STD_VOL), TRUE);
EnableWindow (GetDlgItem (hwndDlg, IDC_HIDDEN_VOL), TRUE);
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT"));
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
@@ -3743,50 +3745,50 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
AddComboPair (GetDlgItem (hwndDlg, IDC_COMBO_BOX_HASH_ALGO), HashGetName(hid), hid);
}
SelectAlgo (GetDlgItem (hwndDlg, IDC_COMBO_BOX_HASH_ALGO), &hash_algo);
ToHyperlink (hwndDlg, IDC_LINK_HASH_INFO);
// Wizard buttons
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT"));
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), TRUE);
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
}
break;
case SIZE_PAGE:
{
wchar_t str[1000];
if (bHiddenVolHost)
{
- wcsncpy (str, GetString ("SIZE_HELP_HIDDEN_HOST_VOL"), sizeof (str) / 2);
+ StringCbCopyW (str, sizeof(str), GetString ("SIZE_HELP_HIDDEN_HOST_VOL"));
}
else
{
- wcsncpy (str, GetString (bHiddenVol ? "SIZE_HELP_HIDDEN_VOL" : "SIZE_HELP"), sizeof (str) / 2);
+ StringCbCopyW (str, sizeof(str), GetString (bHiddenVol ? "SIZE_HELP_HIDDEN_VOL" : "SIZE_HELP"));
}
if (bDevice && !(bHiddenVol && !bHiddenVolHost)) // If raw device but not a hidden volume
{
- _snwprintf (str, sizeof str / 2, L"%s%s",
+ StringCbPrintfW (str, sizeof str, L"%s%s",
GetString ((bHiddenOS && bHiddenVol) ? "SIZE_PARTITION_HIDDEN_SYSENC_HELP" : "SIZE_PARTITION_HELP"),
(bHiddenVolHost && !bHiddenOS) ? GetString ("SIZE_PARTITION_HIDDEN_VOL_HELP") : L"");
}
SendMessage (GetDlgItem (hwndDlg, IDC_SPACE_LEFT), WM_SETFONT, (WPARAM) hBoldFont, (LPARAM) TRUE);
SendMessage (GetDlgItem (hwndDlg, IDC_SIZEBOX), EM_LIMITTEXT, 12, 0);
if(!QueryFreeSpace (hwndDlg, GetDlgItem (hwndDlg, IDC_SPACE_LEFT), TRUE))
{
nUIVolumeSize=0;
nVolumeSize=0;
SetWindowTextW (GetDlgItem (hwndDlg, IDC_SIZEBOX), GetString ("UNKNOWN"));
EnableWindow (GetDlgItem (hwndDlg, IDC_SIZEBOX), FALSE);
EnableWindow (GetDlgItem (hwndDlg, IDC_KB), FALSE);
EnableWindow (GetDlgItem (hwndDlg, IDC_MB), FALSE);
EnableWindow (GetDlgItem (hwndDlg, IDC_GB), FALSE);
}
else if (bDevice && !(bHiddenVol && !bHiddenVolHost)) // If raw device but not a hidden volume
{
@@ -3806,41 +3808,41 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
SendMessage (GetDlgItem (hwndDlg, IDC_KB), BM_SETCHECK, BST_UNCHECKED, 0);
SendMessage (GetDlgItem (hwndDlg, IDC_MB), BM_SETCHECK, BST_UNCHECKED, 0);
SendMessage (GetDlgItem (hwndDlg, IDC_GB), BM_SETCHECK, BST_UNCHECKED, 0);
switch (nMultiplier)
{
case BYTES_PER_KB:
SendMessage (GetDlgItem (hwndDlg, IDC_KB), BM_SETCHECK, BST_CHECKED, 0);
break;
case BYTES_PER_MB:
SendMessage (GetDlgItem (hwndDlg, IDC_MB), BM_SETCHECK, BST_CHECKED, 0);
break;
case BYTES_PER_GB:
SendMessage (GetDlgItem (hwndDlg, IDC_GB), BM_SETCHECK, BST_CHECKED, 0);
break;
}
if (nUIVolumeSize != 0)
{
char szTmp[32];
- sprintf (szTmp, "%I64u", nUIVolumeSize);
+ StringCbPrintfA (szTmp, sizeof(szTmp), "%I64u", nUIVolumeSize);
SetWindowText (GetDlgItem (hwndDlg, IDC_SIZEBOX), szTmp);
}
SetFocus (GetDlgItem (hwndDlg, IDC_SIZEBOX));
SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), str);
if (bHiddenVol)
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString (bHiddenVolHost ? "SIZE_HIDVOL_HOST_TITLE" : "SIZE_HIDVOL_TITLE"));
else
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("SIZE_TITLE"));
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT"));
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), TRUE);
VerifySizeAndUpdate (hwndDlg, FALSE);
@@ -3865,78 +3867,78 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT"));
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), !bInPlaceEncNonSys);
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
break;
case PASSWORD_PAGE:
{
wchar_t str[1000];
hPasswordInputField = GetDlgItem (hwndDlg, IDC_PASSWORD);
hVerifyPasswordInputField = GetDlgItem (hwndDlg, IDC_VERIFY);
if (SysEncInEffect ())
{
ToBootPwdField (hwndDlg, IDC_PASSWORD);
ToBootPwdField (hwndDlg, IDC_VERIFY);
- sprintf (OrigKeyboardLayout, "%08X", (DWORD) GetKeyboardLayout (NULL) & 0xFFFF);
+ StringCbPrintfA (OrigKeyboardLayout, sizeof(OrigKeyboardLayout), "%08X", (DWORD) GetKeyboardLayout (NULL) & 0xFFFF);
if ((DWORD) GetKeyboardLayout (NULL) != 0x00000409 && (DWORD) GetKeyboardLayout (NULL) != 0x04090409)
{
DWORD keybLayout = (DWORD) LoadKeyboardLayout ("00000409", KLF_ACTIVATE);
if (keybLayout != 0x00000409 && keybLayout != 0x04090409)
{
Error ("CANT_CHANGE_KEYB_LAYOUT_FOR_SYS_ENCRYPTION");
EndMainDlg (MainDlg);
return 1;
}
bKeyboardLayoutChanged = TRUE;
}
ShowWindow(GetDlgItem(hwndDlg, IDC_SHOW_PASSWORD), SW_HIDE);
if (SetTimer (MainDlg, TIMER_ID_KEYB_LAYOUT_GUARD, TIMER_INTERVAL_KEYB_LAYOUT_GUARD, NULL) == 0)
{
Error ("CANNOT_SET_TIMER");
EndMainDlg (MainDlg);
return 1;
}
}
if (bHiddenVolHost)
{
- wcsncpy (str, GetString (bHiddenOS ? "PASSWORD_SYSENC_OUTERVOL_HELP" : "PASSWORD_HIDDENVOL_HOST_HELP"), sizeof (str) / 2);
+ StringCbCopyW (str, sizeof(str), GetString (bHiddenOS ? "PASSWORD_SYSENC_OUTERVOL_HELP" : "PASSWORD_HIDDENVOL_HOST_HELP"));
}
else if (bHiddenVol)
{
- _snwprintf (str, sizeof str / 2, L"%s%s",
+ StringCbPrintfW (str, sizeof str, L"%s%s",
GetString (bHiddenOS ? "PASSWORD_HIDDEN_OS_HELP" : "PASSWORD_HIDDENVOL_HELP"),
GetString ("PASSWORD_HELP"));
}
else
{
- wcsncpy (str, GetString ("PASSWORD_HELP"), sizeof (str) / 2);
+ StringCbCopyW (str, sizeof(str), GetString ("PASSWORD_HELP"));
}
SendMessage (GetDlgItem (hwndDlg, IDC_PASSWORD), EM_LIMITTEXT, MAX_PASSWORD, 0);
SendMessage (GetDlgItem (hwndDlg, IDC_VERIFY), EM_LIMITTEXT, MAX_PASSWORD, 0);
SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), szRawPassword);
SetWindowText (GetDlgItem (hwndDlg, IDC_VERIFY), szVerify);
SetFocus (GetDlgItem (hwndDlg, IDC_PASSWORD));
SetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE, KeyFilesEnable && !SysEncInEffect());
EnableWindow (GetDlgItem (hwndDlg, IDC_KEY_FILES), KeyFilesEnable);
SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), str);
if (CreatingHiddenSysVol())
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("PASSWORD_HIDDEN_OS_TITLE"));
else if (bHiddenVol)
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString (bHiddenVolHost ? "PASSWORD_HIDVOL_HOST_TITLE" : "PASSWORD_HIDVOL_TITLE"));
else if (WizardMode == WIZARD_MODE_SYS_DEVICE)
@@ -3949,56 +3951,56 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), TRUE);
VerifyPasswordAndUpdate (hwndDlg, GetDlgItem (GetParent (hwndDlg), IDC_NEXT),
GetDlgItem (hwndDlg, IDC_PASSWORD),
GetDlgItem (hwndDlg, IDC_VERIFY),
NULL,
NULL,
KeyFilesEnable && FirstKeyFile!=NULL && !SysEncInEffect());
volumePassword.Length = strlen ((char *) volumePassword.Text);
}
break;
case FILESYS_PAGE:
{
wchar_t szTmp[8192];
Init2RadButtonPageYesNo (nNeedToStoreFilesOver4GB);
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("FILESYS_PAGE_TITLE"));
- wcscpy (szTmp, GetString ("FILESYS_PAGE_HELP_QUESTION"));
+ StringCbCopyW (szTmp, sizeof(szTmp), GetString ("FILESYS_PAGE_HELP_QUESTION"));
if (bHiddenVolHost)
- wcscat (szTmp, L"\n\n");
+ StringCbCatW (szTmp, sizeof(szTmp), L"\n\n");
else
{
- wcscat (szTmp, L"\n\n\n");
- wcscat (szTmp, GetString ("NOTE_BEGINNING"));
+ StringCbCatW (szTmp, sizeof(szTmp), L"\n\n\n");
+ StringCbCatW (szTmp, sizeof(szTmp), GetString ("NOTE_BEGINNING"));
}
- wcscat (szTmp, GetString ("FILESYS_PAGE_HELP_EXPLANATION"));
+ StringCbCatW (szTmp, sizeof(szTmp), GetString ("FILESYS_PAGE_HELP_EXPLANATION"));
if (bHiddenVolHost)
{
- wcscat (szTmp, L" ");
- wcscat (szTmp, GetString ("FILESYS_PAGE_HELP_EXPLANATION_HIDVOL"));
+ StringCbCatW (szTmp, sizeof(szTmp), L" ");
+ StringCbCatW (szTmp, sizeof(szTmp), GetString ("FILESYS_PAGE_HELP_EXPLANATION_HIDVOL"));
}
SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), szTmp);
}
break;
case SYSENC_COLLECTING_RANDOM_DATA_PAGE:
case NONSYS_INPLACE_ENC_RAND_DATA_PAGE:
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("COLLECTING_RANDOM_DATA_TITLE"));
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT"));
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), TRUE);
SetTimer (GetParent (hwndDlg), TIMER_ID_RANDVIEW, TIMER_INTERVAL_RANDVIEW, NULL);
hRandPoolSys = GetDlgItem (hwndDlg, IDC_SYS_POOL_CONTENTS);
SendMessage (GetDlgItem (hwndDlg, IDC_SYS_POOL_CONTENTS), WM_SETFONT, (WPARAM) hFixedDigitFont, (LPARAM) TRUE);
@@ -4032,41 +4034,41 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
case SYSENC_RESCUE_DISK_CREATION_PAGE:
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("RESCUE_DISK"));
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT"));
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
SetWindowTextW (GetDlgItem (hwndDlg, IDT_RESCUE_DISK_INFO), GetString ("RESCUE_DISK_INFO"));
SetDlgItemText (hwndDlg, IDC_RESCUE_DISK_ISO_PATH, szRescueDiskISO);
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), (GetWindowTextLength (GetDlgItem (hwndDlg, IDC_RESCUE_DISK_ISO_PATH)) > 1));
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), TRUE);
break;
case SYSENC_RESCUE_DISK_BURN_PAGE:
{
wchar_t szTmp[8192];
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString (bDontVerifyRescueDisk ? "RESCUE_DISK_CREATED_TITLE" : "RESCUE_DISK_RECORDING_TITLE"));
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT"));
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
- _snwprintf (szTmp, sizeof szTmp / 2,
+ StringCbPrintfW (szTmp, sizeof szTmp,
GetString (bDontVerifyRescueDisk ? "RESCUE_DISK_BURN_INFO_NO_CHECK" : "RESCUE_DISK_BURN_INFO"),
szRescueDiskISO, IsWindowsIsoBurnerAvailable() ? L"" : GetString ("RESCUE_DISK_BURN_INFO_NONWIN_ISO_BURNER"));
SetWindowTextW (GetDlgItem (hwndDlg, IDT_RESCUE_DISK_BURN_INFO), szTmp);
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
/* The 'Back' button must be disabled now because the user could burn a Rescue Disk, then go back, and
generate a different master key, which would cause the Rescue Disk verification to fail (the result
would be confusion and bug reports). */
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), FALSE);
if (IsWindowsIsoBurnerAvailable())
SetWindowTextW (GetDlgItem (hwndDlg, IDC_DOWNLOAD_CD_BURN_SOFTWARE), GetString ("LAUNCH_WIN_ISOBURN"));
ToHyperlink (hwndDlg, IDC_DOWNLOAD_CD_BURN_SOFTWARE);
if (IsWindowsIsoBurnerAvailable() && !bDontVerifyRescueDisk)
LaunchWindowsIsoBurner (hwndDlg, szRescueDiskISO);
}
break;
@@ -4112,41 +4114,41 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
}
break;
case SYSENC_PRETEST_INFO_PAGE:
if (bHiddenOS)
{
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("HIDDEN_OS_CREATION_PREINFO_TITLE"));
SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString ("HIDDEN_OS_CREATION_PREINFO_HELP"));
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("START"));
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), FALSE);
}
else
{
wchar_t finalMsg[8024] = {0};
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("SYS_ENCRYPTION_PRETEST_TITLE"));
try
{
- wsprintfW (finalMsg,
+ StringCbPrintfW (finalMsg, sizeof(finalMsg),
GetString ("SYS_ENCRYPTION_PRETEST_INFO"),
BootEncObj->GetSystemDriveConfiguration().DriveNumber);
}
catch (Exception &e)
{
e.Show (hwndDlg);
EndMainDlg (MainDlg);
return 0;
}
SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), finalMsg);
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("TEST"));
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), TRUE);
}
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
break;
@@ -4476,46 +4478,46 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
if (!bHiddenVolHost && bHiddenVol && !bHiddenVolFinished)
{
wchar_t msg[4096];
nNeedToStoreFilesOver4GB = -1;
if (bHiddenOS)
{
wchar_t szMaxRecomOuterVolFillSize[100];
__int64 maxRecomOuterVolFillSize = 0;
// Determine the maximum recommended total size of files that can be copied to the outer volume
// while leaving enough space for the hidden volume, which must contain a clone of the OS
maxRecomOuterVolFillSize = nVolumeSize - GetSystemPartitionSize();
// -50% reserve for filesystem "peculiarities"
maxRecomOuterVolFillSize /= 2;
- swprintf (szMaxRecomOuterVolFillSize, L"%I64d %s", maxRecomOuterVolFillSize / BYTES_PER_MB, GetString ("MB"));
+ StringCbPrintfW (szMaxRecomOuterVolFillSize, sizeof(szMaxRecomOuterVolFillSize), L"%I64d %s", maxRecomOuterVolFillSize / BYTES_PER_MB, GetString ("MB"));
- swprintf (msg, GetString ("HIDVOL_HOST_FILLING_HELP_SYSENC"), hiddenVolHostDriveNo + 'A', szMaxRecomOuterVolFillSize);
+ StringCbPrintfW (msg, sizeof(msg), GetString ("HIDVOL_HOST_FILLING_HELP_SYSENC"), hiddenVolHostDriveNo + 'A', szMaxRecomOuterVolFillSize);
}
else
- swprintf (msg, GetString ("HIDVOL_HOST_FILLING_HELP"), hiddenVolHostDriveNo + 'A');
+ StringCbPrintfW (msg, sizeof(msg), GetString ("HIDVOL_HOST_FILLING_HELP"), hiddenVolHostDriveNo + 'A');
SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), msg);
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("HIDVOL_HOST_FILLING_TITLE"));
}
else
{
if (bHiddenOS)
SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString ("SYSENC_HIDDEN_VOL_FORMAT_FINISHED_HELP"));
else
{
SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString (bInPlaceEncNonSys ? "NONSYS_INPLACE_ENC_FINISHED_INFO" : "FORMAT_FINISHED_HELP"));
bConfirmQuit = FALSE;
}
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString (bHiddenVol ? "HIDVOL_FORMAT_FINISHED_TITLE" : "FORMAT_FINISHED_TITLE"));
}
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT"));
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
@@ -4721,43 +4723,43 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
case SYSENC_MULTI_BOOT_ADJACENT_SYS_PAGE:
case SYSENC_MULTI_BOOT_NONWIN_BOOT_LOADER_PAGE:
case SYSENC_PRE_DRIVE_ANALYSIS_PAGE:
if (lw == IDC_CHOICE1 || lw == IDC_CHOICE2)
{
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
return 1;
}
break;
}
if (nCurPageNo == FILESYS_PAGE && (lw == IDC_CHOICE1 || lw == IDC_CHOICE2))
{
if (bWarnOuterVolSuitableFileSys && lw == IDC_CHOICE1 && bHiddenVolHost)
{
wchar_t szTmp [4096];
bWarnOuterVolSuitableFileSys = FALSE; // Do not show this warning anymore (this also prevents potential endless repetition due to some race conditions)
- wcscpy (szTmp, GetString ("FILESYS_PAGE_HELP_EXPLANATION_HIDVOL"));
- wcscat (szTmp, L"\n\n");
- wcscat (szTmp, GetString ("FILESYS_PAGE_HELP_EXPLANATION_HIDVOL_CONFIRM"));
+ StringCbCopyW (szTmp, sizeof(szTmp), GetString ("FILESYS_PAGE_HELP_EXPLANATION_HIDVOL"));
+ StringCbCatW (szTmp, sizeof(szTmp), L"\n\n");
+ StringCbCatW (szTmp, sizeof(szTmp), GetString ("FILESYS_PAGE_HELP_EXPLANATION_HIDVOL_CONFIRM"));
if (MessageBoxW (MainDlg, szTmp, lpszTitle, MB_ICONWARNING | MB_YESNO | MB_DEFBUTTON2) == IDNO)
{
nNeedToStoreFilesOver4GB = 0;
Init2RadButtonPageYesNo (nNeedToStoreFilesOver4GB);
}
}
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
return 1;
}
if (lw == IDC_HIDDEN_VOL && nCurPageNo == VOLUME_TYPE_PAGE)
{
bHiddenVol = TRUE;
bHiddenVolHost = TRUE;
bInPlaceEncNonSys = FALSE;
return 1;
}
@@ -4817,42 +4819,42 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
if (lw == IDC_LIST_BOX
&& (hw == LBN_SELCHANGE || hw == LBN_DBLCLK))
{
BOOL tmpbDevice = FALSE;
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), FALSE);
int selPartitionItemId = (int) SendMessage (GetDlgItem (hwndDlg, IDC_LIST_BOX), LB_GETCURSEL, 0, 0);
if (selPartitionItemId == LB_ERR)
{
// Deselect all
SendMessage (GetDlgItem (hwndDlg, IDC_LIST_BOX), LB_SETCURSEL, (WPARAM) -1, 0);
SetFocus (GetDlgItem (MainDlg, IDC_NEXT));
return 1;
}
SetFocus (GetDlgItem (MainDlg, IDC_NEXT));
- strcpy (szFileName, DeferredNonSysInPlaceEncDevices [selPartitionItemId].Path.c_str());
- CreateFullVolumePath (szDiskFile, szFileName, &tmpbDevice);
+ StringCbCopyA (szFileName, sizeof(szFileName), DeferredNonSysInPlaceEncDevices [selPartitionItemId].Path.c_str());
+ CreateFullVolumePath (szDiskFile, sizeof(szDiskFile), szFileName, &tmpbDevice);
nVolumeSize = GetDeviceSize (szDiskFile);
if (nVolumeSize == -1)
{
handleWin32Error (MainDlg);
return 1;
}
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
return 1;
}
break;
case NONSYS_INPLACE_ENC_ENCRYPTION_PAGE:
{
switch (lw)
{
case IDC_PAUSE:
@@ -5281,41 +5283,41 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
return 1;
}
if (lw == IDC_DISPLAY_KEYS && nCurPageNo == SYSENC_KEYS_GEN_PAGE)
{
showKeys = IsButtonChecked (GetDlgItem (hCurPage, IDC_DISPLAY_KEYS));
DisplayPortionsOfKeys (GetDlgItem (hwndDlg, IDC_HEADER_KEY), GetDlgItem (hwndDlg, IDC_DISK_KEY), HeaderKeyGUIView, MasterKeyGUIView, !showKeys);
return 1;
}
if (nCurPageNo == SYSENC_RESCUE_DISK_CREATION_PAGE)
{
if (lw == IDC_BROWSE)
{
char tmpszRescueDiskISO [TC_MAX_PATH+1];
if (!BrowseFiles (hwndDlg, "OPEN_TITLE", tmpszRescueDiskISO, FALSE, TRUE, NULL))
return 1;
- strcpy (szRescueDiskISO, tmpszRescueDiskISO);
+ StringCbCopyA (szRescueDiskISO, sizeof(szRescueDiskISO), tmpszRescueDiskISO);
SetDlgItemText (hwndDlg, IDC_RESCUE_DISK_ISO_PATH, szRescueDiskISO);
EnableWindow (GetDlgItem (MainDlg, IDC_NEXT), (GetWindowTextLength (GetDlgItem (hwndDlg, IDC_RESCUE_DISK_ISO_PATH)) > 1));
return 1;
}
if ( hw == EN_CHANGE )
{
GetDlgItemText (hwndDlg, IDC_RESCUE_DISK_ISO_PATH, szRescueDiskISO, sizeof(szRescueDiskISO));
EnableWindow (GetDlgItem (MainDlg, IDC_NEXT), (GetWindowTextLength (GetDlgItem (hwndDlg, IDC_RESCUE_DISK_ISO_PATH)) > 1));
return 1;
}
}
if (nCurPageNo == SYSENC_RESCUE_DISK_BURN_PAGE && lw == IDC_DOWNLOAD_CD_BURN_SOFTWARE)
{
if (IsWindowsIsoBurnerAvailable())
LaunchWindowsIsoBurner (hwndDlg, szRescueDiskISO);
else
Applink ("isoburning", TRUE, "");
@@ -5414,41 +5416,41 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
}
SendMessage (GetDlgItem (hwndDlg, IDC_BOX_TITLE), WM_SETFONT, (WPARAM) hTitleFont, (LPARAM) TRUE);
SetWindowTextW (hwndDlg, lpszTitle);
ExtractCommandLine (hwndDlg, (char *) lParam);
if (ComServerMode)
{
InitDialog (hwndDlg);
if (!ComServerFormat ())
{
handleWin32Error (hwndDlg);
exit (1);
}
exit (0);
}
SHGetFolderPath (NULL, CSIDL_MYDOCUMENTS, NULL, 0, szRescueDiskISO);
- strcat (szRescueDiskISO, "\\VeraCrypt Rescue Disk.iso");
+ StringCbCatA (szRescueDiskISO, sizeof(szRescueDiskISO), "\\VeraCrypt Rescue Disk.iso");
if (IsOSAtLeast (WIN_VISTA))
{
// Availability of in-place encryption (which is pre-selected by default whenever
// possible) makes partition-hosted volume creation safer.
bWarnDeviceFormatAdvanced = FALSE;
}
#ifdef _DEBUG
// For faster testing
strcpy (szVerify, "q");
strcpy (szRawPassword, "q");
#endif
PostMessage (hwndDlg, TC_APPMSG_PERFORM_POST_WMINIT_TASKS, 0, 0);
}
return 0;
case WM_SYSCOMMAND:
if (lw == IDC_ABOUT)
@@ -5468,42 +5470,42 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
|| bInPlaceEncNonSys)
{
DisplayRandPool (hRandPoolSys, showKeys);
}
else
{
unsigned char tmp[17];
char tmp2[43];
int i;
if (!showKeys)
return 1;
RandpeekBytes (tmp, sizeof (tmp));
tmp2[0] = 0;
for (i = 0; i < sizeof (tmp); i++)
{
char tmp3[8];
- sprintf (tmp3, "%02X", (int) (unsigned char) tmp[i]);
- strcat (tmp2, tmp3);
+ StringCbPrintfA (tmp3, sizeof(tmp3), "%02X", (int) (unsigned char) tmp[i]);
+ StringCbCatA (tmp2, sizeof(tmp2), tmp3);
}
tmp2[32] = 0;
SetWindowTextW (GetDlgItem (hCurPage, IDC_RANDOM_BYTES), (SingleStringToWide (tmp2) + GetString ("TRIPLE_DOT_GLYPH_ELLIPSIS")).c_str());
burn (tmp, sizeof(tmp));
burn (tmp2, sizeof(tmp2));
}
return 1;
case TIMER_ID_SYSENC_PROGRESS:
{
// Manage system encryption/decryption and update related GUI
try
{
BootEncStatus = BootEncObj->GetStatus();
}
catch (Exception &e)
@@ -5686,58 +5688,58 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
// Keyboard layout is not standard US
WipePasswordsAndKeyfiles ();
SetWindowText (GetDlgItem (hCurPage, IDC_PASSWORD), szRawPassword);
SetWindowText (GetDlgItem (hCurPage, IDC_VERIFY), szVerify);
keybLayout = (DWORD) LoadKeyboardLayout ("00000409", KLF_ACTIVATE);
if (keybLayout != 0x00000409 && keybLayout != 0x04090409)
{
KillTimer (hwndDlg, TIMER_ID_KEYB_LAYOUT_GUARD);
Error ("CANT_CHANGE_KEYB_LAYOUT_FOR_SYS_ENCRYPTION");
EndMainDlg (MainDlg);
return 1;
}
bKeyboardLayoutChanged = TRUE;
wchar_t szTmp [4096];
- wcscpy (szTmp, GetString ("KEYB_LAYOUT_CHANGE_PREVENTED"));
- wcscat (szTmp, L"\n\n");
- wcscat (szTmp, GetString ("KEYB_LAYOUT_SYS_ENC_EXPLANATION"));
+ 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);
}
/* Watch the right Alt key (which is used to enter various characters on non-US keyboards) */
if (bKeyboardLayoutChanged && !bKeybLayoutAltKeyWarningShown)
{
if (GetAsyncKeyState (VK_RMENU) < 0)
{
bKeybLayoutAltKeyWarningShown = TRUE;
wchar_t szTmp [4096];
- wcscpy (szTmp, GetString ("ALT_KEY_CHARS_NOT_FOR_SYS_ENCRYPTION"));
- wcscat (szTmp, L"\n\n");
- wcscat (szTmp, GetString ("KEYB_LAYOUT_SYS_ENC_EXPLANATION"));
+ StringCbCopyW (szTmp, sizeof(szTmp), GetString ("ALT_KEY_CHARS_NOT_FOR_SYS_ENCRYPTION"));
+ StringCbCatW (szTmp, sizeof(szTmp), L"\n\n");
+ StringCbCatW (szTmp, sizeof(szTmp), GetString ("KEYB_LAYOUT_SYS_ENC_EXPLANATION"));
MessageBoxW (MainDlg, szTmp, lpszTitle, MB_ICONINFORMATION | MB_SETFOREGROUND | MB_TOPMOST);
}
}
}
return 1;
case TIMER_ID_SYSENC_DRIVE_ANALYSIS_PROGRESS:
if (bSysEncDriveAnalysisInProgress)
{
UpdateProgressBarProc (GetTickCount() - SysEncDriveAnalysisStart);
if (GetTickCount() - SysEncDriveAnalysisStart > SYSENC_DRIVE_ANALYSIS_ETA)
{
// It's taking longer than expected -- reinit the progress bar
SysEncDriveAnalysisStart = GetTickCount ();
InitProgressBar (SYSENC_DRIVE_ANALYSIS_ETA, 0, FALSE, FALSE, FALSE, TRUE);
}
ArrowWaitCursor ();
@@ -6396,41 +6398,41 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
+ GetString ("NOTE_BEGINNING")
+ GetString ("HIDDEN_OS_WRITE_PROTECTION_BRIEF_INFO")
+ L" "
+ GetString ("HIDDEN_OS_WRITE_PROTECTION_EXPLANATION")).c_str());
NormalCursor ();
return 1;
}
bHiddenVolDirect = FALSE;
}
}
else if (nCurPageNo == VOLUME_LOCATION_PAGE)
{
BOOL tmpbDevice;
WaitCursor();
GetWindowText (GetDlgItem (hCurPage, IDC_COMBO_BOX), szFileName, sizeof (szFileName));
RelativePath2Absolute (szFileName);
- CreateFullVolumePath (szDiskFile, szFileName, &tmpbDevice);
+ CreateFullVolumePath (szDiskFile, sizeof(szDiskFile), szFileName, &tmpbDevice);
if (tmpbDevice != bDevice)
{
if (bDevice)
{
// Not a valid device path
Error ("CANNOT_CALC_SPACE");
NormalCursor ();
return 1;
}
else
{
if (AskWarnYesNo ("DEVICE_SELECTED_IN_NON_DEVICE_MODE") == IDNO)
{
NormalCursor ();
return 1;
}
SwitchWizardToNonSysDeviceMode ();
NormalCursor ();
@@ -6868,41 +6870,41 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
if ((volume.CryptoInfo->HeaderFlags & TC_HEADER_FLAG_NONSYS_INPLACE_ENC) != 0
&& volume.CryptoInfo->EncryptedAreaLength.Value != volume.CryptoInfo->VolumeSize.Value)
{
DeferredNonSysInPlaceEncDevices.push_back (device);
}
CloseVolume (&volume);
}
}
}
if (DeferredNonSysInPlaceEncDevices.empty())
{
Warning ("FOUND_NO_PARTITION_W_DEFERRED_INPLACE_ENC");
NormalCursor();
return 1;
}
else if (DeferredNonSysInPlaceEncDevices.size() == 1)
{
- CreateFullVolumePath (szDiskFile, DeferredNonSysInPlaceEncDevices.front().Path.c_str(), &tmpbDevice);
+ CreateFullVolumePath (szDiskFile, sizeof(szDiskFile), DeferredNonSysInPlaceEncDevices.front().Path.c_str(), &tmpbDevice);
nVolumeSize = GetDeviceSize (szDiskFile);
if (nVolumeSize == -1)
{
handleWin32Error (MainDlg);
NormalCursor();
return 1;
}
nNewPageNo = NONSYS_INPLACE_ENC_ENCRYPTION_PAGE - 1; // Skip irrelevant pages
}
NormalCursor();
}
}
else if (nCurPageNo == FILESYS_PAGE)
{
if (!bHiddenVol && IsHiddenOSRunning() && Get2RadButtonPageAnswer() == 1)
@@ -7025,41 +7027,41 @@ retryCDDriveCheck:
if (IsWindowsIsoBurnerAvailable() && !bDontVerifyRescueDisk)
Info ("RESCUE_DISK_WIN_ISOBURN_PRELAUNCH_NOTE");
NormalCursor ();
}
else if (nCurPageNo == SYSENC_RESCUE_DISK_BURN_PAGE)
{
if (!bDontVerifyRescueDisk)
{
/* Verify that the rescue disk has been written correctly */
try
{
WaitCursor();
if (!BootEncObj->VerifyRescueDisk ())
{
wchar_t szTmp[8000];
- swprintf (szTmp, GetString ("RESCUE_DISK_CHECK_FAILED"),
+ StringCbPrintfW (szTmp, sizeof(szTmp), GetString ("RESCUE_DISK_CHECK_FAILED"),
IsWindowsIsoBurnerAvailable () ? L"" : GetString ("RESCUE_DISK_CHECK_FAILED_SENTENCE_APPENDIX"));
ErrorDirect (szTmp);
NormalCursor ();
#ifndef _DEBUG
return 1;
#endif
}
}
catch (Exception &e)
{
e.Show (hwndDlg);
NormalCursor ();
return 1;
}
NormalCursor ();
}
else
{
@@ -7575,41 +7577,41 @@ ovf_end:
nNewPageNo = VOLUME_LOCATION_PAGE + 1;
}
}
else if (nCurPageNo == HIDDEN_VOL_WIZARD_MODE_PAGE)
{
if (IsButtonChecked (GetDlgItem (hCurPage, IDC_HIDVOL_WIZ_MODE_DIRECT)))
bHiddenVolDirect = TRUE;
else
bHiddenVolDirect = FALSE;
}
else if (nCurPageNo == VOLUME_TYPE_PAGE)
{
if (WizardMode != WIZARD_MODE_SYS_DEVICE)
nNewPageNo = INTRO_PAGE + 1; // Skip irrelevant pages
}
else if (nCurPageNo == VOLUME_LOCATION_PAGE)
{
BOOL tmpbDevice;
GetWindowText (GetDlgItem (hCurPage, IDC_COMBO_BOX), szFileName, sizeof (szFileName));
- CreateFullVolumePath (szDiskFile, szFileName, &tmpbDevice);
+ CreateFullVolumePath (szDiskFile, sizeof(szDiskFile), szFileName, &tmpbDevice);
if (tmpbDevice == bDevice)
{
MoveEditToCombo (GetDlgItem (hCurPage, IDC_COMBO_BOX), bHistory);
SaveSettings (hCurPage);
}
if (!bHiddenVol)
nNewPageNo = VOLUME_TYPE_PAGE + 1; // Skip the hidden volume creation wizard mode selection
}
else if (nCurPageNo == CIPHER_PAGE)
{
LPARAM nIndex;
nIndex = SendMessage (GetDlgItem (hCurPage, IDC_COMBO_BOX), CB_GETCURSEL, 0, 0);
nVolumeEA = SendMessage (GetDlgItem (hCurPage, IDC_COMBO_BOX), CB_GETITEMDATA, nIndex, 0);
nIndex = SendMessage (GetDlgItem (hCurPage, IDC_COMBO_BOX_HASH_ALGO), CB_GETCURSEL, 0, 0);
hash_algo = SendMessage (GetDlgItem (hCurPage, IDC_COMBO_BOX_HASH_ALGO), CB_GETITEMDATA, nIndex, 0);