1
0
mirror of https://github.com/veracrypt/VeraCrypt.git synced 2025-11-11 11:08:02 -06:00

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.

This commit is contained in:
Mounir IDRASSI
2014-07-14 17:41:09 +02:00
parent c01f392a7b
commit c220db0128
15 changed files with 489 additions and 394 deletions

View File

@@ -32,6 +32,8 @@
#include "Mount/MainCom.h" #include "Mount/MainCom.h"
#endif #endif
#include <Strsafe.h>
namespace VeraCrypt namespace VeraCrypt
{ {
#if !defined (SETUP) #if !defined (SETUP)
@@ -604,7 +606,7 @@ namespace VeraCrypt
GetSystemDriveConfiguration(); GetSystemDriveConfiguration();
ProbeRealDriveSizeRequest request; ProbeRealDriveSizeRequest request;
_snwprintf (request.DeviceName, array_capacity (request.DeviceName), L"%hs", DriveConfig.DrivePartition.DevicePath.c_str()); StringCbPrintfW (request.DeviceName, sizeof (request.DeviceName), L"%hs", DriveConfig.DrivePartition.DevicePath.c_str());
CallDriver (TC_IOCTL_PROBE_REAL_DRIVE_SIZE, &request, sizeof (request), &request, sizeof (request)); CallDriver (TC_IOCTL_PROBE_REAL_DRIVE_SIZE, &request, sizeof (request), &request, sizeof (request));
DriveConfig.DrivePartition.Info.PartitionLength = request.RealDriveSize; DriveConfig.DrivePartition.Info.PartitionLength = request.RealDriveSize;
@@ -633,7 +635,7 @@ namespace VeraCrypt
partPath << "\\Device\\Harddisk" << driveNumber << "\\Partition" << partNumber; partPath << "\\Device\\Harddisk" << driveNumber << "\\Partition" << partNumber;
DISK_PARTITION_INFO_STRUCT diskPartInfo; DISK_PARTITION_INFO_STRUCT diskPartInfo;
_snwprintf (diskPartInfo.deviceName, array_capacity (diskPartInfo.deviceName), L"%hs", partPath.str().c_str()); StringCbPrintfW (diskPartInfo.deviceName, sizeof (diskPartInfo.deviceName), L"%hs", partPath.str().c_str());
try try
{ {
@@ -663,7 +665,7 @@ namespace VeraCrypt
// Volume ID // Volume ID
wchar_t volumePath[TC_MAX_PATH]; wchar_t volumePath[TC_MAX_PATH];
if (ResolveSymbolicLink ((wchar_t *) ws.str().c_str(), volumePath)) if (ResolveSymbolicLink ((wchar_t *) ws.str().c_str(), volumePath, sizeof(volumePath)))
{ {
wchar_t volumeName[TC_MAX_PATH]; wchar_t volumeName[TC_MAX_PATH];
HANDLE fh = FindFirstVolumeW (volumeName, array_capacity (volumeName)); HANDLE fh = FindFirstVolumeW (volumeName, array_capacity (volumeName));
@@ -742,8 +744,8 @@ namespace VeraCrypt
memset (&openTestStruct, 0, sizeof (openTestStruct)); memset (&openTestStruct, 0, sizeof (openTestStruct));
DWORD dwResult; DWORD dwResult;
strcpy ((char *) &openTestStruct.wszFileName[0], devicePath); StringCbCopyA ((char *) &openTestStruct.wszFileName[0], sizeof(openTestStruct.wszFileName),devicePath);
ToUNICODE ((char *) &openTestStruct.wszFileName[0]); ToUNICODE ((char *) &openTestStruct.wszFileName[0], sizeof(openTestStruct.wszFileName));
openTestStruct.bDetectTCBootLoader = TRUE; openTestStruct.bDetectTCBootLoader = TRUE;
@@ -844,7 +846,7 @@ namespace VeraCrypt
bool BootEncryption::SystemDriveIsDynamic () bool BootEncryption::SystemDriveIsDynamic ()
{ {
GetSystemDriveConfigurationRequest request; GetSystemDriveConfigurationRequest request;
_snwprintf (request.DevicePath, array_capacity (request.DevicePath), L"%hs", GetSystemDriveConfiguration().DeviceKernelPath.c_str()); StringCbPrintfW (request.DevicePath, sizeof (request.DevicePath), L"%hs", GetSystemDriveConfiguration().DeviceKernelPath.c_str());
CallDriver (TC_IOCTL_GET_SYSTEM_DRIVE_CONFIG, &request, sizeof (request), &request, sizeof (request)); CallDriver (TC_IOCTL_GET_SYSTEM_DRIVE_CONFIG, &request, sizeof (request), &request, sizeof (request));
return request.DriveIsDynamic ? true : false; return request.DriveIsDynamic ? true : false;
@@ -1095,7 +1097,7 @@ namespace VeraCrypt
throw ParameterIncorrect (SRC_POS); throw ParameterIncorrect (SRC_POS);
GetSystemDriveConfigurationRequest request; GetSystemDriveConfigurationRequest request;
_snwprintf (request.DevicePath, array_capacity (request.DevicePath), L"%hs", GetSystemDriveConfiguration().DeviceKernelPath.c_str()); StringCbPrintfW (request.DevicePath, sizeof (request.DevicePath), L"%hs", GetSystemDriveConfiguration().DeviceKernelPath.c_str());
try try
{ {
@@ -1402,8 +1404,10 @@ namespace VeraCrypt
memset (image, 0, RescueIsoImageSize); memset (image, 0, RescueIsoImageSize);
// Primary volume descriptor // Primary volume descriptor
strcpy ((char *)image + 0x8000, "\001CD001\001"); const char* szPrimVolDesc = "\001CD001\001";
strcpy ((char *)image + 0x7fff + 41, "VeraCrypt Rescue Disk "); const char* szPrimVolLabel = "VeraCrypt Rescue Disk ";
memcpy (image + 0x8000, szPrimVolDesc, strlen(szPrimVolDesc) + 1);
memcpy (image + 0x7fff + 41, szPrimVolLabel, strlen(szPrimVolLabel) + 1);
*(uint32 *) (image + 0x7fff + 81) = RescueIsoImageSize / 2048; *(uint32 *) (image + 0x7fff + 81) = RescueIsoImageSize / 2048;
*(uint32 *) (image + 0x7fff + 85) = BE32 (RescueIsoImageSize / 2048); *(uint32 *) (image + 0x7fff + 85) = BE32 (RescueIsoImageSize / 2048);
image[0x7fff + 121] = 1; image[0x7fff + 121] = 1;
@@ -1420,11 +1424,13 @@ namespace VeraCrypt
image[0x7fff + 159] = 0x18; image[0x7fff + 159] = 0x18;
// Boot record volume descriptor // Boot record volume descriptor
strcpy ((char *)image + 0x8801, "CD001\001EL TORITO SPECIFICATION"); const char* szBootRecDesc = "CD001\001EL TORITO SPECIFICATION";
memcpy (image + 0x8801, szBootRecDesc, strlen(szBootRecDesc) + 1);
image[0x8800 + 0x47] = 0x19; image[0x8800 + 0x47] = 0x19;
// Volume descriptor set terminator // Volume descriptor set terminator
strcpy ((char *)image + 0x9000, "\377CD001\001"); const char* szVolDescTerm = "\377CD001\001";
memcpy (image + 0x9000, szVolDescTerm, strlen(szVolDescTerm) + 1);
// Path table // Path table
image[0xA000 + 0] = 1; image[0xA000 + 0] = 1;
@@ -1722,7 +1728,7 @@ namespace VeraCrypt
DWORD size = sizeof (regKeyBuf) - strSize; DWORD size = sizeof (regKeyBuf) - strSize;
// SetupInstallFromInfSection() does not support prepending of values so we have to modify the registry directly // SetupInstallFromInfSection() does not support prepending of values so we have to modify the registry directly
strncpy ((char *) regKeyBuf, filter.c_str(), sizeof (regKeyBuf)); StringCbCopyA ((char *) regKeyBuf, sizeof(regKeyBuf), filter.c_str());
if (RegQueryValueEx (regKey, filterReg.c_str(), NULL, NULL, regKeyBuf + strSize, &size) != ERROR_SUCCESS) if (RegQueryValueEx (regKey, filterReg.c_str(), NULL, NULL, regKeyBuf + strSize, &size) != ERROR_SUCCESS)
size = 1; size = 1;
@@ -2318,7 +2324,7 @@ namespace VeraCrypt
void BootEncryption::RestrictPagingFilesToSystemPartition () void BootEncryption::RestrictPagingFilesToSystemPartition ()
{ {
char pagingFiles[128]; char pagingFiles[128];
strncpy (pagingFiles, "X:\\pagefile.sys 0 0", sizeof (pagingFiles)); StringCbCopyA (pagingFiles, sizeof(pagingFiles), "X:\\pagefile.sys 0 0");
pagingFiles[0] = GetWindowsDirectory()[0]; pagingFiles[0] = GetWindowsDirectory()[0];
throw_sys_if (!WriteLocalMachineRegistryMultiString ("System\\CurrentControlSet\\Control\\Session Manager\\Memory Management", "PagingFiles", pagingFiles, strlen (pagingFiles) + 2)); throw_sys_if (!WriteLocalMachineRegistryMultiString ("System\\CurrentControlSet\\Control\\Session Manager\\Memory Management", "PagingFiles", pagingFiles, strlen (pagingFiles) + 2));

View File

@@ -20,6 +20,7 @@
#include "Apidrvr.h" #include "Apidrvr.h"
#include "Dlgcode.h" #include "Dlgcode.h"
#include "Language.h" #include "Language.h"
#include <Strsafe.h>
/* Except in response to the WM_INITDIALOG message, the dialog box procedure /* 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 should return nonzero if it processes the message, and zero if it does
@@ -44,13 +45,13 @@ BOOL CALLBACK CommandHelpDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM
*tmp = 0; *tmp = 0;
strcpy (tmp, "Command line options:\n\n"); StringCbCopyA (tmp, 8192, "Command line options:\n\n");
for (i = 0; i < as->arg_cnt; i ++) for (i = 0; i < as->arg_cnt; i ++)
{ {
if (!as->args[i].Internal) if (!as->args[i].Internal)
{ {
sprintf(tmp2, "%s\t%s\n", as->args[i].short_name, as->args[i].long_name); StringCchPrintf(tmp2, MAX_PATH * 2, "%s\t%s\n", as->args[i].short_name, as->args[i].long_name);
strcat(tmp,tmp2); StringCchCat(tmp, 8192, tmp2);
} }
} }
@@ -220,7 +221,7 @@ int GetArgumentValue (char **lpszCommandLineArgs, int nArgPos, int *nArgIdx,
{ {
/* Handles the case of no space between parameter code and /* Handles the case of no space between parameter code and
value */ value */
strncpy (lpszValue, &lpszCommandLineArgs[*nArgIdx][nArgPos], nValueSize); StringCbCopyA (lpszValue, nValueSize, &lpszCommandLineArgs[*nArgIdx][nArgPos]);
lpszValue[nValueSize - 1] = 0; lpszValue[nValueSize - 1] = 0;
return HAS_ARGUMENT; return HAS_ARGUMENT;
} }
@@ -231,7 +232,7 @@ int GetArgumentValue (char **lpszCommandLineArgs, int nArgPos, int *nArgIdx,
{ {
/* Handles the case of space between parameter code /* Handles the case of space between parameter code
and value */ and value */
strncpy (lpszValue, &lpszCommandLineArgs[*nArgIdx + 1][x], nValueSize); StringCbCopyA (lpszValue, nValueSize, &lpszCommandLineArgs[*nArgIdx + 1][x]);
lpszValue[nValueSize - 1] = 0; lpszValue[nValueSize - 1] = 0;
(*nArgIdx)++; (*nArgIdx)++;
return HAS_ARGUMENT; return HAS_ARGUMENT;

View File

@@ -29,6 +29,8 @@
#include "Format/FormatCom.h" #include "Format/FormatCom.h"
#include "Format/Tcformat.h" #include "Format/Tcformat.h"
#include <Strsafe.h>
int FormatWriteBufferSize = 1024 * 1024; int FormatWriteBufferSize = 1024 * 1024;
static uint32 FormatSectorSize = 0; static uint32 FormatSectorSize = 0;
@@ -129,8 +131,8 @@ int TCFormatVolume (volatile FORMAT_VOL_PARAMETERS *volParams)
if (volParams->bDevice) if (volParams->bDevice)
{ {
strcpy ((char *)deviceName, volParams->volumePath); StringCbCopyA ((char *)deviceName, sizeof(deviceName), volParams->volumePath);
ToUNICODE ((char *)deviceName); ToUNICODE ((char *)deviceName, sizeof(deviceName));
driveLetter = GetDiskDeviceDriveLetter (deviceName); driveLetter = GetDiskDeviceDriveLetter (deviceName);
} }
@@ -170,7 +172,7 @@ begin_format:
DWORD dwResult; DWORD dwResult;
int nPass; int nPass;
if (FakeDosNameForDevice (volParams->volumePath, dosDev, devName, FALSE) != 0) if (FakeDosNameForDevice (volParams->volumePath, dosDev, sizeof(dosDev), devName, sizeof(devName), FALSE) != 0)
return ERR_OS_ERROR; return ERR_OS_ERROR;
if (IsDeviceMounted (devName)) if (IsDeviceMounted (devName))
@@ -803,10 +805,10 @@ BOOL FormatNtfs (int driveNo, int clusterSize)
if (GetSystemDirectory (dllPath, MAX_PATH)) if (GetSystemDirectory (dllPath, MAX_PATH))
{ {
strcat(dllPath, "\\fmifs.dll"); StringCbCatA(dllPath, sizeof(dllPath), "\\fmifs.dll");
} }
else else
strcpy(dllPath, "C:\\Windows\\System32\\fmifs.dll"); StringCbCopyA(dllPath, sizeof(dllPath), "C:\\Windows\\System32\\fmifs.dll");
hModule = LoadLibrary (dllPath); hModule = LoadLibrary (dllPath);
@@ -819,7 +821,7 @@ BOOL FormatNtfs (int driveNo, int clusterSize)
return FALSE; return FALSE;
} }
wcscat (dir, L":\\"); StringCbCatW (dir, sizeof(dir), L":\\");
FormatExResult = FALSE; FormatExResult = FALSE;

View File

@@ -23,11 +23,12 @@
#include "Platform/Finally.h" #include "Platform/Finally.h"
#include "Platform/ForEach.h" #include "Platform/ForEach.h"
#include <Strsafe.h>
using namespace VeraCrypt; using namespace VeraCrypt;
#define stat _stat #define stat _stat
#define S_IFDIR _S_IFDIR #define S_IFDIR _S_IFDIR
#define snprintf _snprintf
BOOL HiddenFilesPresentInKeyfilePath = FALSE; BOOL HiddenFilesPresentInKeyfilePath = FALSE;
@@ -97,13 +98,16 @@ void KeyFileRemoveAll (KeyFile **firstKeyFile)
KeyFile *KeyFileClone (KeyFile *keyFile) KeyFile *KeyFileClone (KeyFile *keyFile)
{ {
KeyFile *clone; KeyFile *clone = NULL;
if (keyFile == NULL) return NULL; if (keyFile == NULL) return NULL;
clone = (KeyFile *) malloc (sizeof (KeyFile)); clone = (KeyFile *) malloc (sizeof (KeyFile));
strcpy (clone->FileName, keyFile->FileName); if (clone)
clone->Next = NULL; {
StringCbCopyA (clone->FileName, sizeof(clone->FileName), keyFile->FileName);
clone->Next = NULL;
}
return clone; return clone;
} }
@@ -298,7 +302,7 @@ BOOL KeyFilesApply (Password *password, KeyFile *firstKeyFile)
/* Find and process all keyfiles in the directory */ /* Find and process all keyfiles in the directory */
int keyfileCount = 0; int keyfileCount = 0;
snprintf (searchPath, sizeof (searchPath), "%s\\*.*", kf->FileName); StringCbPrintfA (searchPath, sizeof (searchPath), "%s\\*.*", kf->FileName);
if ((searchHandle = _findfirst (searchPath, &fBuf)) == -1) if ((searchHandle = _findfirst (searchPath, &fBuf)) == -1)
{ {
handleWin32Error (MainDlg); handleWin32Error (MainDlg);
@@ -311,7 +315,7 @@ BOOL KeyFilesApply (Password *password, KeyFile *firstKeyFile)
{ {
WIN32_FILE_ATTRIBUTE_DATA fileAttributes; WIN32_FILE_ATTRIBUTE_DATA fileAttributes;
snprintf (kfSub->FileName, sizeof(kfSub->FileName), "%s%c%s", kf->FileName, StringCbPrintfA (kfSub->FileName, sizeof(kfSub->FileName), "%s%c%s", kf->FileName,
'\\', '\\',
fBuf.name fBuf.name
); );
@@ -462,18 +466,21 @@ BOOL CALLBACK KeyFilesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
if (lw == IDC_KEYADD) if (lw == IDC_KEYADD)
{ {
KeyFile *kf = (KeyFile *) malloc (sizeof (KeyFile)); KeyFile *kf = (KeyFile *) malloc (sizeof (KeyFile));
if (SelectMultipleFiles (hwndDlg, "SELECT_KEYFILE", kf->FileName, bHistory)) if (kf)
{ {
do if (SelectMultipleFiles (hwndDlg, "SELECT_KEYFILE", kf->FileName, sizeof(kf->FileName),bHistory))
{ {
param->FirstKeyFile = KeyFileAdd (param->FirstKeyFile, kf); do
LoadKeyList (hwndDlg, param->FirstKeyFile); {
param->FirstKeyFile = KeyFileAdd (param->FirstKeyFile, kf);
LoadKeyList (hwndDlg, param->FirstKeyFile);
kf = (KeyFile *) malloc (sizeof (KeyFile)); kf = (KeyFile *) malloc (sizeof (KeyFile));
} while (SelectMultipleFilesNext (kf->FileName)); } while (SelectMultipleFilesNext (kf->FileName, sizeof(kf->FileName)));
}
free (kf);
} }
free (kf);
return 1; return 1;
} }
@@ -501,10 +508,13 @@ BOOL CALLBACK KeyFilesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
foreach (const SecurityTokenKeyfilePath &keyPath, selectedTokenKeyfiles) foreach (const SecurityTokenKeyfilePath &keyPath, selectedTokenKeyfiles)
{ {
KeyFile *kf = (KeyFile *) malloc (sizeof (KeyFile)); KeyFile *kf = (KeyFile *) malloc (sizeof (KeyFile));
strcpy_s (kf->FileName, sizeof (kf->FileName), WideToSingleString (keyPath).c_str()); if (kf)
{
strcpy_s (kf->FileName, sizeof (kf->FileName), WideToSingleString (keyPath).c_str());
param->FirstKeyFile = KeyFileAdd (param->FirstKeyFile, kf); param->FirstKeyFile = KeyFileAdd (param->FirstKeyFile, kf);
LoadKeyList (hwndDlg, param->FirstKeyFile); LoadKeyList (hwndDlg, param->FirstKeyFile);
}
} }
} }
@@ -574,9 +584,12 @@ BOOL CALLBACK KeyFilesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
while (count-- > 0) while (count-- > 0)
{ {
KeyFile *kf = (KeyFile *) malloc (sizeof (KeyFile)); KeyFile *kf = (KeyFile *) malloc (sizeof (KeyFile));
DragQueryFile (hdrop, i++, kf->FileName, sizeof (kf->FileName)); if (kf)
param->FirstKeyFile = KeyFileAdd (param->FirstKeyFile, kf); {
LoadKeyList (hwndDlg, param->FirstKeyFile); DragQueryFile (hdrop, i++, kf->FileName, sizeof (kf->FileName));
param->FirstKeyFile = KeyFileAdd (param->FirstKeyFile, kf);
LoadKeyList (hwndDlg, param->FirstKeyFile);
}
} }
DragFinish (hdrop); DragFinish (hdrop);
@@ -614,6 +627,8 @@ BOOL CALLBACK KeyFilesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
BOOL KeyfilesPopupMenu (HWND hwndDlg, POINT popupPosition, KeyFilesDlgParam *param) BOOL KeyfilesPopupMenu (HWND hwndDlg, POINT popupPosition, KeyFilesDlgParam *param)
{ {
HMENU popup = CreatePopupMenu (); HMENU popup = CreatePopupMenu ();
if (!popup)
return FALSE;
int sel; int sel;
BOOL status = FALSE; BOOL status = FALSE;
@@ -628,35 +643,40 @@ BOOL KeyfilesPopupMenu (HWND hwndDlg, POINT popupPosition, KeyFilesDlgParam *par
case IDM_KEYFILES_POPUP_ADD_FILES: case IDM_KEYFILES_POPUP_ADD_FILES:
{ {
KeyFile *kf = (KeyFile *) malloc (sizeof (KeyFile)); KeyFile *kf = (KeyFile *) malloc (sizeof (KeyFile));
if (SelectMultipleFiles (hwndDlg, "SELECT_KEYFILE", kf->FileName, bHistory)) if (kf)
{ {
do if (SelectMultipleFiles (hwndDlg, "SELECT_KEYFILE", kf->FileName, sizeof(kf->FileName),bHistory))
{ {
param->FirstKeyFile = KeyFileAdd (param->FirstKeyFile, kf); do
kf = (KeyFile *) malloc (sizeof (KeyFile)); {
} while (SelectMultipleFilesNext (kf->FileName)); param->FirstKeyFile = KeyFileAdd (param->FirstKeyFile, kf);
kf = (KeyFile *) malloc (sizeof (KeyFile));
} while (SelectMultipleFilesNext (kf->FileName, sizeof(kf->FileName)));
param->EnableKeyFiles = TRUE; param->EnableKeyFiles = TRUE;
status = TRUE; status = TRUE;
}
free (kf);
} }
free (kf);
} }
break; break;
case IDM_KEYFILES_POPUP_ADD_DIR: case IDM_KEYFILES_POPUP_ADD_DIR:
{ {
KeyFile *kf = (KeyFile *) malloc (sizeof (KeyFile)); KeyFile *kf = (KeyFile *) malloc (sizeof (KeyFile));
if (kf)
if (BrowseDirectories (hwndDlg,"SELECT_KEYFILE_PATH", kf->FileName))
{ {
param->FirstKeyFile = KeyFileAdd (param->FirstKeyFile, kf); if (BrowseDirectories (hwndDlg,"SELECT_KEYFILE_PATH", kf->FileName))
param->EnableKeyFiles = TRUE; {
status = TRUE; param->FirstKeyFile = KeyFileAdd (param->FirstKeyFile, kf);
} param->EnableKeyFiles = TRUE;
else status = TRUE;
{ }
free (kf); else
{
free (kf);
}
} }
} }
break; break;
@@ -669,11 +689,14 @@ BOOL KeyfilesPopupMenu (HWND hwndDlg, POINT popupPosition, KeyFilesDlgParam *par
foreach (const SecurityTokenKeyfilePath &keyPath, selectedTokenKeyfiles) foreach (const SecurityTokenKeyfilePath &keyPath, selectedTokenKeyfiles)
{ {
KeyFile *kf = (KeyFile *) malloc (sizeof (KeyFile)); KeyFile *kf = (KeyFile *) malloc (sizeof (KeyFile));
strcpy_s (kf->FileName, sizeof (kf->FileName), WideToSingleString (keyPath).c_str()); if (kf)
{
strcpy_s (kf->FileName, sizeof (kf->FileName), WideToSingleString (keyPath).c_str());
param->FirstKeyFile = KeyFileAdd (param->FirstKeyFile, kf); param->FirstKeyFile = KeyFileAdd (param->FirstKeyFile, kf);
param->EnableKeyFiles = TRUE; param->EnableKeyFiles = TRUE;
status = TRUE; status = TRUE;
}
} }
} }
} }

View File

@@ -26,6 +26,8 @@
#include "../Setup/Resource.h" #include "../Setup/Resource.h"
#endif #endif
#include <Strsafe.h>
BOOL LocalizationActive; BOOL LocalizationActive;
int LocalizationSerialNo; int LocalizationSerialNo;
@@ -68,8 +70,9 @@ static char *MapNextLanguageFile ()
GetModuleFileNameW (NULL, f, sizeof (f) / sizeof (f[0])); GetModuleFileNameW (NULL, f, sizeof (f) / sizeof (f[0]));
t = wcsrchr (f, L'\\'); t = wcsrchr (f, L'\\');
if (t == NULL) return NULL; if (t == NULL) return NULL;
wcscpy (t, L"\\Language*.xml"); *t = 0;
StringCbCatW (f, sizeof(f), L"\\Language*.xml");
LanguageFileFindHandle = FindFirstFileW (f, &find); LanguageFileFindHandle = FindFirstFileW (f, &find);
} }
@@ -88,14 +91,29 @@ static char *MapNextLanguageFile ()
GetModuleFileNameW (NULL, f, sizeof (f) / sizeof(f[0])); GetModuleFileNameW (NULL, f, sizeof (f) / sizeof(f[0]));
t = wcsrchr (f, L'\\'); t = wcsrchr (f, L'\\');
wcscpy (t + 1, find.cFileName); if (t == NULL)
{
free(LanguageFileBuffer);
return NULL;
}
t[1] = 0;
StringCbCatW (f, sizeof(f),find.cFileName);
file = CreateFileW (f, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); file = CreateFileW (f, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
if (file == INVALID_HANDLE_VALUE) return NULL; if (file == INVALID_HANDLE_VALUE)
{
free(LanguageFileBuffer);
return NULL;
}
ReadFile (file, LanguageFileBuffer, find.nFileSizeLow, &read, NULL); ReadFile (file, LanguageFileBuffer, find.nFileSizeLow, &read, NULL);
CloseHandle (file); CloseHandle (file);
if (read != find.nFileSizeLow) return NULL; if (read != find.nFileSizeLow)
{
free(LanguageFileBuffer);
return NULL;
}
return LanguageFileBuffer; return LanguageFileBuffer;
} }
@@ -130,7 +148,7 @@ BOOL LoadLanguageFile ()
ClearDictionaryPool (); ClearDictionaryPool ();
if (PreferredLangId[0] != 0) if (PreferredLangId[0] != 0)
strcpy (langId, PreferredLangId); StringCbCopyA (langId, sizeof(langId), PreferredLangId);
// Parse all available language files until preferred language is found // Parse all available language files until preferred language is found
for (res = MapFirstLanguageFile (); res != NULL; res = MapNextLanguageFile ()) for (res = MapFirstLanguageFile (); res != NULL; res = MapNextLanguageFile ())
@@ -147,7 +165,7 @@ BOOL LoadLanguageFile ()
if (defaultLangParsed && strcmp (attr, VERSION_STRING) && strcmp (attr, "DEBUG")) if (defaultLangParsed && strcmp (attr, VERSION_STRING) && strcmp (attr, "DEBUG"))
{ {
wchar_t m[2048]; wchar_t m[2048];
swprintf (m, L"The installed language pack is incompatible with this version of VeraCrypt (the language pack is for VeraCrypt %hs). A newer version may be available at www.idrix.fr.\n\nTo prevent this message from being displayed, do any of the following:\n\n- Select 'Settings' > 'Language'; then select 'English' and click 'OK'.\n\n- Remove or replace the language pack with a compatible version (the language pack may reside e.g. in 'C:\\Program Files\\VeraCrypt' or '%%LOCALAPPDATA%%\\VirtualStore\\Program Files\\VeraCrypt', etc.)", attr); StringCbPrintfW (m, sizeof(m), L"The installed language pack is incompatible with this version of VeraCrypt (the language pack is for VeraCrypt %hs). A newer version may be available at www.idrix.fr.\n\nTo prevent this message from being displayed, do any of the following:\n\n- Select 'Settings' > 'Language'; then select 'English' and click 'OK'.\n\n- Remove or replace the language pack with a compatible version (the language pack may reside e.g. in 'C:\\Program Files\\VeraCrypt' or '%%LOCALAPPDATA%%\\VirtualStore\\Program Files\\VeraCrypt', etc.)", attr);
MessageBoxW (NULL, m, L"VeraCrypt", MB_ICONERROR); MessageBoxW (NULL, m, L"VeraCrypt", MB_ICONERROR);
continue; continue;
} }
@@ -189,7 +207,7 @@ BOOL LoadLanguageFile ()
XmlGetAttributeText (xml, "size", attr, sizeof (attr)); XmlGetAttributeText (xml, "size", attr, sizeof (attr));
sscanf (attr, "%d", &font.Size); sscanf (attr, "%d", &font.Size);
strcpy (attr, "font_"); StringCbCopyA (attr, sizeof(attr), "font_");
XmlGetAttributeText (xml, "class", attr + 5, sizeof (attr) - 5); XmlGetAttributeText (xml, "class", attr + 5, sizeof (attr) - 5);
AddDictionaryEntry ( AddDictionaryEntry (
AddPoolData ((void *) attr, strlen (attr) + 1), 0, AddPoolData ((void *) attr, strlen (attr) + 1), 0,
@@ -375,13 +393,13 @@ BOOL CALLBACK LanguageDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
// Language pack version // Language pack version
if (!ActiveLangPackVersion[0] || memcmp (ActiveLangPackVersion, "0.0.0", 5) == 0) if (!ActiveLangPackVersion[0] || memcmp (ActiveLangPackVersion, "0.0.0", 5) == 0)
{ {
swprintf (szVers, GetString("LANG_PACK_VERSION"), L"--"); StringCbPrintfW (szVers, sizeof(szVers), GetString("LANG_PACK_VERSION"), L"--");
} }
else else
{ {
nLen = MultiByteToWideChar (CP_UTF8, 0, ActiveLangPackVersion, -1, wversion, sizeof (wversion) / sizeof(wversion[0])); nLen = MultiByteToWideChar (CP_UTF8, 0, ActiveLangPackVersion, -1, wversion, sizeof (wversion) / sizeof(wversion[0]));
if (nLen != 0 && nLen != ERROR_NO_UNICODE_TRANSLATION) if (nLen != 0 && nLen != ERROR_NO_UNICODE_TRANSLATION)
swprintf (szVers, GetString("LANG_PACK_VERSION"), wversion); StringCbPrintfW (szVers, sizeof(szVers),GetString("LANG_PACK_VERSION"), wversion);
} }
SetWindowTextW (GetDlgItem (hwndDlg, IDC_LANGPACK_VERSION), szVers); SetWindowTextW (GetDlgItem (hwndDlg, IDC_LANGPACK_VERSION), szVers);
@@ -394,7 +412,7 @@ BOOL CALLBACK LanguageDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
} }
} }
strcpy (lastLangId, attr); StringCbCopyA (lastLangId, sizeof(lastLangId),attr);
langCount++; langCount++;
} }
} }
@@ -410,7 +428,7 @@ BOOL CALLBACK LanguageDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
EndDialog (hwndDlg, IDCANCEL); EndDialog (hwndDlg, IDCANCEL);
if (langCount == 2) if (langCount == 2)
strcpy (PreferredLangId, lastLangId); StringCbCopyA (PreferredLangId, sizeof(PreferredLangId), lastLangId);
EndDialog (hwndDlg, IDOK); EndDialog (hwndDlg, IDOK);
} }
@@ -446,7 +464,7 @@ BOOL CALLBACK LanguageDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
} }
if (SendDlgItemMessage (hwndDlg, IDC_LANGLIST, LB_GETCOUNT, 0, 0) > 1) if (SendDlgItemMessage (hwndDlg, IDC_LANGLIST, LB_GETCOUNT, 0, 0) > 1)
strcpy (PreferredLangId, l); StringCbCopyA (PreferredLangId, sizeof(PreferredLangId), l);
} }
} }
@@ -465,7 +483,7 @@ BOOL CALLBACK LanguageDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
char tmpstr [256]; char tmpstr [256];
if (strlen (ActiveLangPackVersion) > 0 && strlen (GetPreferredLangId()) > 0) if (strlen (ActiveLangPackVersion) > 0 && strlen (GetPreferredLangId()) > 0)
sprintf (tmpstr, "&langpackversion=%s&lang=%s", ActiveLangPackVersion, GetPreferredLangId()); StringCbPrintfA (tmpstr, sizeof(tmpstr), "&langpackversion=%s&lang=%s", ActiveLangPackVersion, GetPreferredLangId());
else else
tmpstr[0] = 0; tmpstr[0] = 0;
@@ -488,7 +506,7 @@ char *GetPreferredLangId ()
void SetPreferredLangId (char *langId) void SetPreferredLangId (char *langId)
{ {
strncpy (PreferredLangId, langId, 5); StringCbCopyA (PreferredLangId, sizeof(PreferredLangId), langId);
} }
@@ -503,7 +521,7 @@ wchar_t *GetString (const char *stringId)
WCHAR *str = (WCHAR *) GetDictionaryValue (stringId); WCHAR *str = (WCHAR *) GetDictionaryValue (stringId);
if (str != NULL) return str; if (str != NULL) return str;
wsprintfW (UnknownString, UNKNOWN_STRING_ID L"%hs" UNKNOWN_STRING_ID, stringId); StringCbPrintfW (UnknownString, sizeof(UnknownString), UNKNOWN_STRING_ID L"%hs" UNKNOWN_STRING_ID, stringId);
return UnknownString; return UnknownString;
} }

View File

@@ -17,6 +17,8 @@
#include "../Format/FormatCom.h" #include "../Format/FormatCom.h"
#include "../Format/resource.h" #include "../Format/resource.h"
#include <Strsafe.h>
static ULONG prevTime, startTime; static ULONG prevTime, startTime;
static __int64 TotalSize; static __int64 TotalSize;
static __int64 resumedPointBytesDone; static __int64 resumedPointBytesDone;
@@ -74,31 +76,31 @@ BOOL UpdateProgressBarProc (__int64 byteOffset)
double perc = (double) (100.0 * (bProgressBarReverse ? ((double) (TotalSize - byteOffset)) : ((double) byteOffset)) / (TotalSize == 0 ? 0.0001 : ((double) TotalSize))); double perc = (double) (100.0 * (bProgressBarReverse ? ((double) (TotalSize - byteOffset)) : ((double) byteOffset)) / (TotalSize == 0 ? 0.0001 : ((double) TotalSize)));
if (perc > 99.999999999) if (perc > 99.999999999)
wcscpy (text, GetString ("PROCESSED_PORTION_100_PERCENT")); StringCbCopyW (text,sizeof(text), GetString ("PROCESSED_PORTION_100_PERCENT"));
else else
_snwprintf (text, sizeof text/2, GetString ("PROCESSED_PORTION_X_PERCENT"), perc); StringCbPrintfW (text, sizeof text, GetString ("PROCESSED_PORTION_X_PERCENT"), perc);
wcscat (speed, L" "); StringCbCatW (speed, sizeof(speed), L" ");
} }
else else
{ {
GetSizeString (bytesDone, text); GetSizeString (bytesDone, text, sizeof(text));
if (bytesDone < (unsigned __int64) BYTES_PER_MB * 1000000) if (bytesDone < (unsigned __int64) BYTES_PER_MB * 1000000)
swprintf(text, L"%I64d %s ", bytesDone / BYTES_PER_MB, GetString ("MB")); StringCbPrintfW(text, sizeof(text), L"%I64d %s ", bytesDone / BYTES_PER_MB, GetString ("MB"));
else if (bytesDone < (unsigned __int64) BYTES_PER_GB * 1000000) else if (bytesDone < (unsigned __int64) BYTES_PER_GB * 1000000)
swprintf(text, L"%I64d %s ", bytesDone / BYTES_PER_GB, GetString ("GB")); StringCbPrintfW(text, sizeof(text), L"%I64d %s ", bytesDone / BYTES_PER_GB, GetString ("GB"));
else if (bytesDone < (unsigned __int64) BYTES_PER_TB * 1000000) else if (bytesDone < (unsigned __int64) BYTES_PER_TB * 1000000)
swprintf(text, L"%I64d %s ", bytesDone / BYTES_PER_TB, GetString ("TB")); StringCbPrintfW(text, sizeof(text), L"%I64d %s ", bytesDone / BYTES_PER_TB, GetString ("TB"));
else else
swprintf(text, L"%I64d %s ", bytesDone / BYTES_PER_PB, GetString ("PB")); StringCbPrintfW(text, sizeof(text), L"%I64d %s ", bytesDone / BYTES_PER_PB, GetString ("PB"));
} }
SetWindowTextW (GetDlgItem (hCurPage, IDC_BYTESWRITTEN), text); SetWindowTextW (GetDlgItem (hCurPage, IDC_BYTESWRITTEN), text);
if (!bShowStatus) if (!bShowStatus)
{ {
GetSpeedString (bRWThroughput ? bytesPerSec*2 : bytesPerSec, speed); GetSpeedString (bRWThroughput ? bytesPerSec*2 : bytesPerSec, speed, sizeof(speed));
wcscat (speed, L" "); StringCbCatW (speed, sizeof(speed), L" ");
SetWindowTextW (GetDlgItem (hCurPage, IDC_WRITESPEED), speed); SetWindowTextW (GetDlgItem (hCurPage, IDC_WRITESPEED), speed);
} }
@@ -107,15 +109,15 @@ BOOL UpdateProgressBarProc (__int64 byteOffset)
int64 sec = (int64) ((bProgressBarReverse ? byteOffset : (TotalSize - byteOffset)) / (bytesPerSec == 0 ? 0.001 : bytesPerSec)); int64 sec = (int64) ((bProgressBarReverse ? byteOffset : (TotalSize - byteOffset)) / (bytesPerSec == 0 ? 0.001 : bytesPerSec));
if (bytesPerSec == 0 || sec > 60 * 60 * 24 * 999) if (bytesPerSec == 0 || sec > 60 * 60 * 24 * 999)
swprintf (text, L"%s ", GetString ("NOT_APPLICABLE_OR_NOT_AVAILABLE")); StringCbPrintfW (text, sizeof(text), L"%s ", GetString ("NOT_APPLICABLE_OR_NOT_AVAILABLE"));
else if (sec >= 60 * 60 * 24 * 2) else if (sec >= 60 * 60 * 24 * 2)
swprintf (text, L"%I64d %s ", sec / (60 * 24 * 60), days); StringCbPrintfW (text, sizeof(text), L"%I64d %s ", sec / (60 * 24 * 60), days);
else if (sec >= 120 * 60) else if (sec >= 120 * 60)
swprintf (text, L"%I64d %s ", sec / (60 * 60), hours); StringCbPrintfW (text, sizeof(text), L"%I64d %s ", sec / (60 * 60), hours);
else if (sec >= 120) else if (sec >= 120)
swprintf (text, L"%I64d %s ", sec / 60, minutes); StringCbPrintfW (text, sizeof(text), L"%I64d %s ", sec / 60, minutes);
else else
swprintf (text, L"%I64d %s ", sec, seconds); StringCbPrintfW (text, sizeof(text), L"%I64d %s ", sec, seconds);
SetWindowTextW (GetDlgItem (hCurPage, IDC_TIMEREMAIN), text); SetWindowTextW (GetDlgItem (hCurPage, IDC_TIMEREMAIN), text);
} }

View File

@@ -12,6 +12,7 @@
#include "Tcdefs.h" #include "Tcdefs.h"
#include "Crc.h" #include "Crc.h"
#include "Random.h" #include "Random.h"
#include <Strsafe.h>
static unsigned __int8 buffer[RNG_POOL_SIZE]; static unsigned __int8 buffer[RNG_POOL_SIZE];
static unsigned char *pRandPool = NULL; static unsigned char *pRandPool = NULL;
@@ -576,10 +577,10 @@ BOOL SlowPoll (void)
char dllPath[MAX_PATH]; char dllPath[MAX_PATH];
if (GetSystemDirectory (dllPath, MAX_PATH)) if (GetSystemDirectory (dllPath, MAX_PATH))
{ {
strcat(dllPath, "\\NETAPI32.DLL"); StringCbCatA(dllPath, sizeof(dllPath), "\\NETAPI32.DLL");
} }
else else
strcpy(dllPath, "C:\\Windows\\System32\\NETAPI32.DLL"); StringCbCopyA(dllPath, sizeof(dllPath), "C:\\Windows\\System32\\NETAPI32.DLL");
hNetAPI32 = LoadLibrary (dllPath); hNetAPI32 = LoadLibrary (dllPath);
if (hNetAPI32 != NULL) if (hNetAPI32 != NULL)
@@ -630,7 +631,7 @@ BOOL SlowPoll (void)
char szDevice[24]; char szDevice[24];
/* Check whether we can access this device */ /* Check whether we can access this device */
sprintf (szDevice, "\\\\.\\PhysicalDrive%d", nDrive); StringCbPrintfA (szDevice, sizeof(szDevice), "\\\\.\\PhysicalDrive%d", nDrive);
hDevice = CreateFile (szDevice, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, hDevice = CreateFile (szDevice, 0, FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, NULL); NULL, OPEN_EXISTING, 0, NULL);
if (hDevice == INVALID_HANDLE_VALUE) if (hDevice == INVALID_HANDLE_VALUE)

View File

@@ -197,7 +197,7 @@ typedef int BOOL;
# ifdef DEVICE_DRIVER # ifdef DEVICE_DRIVER
# define trace_msg Dump # define trace_msg Dump
# elif defined (_WIN32) # elif defined (_WIN32)
# define trace_msg(...) do { char msg[2048]; _snprintf (msg, sizeof (msg), __VA_ARGS__); OutputDebugString (msg); } while (0) # define trace_msg(...) do { char msg[2048]; StringCbPrintfA (msg, sizeof (msg), __VA_ARGS__); OutputDebugString (msg); } while (0)
# endif # endif
# define trace_point trace_msg (__FUNCTION__ ":" TC_TO_STRING(__LINE__) "\n") # define trace_point trace_msg (__FUNCTION__ ":" TC_TO_STRING(__LINE__) "\n")
# else # else

View File

@@ -33,6 +33,9 @@
#include "Volumes.h" #include "Volumes.h"
#include "Pkcs5.h" #include "Pkcs5.h"
#ifdef _WIN32
#include <Strsafe.h>
#endif
/* Volume header v5 structure (used since TrueCrypt 7.0): */ /* Volume header v5 structure (used since TrueCrypt 7.0): */
// //
@@ -187,6 +190,9 @@ int ReadVolumeHeader (BOOL bBoot, char *encryptedHeader, Password *password, PCR
} }
else else
{ {
if (!retInfo)
return ERR_PARAMETER_INCORRECT;
cryptoInfo = *retInfo = crypto_open (); cryptoInfo = *retInfo = crypto_open ();
if (cryptoInfo == NULL) if (cryptoInfo == NULL)
return ERR_OUTOFMEMORY; return ERR_OUTOFMEMORY;
@@ -934,16 +940,16 @@ int CreateVolumeHeaderInMemory (BOOL bBoot, char *header, int ea, int mode, Pass
for (i = 0; i < j; i++) for (i = 0; i < j; i++)
{ {
char tmp2[8] = {0}; char tmp2[8] = {0};
sprintf (tmp2, "%02X", (int) (unsigned char) keyInfo.master_keydata[i + primaryKeyOffset]); StringCbPrintfA (tmp2, sizeof(tmp2), "%02X", (int) (unsigned char) keyInfo.master_keydata[i + primaryKeyOffset]);
strcat (MasterKeyGUIView, tmp2); StringCbCatA (MasterKeyGUIView, sizeof(MasterKeyGUIView), tmp2);
} }
HeaderKeyGUIView[0] = 0; HeaderKeyGUIView[0] = 0;
for (i = 0; i < NBR_KEY_BYTES_TO_DISPLAY; i++) for (i = 0; i < NBR_KEY_BYTES_TO_DISPLAY; i++)
{ {
char tmp2[8]; char tmp2[8];
sprintf (tmp2, "%02X", (int) (unsigned char) dk[primaryKeyOffset + i]); StringCbPrintfA (tmp2, sizeof(tmp2), "%02X", (int) (unsigned char) dk[primaryKeyOffset + i]);
strcat (HeaderKeyGUIView, tmp2); StringCbCatA (HeaderKeyGUIView, sizeof(HeaderKeyGUIView), tmp2);
} }
if (dots3) if (dots3)

View File

@@ -34,6 +34,8 @@ IMPORTANT: Due to this issue, functions in this file must not directly interact
#include "InPlace.h" #include "InPlace.h"
#include <Strsafe.h>
using namespace std; using namespace std;
using namespace VeraCrypt; using namespace VeraCrypt;
@@ -151,15 +153,15 @@ BOOL CheckRequirementsForNonSysInPlaceEnc (const char *devicePath, BOOL silent)
/* Access to the partition */ /* Access to the partition */
strcpy ((char *) devPath, devicePath); StringCbCopyA ((char *) devPath, sizeof(devPath), devicePath);
ToUNICODE ((char *) devPath); ToUNICODE ((char *) devPath, sizeof(devPath));
driveLetterNo = GetDiskDeviceDriveLetter (devPath); driveLetterNo = GetDiskDeviceDriveLetter (devPath);
if (driveLetterNo >= 0) if (driveLetterNo >= 0)
szRootPath[0] = (char) driveLetterNo + 'A'; 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) if (!silent)
{ {
@@ -348,13 +350,13 @@ int EncryptPartitionInPlaceBegin (volatile FORMAT_VOL_PARAMETERS *volParams, vol
dataAreaSize = GetVolumeDataAreaSize (volParams->hiddenVol, deviceSize); dataAreaSize = GetVolumeDataAreaSize (volParams->hiddenVol, deviceSize);
strcpy ((char *)deviceName, volParams->volumePath); StringCbCopyA ((char *)deviceName, sizeof(deviceName), volParams->volumePath);
ToUNICODE ((char *)deviceName); ToUNICODE ((char *)deviceName, sizeof(deviceName));
driveLetter = GetDiskDeviceDriveLetter (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; nStatus = ERR_OS_ERROR;
goto closing_seq; goto closing_seq;
@@ -710,10 +712,10 @@ int EncryptPartitionInPlaceResume (HANDLE dev,
if (dev == INVALID_HANDLE_VALUE) if (dev == INVALID_HANDLE_VALUE)
{ {
strcpy ((char *)deviceName, devicePath); StringCbCopyA ((char *)deviceName, sizeof(deviceName), devicePath);
ToUNICODE ((char *)deviceName); 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; nStatus = ERR_OS_ERROR;
goto closing_seq; goto closing_seq;
@@ -1085,9 +1087,9 @@ closing_seq:
wchar_t msg[30000] = {0}; wchar_t msg[30000] = {0};
wchar_t sizeStr[500] = {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"), GetString ("ZEROED_BAD_SECTOR_COUNT"),
zeroedSectorCount, zeroedSectorCount,
sizeStr); sizeStr);
@@ -1369,10 +1371,10 @@ void ShowInPlaceEncErrMsgWAltSteps (char *iniStrId, BOOL bErr)
{ {
wchar_t msg[30000]; wchar_t msg[30000];
wcscpy (msg, GetString (iniStrId)); StringCbCopyW (msg, sizeof(msg), GetString (iniStrId));
wcscat (msg, L"\n\n\n"); StringCbCatW (msg, sizeof(msg), L"\n\n\n");
wcscat (msg, GetString ("INPLACE_ENC_ALTERNATIVE_STEPS")); StringCbCatW (msg, sizeof(msg), GetString ("INPLACE_ENC_ALTERNATIVE_STEPS"));
if (bErr) if (bErr)
ErrorDirect (msg); ErrorDirect (msg);
@@ -1414,7 +1416,7 @@ BOOL SaveNonSysInPlaceEncSettings (int delta, WipeAlgorithmId newWipeAlgorithm)
{ {
if (newWipeAlgorithm != TC_WIPE_NONE) 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); SaveBufferToFile (str, GetConfigPath (TC_APPD_FILENAME_NONSYS_INPLACE_ENC_WIPE), strlen(str), FALSE);
} }
@@ -1423,7 +1425,7 @@ BOOL SaveNonSysInPlaceEncSettings (int delta, WipeAlgorithmId newWipeAlgorithm)
remove (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); return SaveBufferToFile (str, GetConfigPath (TC_APPD_FILENAME_NONSYS_INPLACE_ENC), strlen(str), FALSE);
} }

View File

@@ -48,6 +48,8 @@
#include "Wipe.h" #include "Wipe.h"
#include "Xml.h" #include "Xml.h"
#include <Strsafe.h>
using namespace VeraCrypt; using namespace VeraCrypt;
enum wizard_pages enum wizard_pages
@@ -1217,7 +1219,7 @@ void ComboSelChangeEA (HWND hwndDlg)
switch (cnt) // Number of ciphers in the cascade switch (cnt) // Number of ciphers in the cascade
{ {
case 2: case 2:
swprintf (auxLine, GetString ("TWO_LAYER_CASCADE_HELP"), StringCbPrintfW (auxLine, sizeof(auxLine), GetString ("TWO_LAYER_CASCADE_HELP"),
CipherGetName (cipherIDs[1]), CipherGetName (cipherIDs[1]),
CipherGetKeySize (cipherIDs[1])*8, CipherGetKeySize (cipherIDs[1])*8,
CipherGetName (cipherIDs[0]), CipherGetName (cipherIDs[0]),
@@ -1225,7 +1227,7 @@ void ComboSelChangeEA (HWND hwndDlg)
break; break;
case 3: case 3:
swprintf (auxLine, GetString ("THREE_LAYER_CASCADE_HELP"), StringCbPrintfW (auxLine, sizeof(auxLine), GetString ("THREE_LAYER_CASCADE_HELP"),
CipherGetName (cipherIDs[2]), CipherGetName (cipherIDs[2]),
CipherGetKeySize (cipherIDs[2])*8, CipherGetKeySize (cipherIDs[2])*8,
CipherGetName (cipherIDs[1]), CipherGetName (cipherIDs[1]),
@@ -1235,7 +1237,7 @@ void ComboSelChangeEA (HWND hwndDlg)
break; 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); SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), auxLine);
} }
@@ -1454,11 +1456,11 @@ static void UpdateSysEncProgressBar (void)
// Status // Status
if (locBootEncStatus.TransformWaitingForIdle) if (locBootEncStatus.TransformWaitingForIdle)
wcscpy (tmpStr, GetString ("PROGRESS_STATUS_WAITING")); StringCbCopyW (tmpStr, sizeof(tmpStr), GetString ("PROGRESS_STATUS_WAITING"));
else 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); SetWindowTextW (GetDlgItem (hCurPage, IDC_WRITESPEED), tmpStr);
} }
@@ -1518,17 +1520,17 @@ static void UpdateSysEncControls (void)
{ {
wchar_t tmpStr[100]; 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")); "PROGRESS_STATUS_FINISHED" : "PROGRESS_STATUS_PAUSED"));
wcscat (tmpStr, L" "); StringCbCatW (tmpStr, sizeof(tmpStr), L" ");
// Status // Status
SetWindowTextW (GetDlgItem (hCurPage, IDC_WRITESPEED), tmpStr); SetWindowTextW (GetDlgItem (hCurPage, IDC_WRITESPEED), tmpStr);
if (SysDriveOrPartitionFullyEncrypted (TRUE) || SystemEncryptionStatus == SYSENC_STATUS_NONE) if (SysDriveOrPartitionFullyEncrypted (TRUE) || SystemEncryptionStatus == SYSENC_STATUS_NONE)
{ {
wcscpy (tmpStr, GetString ("PROCESSED_PORTION_100_PERCENT")); StringCbCopyW (tmpStr, sizeof(tmpStr), GetString ("PROCESSED_PORTION_100_PERCENT"));
wcscat (tmpStr, L" "); StringCbCatW (tmpStr, sizeof(tmpStr), L" ");
SetWindowTextW (GetDlgItem (hCurPage, IDC_BYTESWRITTEN), tmpStr); SetWindowTextW (GetDlgItem (hCurPage, IDC_BYTESWRITTEN), tmpStr);
} }
@@ -1699,9 +1701,9 @@ static BOOL GetDevicePathForHiddenOS (void)
try 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) catch (Exception &e)
{ {
@@ -1804,29 +1806,29 @@ void ShowNonSysInPlaceEncUIStatus (void)
switch (NonSysInplaceEncStatus) switch (NonSysInplaceEncStatus)
{ {
case NONSYS_INPLACE_ENC_STATUS_PAUSED: case NONSYS_INPLACE_ENC_STATUS_PAUSED:
wcscpy (nonSysInplaceEncUIStatus, GetString ("PROGRESS_STATUS_PAUSED")); StringCbCopyW (nonSysInplaceEncUIStatus, sizeof(nonSysInplaceEncUIStatus), GetString ("PROGRESS_STATUS_PAUSED"));
break; break;
case NONSYS_INPLACE_ENC_STATUS_PREPARING: case NONSYS_INPLACE_ENC_STATUS_PREPARING:
wcscpy (nonSysInplaceEncUIStatus, GetString ("PROGRESS_STATUS_PREPARING")); StringCbCopyW (nonSysInplaceEncUIStatus, sizeof(nonSysInplaceEncUIStatus), GetString ("PROGRESS_STATUS_PREPARING"));
break; break;
case NONSYS_INPLACE_ENC_STATUS_RESIZING: case NONSYS_INPLACE_ENC_STATUS_RESIZING:
wcscpy (nonSysInplaceEncUIStatus, GetString ("PROGRESS_STATUS_RESIZING")); StringCbCopyW (nonSysInplaceEncUIStatus, sizeof(nonSysInplaceEncUIStatus), GetString ("PROGRESS_STATUS_RESIZING"));
break; break;
case NONSYS_INPLACE_ENC_STATUS_ENCRYPTING: case NONSYS_INPLACE_ENC_STATUS_ENCRYPTING:
wcscpy (nonSysInplaceEncUIStatus, GetString ("PROGRESS_STATUS_ENCRYPTING")); StringCbCopyW (nonSysInplaceEncUIStatus, sizeof(nonSysInplaceEncUIStatus), GetString ("PROGRESS_STATUS_ENCRYPTING"));
break; break;
case NONSYS_INPLACE_ENC_STATUS_FINALIZING: case NONSYS_INPLACE_ENC_STATUS_FINALIZING:
wcscpy (nonSysInplaceEncUIStatus, GetString ("PROGRESS_STATUS_FINALIZING")); StringCbCopyW (nonSysInplaceEncUIStatus, sizeof(nonSysInplaceEncUIStatus), GetString ("PROGRESS_STATUS_FINALIZING"));
break; break;
case NONSYS_INPLACE_ENC_STATUS_FINISHED: case NONSYS_INPLACE_ENC_STATUS_FINISHED:
wcscpy (nonSysInplaceEncUIStatus, GetString ("PROGRESS_STATUS_FINISHED")); StringCbCopyW (nonSysInplaceEncUIStatus, sizeof(nonSysInplaceEncUIStatus), GetString ("PROGRESS_STATUS_FINISHED"));
break; break;
case NONSYS_INPLACE_ENC_STATUS_ERROR: case NONSYS_INPLACE_ENC_STATUS_ERROR:
wcscpy (nonSysInplaceEncUIStatus, GetString ("PROGRESS_STATUS_ERROR")); StringCbCopyW (nonSysInplaceEncUIStatus, sizeof(nonSysInplaceEncUIStatus), GetString ("PROGRESS_STATUS_ERROR"));
break; break;
} }
wcscat (nonSysInplaceEncUIStatus, L" "); StringCbCatW (nonSysInplaceEncUIStatus, sizeof(nonSysInplaceEncUIStatus), L" ");
SetWindowTextW (GetDlgItem (hCurPage, IDC_WRITESPEED), nonSysInplaceEncUIStatus); SetWindowTextW (GetDlgItem (hCurPage, IDC_WRITESPEED), nonSysInplaceEncUIStatus);
} }
@@ -1974,10 +1976,10 @@ void DisplayRandPool (HWND hPoolDisplay, BOOL bShow)
{ {
tmpByte = randPool[row * RANDPOOL_DISPLAY_COLUMNS + col]; tmpByte = randPool[row * RANDPOOL_DISPLAY_COLUMNS + col];
sprintf ((char *) tmp, bRandPoolDispAscii ? ((tmpByte >= 32 && tmpByte < 255 && tmpByte != '&') ? " %c " : " . ") : "%02X ", tmpByte); StringCbPrintfA ((char *) tmp, sizeof(tmp), bRandPoolDispAscii ? ((tmpByte >= 32 && tmpByte < 255 && tmpByte != '&') ? " %c " : " . ") : "%02X ", tmpByte);
strcat ((char *) outRandPoolDispBuffer, (char *) tmp); StringCbCatA ((char *) outRandPoolDispBuffer, sizeof(outRandPoolDispBuffer), (char *) tmp);
} }
strcat ((char *) outRandPoolDispBuffer, "\n"); StringCbCatA ((char *) outRandPoolDispBuffer, sizeof(outRandPoolDispBuffer), "\n");
} }
SetWindowText (hPoolDisplay, (char *) outRandPoolDispBuffer); SetWindowText (hPoolDisplay, (char *) outRandPoolDispBuffer);
@@ -2300,7 +2302,7 @@ static void __cdecl volTransformThreadFunction (void *hwndDlgArg)
if (! ((bHiddenVol && !bHiddenVolHost) && errno != EACCES)) // Only ask ask for permission to overwrite an existing volume if we're not creating a hidden volume 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"), GetString (errno == EACCES ? "READONLYPROMPT" : "OVERWRITEPROMPT"),
szDiskFile); szDiskFile);
@@ -2463,7 +2465,7 @@ static void __cdecl volTransformThreadFunction (void *hwndDlgArg)
} }
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) 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); MessageBoxW (hwndDlg, szMsg, lpszTitle, ICON_HAND);
} }
@@ -2904,11 +2906,11 @@ int PrintFreeSpace (HWND hwndTextBox, char *lpszDrive, PLARGE_INTEGER lDiskFree)
if (bHiddenVol && !bHiddenVolHost) // If it's a hidden volume 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); SetWindowTextW (GetDlgItem (hwndTextBox, IDC_SIZEBOX), szTmp2);
} }
else 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); SetWindowTextW (hwndTextBox, szTmp2);
@@ -2925,7 +2927,7 @@ void DisplaySizingErrorText (HWND hwndTextBox)
if (translateWin32Error (szTmp, sizeof (szTmp) / sizeof(szTmp[0]))) if (translateWin32Error (szTmp, sizeof (szTmp) / sizeof(szTmp[0])))
{ {
wchar_t szTmp2[1024]; 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); SetWindowTextW (hwndTextBox, szTmp2);
} }
else else
@@ -3152,8 +3154,8 @@ static BOOL FinalPreTransformPrompts (void)
int driveNo; int driveNo;
WCHAR deviceName[MAX_PATH]; WCHAR deviceName[MAX_PATH];
strcpy ((char *)deviceName, szFileName); StringCbCopyA ((char *)deviceName, sizeof(deviceName), szFileName);
ToUNICODE ((char *)deviceName); ToUNICODE ((char *)deviceName, sizeof(deviceName));
driveNo = GetDiskDeviceDriveLetter (deviceName); driveNo = GetDiskDeviceDriveLetter (deviceName);
@@ -3171,7 +3173,7 @@ static BOOL FinalPreTransformPrompts (void)
if (!GetDriveLabel (driveNo, volumeLabel, sizeof (volumeLabel))) if (!GetDriveLabel (driveNo, volumeLabel, sizeof (volumeLabel)))
volumeLabel[0] = 0; 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 else
{ {
@@ -3180,9 +3182,9 @@ static BOOL FinalPreTransformPrompts (void)
} }
if (bHiddenOS && bHiddenVolHost) 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 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)); x = MessageBoxW (MainDlg, szTmp, lpszTitle, YES_NO | MB_ICONWARNING | (bInPlaceEncNonSys ? MB_DEFBUTTON1 : MB_DEFBUTTON2));
@@ -3208,27 +3210,27 @@ static BOOL FinalPreTransformPrompts (void)
wchar_t tmpMcOption1 [500]; wchar_t tmpMcOption1 [500];
wchar_t tmpMcOptionCancel [50]; wchar_t tmpMcOptionCancel [50];
wcscpy (tmpMcMsg, GetString("OVERWRITEPROMPT_DEVICE_SECOND_WARNING_LOTS_OF_DATA")); StringCbCopyW (tmpMcMsg, sizeof(tmpMcMsg), GetString("OVERWRITEPROMPT_DEVICE_SECOND_WARNING_LOTS_OF_DATA"));
wcscpy (tmpMcOption1, GetString("ERASE_FILES_BY_CREATING_VOLUME")); StringCbCopyW (tmpMcOption1, sizeof(tmpMcOption1), GetString("ERASE_FILES_BY_CREATING_VOLUME"));
wcscpy (tmpMcOptionCancel, GetString("CANCEL")); StringCbCopyW (tmpMcOptionCancel, sizeof(tmpMcOptionCancel), GetString("CANCEL"));
wcscat (tmpMcMsg, L"\n\n"); StringCbCatW (tmpMcMsg, sizeof(tmpMcMsg), L"\n\n");
wcscat (tmpMcMsg, GetString("DRIVE_LETTER_ITEM")); StringCbCatW (tmpMcMsg, sizeof(tmpMcMsg), GetString("DRIVE_LETTER_ITEM"));
swprintf_s (szTmp, sizeof (szTmp)/2, L"%hc:", 'A' + driveNo); StringCbPrintfW (szTmp, sizeof (szTmp), L"%hc:", 'A' + driveNo);
wcscat (tmpMcMsg, szTmp); StringCbCatW (tmpMcMsg, sizeof(tmpMcMsg), szTmp);
wcscat (tmpMcMsg, L"\n"); StringCbCatW (tmpMcMsg, sizeof(tmpMcMsg), L"\n");
wcscat (tmpMcMsg, GetString("LABEL_ITEM")); StringCbCatW (tmpMcMsg, sizeof(tmpMcMsg), GetString("LABEL_ITEM"));
wcscat (tmpMcMsg, volumeLabel[0] != 0 ? volumeLabel : GetString("NOT_APPLICABLE_OR_NOT_AVAILABLE")); StringCbCatW (tmpMcMsg, sizeof(tmpMcMsg), volumeLabel[0] != 0 ? volumeLabel : GetString("NOT_APPLICABLE_OR_NOT_AVAILABLE"));
wcscat (tmpMcMsg, L"\n"); StringCbCatW (tmpMcMsg, sizeof(tmpMcMsg), L"\n");
wcscat (tmpMcMsg, GetString("SIZE_ITEM")); StringCbCatW (tmpMcMsg, sizeof(tmpMcMsg), GetString("SIZE_ITEM"));
GetSizeString (nVolumeSize, szTmp); GetSizeString (nVolumeSize, szTmp, sizeof(szTmp));
wcscat (tmpMcMsg, szTmp); StringCbCatW (tmpMcMsg, sizeof(tmpMcMsg), szTmp);
wcscat (tmpMcMsg, L"\n"); StringCbCatW (tmpMcMsg, sizeof(tmpMcMsg), L"\n");
wcscat (tmpMcMsg, GetString("PATH_ITEM")); StringCbCatW (tmpMcMsg, sizeof(tmpMcMsg), GetString("PATH_ITEM"));
wcscat (tmpMcMsg, deviceName); StringCbCatW (tmpMcMsg, sizeof(tmpMcMsg), deviceName);
wchar_t *tmpStr[] = {L"", tmpMcMsg, tmpMcOption1, tmpMcOptionCancel, 0}; wchar_t *tmpStr[] = {L"", tmpMcMsg, tmpMcOption1, tmpMcOptionCancel, 0};
switch (AskMultiChoice ((void **) tmpStr, TRUE)) switch (AskMultiChoice ((void **) tmpStr, TRUE))
@@ -3258,8 +3260,8 @@ void HandleOldAssignedDriveLetter (void)
WCHAR deviceName[MAX_PATH]; WCHAR deviceName[MAX_PATH];
int driveLetter = -1; int driveLetter = -1;
strcpy ((char *)deviceName, szDiskFile); StringCbCopyA ((char *)deviceName, sizeof(deviceName), szDiskFile);
ToUNICODE ((char *)deviceName); ToUNICODE ((char *)deviceName, sizeof(deviceName));
driveLetter = GetDiskDeviceDriveLetter (deviceName); driveLetter = GetDiskDeviceDriveLetter (deviceName);
if (!bHiddenVolHost if (!bHiddenVolHost
@@ -3269,7 +3271,7 @@ void HandleOldAssignedDriveLetter (void)
char rootPath[] = { (char) driveLetter + 'A', ':', '\\', 0 }; char rootPath[] = { (char) driveLetter + 'A', ':', '\\', 0 };
wchar_t szTmp[8192]; 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); MessageBoxW (MainDlg, szTmp, lpszTitle, MB_ICONWARNING);
} }
} }
@@ -3302,7 +3304,7 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
case WM_INITDIALOG: case WM_INITDIALOG:
LocalizeDialog (hwndDlg, "IDD_VOL_CREATION_WIZARD_DLG"); LocalizeDialog (hwndDlg, "IDD_VOL_CREATION_WIZARD_DLG");
sprintf (PageDebugId, "FORMAT_PAGE_%d", nCurPageNo); StringCbPrintfA (PageDebugId, sizeof(PageDebugId), "FORMAT_PAGE_%d", nCurPageNo);
LastDialogId = PageDebugId; LastDialogId = PageDebugId;
switch (nCurPageNo) switch (nCurPageNo)
@@ -3760,16 +3762,16 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
if (bHiddenVolHost) if (bHiddenVolHost)
{ {
wcsncpy (str, GetString ("SIZE_HELP_HIDDEN_HOST_VOL"), sizeof (str) / 2); StringCbCopyW (str, sizeof(str), GetString ("SIZE_HELP_HIDDEN_HOST_VOL"));
} }
else 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 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"), GetString ((bHiddenOS && bHiddenVol) ? "SIZE_PARTITION_HIDDEN_SYSENC_HELP" : "SIZE_PARTITION_HELP"),
(bHiddenVolHost && !bHiddenOS) ? GetString ("SIZE_PARTITION_HIDDEN_VOL_HELP") : L""); (bHiddenVolHost && !bHiddenOS) ? GetString ("SIZE_PARTITION_HIDDEN_VOL_HELP") : L"");
} }
@@ -3823,7 +3825,7 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
if (nUIVolumeSize != 0) if (nUIVolumeSize != 0)
{ {
char szTmp[32]; char szTmp[32];
sprintf (szTmp, "%I64u", nUIVolumeSize); StringCbPrintfA (szTmp, sizeof(szTmp), "%I64u", nUIVolumeSize);
SetWindowText (GetDlgItem (hwndDlg, IDC_SIZEBOX), szTmp); SetWindowText (GetDlgItem (hwndDlg, IDC_SIZEBOX), szTmp);
} }
@@ -3882,7 +3884,7 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
ToBootPwdField (hwndDlg, IDC_PASSWORD); ToBootPwdField (hwndDlg, IDC_PASSWORD);
ToBootPwdField (hwndDlg, IDC_VERIFY); 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) if ((DWORD) GetKeyboardLayout (NULL) != 0x00000409 && (DWORD) GetKeyboardLayout (NULL) != 0x04090409)
{ {
@@ -3909,17 +3911,17 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
if (bHiddenVolHost) 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) 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 (bHiddenOS ? "PASSWORD_HIDDEN_OS_HELP" : "PASSWORD_HIDDENVOL_HELP"),
GetString ("PASSWORD_HELP")); GetString ("PASSWORD_HELP"));
} }
else 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_PASSWORD), EM_LIMITTEXT, MAX_PASSWORD, 0);
@@ -3966,22 +3968,22 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
Init2RadButtonPageYesNo (nNeedToStoreFilesOver4GB); Init2RadButtonPageYesNo (nNeedToStoreFilesOver4GB);
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("FILESYS_PAGE_TITLE")); 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) if (bHiddenVolHost)
wcscat (szTmp, L"\n\n"); StringCbCatW (szTmp, sizeof(szTmp), L"\n\n");
else else
{ {
wcscat (szTmp, L"\n\n\n"); StringCbCatW (szTmp, sizeof(szTmp), L"\n\n\n");
wcscat (szTmp, GetString ("NOTE_BEGINNING")); 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) if (bHiddenVolHost)
{ {
wcscat (szTmp, L" "); StringCbCatW (szTmp, sizeof(szTmp), L" ");
wcscat (szTmp, GetString ("FILESYS_PAGE_HELP_EXPLANATION_HIDVOL")); StringCbCatW (szTmp, sizeof(szTmp), GetString ("FILESYS_PAGE_HELP_EXPLANATION_HIDVOL"));
} }
SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), szTmp); SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), szTmp);
@@ -4049,7 +4051,7 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT")); SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT"));
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV")); 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"), GetString (bDontVerifyRescueDisk ? "RESCUE_DISK_BURN_INFO_NO_CHECK" : "RESCUE_DISK_BURN_INFO"),
szRescueDiskISO, IsWindowsIsoBurnerAvailable() ? L"" : GetString ("RESCUE_DISK_BURN_INFO_NONWIN_ISO_BURNER")); szRescueDiskISO, IsWindowsIsoBurnerAvailable() ? L"" : GetString ("RESCUE_DISK_BURN_INFO_NONWIN_ISO_BURNER"));
@@ -4129,7 +4131,7 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
try try
{ {
wsprintfW (finalMsg, StringCbPrintfW (finalMsg, sizeof(finalMsg),
GetString ("SYS_ENCRYPTION_PRETEST_INFO"), GetString ("SYS_ENCRYPTION_PRETEST_INFO"),
BootEncObj->GetSystemDriveConfiguration().DriveNumber); BootEncObj->GetSystemDriveConfiguration().DriveNumber);
} }
@@ -4493,12 +4495,12 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
// -50% reserve for filesystem "peculiarities" // -50% reserve for filesystem "peculiarities"
maxRecomOuterVolFillSize /= 2; 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 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 (hwndDlg, IDC_BOX_HELP), msg);
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("HIDVOL_HOST_FILLING_TITLE")); SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("HIDVOL_HOST_FILLING_TITLE"));
@@ -4738,9 +4740,9 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
bWarnOuterVolSuitableFileSys = FALSE; // Do not show this warning anymore (this also prevents potential endless repetition due to some race conditions) 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")); StringCbCopyW (szTmp, sizeof(szTmp), GetString ("FILESYS_PAGE_HELP_EXPLANATION_HIDVOL"));
wcscat (szTmp, L"\n\n"); StringCbCatW (szTmp, sizeof(szTmp), L"\n\n");
wcscat (szTmp, GetString ("FILESYS_PAGE_HELP_EXPLANATION_HIDVOL_CONFIRM")); StringCbCatW (szTmp, sizeof(szTmp), GetString ("FILESYS_PAGE_HELP_EXPLANATION_HIDVOL_CONFIRM"));
if (MessageBoxW (MainDlg, szTmp, lpszTitle, MB_ICONWARNING | MB_YESNO | MB_DEFBUTTON2) == IDNO) if (MessageBoxW (MainDlg, szTmp, lpszTitle, MB_ICONWARNING | MB_YESNO | MB_DEFBUTTON2) == IDNO)
{ {
@@ -4834,8 +4836,8 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
SetFocus (GetDlgItem (MainDlg, IDC_NEXT)); SetFocus (GetDlgItem (MainDlg, IDC_NEXT));
strcpy (szFileName, DeferredNonSysInPlaceEncDevices [selPartitionItemId].Path.c_str()); StringCbCopyA (szFileName, sizeof(szFileName), DeferredNonSysInPlaceEncDevices [selPartitionItemId].Path.c_str());
CreateFullVolumePath (szDiskFile, szFileName, &tmpbDevice); CreateFullVolumePath (szDiskFile, sizeof(szDiskFile), szFileName, &tmpbDevice);
nVolumeSize = GetDeviceSize (szDiskFile); nVolumeSize = GetDeviceSize (szDiskFile);
if (nVolumeSize == -1) if (nVolumeSize == -1)
@@ -5298,7 +5300,7 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
if (!BrowseFiles (hwndDlg, "OPEN_TITLE", tmpszRescueDiskISO, FALSE, TRUE, NULL)) if (!BrowseFiles (hwndDlg, "OPEN_TITLE", tmpszRescueDiskISO, FALSE, TRUE, NULL))
return 1; return 1;
strcpy (szRescueDiskISO, tmpszRescueDiskISO); StringCbCopyA (szRescueDiskISO, sizeof(szRescueDiskISO), tmpszRescueDiskISO);
SetDlgItemText (hwndDlg, IDC_RESCUE_DISK_ISO_PATH, szRescueDiskISO); SetDlgItemText (hwndDlg, IDC_RESCUE_DISK_ISO_PATH, szRescueDiskISO);
EnableWindow (GetDlgItem (MainDlg, IDC_NEXT), (GetWindowTextLength (GetDlgItem (hwndDlg, IDC_RESCUE_DISK_ISO_PATH)) > 1)); EnableWindow (GetDlgItem (MainDlg, IDC_NEXT), (GetWindowTextLength (GetDlgItem (hwndDlg, IDC_RESCUE_DISK_ISO_PATH)) > 1));
@@ -5431,7 +5433,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
} }
SHGetFolderPath (NULL, CSIDL_MYDOCUMENTS, NULL, 0, szRescueDiskISO); 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)) if (IsOSAtLeast (WIN_VISTA))
{ {
@@ -5485,8 +5487,8 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
for (i = 0; i < sizeof (tmp); i++) for (i = 0; i < sizeof (tmp); i++)
{ {
char tmp3[8]; char tmp3[8];
sprintf (tmp3, "%02X", (int) (unsigned char) tmp[i]); StringCbPrintfA (tmp3, sizeof(tmp3), "%02X", (int) (unsigned char) tmp[i]);
strcat (tmp2, tmp3); StringCbCatA (tmp2, sizeof(tmp2), tmp3);
} }
tmp2[32] = 0; tmp2[32] = 0;
@@ -5703,9 +5705,9 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
bKeyboardLayoutChanged = TRUE; bKeyboardLayoutChanged = TRUE;
wchar_t szTmp [4096]; wchar_t szTmp [4096];
wcscpy (szTmp, GetString ("KEYB_LAYOUT_CHANGE_PREVENTED")); StringCbCopyW (szTmp, sizeof(szTmp), GetString ("KEYB_LAYOUT_CHANGE_PREVENTED"));
wcscat (szTmp, L"\n\n"); StringCbCatW (szTmp, sizeof(szTmp), L"\n\n");
wcscat (szTmp, GetString ("KEYB_LAYOUT_SYS_ENC_EXPLANATION")); StringCbCatW (szTmp, sizeof(szTmp), GetString ("KEYB_LAYOUT_SYS_ENC_EXPLANATION"));
MessageBoxW (MainDlg, szTmp, lpszTitle, MB_ICONWARNING | MB_SETFOREGROUND | MB_TOPMOST); MessageBoxW (MainDlg, szTmp, lpszTitle, MB_ICONWARNING | MB_SETFOREGROUND | MB_TOPMOST);
} }
@@ -5718,9 +5720,9 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
bKeybLayoutAltKeyWarningShown = TRUE; bKeybLayoutAltKeyWarningShown = TRUE;
wchar_t szTmp [4096]; wchar_t szTmp [4096];
wcscpy (szTmp, GetString ("ALT_KEY_CHARS_NOT_FOR_SYS_ENCRYPTION")); StringCbCopyW (szTmp, sizeof(szTmp), GetString ("ALT_KEY_CHARS_NOT_FOR_SYS_ENCRYPTION"));
wcscat (szTmp, L"\n\n"); StringCbCatW (szTmp, sizeof(szTmp), L"\n\n");
wcscat (szTmp, GetString ("KEYB_LAYOUT_SYS_ENC_EXPLANATION")); StringCbCatW (szTmp, sizeof(szTmp), GetString ("KEYB_LAYOUT_SYS_ENC_EXPLANATION"));
MessageBoxW (MainDlg, szTmp, lpszTitle, MB_ICONINFORMATION | MB_SETFOREGROUND | MB_TOPMOST); MessageBoxW (MainDlg, szTmp, lpszTitle, MB_ICONINFORMATION | MB_SETFOREGROUND | MB_TOPMOST);
} }
} }
@@ -6413,7 +6415,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
GetWindowText (GetDlgItem (hCurPage, IDC_COMBO_BOX), szFileName, sizeof (szFileName)); GetWindowText (GetDlgItem (hCurPage, IDC_COMBO_BOX), szFileName, sizeof (szFileName));
RelativePath2Absolute (szFileName); RelativePath2Absolute (szFileName);
CreateFullVolumePath (szDiskFile, szFileName, &tmpbDevice); CreateFullVolumePath (szDiskFile, sizeof(szDiskFile), szFileName, &tmpbDevice);
if (tmpbDevice != bDevice) if (tmpbDevice != bDevice)
{ {
@@ -6885,7 +6887,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
} }
else if (DeferredNonSysInPlaceEncDevices.size() == 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); nVolumeSize = GetDeviceSize (szDiskFile);
if (nVolumeSize == -1) if (nVolumeSize == -1)
@@ -7042,7 +7044,7 @@ retryCDDriveCheck:
{ {
wchar_t szTmp[8000]; 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")); IsWindowsIsoBurnerAvailable () ? L"" : GetString ("RESCUE_DISK_CHECK_FAILED_SENTENCE_APPENDIX"));
ErrorDirect (szTmp); ErrorDirect (szTmp);
@@ -7592,7 +7594,7 @@ ovf_end:
BOOL tmpbDevice; BOOL tmpbDevice;
GetWindowText (GetDlgItem (hCurPage, IDC_COMBO_BOX), szFileName, sizeof (szFileName)); GetWindowText (GetDlgItem (hCurPage, IDC_COMBO_BOX), szFileName, sizeof (szFileName));
CreateFullVolumePath (szDiskFile, szFileName, &tmpbDevice); CreateFullVolumePath (szDiskFile, sizeof(szDiskFile), szFileName, &tmpbDevice);
if (tmpbDevice == bDevice) if (tmpbDevice == bDevice)
{ {

View File

@@ -56,7 +56,7 @@ namespace VeraCrypt
string volumeDevPath = favorite.Path; string volumeDevPath = favorite.Path;
wchar_t resolvedVolumeDevPath[TC_MAX_PATH]; wchar_t resolvedVolumeDevPath[TC_MAX_PATH];
if (ResolveSymbolicLink (SingleStringToWide (volumeDevPath).c_str(), resolvedVolumeDevPath)) if (ResolveSymbolicLink (SingleStringToWide (volumeDevPath).c_str(), resolvedVolumeDevPath, sizeof(resolvedVolumeDevPath)))
volumeDevPath = WideToSingleString (resolvedVolumeDevPath); volumeDevPath = WideToSingleString (resolvedVolumeDevPath);
char volumeName[TC_MAX_PATH]; char volumeName[TC_MAX_PATH];
@@ -414,7 +414,7 @@ namespace VeraCrypt
if (FavoriteVolumes.empty()) if (FavoriteVolumes.empty())
return; return;
AppendMenu (FavoriteVolumesMenu, MF_SEPARATOR, 0, NULL); AppendMenu (FavoriteVolumesMenu, MF_SEPARATOR, 0, "");
int i = 0; int i = 0;
foreach (const FavoriteVolume &favorite, FavoriteVolumes) foreach (const FavoriteVolume &favorite, FavoriteVolumes)

View File

@@ -13,6 +13,8 @@
#include "Mount.h" #include "Mount.h"
#include "Resource.h" #include "Resource.h"
#include <Strsafe.h>
#define MAX_KEY_COMB_NAME_LEN 260 #define MAX_KEY_COMB_NAME_LEN 260
TCHOTKEY Hotkeys [NBR_HOTKEYS]; TCHOTKEY Hotkeys [NBR_HOTKEYS];
@@ -46,56 +48,56 @@ BOOL GetKeyName (UINT vKey, wchar_t *keyName)
if (vKey >= 0x30 && vKey <= 0x5a) if (vKey >= 0x30 && vKey <= 0x5a)
{ {
// ASCII characters // ASCII characters
wsprintfW (keyName, L"%hc", (char) vKey); StringCbPrintfW (keyName, MAX_KEY_COMB_NAME_LEN, L"%hc", (char) vKey);
} }
else if (vKey >= 0xE9 && vKey <= 0xF5) else if (vKey >= 0xE9 && vKey <= 0xF5)
{ {
// OEM-specific // OEM-specific
wsprintfW (keyName, L"OEM-%d", vKey); StringCbPrintfW (keyName, MAX_KEY_COMB_NAME_LEN, L"OEM-%d", vKey);
} }
else if (vKey >= VK_F1 && vKey <= VK_F24) else if (vKey >= VK_F1 && vKey <= VK_F24)
{ {
// F1-F24 // F1-F24
wsprintfW (keyName, L"F%d", vKey - VK_F1 + 1); StringCbPrintfW (keyName, MAX_KEY_COMB_NAME_LEN, L"F%d", vKey - VK_F1 + 1);
} }
else if (vKey >= VK_NUMPAD0 && vKey <= VK_NUMPAD9) else if (vKey >= VK_NUMPAD0 && vKey <= VK_NUMPAD9)
{ {
// Numpad numbers // Numpad numbers
wsprintfW (keyName, L"%s %d", GetString ("VK_NUMPAD"), vKey - VK_NUMPAD0); StringCbPrintfW (keyName, MAX_KEY_COMB_NAME_LEN, L"%s %d", GetString ("VK_NUMPAD"), vKey - VK_NUMPAD0);
} }
else else
{ {
switch (vKey) switch (vKey)
{ {
case VK_MULTIPLY: wsprintfW (keyName, L"%s *", GetString ("VK_NUMPAD")); break; case VK_MULTIPLY: StringCbPrintfW (keyName, MAX_KEY_COMB_NAME_LEN, L"%s *", GetString ("VK_NUMPAD")); break;
case VK_ADD: wsprintfW (keyName, L"%s +", GetString ("VK_NUMPAD")); break; case VK_ADD: StringCbPrintfW (keyName, MAX_KEY_COMB_NAME_LEN, L"%s +", GetString ("VK_NUMPAD")); break;
case VK_SEPARATOR: wsprintfW (keyName, L"%s Separator", GetString ("VK_NUMPAD")); break; case VK_SEPARATOR: StringCbPrintfW (keyName, MAX_KEY_COMB_NAME_LEN, L"%s Separator", GetString ("VK_NUMPAD")); break;
case VK_SUBTRACT: wsprintfW (keyName, L"%s -", GetString ("VK_NUMPAD")); break; case VK_SUBTRACT: StringCbPrintfW (keyName, MAX_KEY_COMB_NAME_LEN, L"%s -", GetString ("VK_NUMPAD")); break;
case VK_DECIMAL: wsprintfW (keyName, L"%s .", GetString ("VK_NUMPAD")); break; case VK_DECIMAL: StringCbPrintfW (keyName, MAX_KEY_COMB_NAME_LEN, L"%s .", GetString ("VK_NUMPAD")); break;
case VK_DIVIDE: wsprintfW (keyName, L"%s /", GetString ("VK_NUMPAD")); break; case VK_DIVIDE: StringCbPrintfW (keyName, MAX_KEY_COMB_NAME_LEN, L"%s /", GetString ("VK_NUMPAD")); break;
case VK_OEM_1: wcscpy (keyName, L"OEM 1 (';')"); break; case VK_OEM_1: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"OEM 1 (';')"); break;
case VK_OEM_PLUS: wcscpy (keyName, L"+"); break; case VK_OEM_PLUS: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"+"); break;
case VK_OEM_COMMA: wcscpy (keyName, L","); break; case VK_OEM_COMMA: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L","); break;
case VK_OEM_MINUS: wcscpy (keyName, L"-"); break; case VK_OEM_MINUS: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"-"); break;
case VK_OEM_PERIOD: wcscpy (keyName, L"."); break; case VK_OEM_PERIOD: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"."); break;
case VK_OEM_2: wcscpy (keyName, L"OEM 2 ('/')"); break; case VK_OEM_2: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"OEM 2 ('/')"); break;
case VK_OEM_3: wcscpy (keyName, L"OEM 3 (`)"); break; case VK_OEM_3: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"OEM 3 (`)"); break;
case VK_OEM_4: wcscpy (keyName, L"OEM 4 ('[')"); break; case VK_OEM_4: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"OEM 4 ('[')"); break;
case VK_OEM_5: wcscpy (keyName, L"OEM 5 ('\\')"); break; case VK_OEM_5: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"OEM 5 ('\\')"); break;
case VK_OEM_6: wcscpy (keyName, L"OEM 6 (']')"); break; case VK_OEM_6: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"OEM 6 (']')"); break;
case VK_OEM_7: wcscpy (keyName, L"OEM 7 (')"); break; case VK_OEM_7: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"OEM 7 (')"); break;
case VK_OEM_8: wcscpy (keyName, L"OEM 8"); break; case VK_OEM_8: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"OEM 8"); break;
case VK_OEM_AX: wcscpy (keyName, L"OEM AX"); break; case VK_OEM_AX: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"OEM AX"); break;
case VK_OEM_102: wcscpy (keyName, L"OEM 102"); break; case VK_OEM_102: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"OEM 102"); break;
case VK_ICO_HELP: wcscpy (keyName, L"ICO_HELP"); break; case VK_ICO_HELP: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"ICO_HELP"); break;
case VK_ICO_00: wcscpy (keyName, L"ICO_00"); break; case VK_ICO_00: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"ICO_00"); break;
case VK_ICO_CLEAR: wcscpy (keyName, L"ICO_CLEAR"); break; case VK_ICO_CLEAR: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"ICO_CLEAR"); break;
case VK_ATTN: wcscpy (keyName, L"Attn"); break; case VK_ATTN: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"Attn"); break;
case VK_CRSEL: wcscpy (keyName, L"CrSel"); break; case VK_CRSEL: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"CrSel"); break;
case VK_EXSEL: wcscpy (keyName, L"ExSel"); break; case VK_EXSEL: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"ExSel"); break;
case VK_EREOF: wcscpy (keyName, L"Erase EOF"); break; case VK_EREOF: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"Erase EOF"); break;
case VK_PA1: wcscpy (keyName, L"PA1"); break; case VK_PA1: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"PA1"); break;
case VK_OEM_CLEAR: wcscpy (keyName, L"OEM Clear"); break; case VK_OEM_CLEAR: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"OEM Clear"); break;
case 0: case 0:
case 1: case 1:
@@ -107,12 +109,12 @@ BOOL GetKeyName (UINT vKey, wchar_t *keyName)
{ {
char key[16]; char key[16];
wchar_t *desc; wchar_t *desc;
sprintf (key, "VKEY_%02X", vKey); StringCbPrintfA (key, sizeof(key),"VKEY_%02X", vKey);
desc = GetString (key); desc = GetString (key);
if (desc == UnknownString) if (desc == UnknownString)
result = FALSE; result = FALSE;
else else
wcsncpy (keyName, desc, MAX_KEY_COMB_NAME_LEN); StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, desc);
} }
} }
} }
@@ -226,36 +228,36 @@ static void DisplayHotkeyList (HWND hwndDlg)
SendMessageW (hList,LVM_INSERTITEMW,0,(LPARAM)&item); SendMessageW (hList,LVM_INSERTITEMW,0,(LPARAM)&item);
item.iSubItem = 1; item.iSubItem = 1;
wcscpy (Shortcut, L""); Shortcut[0] = 0;
wcscpy (ShortcutMod, L""); ShortcutMod[0] = 0;
if (GetKeyName (tmpHotkeys[i].vKeyCode, Shortcut)) if (GetKeyName (tmpHotkeys[i].vKeyCode, Shortcut))
{ {
if (tmpHotkeys[i].vKeyModifiers & MOD_CONTROL) if (tmpHotkeys[i].vKeyModifiers & MOD_CONTROL)
{ {
wcscat (ShortcutMod, GetString ("VK_CONTROL")); StringCbCatW (ShortcutMod, sizeof(ShortcutMod),GetString ("VK_CONTROL"));
wcscat (ShortcutMod, L"+"); StringCbCatW (ShortcutMod, sizeof(ShortcutMod),L"+");
} }
if (tmpHotkeys[i].vKeyModifiers & MOD_SHIFT) if (tmpHotkeys[i].vKeyModifiers & MOD_SHIFT)
{ {
wcscat (ShortcutMod, GetString ("VK_SHIFT")); StringCbCatW (ShortcutMod, sizeof(ShortcutMod),GetString ("VK_SHIFT"));
wcscat (ShortcutMod, L"+"); StringCbCatW (ShortcutMod, sizeof(ShortcutMod),L"+");
} }
if (tmpHotkeys[i].vKeyModifiers & MOD_ALT) if (tmpHotkeys[i].vKeyModifiers & MOD_ALT)
{ {
wcscat (ShortcutMod, GetString ("VK_ALT")); StringCbCatW (ShortcutMod, sizeof(ShortcutMod),GetString ("VK_ALT"));
wcscat (ShortcutMod, L"+"); StringCbCatW (ShortcutMod, sizeof(ShortcutMod),L"+");
} }
if (tmpHotkeys[i].vKeyModifiers & MOD_WIN) if (tmpHotkeys[i].vKeyModifiers & MOD_WIN)
{ {
wcscat (ShortcutMod, GetString ("VK_WIN")); StringCbCatW (ShortcutMod, sizeof(ShortcutMod),GetString ("VK_WIN"));
wcscat (ShortcutMod, L"+"); StringCbCatW (ShortcutMod, sizeof(ShortcutMod),L"+");
} }
wsprintfW (ShortcutFinal, L"%s%s", ShortcutMod, Shortcut); StringCbPrintfW (ShortcutFinal, sizeof(ShortcutFinal), L"%s%s", ShortcutMod, Shortcut);
item.pszText = ShortcutFinal; item.pszText = ShortcutFinal;
} }
else else

View File

@@ -46,6 +46,8 @@
#include "../Platform/Finally.h" #include "../Platform/Finally.h"
#include "../Platform/ForEach.h" #include "../Platform/ForEach.h"
#include <Strsafe.h>
using namespace VeraCrypt; using namespace VeraCrypt;
enum timer_ids enum timer_ids
@@ -534,7 +536,7 @@ void SaveSettings (HWND hwndDlg)
// Drive Letter // Drive Letter
lLetter = GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST)); lLetter = GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST));
if (LOWORD (lLetter) != 0xffff) if (LOWORD (lLetter) != 0xffff)
sprintf (szTmp, "%c:", (char) HIWORD (lLetter)); StringCbPrintfA (szTmp, sizeof(szTmp), "%c:", (char) HIWORD (lLetter));
ConfigWriteString ("LastSelectedDrive", szTmp); ConfigWriteString ("LastSelectedDrive", szTmp);
ConfigWriteInt ("CloseSecurityTokenSessionsAfterMount", CloseSecurityTokenSessionsAfterMount); ConfigWriteInt ("CloseSecurityTokenSessionsAfterMount", CloseSecurityTokenSessionsAfterMount);
@@ -721,19 +723,19 @@ static void PopulateSysEncContextMenu (HMENU popup, BOOL bToolsOnly)
AppendMenuW (popup, MF_STRING, IDM_PERMANENTLY_DECRYPT_SYS, GetString ("PERMANENTLY_DECRYPT")); AppendMenuW (popup, MF_STRING, IDM_PERMANENTLY_DECRYPT_SYS, GetString ("PERMANENTLY_DECRYPT"));
AppendMenuW (popup, MF_STRING, IDM_ENCRYPT_SYSTEM_DEVICE, GetString ("ENCRYPT")); AppendMenuW (popup, MF_STRING, IDM_ENCRYPT_SYSTEM_DEVICE, GetString ("ENCRYPT"));
AppendMenu (popup, MF_SEPARATOR, 0, NULL); AppendMenu (popup, MF_SEPARATOR, 0, "");
} }
} }
AppendMenuW (popup, MF_STRING, IDM_CHANGE_SYS_PASSWORD, GetString ("IDM_CHANGE_SYS_PASSWORD")); AppendMenuW (popup, MF_STRING, IDM_CHANGE_SYS_PASSWORD, GetString ("IDM_CHANGE_SYS_PASSWORD"));
AppendMenuW (popup, MF_STRING, IDM_CHANGE_SYS_HEADER_KEY_DERIV_ALGO, GetString ("IDM_CHANGE_SYS_HEADER_KEY_DERIV_ALGO")); AppendMenuW (popup, MF_STRING, IDM_CHANGE_SYS_HEADER_KEY_DERIV_ALGO, GetString ("IDM_CHANGE_SYS_HEADER_KEY_DERIV_ALGO"));
AppendMenu (popup, MF_SEPARATOR, 0, NULL); AppendMenu (popup, MF_SEPARATOR, 0, "");
AppendMenuW (popup, MF_STRING, IDM_SYS_ENC_SETTINGS, GetString ("IDM_SYS_ENC_SETTINGS")); AppendMenuW (popup, MF_STRING, IDM_SYS_ENC_SETTINGS, GetString ("IDM_SYS_ENC_SETTINGS"));
if (!IsHiddenOSRunning()) if (!IsHiddenOSRunning())
{ {
AppendMenu (popup, MF_SEPARATOR, 0, NULL); AppendMenu (popup, MF_SEPARATOR, 0, "");
AppendMenuW (popup, MF_STRING, IDM_CREATE_RESCUE_DISK, GetString ("IDM_CREATE_RESCUE_DISK")); AppendMenuW (popup, MF_STRING, IDM_CREATE_RESCUE_DISK, GetString ("IDM_CREATE_RESCUE_DISK"));
AppendMenuW (popup, MF_STRING, IDM_VERIFY_RESCUE_DISK, GetString ("IDM_VERIFY_RESCUE_DISK")); AppendMenuW (popup, MF_STRING, IDM_VERIFY_RESCUE_DISK, GetString ("IDM_VERIFY_RESCUE_DISK"));
} }
@@ -742,10 +744,10 @@ static void PopulateSysEncContextMenu (HMENU popup, BOOL bToolsOnly)
{ {
if (SysDriveOrPartitionFullyEncrypted (FALSE) && !IsHiddenOSRunning()) if (SysDriveOrPartitionFullyEncrypted (FALSE) && !IsHiddenOSRunning())
{ {
AppendMenu (popup, MF_SEPARATOR, 0, NULL); AppendMenu (popup, MF_SEPARATOR, 0, "");
AppendMenuW (popup, MF_STRING, IDM_PERMANENTLY_DECRYPT_SYS, GetString ("PERMANENTLY_DECRYPT")); AppendMenuW (popup, MF_STRING, IDM_PERMANENTLY_DECRYPT_SYS, GetString ("PERMANENTLY_DECRYPT"));
} }
AppendMenu (popup, MF_SEPARATOR, 0, NULL); AppendMenu (popup, MF_SEPARATOR, 0, "");
AppendMenuW (popup, MF_STRING, IDM_VOLUME_PROPERTIES, GetString ("IDPM_PROPERTIES")); AppendMenuW (popup, MF_STRING, IDM_VOLUME_PROPERTIES, GetString ("IDPM_PROPERTIES"));
} }
} }
@@ -764,7 +766,7 @@ BOOL CheckSysEncMountWithoutPBA (const char *devicePath, BOOL quiet)
if (strlen (devicePath) < 2) if (strlen (devicePath) < 2)
{ {
GetWindowText (GetDlgItem (MainDlg, IDC_VOLUME), szDevicePath, sizeof (szDevicePath)); GetWindowText (GetDlgItem (MainDlg, IDC_VOLUME), szDevicePath, sizeof (szDevicePath));
CreateFullVolumePath (szDiskFile, szDevicePath, &tmpbDevice); CreateFullVolumePath (szDiskFile, sizeof(szDiskFile), szDevicePath, &tmpbDevice);
if (!tmpbDevice) if (!tmpbDevice)
{ {
@@ -783,7 +785,7 @@ BOOL CheckSysEncMountWithoutPBA (const char *devicePath, BOOL quiet)
} }
} }
else else
strncpy (szDevicePath, devicePath, sizeof (szDevicePath) - 1); StringCbCopyA (szDevicePath, sizeof(szDevicePath), devicePath);
char *partionPortion = strrchr (szDevicePath, '\\'); char *partionPortion = strrchr (szDevicePath, '\\');
@@ -815,7 +817,7 @@ BOOL CheckSysEncMountWithoutPBA (const char *devicePath, BOOL quiet)
return FALSE; return FALSE;
} }
_snprintf (parentDrivePath, StringCbPrintfA (parentDrivePath,
sizeof (parentDrivePath), sizeof (parentDrivePath),
"\\Device\\Harddisk%d\\Partition0", "\\Device\\Harddisk%d\\Partition0",
driveNo); driveNo);
@@ -872,7 +874,7 @@ BOOL TCBootLoaderOnInactiveSysEncDrive (void)
if (sscanf (szDevicePath, "\\Device\\Harddisk%d\\Partition", &driveNo) != 1) if (sscanf (szDevicePath, "\\Device\\Harddisk%d\\Partition", &driveNo) != 1)
return FALSE; return FALSE;
_snprintf (parentDrivePath, StringCbPrintfA (parentDrivePath,
sizeof (parentDrivePath), sizeof (parentDrivePath),
"\\Device\\Harddisk%d\\Partition0", "\\Device\\Harddisk%d\\Partition0",
driveNo); driveNo);
@@ -949,15 +951,16 @@ static void LaunchVolCreationWizard (HWND hwndDlg, const char *arg)
PROCESS_INFORMATION pi; PROCESS_INFORMATION pi;
ZeroMemory (&si, sizeof (si)); ZeroMemory (&si, sizeof (si));
strcpy (++tmp, "VeraCrypt Format.exe\""); *tmp = 0;
StringCbCopyA (t, sizeof(t), "\\VeraCrypt Format.exe\"");
if (!FileExists(t)) if (!FileExists(t))
Error ("VOL_CREATION_WIZARD_NOT_FOUND"); // Display a user-friendly error message and advise what to do Error ("VOL_CREATION_WIZARD_NOT_FOUND"); // Display a user-friendly error message and advise what to do
if (strlen (arg) > 0) if (strlen (arg) > 0)
{ {
strcat (t, " "); StringCbCatA (t, sizeof(t), " ");
strcat (t, arg); StringCbCatA (t, sizeof(t), arg);
} }
if (!CreateProcess (NULL, (LPSTR) t, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi)) if (!CreateProcess (NULL, (LPSTR) t, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi))
@@ -1068,7 +1071,8 @@ void LoadDriveLetters (HWND hTree, int drive)
listItem.iItem = item++; listItem.iItem = item++;
listItem.pszText = szTmp; listItem.pszText = szTmp;
strcpy (szTmp, " "); szTmp[0] = ' ';
szTmp[1] = 0;
listItem.lParam = MAKELONG (TC_MLIST_ITEM_SYS_DRIVE, ENC_SYSDRIVE_PSEUDO_DRIVE_LETTER); listItem.lParam = MAKELONG (TC_MLIST_ITEM_SYS_DRIVE, ENC_SYSDRIVE_PSEUDO_DRIVE_LETTER);
@@ -1082,7 +1086,7 @@ void LoadDriveLetters (HWND hTree, int drive)
// Fully encrypted // Fully encrypted
if (SysDriveOrPartitionFullyEncrypted (TRUE)) if (SysDriveOrPartitionFullyEncrypted (TRUE))
{ {
wcscpy (szTmpW, GetString ("SYSTEM_DRIVE")); StringCbCopyW (szTmpW, sizeof(szTmpW), GetString ("SYSTEM_DRIVE"));
} }
else else
{ {
@@ -1094,23 +1098,23 @@ void LoadDriveLetters (HWND hTree, int drive)
if (BootEncStatus.SetupMode != SetupDecryption) if (BootEncStatus.SetupMode != SetupDecryption)
{ {
_snwprintf (szTmpW, StringCbPrintfW (szTmpW,
sizeof szTmpW/2, sizeof szTmpW,
GetString ("SYSTEM_DRIVE_ENCRYPTING"), GetString ("SYSTEM_DRIVE_ENCRYPTING"),
(double) GetSysEncDeviceEncryptedPartSize (TRUE) / (double) GetSysEncDeviceSize (TRUE) * 100.0); (double) GetSysEncDeviceEncryptedPartSize (TRUE) / (double) GetSysEncDeviceSize (TRUE) * 100.0);
} }
else else
{ {
_snwprintf (szTmpW, StringCbPrintfW (szTmpW,
sizeof szTmpW/2, sizeof szTmpW,
GetString ("SYSTEM_DRIVE_DECRYPTING"), GetString ("SYSTEM_DRIVE_DECRYPTING"),
100.0 - ((double) GetSysEncDeviceEncryptedPartSize (TRUE) / (double) GetSysEncDeviceSize (TRUE) * 100.0)); 100.0 - ((double) GetSysEncDeviceEncryptedPartSize (TRUE) / (double) GetSysEncDeviceSize (TRUE) * 100.0));
} }
} }
else else
{ {
_snwprintf (szTmpW, StringCbPrintfW (szTmpW,
sizeof szTmpW/2, sizeof szTmpW,
GetString ("SYSTEM_DRIVE_PARTIALLY_ENCRYPTED"), GetString ("SYSTEM_DRIVE_PARTIALLY_ENCRYPTED"),
(double) GetSysEncDeviceEncryptedPartSize (TRUE) / (double) GetSysEncDeviceSize (TRUE) * 100.0); (double) GetSysEncDeviceEncryptedPartSize (TRUE) / (double) GetSysEncDeviceSize (TRUE) * 100.0);
} }
@@ -1118,7 +1122,7 @@ void LoadDriveLetters (HWND hTree, int drive)
ListSubItemSetW (hTree, listItem.iItem, 1, szTmpW); ListSubItemSetW (hTree, listItem.iItem, 1, szTmpW);
GetSizeString (GetSysEncDeviceSize(TRUE), szTmpW); GetSizeString (GetSysEncDeviceSize(TRUE), szTmpW, sizeof(szTmpW));
ListSubItemSetW (hTree, listItem.iItem, 2, szTmpW); ListSubItemSetW (hTree, listItem.iItem, 2, szTmpW);
EAGetName (szTmp, propSysEnc.ea); EAGetName (szTmp, propSysEnc.ea);
@@ -1182,7 +1186,7 @@ void LoadDriveLetters (HWND hTree, int drive)
// Fully encrypted // Fully encrypted
if (SysDriveOrPartitionFullyEncrypted (TRUE)) if (SysDriveOrPartitionFullyEncrypted (TRUE))
{ {
wcscpy (szTmpW, GetString (IsHiddenOSRunning() ? "HIDDEN_SYSTEM_PARTITION" : "SYSTEM_PARTITION")); StringCbCopyW (szTmpW, sizeof(szTmpW), GetString (IsHiddenOSRunning() ? "HIDDEN_SYSTEM_PARTITION" : "SYSTEM_PARTITION"));
} }
else else
{ {
@@ -1194,23 +1198,23 @@ void LoadDriveLetters (HWND hTree, int drive)
if (BootEncStatus.SetupMode != SetupDecryption) if (BootEncStatus.SetupMode != SetupDecryption)
{ {
_snwprintf (szTmpW, StringCbPrintfW (szTmpW,
sizeof szTmpW/2, sizeof szTmpW,
GetString ("SYSTEM_PARTITION_ENCRYPTING"), GetString ("SYSTEM_PARTITION_ENCRYPTING"),
(double) GetSysEncDeviceEncryptedPartSize (TRUE) / (double) GetSysEncDeviceSize (TRUE) * 100.0); (double) GetSysEncDeviceEncryptedPartSize (TRUE) / (double) GetSysEncDeviceSize (TRUE) * 100.0);
} }
else else
{ {
_snwprintf (szTmpW, StringCbPrintfW (szTmpW,
sizeof szTmpW/2, sizeof szTmpW,
GetString ("SYSTEM_PARTITION_DECRYPTING"), GetString ("SYSTEM_PARTITION_DECRYPTING"),
100.0 - ((double) GetSysEncDeviceEncryptedPartSize (TRUE) / (double) GetSysEncDeviceSize (TRUE) * 100.0)); 100.0 - ((double) GetSysEncDeviceEncryptedPartSize (TRUE) / (double) GetSysEncDeviceSize (TRUE) * 100.0));
} }
} }
else else
{ {
_snwprintf (szTmpW, StringCbPrintfW (szTmpW,
sizeof szTmpW/2, sizeof szTmpW,
GetString ("SYSTEM_PARTITION_PARTIALLY_ENCRYPTED"), GetString ("SYSTEM_PARTITION_PARTIALLY_ENCRYPTED"),
(double) GetSysEncDeviceEncryptedPartSize (TRUE) / (double) GetSysEncDeviceSize (TRUE) * 100.0); (double) GetSysEncDeviceEncryptedPartSize (TRUE) / (double) GetSysEncDeviceSize (TRUE) * 100.0);
} }
@@ -1220,7 +1224,7 @@ void LoadDriveLetters (HWND hTree, int drive)
} }
else else
{ {
ToSBCS (driver.wszVolume[i]); ToSBCS (driver.wszVolume[i], sizeof(driver.wszVolume[i]));
char *path = (char *) driver.wszVolume[i]; char *path = (char *) driver.wszVolume[i];
if (memcmp (path, "\\??\\", 4) == 0) if (memcmp (path, "\\??\\", 4) == 0)
@@ -1235,7 +1239,7 @@ void LoadDriveLetters (HWND hTree, int drive)
ListSubItemSet (hTree, listItem.iItem, 1, (char *) FitPathInGfxWidth (hTree, hUserFont, ListView_GetColumnWidth (hTree, 1) - GetTextGfxWidth (hTree, L"___", hUserFont), path).c_str()); ListSubItemSet (hTree, listItem.iItem, 1, (char *) FitPathInGfxWidth (hTree, hUserFont, ListView_GetColumnWidth (hTree, 1) - GetTextGfxWidth (hTree, L"___", hUserFont), path).c_str());
} }
GetSizeString (bSysEncPartition ? GetSysEncDeviceSize(TRUE) : driver.diskLength[i], szTmpW); GetSizeString (bSysEncPartition ? GetSysEncDeviceSize(TRUE) : driver.diskLength[i], szTmpW, sizeof(szTmpW));
ListSubItemSetW (hTree, listItem.iItem, 2, szTmpW); ListSubItemSetW (hTree, listItem.iItem, 2, szTmpW);
EAGetName (szTmp, bSysEncPartition ? propSysEnc.ea : driver.ea[i]); EAGetName (szTmp, bSysEncPartition ? propSysEnc.ea : driver.ea[i]);
@@ -1276,7 +1280,7 @@ void LoadDriveLetters (HWND hTree, int drive)
wchar_t szTmp[4096]; wchar_t szTmp[4096];
VolumeNotificationsList.bHidVolDamagePrevReported[i] = TRUE; VolumeNotificationsList.bHidVolDamagePrevReported[i] = TRUE;
swprintf (szTmp, GetString ("DAMAGE_TO_HIDDEN_VOLUME_PREVENTED"), i+'A'); StringCbPrintfW (szTmp, sizeof(szTmp), GetString ("DAMAGE_TO_HIDDEN_VOLUME_PREVENTED"), i+'A');
SetForegroundWindow (GetParent(hTree)); SetForegroundWindow (GetParent(hTree));
MessageBoxW (GetParent(hTree), szTmp, lpszTitle, MB_ICONWARNING | MB_SETFOREGROUND | MB_TOPMOST); MessageBoxW (GetParent(hTree), szTmp, lpszTitle, MB_ICONWARNING | MB_SETFOREGROUND | MB_TOPMOST);
} }
@@ -1554,9 +1558,9 @@ BOOL CALLBACK PasswordChangeDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPAR
bKeyboardLayoutChanged = TRUE; bKeyboardLayoutChanged = TRUE;
wchar_t szTmp [4096]; wchar_t szTmp [4096];
wcscpy (szTmp, GetString ("KEYB_LAYOUT_CHANGE_PREVENTED")); StringCbCopyW (szTmp, sizeof(szTmp), GetString ("KEYB_LAYOUT_CHANGE_PREVENTED"));
wcscat (szTmp, L"\n\n"); StringCbCatW (szTmp, sizeof(szTmp), L"\n\n");
wcscat (szTmp, GetString ("KEYB_LAYOUT_SYS_ENC_EXPLANATION")); StringCbCatW (szTmp, sizeof(szTmp), GetString ("KEYB_LAYOUT_SYS_ENC_EXPLANATION"));
MessageBoxW (MainDlg, szTmp, lpszTitle, MB_ICONWARNING | MB_SETFOREGROUND | MB_TOPMOST); MessageBoxW (MainDlg, szTmp, lpszTitle, MB_ICONWARNING | MB_SETFOREGROUND | MB_TOPMOST);
} }
@@ -1570,9 +1574,9 @@ BOOL CALLBACK PasswordChangeDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPAR
bKeybLayoutAltKeyWarningShown = TRUE; bKeybLayoutAltKeyWarningShown = TRUE;
wchar_t szTmp [4096]; wchar_t szTmp [4096];
wcscpy (szTmp, GetString ("ALT_KEY_CHARS_NOT_FOR_SYS_ENCRYPTION")); StringCbCopyW (szTmp, sizeof(szTmp), GetString ("ALT_KEY_CHARS_NOT_FOR_SYS_ENCRYPTION"));
wcscat (szTmp, L"\n\n"); StringCbCatW (szTmp, sizeof(szTmp), L"\n\n");
wcscat (szTmp, GetString ("KEYB_LAYOUT_SYS_ENC_EXPLANATION")); StringCbCatW (szTmp, sizeof(szTmp), GetString ("KEYB_LAYOUT_SYS_ENC_EXPLANATION"));
MessageBoxW (MainDlg, szTmp, lpszTitle, MB_ICONINFORMATION | MB_SETFOREGROUND | MB_TOPMOST); MessageBoxW (MainDlg, szTmp, lpszTitle, MB_ICONINFORMATION | MB_SETFOREGROUND | MB_TOPMOST);
} }
} }
@@ -1899,12 +1903,12 @@ BOOL CALLBACK PasswordDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
wstring label = GetFavoriteVolumeLabel (PasswordDlgVolume); wstring label = GetFavoriteVolumeLabel (PasswordDlgVolume);
if (!label.empty()) if (!label.empty())
{ {
wsprintfW (s, GetString ("ENTER_PASSWORD_FOR_LABEL"), label.c_str()); StringCbPrintfW (s, sizeof(s), GetString ("ENTER_PASSWORD_FOR_LABEL"), label.c_str());
} }
else else
{ {
wsprintfW (s, GetString ("ENTER_PASSWORD_FOR"), "___"); StringCbPrintfW (s, sizeof(s), GetString ("ENTER_PASSWORD_FOR"), "___");
wsprintfW (s, GetString ("ENTER_PASSWORD_FOR"), FitPathInGfxWidth (hwndDlg, WindowTitleBarFont, rect.right - rect.left - GetTextGfxWidth (hwndDlg, s, WindowTitleBarFont), PasswordDlgVolume).c_str()); StringCbPrintfW (s, sizeof(s), GetString ("ENTER_PASSWORD_FOR"), FitPathInGfxWidth (hwndDlg, WindowTitleBarFont, rect.right - rect.left - GetTextGfxWidth (hwndDlg, s, WindowTitleBarFont), PasswordDlgVolume).c_str());
} }
SetWindowTextW (hwndDlg, s); SetWindowTextW (hwndDlg, s);
@@ -1957,7 +1961,7 @@ BOOL CALLBACK PasswordDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), tmp); SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), tmp);
SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), ""); SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), "");
sprintf (OrigKeyboardLayout, "%08X", (DWORD) GetKeyboardLayout (NULL) & 0xFFFF); StringCbPrintfA (OrigKeyboardLayout, sizeof(OrigKeyboardLayout),"%08X", (DWORD) GetKeyboardLayout (NULL) & 0xFFFF);
DWORD keybLayout = (DWORD) LoadKeyboardLayout ("00000409", KLF_ACTIVATE); DWORD keybLayout = (DWORD) LoadKeyboardLayout ("00000409", KLF_ACTIVATE);
@@ -2015,9 +2019,9 @@ BOOL CALLBACK PasswordDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
} }
wchar_t szTmp [4096]; wchar_t szTmp [4096];
wcscpy (szTmp, GetString ("KEYB_LAYOUT_CHANGE_PREVENTED")); StringCbCopyW (szTmp, sizeof(szTmp), GetString ("KEYB_LAYOUT_CHANGE_PREVENTED"));
wcscat (szTmp, L"\n\n"); StringCbCatW (szTmp, sizeof(szTmp), L"\n\n");
wcscat (szTmp, GetString ("KEYB_LAYOUT_SYS_ENC_EXPLANATION")); StringCbCatW (szTmp, sizeof(szTmp), GetString ("KEYB_LAYOUT_SYS_ENC_EXPLANATION"));
MessageBoxW (MainDlg, szTmp, lpszTitle, MB_ICONWARNING | MB_SETFOREGROUND | MB_TOPMOST); MessageBoxW (MainDlg, szTmp, lpszTitle, MB_ICONWARNING | MB_SETFOREGROUND | MB_TOPMOST);
} }
} }
@@ -2152,9 +2156,12 @@ BOOL CALLBACK PasswordDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
while (count-- > 0) while (count-- > 0)
{ {
KeyFile *kf = (KeyFile *) malloc (sizeof (KeyFile)); KeyFile *kf = (KeyFile *) malloc (sizeof (KeyFile));
DragQueryFile (hdrop, i++, kf->FileName, sizeof (kf->FileName)); if (kf)
FirstKeyFile = KeyFileAdd (FirstKeyFile, kf); {
KeyFilesEnable = TRUE; DragQueryFile (hdrop, i++, kf->FileName, sizeof (kf->FileName));
FirstKeyFile = KeyFileAdd (FirstKeyFile, kf);
KeyFilesEnable = TRUE;
}
} }
SetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE, KeyFilesEnable); SetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE, KeyFilesEnable);
@@ -2351,23 +2358,27 @@ BOOL CALLBACK PreferencesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM
if (lw == IDC_MORE_SETTINGS) if (lw == IDC_MORE_SETTINGS)
{ {
HMENU popup = CreatePopupMenu (); HMENU popup = CreatePopupMenu ();
if (popup)
{
AppendMenuW (popup, MF_STRING, IDM_LANGUAGE, GetString ("IDM_LANGUAGE"));
AppendMenuW (popup, MF_STRING, IDM_HOTKEY_SETTINGS, GetString ("IDM_HOTKEY_SETTINGS"));
AppendMenuW (popup, MF_STRING, IDM_PERFORMANCE_SETTINGS, GetString ("IDM_PERFORMANCE_SETTINGS"));
AppendMenuW (popup, MF_STRING, IDM_SYSENC_SETTINGS, GetString ("IDM_SYSENC_SETTINGS"));
AppendMenuW (popup, MF_STRING, IDM_SYS_FAVORITES_SETTINGS, GetString ("IDM_SYS_FAVORITES_SETTINGS"));
AppendMenuW (popup, MF_STRING, IDM_DEFAULT_KEYFILES, GetString ("IDM_DEFAULT_KEYFILES"));
AppendMenuW (popup, MF_STRING, IDM_TOKEN_PREFERENCES, GetString ("IDM_TOKEN_PREFERENCES"));
AppendMenuW (popup, MF_STRING, IDM_LANGUAGE, GetString ("IDM_LANGUAGE")); RECT rect;
AppendMenuW (popup, MF_STRING, IDM_HOTKEY_SETTINGS, GetString ("IDM_HOTKEY_SETTINGS")); GetWindowRect (GetDlgItem (hwndDlg, IDC_MORE_SETTINGS), &rect);
AppendMenuW (popup, MF_STRING, IDM_PERFORMANCE_SETTINGS, GetString ("IDM_PERFORMANCE_SETTINGS"));
AppendMenuW (popup, MF_STRING, IDM_SYSENC_SETTINGS, GetString ("IDM_SYSENC_SETTINGS"));
AppendMenuW (popup, MF_STRING, IDM_SYS_FAVORITES_SETTINGS, GetString ("IDM_SYS_FAVORITES_SETTINGS"));
AppendMenuW (popup, MF_STRING, IDM_DEFAULT_KEYFILES, GetString ("IDM_DEFAULT_KEYFILES"));
AppendMenuW (popup, MF_STRING, IDM_TOKEN_PREFERENCES, GetString ("IDM_TOKEN_PREFERENCES"));
RECT rect; int menuItem = TrackPopupMenu (popup, TPM_RETURNCMD | TPM_LEFTBUTTON, rect.left + 2, rect.top + 2, 0, hwndDlg, NULL);
GetWindowRect (GetDlgItem (hwndDlg, IDC_MORE_SETTINGS), &rect); DestroyMenu (popup);
int menuItem = TrackPopupMenu (popup, TPM_RETURNCMD | TPM_LEFTBUTTON, rect.left + 2, rect.top + 2, 0, hwndDlg, NULL); SendMessage (MainDlg, WM_COMMAND, menuItem, NULL);
DestroyMenu (popup); return 1;
}
SendMessage (MainDlg, WM_COMMAND, menuItem, NULL); else
return 1; return 0;
} }
if (HIWORD (wParam) == BN_CLICKED) if (HIWORD (wParam) == BN_CLICKED)
@@ -2739,7 +2750,7 @@ BOOL CALLBACK VolumePropertiesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
// Size // Size
ListItemAddW (list, i, GetString ("SIZE")); ListItemAddW (list, i, GetString ("SIZE"));
swprintf (sw, L"%I64u %s", prop.diskLength, GetString ("BYTES")); StringCbPrintfW (sw, sizeof(sw), L"%I64u %s", prop.diskLength, GetString ("BYTES"));
ListSubItemSetW (list, i++, 1, sw); ListSubItemSetW (list, i++, 1, sw);
// Type // Type
@@ -2802,7 +2813,7 @@ BOOL CALLBACK VolumePropertiesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
// Primary key // Primary key
ListItemAddW (list, i, GetString ("KEY_SIZE")); ListItemAddW (list, i, GetString ("KEY_SIZE"));
wsprintfW (sw, L"%d %s", size * 8, GetString ("BITS")); StringCbPrintfW (sw, sizeof(sw), L"%d %s", size * 8, GetString ("BITS"));
ListSubItemSetW (list, i++, 1, sw); ListSubItemSetW (list, i++, 1, sw);
if (strcmp (EAGetModeName (prop.ea, prop.mode, TRUE), "XTS") == 0) if (strcmp (EAGetModeName (prop.ea, prop.mode, TRUE), "XTS") == 0)
@@ -2817,7 +2828,7 @@ BOOL CALLBACK VolumePropertiesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
// Tweak key (LRW) // Tweak key (LRW)
ListItemAddW (list, i, GetString ("SECONDARY_KEY_SIZE_LRW")); ListItemAddW (list, i, GetString ("SECONDARY_KEY_SIZE_LRW"));
swprintf (sw, L"%d %s", CipherGetBlockSize (EAGetFirstCipher(prop.ea))*8, GetString ("BITS")); StringCbPrintfW (sw, sizeof(sw), L"%d %s", CipherGetBlockSize (EAGetFirstCipher(prop.ea))*8, GetString ("BITS"));
ListSubItemSetW (list, i++, 1, sw); ListSubItemSetW (list, i++, 1, sw);
} }
} }
@@ -2830,20 +2841,20 @@ BOOL CALLBACK VolumePropertiesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
wchar_t tmpstr[64]; wchar_t tmpstr[64];
int i = EAGetLastCipher(prop.ea); int i = EAGetLastCipher(prop.ea);
swprintf (sw, L"%d", CipherGetBlockSize(i)*8); StringCbPrintfW (sw, sizeof(sw), L"%d", CipherGetBlockSize(i)*8);
while (i = EAGetPreviousCipher(prop.ea, i)) while (i = EAGetPreviousCipher(prop.ea, i))
{ {
swprintf (tmpstr, L"/%d", CipherGetBlockSize(i)*8); StringCbPrintfW (tmpstr, sizeof(tmpstr), L"/%d", CipherGetBlockSize(i)*8);
wcscat (sw, tmpstr); StringCbCatW (sw, sizeof(sw), tmpstr);
} }
wcscat (sw, L" "); StringCbCatW (sw, sizeof(sw), L" ");
} }
else else
{ {
swprintf (sw, L"%d ", CipherGetBlockSize (EAGetFirstCipher(prop.ea))*8); StringCbPrintfW (sw, sizeof(sw), L"%d ", CipherGetBlockSize (EAGetFirstCipher(prop.ea))*8);
} }
wcscat (sw, GetString ("BITS")); StringCbCatW (sw, sizeof(sw), GetString ("BITS"));
ListSubItemSetW (list, i++, 1, sw); ListSubItemSetW (list, i++, 1, sw);
// Mode // Mode
@@ -2906,7 +2917,7 @@ BOOL CALLBACK VolumePropertiesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
{ {
// Volume format version // Volume format version
ListItemAddW (list, i, GetString ("VOLUME_FORMAT_VERSION")); ListItemAddW (list, i, GetString ("VOLUME_FORMAT_VERSION"));
sprintf (szTmp, "%d", prop.volFormatVersion); StringCbPrintfA (szTmp, sizeof(szTmp), "%d", prop.volFormatVersion);
ListSubItemSet (list, i++, 1, szTmp); ListSubItemSet (list, i++, 1, szTmp);
// Backup header // Backup header
@@ -2916,12 +2927,12 @@ BOOL CALLBACK VolumePropertiesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
// Total data read // Total data read
ListItemAddW (list, i, GetString ("TOTAL_DATA_READ")); ListItemAddW (list, i, GetString ("TOTAL_DATA_READ"));
GetSizeString (prop.totalBytesRead, sw); GetSizeString (prop.totalBytesRead, sw, sizeof(sw));
ListSubItemSetW (list, i++, 1, sw); ListSubItemSetW (list, i++, 1, sw);
// Total data written // Total data written
ListItemAddW (list, i, GetString ("TOTAL_DATA_WRITTEN")); ListItemAddW (list, i, GetString ("TOTAL_DATA_WRITTEN"));
GetSizeString (prop.totalBytesWritten, sw); GetSizeString (prop.totalBytesWritten, sw, sizeof(sw));
ListSubItemSetW (list, i++, 1, sw); ListSubItemSetW (list, i++, 1, sw);
if (bSysEnc) if (bSysEnc)
@@ -2939,8 +2950,8 @@ BOOL CALLBACK VolumePropertiesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
else else
{ {
_snwprintf (sw, StringCbPrintfW (sw,
sizeof sw/2, sizeof sw,
GetString ("PROCESSED_PORTION_X_PERCENT"), GetString ("PROCESSED_PORTION_X_PERCENT"),
(double) GetSysEncDeviceEncryptedPartSize (FALSE) / (double) GetSysEncDeviceSize (FALSE) * 100.0); (double) GetSysEncDeviceEncryptedPartSize (FALSE) / (double) GetSysEncDeviceSize (FALSE) * 100.0);
@@ -3078,6 +3089,7 @@ BOOL CALLBACK TravelerDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
char sysDir[MAX_PATH]; char sysDir[MAX_PATH];
char volName[MAX_PATH]; char volName[MAX_PATH];
int drive; int drive;
char* ptr;
GetDlgItemText (hwndDlg, IDC_DIRECTORY, dstDir, sizeof dstDir); GetDlgItemText (hwndDlg, IDC_DIRECTORY, dstDir, sizeof dstDir);
volName[0] = 0; volName[0] = 0;
@@ -3111,21 +3123,22 @@ BOOL CALLBACK TravelerDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
if (volName[1] != 0) if (volName[1] != 0)
{ {
volName[0] = '"'; volName[0] = '"';
strcat (volName, "\""); StringCbCatA (volName, sizeof(volName), "\"");
} }
GetModuleFileName (NULL, appDir, sizeof (appDir)); GetModuleFileName (NULL, appDir, sizeof (appDir));
strrchr (appDir, '\\')[0] = 0; if (ptr = strrchr (appDir, '\\'))
ptr[0] = 0;
WaitCursor (); WaitCursor ();
GetSystemDirectory (sysDir, sizeof (sysDir)); GetSystemDirectory (sysDir, sizeof (sysDir));
sprintf (dstPath, "%s\\VeraCrypt", dstDir); StringCbPrintfA (dstPath, sizeof(dstPath), "%s\\VeraCrypt", dstDir);
CreateDirectory (dstPath, NULL); CreateDirectory (dstPath, NULL);
// Main app // Main app
sprintf (srcPath, "%s\\VeraCrypt.exe", appDir); StringCbPrintfA (srcPath, sizeof(srcPath), "%s\\VeraCrypt.exe", appDir);
sprintf (dstPath, "%s\\VeraCrypt\\VeraCrypt.exe", dstDir); StringCbPrintfA (dstPath, sizeof(dstPath), "%s\\VeraCrypt\\VeraCrypt.exe", dstDir);
if (!TCCopyFile (srcPath, dstPath)) if (!TCCopyFile (srcPath, dstPath))
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg);
@@ -3135,8 +3148,8 @@ BOOL CALLBACK TravelerDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
// Wizard // Wizard
if (copyWizard) if (copyWizard)
{ {
sprintf (srcPath, "%s\\VeraCrypt Format.exe", appDir); StringCbPrintfA (srcPath, sizeof(srcPath), "%s\\VeraCrypt Format.exe", appDir);
sprintf (dstPath, "%s\\VeraCrypt\\VeraCrypt Format.exe", dstDir); StringCbPrintfA (dstPath, sizeof(dstPath), "%s\\VeraCrypt\\VeraCrypt Format.exe", dstDir);
if (!TCCopyFile (srcPath, dstPath)) if (!TCCopyFile (srcPath, dstPath))
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg);
@@ -3145,8 +3158,8 @@ BOOL CALLBACK TravelerDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
} }
// Driver // Driver
sprintf (srcPath, "%s\\veracrypt.sys", appDir); StringCbPrintfA (srcPath, sizeof(srcPath), "%s\\veracrypt.sys", appDir);
sprintf (dstPath, "%s\\VeraCrypt\\veracrypt.sys", dstDir); StringCbPrintfA (dstPath, sizeof(dstPath), "%s\\VeraCrypt\\veracrypt.sys", dstDir);
if (!TCCopyFile (srcPath, dstPath)) if (!TCCopyFile (srcPath, dstPath))
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg);
@@ -3154,8 +3167,8 @@ BOOL CALLBACK TravelerDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
} }
// Driver x64 // Driver x64
sprintf (srcPath, "%s\\veracrypt-x64.sys", appDir); StringCbPrintfA (srcPath, sizeof(srcPath), "%s\\veracrypt-x64.sys", appDir);
sprintf (dstPath, "%s\\VeraCrypt\\veracrypt-x64.sys", dstDir); StringCbPrintfA (dstPath, sizeof(dstPath), "%s\\VeraCrypt\\veracrypt-x64.sys", dstDir);
if (!TCCopyFile (srcPath, dstPath)) if (!TCCopyFile (srcPath, dstPath))
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg);
@@ -3165,13 +3178,13 @@ BOOL CALLBACK TravelerDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
if (GetPreferredLangId () && strcmp (GetPreferredLangId (), "en") != 0) if (GetPreferredLangId () && strcmp (GetPreferredLangId (), "en") != 0)
{ {
// Language pack // Language pack
sprintf (srcPath, "%s\\Language.%s.xml", appDir, GetPreferredLangId ()); StringCbPrintfA (srcPath, sizeof(srcPath), "%s\\Language.%s.xml", appDir, GetPreferredLangId ());
sprintf (dstPath, "%s\\VeraCrypt\\Language.%s.xml", dstDir, GetPreferredLangId ()); StringCbPrintfA (dstPath, sizeof(dstPath), "%s\\VeraCrypt\\Language.%s.xml", dstDir, GetPreferredLangId ());
TCCopyFile (srcPath, dstPath); TCCopyFile (srcPath, dstPath);
} }
// AutoRun // AutoRun
sprintf (dstPath, "%s\\autorun.inf", dstDir); StringCbPrintfA (dstPath, sizeof(dstPath), "%s\\autorun.inf", dstDir);
DeleteFile (dstPath); DeleteFile (dstPath);
if (bAutoRun) if (bAutoRun)
{ {
@@ -3187,7 +3200,7 @@ BOOL CALLBACK TravelerDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
goto stop; goto stop;
} }
sprintf (autoMount, "VeraCrypt\\VeraCrypt.exe /q background%s%s%s%s /m rm /v %s", StringCbPrintfA (autoMount, sizeof(autoMount), "VeraCrypt\\VeraCrypt.exe /q background%s%s%s%s /m rm /v %s",
drive > 0 ? driveLetter : "", drive > 0 ? driveLetter : "",
bExplore ? " /e" : "", bExplore ? " /e" : "",
bCacheInDriver ? " /c y" : "", bCacheInDriver ? " /c y" : "",
@@ -3452,7 +3465,7 @@ static BOOL Mount (HWND hwndDlg, int nDosDriveNo, char *szFileName)
} }
else if (!Silent) else if (!Silent)
{ {
strcpy (PasswordDlgVolume, szFileName); StringCbCopyA (PasswordDlgVolume, sizeof(PasswordDlgVolume), szFileName);
if (!AskVolumePassword (hwndDlg, &VolumePassword, NULL, TRUE)) if (!AskVolumePassword (hwndDlg, &VolumePassword, NULL, TRUE))
goto ret; goto ret;
@@ -3615,7 +3628,7 @@ retry:
wchar_t msg[4096]; wchar_t msg[4096];
VolumeNotificationsList.bHidVolDamagePrevReported [unmount.nDosDriveNo] = TRUE; VolumeNotificationsList.bHidVolDamagePrevReported [unmount.nDosDriveNo] = TRUE;
swprintf (msg, GetString ("DAMAGE_TO_HIDDEN_VOLUME_PREVENTED"), unmount.nDosDriveNo + 'A'); StringCbPrintfW (msg, sizeof(msg), GetString ("DAMAGE_TO_HIDDEN_VOLUME_PREVENTED"), unmount.nDosDriveNo + 'A');
SetForegroundWindow (hwndDlg); SetForegroundWindow (hwndDlg);
MessageBoxW (hwndDlg, msg, lpszTitle, MB_ICONWARNING | MB_SETFOREGROUND | MB_TOPMOST); MessageBoxW (hwndDlg, msg, lpszTitle, MB_ICONWARNING | MB_SETFOREGROUND | MB_TOPMOST);
@@ -3836,9 +3849,9 @@ static BOOL MountAllDevices (HWND hwndDlg, BOOL bPasswordPrompt)
{ {
WCHAR szTmp[4096]; WCHAR szTmp[4096];
swprintf (szTmp, GetString (KeyFilesEnable || FirstCmdKeyFile ? "PASSWORD_OR_KEYFILE_WRONG_AUTOMOUNT" : "PASSWORD_WRONG_AUTOMOUNT")); StringCbPrintfW (szTmp, sizeof(szTmp), GetString (KeyFilesEnable || FirstCmdKeyFile ? "PASSWORD_OR_KEYFILE_WRONG_AUTOMOUNT" : "PASSWORD_WRONG_AUTOMOUNT"));
if (CheckCapsLock (hwndDlg, TRUE)) if (CheckCapsLock (hwndDlg, TRUE))
wcscat (szTmp, GetString ("PASSWORD_WRONG_CAPSLOCK_ON")); StringCbCatW (szTmp, sizeof(szTmp), GetString ("PASSWORD_WRONG_CAPSLOCK_ON"));
MessageBoxW (hwndDlg, szTmp, lpszTitle, MB_ICONWARNING); MessageBoxW (hwndDlg, szTmp, lpszTitle, MB_ICONWARNING);
} }
@@ -3986,7 +3999,7 @@ static void ChangeSysEncPassword (HWND hwndDlg, BOOL bOnlyChangeKDF)
if (CreateSysEncMutex ()) // If no instance of the wizard is currently taking care of system encryption if (CreateSysEncMutex ()) // If no instance of the wizard is currently taking care of system encryption
{ {
sprintf (OrigKeyboardLayout, "%08X", (DWORD) GetKeyboardLayout (NULL) & 0xFFFF); StringCbPrintfA (OrigKeyboardLayout, sizeof(OrigKeyboardLayout), "%08X", (DWORD) GetKeyboardLayout (NULL) & 0xFFFF);
bSysEncPwdChangeDlgMode = TRUE; bSysEncPwdChangeDlgMode = TRUE;
@@ -4251,7 +4264,7 @@ void CreateRescueDisk (void)
WaitCursor(); WaitCursor();
BootEncObj->CreateRescueIsoImage (false, szRescueDiskISO); BootEncObj->CreateRescueIsoImage (false, szRescueDiskISO);
_snwprintf (szTmp, sizeof szTmp / 2, StringCbPrintfW (szTmp, sizeof szTmp,
GetString (IsWindowsIsoBurnerAvailable() ? "RESCUE_DISK_NON_WIZARD_CREATION_WIN_ISOBURN" : "RESCUE_DISK_NON_WIZARD_CREATION_BURN"), GetString (IsWindowsIsoBurnerAvailable() ? "RESCUE_DISK_NON_WIZARD_CREATION_WIN_ISOBURN" : "RESCUE_DISK_NON_WIZARD_CREATION_BURN"),
szRescueDiskISO); szRescueDiskISO);
@@ -4785,7 +4798,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
{ {
VolumePassword.Length = 0; VolumePassword.Length = 0;
strcpy (PasswordDlgVolume, szFileName); StringCbCopyA (PasswordDlgVolume, sizeof(PasswordDlgVolume),szFileName);
if (!AskVolumePassword (hwndDlg, &VolumePassword, NULL, TRUE)) if (!AskVolumePassword (hwndDlg, &VolumePassword, NULL, TRUE))
break; break;
@@ -5323,7 +5336,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
if (MainWindowHidden) if (MainWindowHidden)
{ {
AppendMenuW (popup, MF_STRING, IDM_SHOW_HIDE, GetString ("SHOW_TC")); AppendMenuW (popup, MF_STRING, IDM_SHOW_HIDE, GetString ("SHOW_TC"));
AppendMenu (popup, MF_SEPARATOR, 0, NULL); AppendMenu (popup, MF_SEPARATOR, 0, "");
} }
else if (bEnableBkgTask else if (bEnableBkgTask
&& (!(LastKnownMountList.ulMountedDrives == 0 && (!(LastKnownMountList.ulMountedDrives == 0
@@ -5332,12 +5345,12 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
&& GetDriverRefCount () < 2))) && GetDriverRefCount () < 2)))
{ {
AppendMenuW (popup, MF_STRING, IDM_SHOW_HIDE, GetString ("HIDE_TC")); AppendMenuW (popup, MF_STRING, IDM_SHOW_HIDE, GetString ("HIDE_TC"));
AppendMenu (popup, MF_SEPARATOR, 0, NULL); AppendMenu (popup, MF_SEPARATOR, 0, "");
} }
AppendMenuW (popup, MF_STRING, IDM_MOUNTALL, GetString ("IDC_MOUNTALL")); AppendMenuW (popup, MF_STRING, IDM_MOUNTALL, GetString ("IDC_MOUNTALL"));
AppendMenuW (popup, MF_STRING, IDM_MOUNT_FAVORITE_VOLUMES, GetString ("IDM_MOUNT_FAVORITE_VOLUMES")); AppendMenuW (popup, MF_STRING, IDM_MOUNT_FAVORITE_VOLUMES, GetString ("IDM_MOUNT_FAVORITE_VOLUMES"));
AppendMenuW (popup, MF_STRING, IDM_UNMOUNTALL, GetString ("IDC_UNMOUNTALL")); AppendMenuW (popup, MF_STRING, IDM_UNMOUNTALL, GetString ("IDC_UNMOUNTALL"));
AppendMenu (popup, MF_SEPARATOR, 0, NULL); AppendMenu (popup, MF_SEPARATOR, 0, "");
for (n = 0; n < 2; n++) for (n = 0; n < 2; n++)
{ {
@@ -5352,7 +5365,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
wstring label = GetFavoriteVolumeLabel (WideToSingleString (vol)); wstring label = GetFavoriteVolumeLabel (WideToSingleString (vol));
wsprintfW (s, L"%s %c: (%s)", StringCbPrintfW (s, sizeof(s), L"%s %c: (%s)",
GetString (n==0 ? "OPEN" : "DISMOUNT"), GetString (n==0 ? "OPEN" : "DISMOUNT"),
i + L'A', i + L'A',
label.empty() ? vol : label.c_str()); label.empty() ? vol : label.c_str());
@@ -5360,14 +5373,14 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
} }
} }
if (LastKnownMountList.ulMountedDrives != 0) if (LastKnownMountList.ulMountedDrives != 0)
AppendMenu (popup, MF_SEPARATOR, 0, NULL); AppendMenu (popup, MF_SEPARATOR, 0, "");
} }
AppendMenuW (popup, MF_STRING, IDM_HELP, GetString ("MENU_HELP")); AppendMenuW (popup, MF_STRING, IDM_HELP, GetString ("MENU_HELP"));
AppendMenuW (popup, MF_STRING, IDM_HOMEPAGE_SYSTRAY, GetString ("HOMEPAGE")); AppendMenuW (popup, MF_STRING, IDM_HOMEPAGE_SYSTRAY, GetString ("HOMEPAGE"));
AppendMenuW (popup, MF_STRING, IDM_PREFERENCES, GetString ("IDM_PREFERENCES")); AppendMenuW (popup, MF_STRING, IDM_PREFERENCES, GetString ("IDM_PREFERENCES"));
AppendMenuW (popup, MF_STRING, IDM_ABOUT, GetString ("IDM_ABOUT")); AppendMenuW (popup, MF_STRING, IDM_ABOUT, GetString ("IDM_ABOUT"));
AppendMenu (popup, MF_SEPARATOR, 0, NULL); AppendMenu (popup, MF_SEPARATOR, 0, "");
AppendMenuW (popup, MF_STRING, IDCANCEL, GetString ("EXIT")); AppendMenuW (popup, MF_STRING, IDCANCEL, GetString ("EXIT"));
GetCursorPos (&pos); GetCursorPos (&pos);
@@ -5393,7 +5406,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
if (Dismount (hwndDlg, sel - TRAYICON_MENU_DRIVE_OFFSET - 26)) if (Dismount (hwndDlg, sel - TRAYICON_MENU_DRIVE_OFFSET - 26))
{ {
wchar_t txt [2048]; wchar_t txt [2048];
wsprintfW (txt, GetString ("VOLUME_MOUNTED_AS_DRIVE_LETTER_X_DISMOUNTED"), sel - TRAYICON_MENU_DRIVE_OFFSET - 26 + L'A'); StringCbPrintfW (txt, sizeof(txt), GetString ("VOLUME_MOUNTED_AS_DRIVE_LETTER_X_DISMOUNTED"), sel - TRAYICON_MENU_DRIVE_OFFSET - 26 + L'A');
InfoBalloonDirect (GetString ("SUCCESSFULLY_DISMOUNTED"), txt); InfoBalloonDirect (GetString ("SUCCESSFULLY_DISMOUNTED"), txt);
} }
@@ -5499,7 +5512,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
if (wcsstr (vol, L"\\??\\") == vol) if (wcsstr (vol, L"\\??\\") == vol)
vol += 4; vol += 4;
_snprintf (volp, sizeof(volp), "%ls", vol); StringCbPrintfA (volp, sizeof(volp), "%ls", vol);
if (IsVolumeDeviceHosted (volp)) if (IsVolumeDeviceHosted (volp))
{ {
@@ -5603,7 +5616,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
// No mounted volume at this drive letter // No mounted volume at this drive letter
AppendMenuW (popup, MF_STRING, IDM_MOUNT_VOLUME, GetString ("IDM_MOUNT_VOLUME")); AppendMenuW (popup, MF_STRING, IDM_MOUNT_VOLUME, GetString ("IDM_MOUNT_VOLUME"));
AppendMenu (popup, MF_SEPARATOR, 0, NULL); AppendMenu (popup, MF_SEPARATOR, 0, "");
AppendMenuW (popup, MF_STRING, IDPM_SELECT_FILE_AND_MOUNT, GetString ("SELECT_FILE_AND_MOUNT")); AppendMenuW (popup, MF_STRING, IDPM_SELECT_FILE_AND_MOUNT, GetString ("SELECT_FILE_AND_MOUNT"));
AppendMenuW (popup, MF_STRING, IDPM_SELECT_DEVICE_AND_MOUNT, GetString ("SELECT_DEVICE_AND_MOUNT")); AppendMenuW (popup, MF_STRING, IDPM_SELECT_DEVICE_AND_MOUNT, GetString ("SELECT_DEVICE_AND_MOUNT"));
break; break;
@@ -5614,13 +5627,13 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
AppendMenuW (popup, MF_STRING, IDM_UNMOUNT_VOLUME, GetString ("DISMOUNT")); AppendMenuW (popup, MF_STRING, IDM_UNMOUNT_VOLUME, GetString ("DISMOUNT"));
AppendMenuW (popup, MF_STRING, IDPM_OPEN_VOLUME, GetString ("OPEN")); AppendMenuW (popup, MF_STRING, IDPM_OPEN_VOLUME, GetString ("OPEN"));
AppendMenu (popup, MF_SEPARATOR, 0, NULL); AppendMenu (popup, MF_SEPARATOR, 0, "");
AppendMenuW (popup, MF_STRING, IDPM_CHECK_FILESYS, GetString ("IDPM_CHECK_FILESYS")); AppendMenuW (popup, MF_STRING, IDPM_CHECK_FILESYS, GetString ("IDPM_CHECK_FILESYS"));
AppendMenuW (popup, MF_STRING, IDPM_REPAIR_FILESYS, GetString ("IDPM_REPAIR_FILESYS")); AppendMenuW (popup, MF_STRING, IDPM_REPAIR_FILESYS, GetString ("IDPM_REPAIR_FILESYS"));
AppendMenu (popup, MF_SEPARATOR, 0, NULL); AppendMenu (popup, MF_SEPARATOR, 0, "");
AppendMenuW (popup, MF_STRING, IDPM_ADD_TO_FAVORITES, GetString ("IDPM_ADD_TO_FAVORITES")); AppendMenuW (popup, MF_STRING, IDPM_ADD_TO_FAVORITES, GetString ("IDPM_ADD_TO_FAVORITES"));
AppendMenuW (popup, MF_STRING, IDPM_ADD_TO_SYSTEM_FAVORITES, GetString ("IDPM_ADD_TO_SYSTEM_FAVORITES")); AppendMenuW (popup, MF_STRING, IDPM_ADD_TO_SYSTEM_FAVORITES, GetString ("IDPM_ADD_TO_SYSTEM_FAVORITES"));
AppendMenu (popup, MF_SEPARATOR, 0, NULL); AppendMenu (popup, MF_SEPARATOR, 0, "");
AppendMenuW (popup, MF_STRING, IDM_VOLUME_PROPERTIES, GetString ("IDPM_PROPERTIES")); AppendMenuW (popup, MF_STRING, IDM_VOLUME_PROPERTIES, GetString ("IDPM_PROPERTIES"));
break; break;
@@ -5867,10 +5880,10 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
{ {
AppendMenuW (popup, MF_STRING, IDM_CHANGE_PASSWORD, GetString ("IDM_CHANGE_PASSWORD")); AppendMenuW (popup, MF_STRING, IDM_CHANGE_PASSWORD, GetString ("IDM_CHANGE_PASSWORD"));
AppendMenuW (popup, MF_STRING, IDM_CHANGE_HEADER_KEY_DERIV_ALGO, GetString ("IDM_CHANGE_HEADER_KEY_DERIV_ALGO")); AppendMenuW (popup, MF_STRING, IDM_CHANGE_HEADER_KEY_DERIV_ALGO, GetString ("IDM_CHANGE_HEADER_KEY_DERIV_ALGO"));
AppendMenu (popup, MF_SEPARATOR, 0, NULL); AppendMenu (popup, MF_SEPARATOR, 0, "");
AppendMenuW (popup, MF_STRING, IDM_ADD_REMOVE_VOL_KEYFILES, GetString ("IDM_ADD_REMOVE_VOL_KEYFILES")); AppendMenuW (popup, MF_STRING, IDM_ADD_REMOVE_VOL_KEYFILES, GetString ("IDM_ADD_REMOVE_VOL_KEYFILES"));
AppendMenuW (popup, MF_STRING, IDM_REMOVE_ALL_KEYFILES_FROM_VOL, GetString ("IDM_REMOVE_ALL_KEYFILES_FROM_VOL")); AppendMenuW (popup, MF_STRING, IDM_REMOVE_ALL_KEYFILES_FROM_VOL, GetString ("IDM_REMOVE_ALL_KEYFILES_FROM_VOL"));
AppendMenu (popup, MF_SEPARATOR, 0, NULL); AppendMenu (popup, MF_SEPARATOR, 0, "");
AppendMenuW (popup, MF_STRING, IDM_BACKUP_VOL_HEADER, GetString ("IDM_BACKUP_VOL_HEADER")); AppendMenuW (popup, MF_STRING, IDM_BACKUP_VOL_HEADER, GetString ("IDM_BACKUP_VOL_HEADER"));
AppendMenuW (popup, MF_STRING, IDM_RESTORE_VOL_HEADER, GetString ("IDM_RESTORE_VOL_HEADER")); AppendMenuW (popup, MF_STRING, IDM_RESTORE_VOL_HEADER, GetString ("IDM_RESTORE_VOL_HEADER"));
} }
@@ -6250,9 +6263,9 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
// volPathHigher will contain the volume path selected in the main drive list // volPathHigher will contain the volume path selected in the main drive list
wstring volPathHigher (prop.wszVolume); wstring volPathHigher (prop.wszVolume);
ToSBCS (prop.wszVolume); ToSBCS (prop.wszVolume, sizeof(prop.wszVolume));
strcpy ((char *) volPathLowerW, volPathLower); StringCbCopyA ((char *) volPathLowerW, sizeof(volPathLowerW), volPathLower);
ToUNICODE ((char *) volPathLowerW); ToUNICODE ((char *) volPathLowerW, sizeof(volPathLowerW));
if (strcmp (((memcmp ((char *) prop.wszVolume, "\\??\\", 4) == 0) ? (char *) prop.wszVolume + 4 : (char *) prop.wszVolume), volPathLower) != 0) if (strcmp (((memcmp ((char *) prop.wszVolume, "\\??\\", 4) == 0) ? (char *) prop.wszVolume + 4 : (char *) prop.wszVolume), volPathLower) != 0)
{ {
@@ -6700,8 +6713,11 @@ void ExtractCommandLine (HWND hwndDlg, char *lpszCommandLine)
KeyFile *kf; KeyFile *kf;
RelativePath2Absolute (tmpPath); RelativePath2Absolute (tmpPath);
kf = (KeyFile *) malloc (sizeof (KeyFile)); kf = (KeyFile *) malloc (sizeof (KeyFile));
strncpy (kf->FileName, tmpPath, sizeof (kf->FileName) - 1); if (kf)
FirstCmdKeyFile = KeyFileAdd (FirstCmdKeyFile, kf); {
StringCbCopyA (kf->FileName, sizeof(kf->FileName), tmpPath);
FirstCmdKeyFile = KeyFileAdd (FirstCmdKeyFile, kf);
}
} }
break; break;
@@ -7025,7 +7041,7 @@ BOOL TaskBarIconAdd (HWND hwnd)
| LR_SHARED | LR_SHARED
| (nCurrentOS != WIN_2000 ? LR_DEFAULTCOLOR : LR_VGACOLOR)); // Windows 2000 cannot display more than 16 fixed colors in notification tray | (nCurrentOS != WIN_2000 ? LR_DEFAULTCOLOR : LR_VGACOLOR)); // Windows 2000 cannot display more than 16 fixed colors in notification tray
wcscpy (tnid.szTip, L"VeraCrypt"); StringCbCopyW (tnid.szTip, sizeof(tnid.szTip), L"VeraCrypt");
return Shell_NotifyIconW (NIM_ADD, &tnid); return Shell_NotifyIconW (NIM_ADD, &tnid);
} }
@@ -7450,7 +7466,7 @@ void ChangeMainWindowVisibility ()
} }
int BackupVolumeHeader (HWND hwndDlg, BOOL bRequireConfirmation, char *lpszVolume) int BackupVolumeHeader (HWND hwndDlg, BOOL bRequireConfirmation, const char *lpszVolume)
{ {
int nStatus = ERR_OS_ERROR; int nStatus = ERR_OS_ERROR;
wchar_t szTmp[4096]; wchar_t szTmp[4096];
@@ -7461,6 +7477,13 @@ int BackupVolumeHeader (HWND hwndDlg, BOOL bRequireConfirmation, char *lpszVolum
byte temporaryKey[MASTER_KEYDATA_SIZE]; byte temporaryKey[MASTER_KEYDATA_SIZE];
byte originalK2[MASTER_KEYDATA_SIZE]; byte originalK2[MASTER_KEYDATA_SIZE];
if (!lpszVolume)
{
nStatus = ERR_OUTOFMEMORY;
handleError (hwndDlg, nStatus);
return nStatus;
}
volume.VolumeIsOpen = FALSE; volume.VolumeIsOpen = FALSE;
hiddenVolume.VolumeIsOpen = FALSE; hiddenVolume.VolumeIsOpen = FALSE;
@@ -7560,7 +7583,7 @@ noHidden:
goto error; goto error;
} }
swprintf (szTmp, GetString ("CONFIRM_VOL_HEADER_BAK"), lpszVolume); StringCbPrintfW (szTmp, sizeof(szTmp), GetString ("CONFIRM_VOL_HEADER_BAK"), lpszVolume);
if (bRequireConfirmation if (bRequireConfirmation
&& (MessageBoxW (hwndDlg, szTmp, lpszTitle, YES_NO|MB_ICONQUESTION|MB_DEFBUTTON1) == IDNO)) && (MessageBoxW (hwndDlg, szTmp, lpszTitle, YES_NO|MB_ICONQUESTION|MB_DEFBUTTON1) == IDNO))
@@ -7672,7 +7695,7 @@ error:
} }
int RestoreVolumeHeader (HWND hwndDlg, char *lpszVolume) int RestoreVolumeHeader (HWND hwndDlg, const char *lpszVolume)
{ {
int nDosLinkCreated = -1, nStatus = ERR_OS_ERROR; int nDosLinkCreated = -1, nStatus = ERR_OS_ERROR;
char szDiskFile[TC_MAX_PATH], szCFDevice[TC_MAX_PATH]; char szDiskFile[TC_MAX_PATH], szCFDevice[TC_MAX_PATH];
@@ -7691,6 +7714,13 @@ int RestoreVolumeHeader (HWND hwndDlg, char *lpszVolume)
LARGE_INTEGER headerOffset; LARGE_INTEGER headerOffset;
CRYPTO_INFO *restoredCryptoInfo = NULL; CRYPTO_INFO *restoredCryptoInfo = NULL;
if (!lpszVolume)
{
nStatus = ERR_OUTOFMEMORY;
handleError (hwndDlg, nStatus);
return nStatus;
}
switch (IsSystemDevicePath (lpszVolume, hwndDlg, TRUE)) switch (IsSystemDevicePath (lpszVolume, hwndDlg, TRUE))
{ {
case 1: case 1:
@@ -7750,7 +7780,7 @@ int RestoreVolumeHeader (HWND hwndDlg, char *lpszVolume)
// Open the volume using backup header // Open the volume using backup header
while (TRUE) while (TRUE)
{ {
strncpy (PasswordDlgVolume, lpszVolume, sizeof (PasswordDlgVolume) - 1); StringCbCopyA (PasswordDlgVolume, sizeof(PasswordDlgVolume), lpszVolume);
if (!AskVolumePassword (hwndDlg, &VolumePassword, NULL, FALSE)) if (!AskVolumePassword (hwndDlg, &VolumePassword, NULL, FALSE))
{ {
nStatus = ERR_SUCCESS; nStatus = ERR_SUCCESS;
@@ -7806,7 +7836,7 @@ int RestoreVolumeHeader (HWND hwndDlg, char *lpszVolume)
{ {
// Restore header from an external backup // Restore header from an external backup
swprintf (szTmp, GetString ("CONFIRM_VOL_HEADER_RESTORE"), lpszVolume); StringCbPrintfW (szTmp, sizeof(szTmp), GetString ("CONFIRM_VOL_HEADER_RESTORE"), lpszVolume);
if (MessageBoxW (hwndDlg, szTmp, lpszTitle, YES_NO|MB_ICONWARNING|MB_DEFBUTTON2) == IDNO) if (MessageBoxW (hwndDlg, szTmp, lpszTitle, YES_NO|MB_ICONWARNING|MB_DEFBUTTON2) == IDNO)
{ {
@@ -7837,13 +7867,13 @@ int RestoreVolumeHeader (HWND hwndDlg, char *lpszVolume)
goto error; goto error;
} }
CreateFullVolumePath (szDiskFile, lpszVolume, &bDevice); CreateFullVolumePath (szDiskFile, sizeof(szDiskFile), lpszVolume, &bDevice);
if (bDevice == FALSE) if (bDevice == FALSE)
strcpy (szCFDevice, szDiskFile); StringCbCopyA (szCFDevice, sizeof(szCFDevice), szDiskFile);
else else
{ {
nDosLinkCreated = FakeDosNameForDevice (szDiskFile, szDosDevice, szCFDevice, FALSE); nDosLinkCreated = FakeDosNameForDevice (szDiskFile, szDosDevice, sizeof(szDosDevice),szCFDevice, sizeof(szCFDevice),FALSE);
if (nDosLinkCreated != 0) if (nDosLinkCreated != 0)
goto error; goto error;
} }
@@ -8302,12 +8332,12 @@ static BOOL CALLBACK SecurityTokenPreferencesDlgProc (HWND hwndDlg, UINT msg, WP
else else
{ {
char prevSecurityTokenLibraryPath[MAX_PATH]; char prevSecurityTokenLibraryPath[MAX_PATH];
strcpy (prevSecurityTokenLibraryPath, SecurityTokenLibraryPath); StringCbCopyA (prevSecurityTokenLibraryPath, sizeof(prevSecurityTokenLibraryPath), SecurityTokenLibraryPath);
strcpy (SecurityTokenLibraryPath, securityTokenLibraryPath); StringCbCopyA (SecurityTokenLibraryPath, sizeof(SecurityTokenLibraryPath), securityTokenLibraryPath);
if (!InitSecurityTokenLibrary()) if (!InitSecurityTokenLibrary())
{ {
strcpy (SecurityTokenLibraryPath, prevSecurityTokenLibraryPath); StringCbCopyA (SecurityTokenLibraryPath, sizeof(SecurityTokenLibraryPath), prevSecurityTokenLibraryPath);
return 1; return 1;
} }
} }
@@ -8393,7 +8423,7 @@ static BOOL CALLBACK SecurityTokenPreferencesDlgProc (HWND hwndDlg, UINT msg, WP
Info ("SELECT_PKCS11_MODULE_HELP"); Info ("SELECT_PKCS11_MODULE_HELP");
wsprintfW (browseFilter, L"%ls (*.dll)%c*.dll%c%c", GetString ("DLL_FILES"), 0, 0, 0); StringCbPrintfW (browseFilter, sizeof(browseFilter), L"%ls (*.dll)%c*.dll%c%c", GetString ("DLL_FILES"), 0, 0, 0);
GetSystemDirectory (systemDir, sizeof (systemDir)); GetSystemDirectory (systemDir, sizeof (systemDir));
if (BrowseFilesInDir (hwndDlg, "SELECT_PKCS11_MODULE", systemDir, securityTokenLibraryPath, TRUE, FALSE, browseFilter)) if (BrowseFilesInDir (hwndDlg, "SELECT_PKCS11_MODULE", systemDir, securityTokenLibraryPath, TRUE, FALSE, browseFilter))

View File

@@ -94,8 +94,8 @@ BOOL WholeSysDriveEncryption (BOOL bSilent);
BOOL CheckSysEncMountWithoutPBA (const char *devicePath, BOOL quiet); BOOL CheckSysEncMountWithoutPBA (const char *devicePath, BOOL quiet);
BOOL TCBootLoaderOnInactiveSysEncDrive (void); BOOL TCBootLoaderOnInactiveSysEncDrive (void);
void CreateRescueDisk (void); void CreateRescueDisk (void);
int BackupVolumeHeader (HWND hwndDlg, BOOL bRequireConfirmation, char *lpszVolume); int BackupVolumeHeader (HWND hwndDlg, BOOL bRequireConfirmation, const char *lpszVolume);
int RestoreVolumeHeader (HWND hwndDlg, char *lpszVolume); int RestoreVolumeHeader (HWND hwndDlg, const char *lpszVolume);
void SecurityTokenPreferencesDialog (HWND hwndDlg); void SecurityTokenPreferencesDialog (HWND hwndDlg);
static BOOL CALLBACK PerformanceSettingsDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); static BOOL CALLBACK PerformanceSettingsDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
static BOOL CALLBACK BootLoaderPreferencesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); static BOOL CALLBACK BootLoaderPreferencesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);