VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Common
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2015-11-25 01:41:37 +0100
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2015-11-26 01:44:52 +0100
commit90bd57fe40e66fc829ecb01482d32d604b0df19c (patch)
tree6d6de0d9a31c82d0598f68c2d160cb9e565bd5ea /src/Common
parentec7d96fcb733021c214b414a1ba2841039733dd2 (diff)
downloadVeraCrypt-90bd57fe40e66fc829ecb01482d32d604b0df19c.tar.gz
VeraCrypt-90bd57fe40e66fc829ecb01482d32d604b0df19c.zip
Windows: Full UNICODE rewrite and implement support for UNICODE passwords.
Diffstat (limited to 'src/Common')
-rw-r--r--src/Common/Apidrvr.h4
-rw-r--r--src/Common/BaseCom.cpp11
-rw-r--r--src/Common/BootEncryption.cpp229
-rw-r--r--src/Common/BootEncryption.h44
-rw-r--r--src/Common/Cmdline.c58
-rw-r--r--src/Common/Cmdline.h12
-rw-r--r--src/Common/Combo.c37
-rw-r--r--src/Common/Combo.h2
-rw-r--r--src/Common/Crypto.c84
-rw-r--r--src/Common/Crypto.h28
-rw-r--r--src/Common/Dlgcode.c1464
-rw-r--r--src/Common/Dlgcode.h195
-rw-r--r--src/Common/Exception.h10
-rw-r--r--src/Common/Format.c27
-rw-r--r--src/Common/Format.h2
-rw-r--r--src/Common/Keyfiles.c41
-rw-r--r--src/Common/Keyfiles.h6
-rw-r--r--src/Common/Language.c8
-rw-r--r--src/Common/Language.xml74
-rw-r--r--src/Common/Password.c38
-rw-r--r--src/Common/Password.h2
-rw-r--r--src/Common/Pkcs5.c12
-rw-r--r--src/Common/Pkcs5.h12
-rw-r--r--src/Common/Random.c20
-rw-r--r--src/Common/Registry.c74
-rw-r--r--src/Common/Registry.h35
-rw-r--r--src/Common/SecurityToken.cpp8
-rw-r--r--src/Common/SecurityToken.h4
-rw-r--r--src/Common/Tcdefs.h3
-rw-r--r--src/Common/Tests.c36
-rw-r--r--src/Common/Xml.c53
-rw-r--r--src/Common/Xml.h3
32 files changed, 1289 insertions, 1347 deletions
diff --git a/src/Common/Apidrvr.h b/src/Common/Apidrvr.h
index 3f74176c..5ba6c884 100644
--- a/src/Common/Apidrvr.h
+++ b/src/Common/Apidrvr.h
@@ -311,11 +311,7 @@ typedef struct
#pragma pack (pop)
-#ifdef TC_WINDOWS_DRIVER
#define DRIVER_STR WIDE
-#else
-#define DRIVER_STR
-#endif
#define TC_UNIQUE_ID_PREFIX "VeraCryptVolume"
#define TC_MOUNT_PREFIX L"\\Device\\VeraCryptVolume"
diff --git a/src/Common/BaseCom.cpp b/src/Common/BaseCom.cpp
index 74d44320..a3bc42fe 100644
--- a/src/Common/BaseCom.cpp
+++ b/src/Common/BaseCom.cpp
@@ -128,16 +128,9 @@ BOOL BaseCom::IsPagingFileActive (BOOL checkNonWindowsPartitionsOnly)
DWORD BaseCom::ReadWriteFile (BOOL write, BOOL device, BSTR filePath, BSTR *bufferBstr, unsigned __int64 offset, unsigned __int32 size, DWORD *sizeDone)
{
- USES_CONVERSION;
- CW2A szFilePathA(filePath);
- if (!szFilePathA.m_psz)
- {
- return ERROR_NOT_ENOUGH_MEMORY;
- }
-
try
{
- auto_ptr <File> file (device ? new Device (string (szFilePathA.m_psz), !write) : new File (string (szFilePathA.m_psz), !write));
+ auto_ptr <File> file (device ? new Device (filePath, !write) : new File (filePath, !write));
file->CheckOpened (SRC_POS);
file->SeekAt (offset);
@@ -246,7 +239,7 @@ DWORD BaseCom::SetDriverServiceStartType (DWORD startType)
DWORD BaseCom::WriteLocalMachineRegistryDwordValue (BSTR keyPath, BSTR valueName, DWORD value)
{
- if (!::WriteLocalMachineRegistryDwordW (keyPath, valueName, value))
+ if (!::WriteLocalMachineRegistryDword (keyPath, valueName, value))
return GetLastError();
return ERROR_SUCCESS;
diff --git a/src/Common/BootEncryption.cpp b/src/Common/BootEncryption.cpp
index 8b8c122c..9edc89e2 100644
--- a/src/Common/BootEncryption.cpp
+++ b/src/Common/BootEncryption.cpp
@@ -76,17 +76,17 @@ namespace VeraCrypt
}
}
- static void CopyFile (const string &sourceFile, const string &destinationFile)
+ static void CopyFile (const wstring &sourceFile, const wstring &destinationFile)
{
Elevate();
DWORD result;
CComBSTR sourceFileBstr, destinationFileBstr;
- BSTR bstr = A2WBSTR(sourceFile.c_str());
+ BSTR bstr = W2BSTR(sourceFile.c_str());
if (bstr)
{
sourceFileBstr.Attach (bstr);
- bstr = A2WBSTR(destinationFile.c_str());
+ bstr = W2BSTR(destinationFile.c_str());
if (bstr)
{
destinationFileBstr.Attach (bstr);
@@ -109,12 +109,12 @@ namespace VeraCrypt
}
}
- static void DeleteFile (const string &file)
+ static void DeleteFile (const wstring &file)
{
Elevate();
CComBSTR fileBstr;
DWORD result;
- BSTR bstr = A2WBSTR(file.c_str());
+ BSTR bstr = W2BSTR(file.c_str());
if (bstr)
{
fileBstr.Attach (bstr);
@@ -132,7 +132,7 @@ namespace VeraCrypt
}
}
- static void ReadWriteFile (BOOL write, BOOL device, const string &filePath, byte *buffer, uint64 offset, uint32 size, DWORD *sizeDone)
+ static void ReadWriteFile (BOOL write, BOOL device, const wstring &filePath, byte *buffer, uint64 offset, uint32 size, DWORD *sizeDone)
{
Elevate();
@@ -140,7 +140,7 @@ namespace VeraCrypt
CComBSTR bufferBstr, fileBstr;
if (bufferBstr.AppendBytes ((const char *) buffer, size) != S_OK)
throw ParameterIncorrect (SRC_POS);
- BSTR bstr = A2WBSTR(filePath.c_str());
+ BSTR bstr = W2BSTR(filePath.c_str());
if (bstr)
{
fileBstr.Attach (bstr);
@@ -168,17 +168,17 @@ namespace VeraCrypt
return ElevatedComInstance->IsPagingFileActive (checkNonWindowsPartitionsOnly);
}
- static void WriteLocalMachineRegistryDwordValue (char *keyPath, char *valueName, DWORD value)
+ static void WriteLocalMachineRegistryDwordValue (wchar_t *keyPath, wchar_t *valueName, DWORD value)
{
Elevate();
DWORD result;
CComBSTR keyPathBstr, valueNameBstr;
- BSTR bstr = A2WBSTR(keyPath);
+ BSTR bstr = W2BSTR(keyPath);
if (bstr)
{
keyPathBstr.Attach (bstr);
- bstr = A2WBSTR(valueName);
+ bstr = W2BSTR(valueName);
if (bstr)
{
valueNameBstr.Attach (bstr);
@@ -289,7 +289,7 @@ namespace VeraCrypt
public:
static void AddReference () { }
static void CallDriver (DWORD ioctl, void *input, DWORD inputSize, void *output, DWORD outputSize) { throw ParameterIncorrect (SRC_POS); }
- static void ReadWriteFile (BOOL write, BOOL device, const string &filePath, byte *buffer, uint64 offset, uint32 size, DWORD *sizeDone) { throw ParameterIncorrect (SRC_POS); }
+ static void ReadWriteFile (BOOL write, BOOL device, const wstring &filePath, byte *buffer, uint64 offset, uint32 size, DWORD *sizeDone) { throw ParameterIncorrect (SRC_POS); }
static void RegisterFilterDriver (bool registerDriver, BootEncryption::FilterType filterType) { throw ParameterIncorrect (SRC_POS); }
static void Release () { }
static void SetDriverServiceStartType (DWORD startType) { throw ParameterIncorrect (SRC_POS); }
@@ -298,7 +298,7 @@ namespace VeraCrypt
#endif // SETUP
- File::File (string path, bool readOnly, bool create) : Elevated (false), FileOpen (false), LastError(0)
+ File::File (wstring path, bool readOnly, bool create) : Elevated (false), FileOpen (false), LastError(0)
{
Handle = CreateFile (path.c_str(),
readOnly ? GENERIC_READ : GENERIC_READ | GENERIC_WRITE,
@@ -417,18 +417,18 @@ namespace VeraCrypt
}
}
- void Show (HWND parent, const string &str)
+ void Show (HWND parent, const wstring &str)
{
MessageBox (parent, str.c_str(), NULL, 0);
}
- Device::Device (string path, bool readOnly)
+ Device::Device (wstring path, bool readOnly)
{
FileOpen = false;
Elevated = false;
- Handle = CreateFile ((string ("\\\\.\\") + path).c_str(),
+ Handle = CreateFile ((wstring (L"\\\\.\\") + path).c_str(),
readOnly ? GENERIC_READ : GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
FILE_FLAG_RANDOM_ACCESS | FILE_FLAG_WRITE_THROUGH, NULL);
@@ -616,7 +616,7 @@ namespace VeraCrypt
DWORD BootEncryption::GetDriverServiceStartType ()
{
DWORD startType;
- throw_sys_if (!ReadLocalMachineRegistryDword ("SYSTEM\\CurrentControlSet\\Services\\veracrypt", "Start", &startType));
+ throw_sys_if (!ReadLocalMachineRegistryDword (L"SYSTEM\\CurrentControlSet\\Services\\veracrypt", L"Start", &startType));
return startType;
}
@@ -645,42 +645,42 @@ namespace VeraCrypt
finally_do_arg (SC_HANDLE, serviceManager, { CloseServiceHandle (finally_arg); });
- SC_HANDLE service = OpenService (serviceManager, "veracrypt", SERVICE_CHANGE_CONFIG);
+ SC_HANDLE service = OpenService (serviceManager, L"veracrypt", SERVICE_CHANGE_CONFIG);
throw_sys_if (!service);
finally_do_arg (SC_HANDLE, service, { CloseServiceHandle (finally_arg); });
// Windows versions preceding Vista can be installed on FAT filesystem which does not
// support long filenames during boot. Convert the driver path to short form if required.
- string driverPath;
+ wstring driverPath;
if (startOnBoot && !IsOSAtLeast (WIN_VISTA))
{
- char pathBuf[MAX_PATH];
- char filesystem[128];
+ wchar_t pathBuf[MAX_PATH];
+ wchar_t filesystem[128];
- string path (GetWindowsDirectory());
- path += "\\drivers\\veracrypt.sys";
+ wstring path (GetWindowsDirectory());
+ path += L"\\drivers\\veracrypt.sys";
- if (GetVolumePathName (path.c_str(), pathBuf, sizeof (pathBuf))
- && GetVolumeInformation (pathBuf, NULL, 0, NULL, NULL, NULL, filesystem, sizeof(filesystem))
- && memcmp (filesystem, "FAT", 3) == 0)
+ if (GetVolumePathName (path.c_str(), pathBuf, ARRAYSIZE (pathBuf))
+ && GetVolumeInformation (pathBuf, NULL, 0, NULL, NULL, NULL, filesystem, ARRAYSIZE(filesystem))
+ && wmemcmp (filesystem, L"FAT", 3) == 0)
{
- throw_sys_if (GetShortPathName (path.c_str(), pathBuf, sizeof (pathBuf)) == 0);
+ throw_sys_if (GetShortPathName (path.c_str(), pathBuf, ARRAYSIZE (pathBuf)) == 0);
// Convert absolute path to relative to the Windows directory
driverPath = pathBuf;
- driverPath = driverPath.substr (driverPath.rfind ("\\", driverPath.rfind ("\\", driverPath.rfind ("\\") - 1) - 1) + 1);
+ driverPath = driverPath.substr (driverPath.rfind (L"\\", driverPath.rfind (L"\\", driverPath.rfind (L"\\") - 1) - 1) + 1);
}
}
throw_sys_if (!ChangeServiceConfig (service, SERVICE_NO_CHANGE, SERVICE_NO_CHANGE,
startOnBoot ? SERVICE_ERROR_SEVERE : SERVICE_ERROR_NORMAL,
driverPath.empty() ? NULL : driverPath.c_str(),
- startOnBoot ? "Filter" : NULL,
+ startOnBoot ? L"Filter" : NULL,
NULL, NULL, NULL, NULL, NULL));
// ChangeServiceConfig() rejects SERVICE_BOOT_START with ERROR_INVALID_PARAMETER
- throw_sys_if (!WriteLocalMachineRegistryDword ("SYSTEM\\CurrentControlSet\\Services\\veracrypt", "Start", startType));
+ throw_sys_if (!WriteLocalMachineRegistryDword (L"SYSTEM\\CurrentControlSet\\Services\\veracrypt", L"Start", startType));
}
@@ -692,7 +692,7 @@ namespace VeraCrypt
GetSystemDriveConfiguration();
ProbeRealDriveSizeRequest request;
- StringCbPrintfW (request.DeviceName, sizeof (request.DeviceName), L"%hs", DriveConfig.DrivePartition.DevicePath.c_str());
+ StringCbCopyW (request.DeviceName, sizeof (request.DeviceName), DriveConfig.DrivePartition.DevicePath.c_str());
CallDriver (TC_IOCTL_PROBE_REAL_DRIVE_SIZE, &request, sizeof (request), &request, sizeof (request));
DriveConfig.DrivePartition.Info.PartitionLength = request.RealDriveSize;
@@ -717,11 +717,11 @@ namespace VeraCrypt
for (int partNumber = 0; partNumber < 64; ++partNumber)
{
- stringstream partPath;
- partPath << "\\Device\\Harddisk" << driveNumber << "\\Partition" << partNumber;
+ wstringstream partPath;
+ partPath << L"\\Device\\Harddisk" << driveNumber << L"\\Partition" << partNumber;
DISK_PARTITION_INFO_STRUCT diskPartInfo = {0};
- StringCbPrintfW (diskPartInfo.deviceName, sizeof (diskPartInfo.deviceName), L"%hs", partPath.str().c_str());
+ StringCbCopyW (diskPartInfo.deviceName, sizeof (diskPartInfo.deviceName), partPath.str().c_str());
try
{
@@ -748,19 +748,17 @@ namespace VeraCrypt
part.IsGPT = diskPartInfo.IsGPT;
// Mount point
- wstringstream ws;
- ws << partPath.str().c_str();
- int driveNumber = GetDiskDeviceDriveLetter ((wchar_t *) ws.str().c_str());
+ int driveNumber = GetDiskDeviceDriveLetter ((wchar_t *) partPath.str().c_str());
if (driveNumber >= 0)
{
- part.MountPoint += (char) (driveNumber + 'A');
- part.MountPoint += ":";
+ part.MountPoint += (wchar_t) (driveNumber + L'A');
+ part.MountPoint += L":";
}
// Volume ID
wchar_t volumePath[TC_MAX_PATH];
- if (ResolveSymbolicLink ((wchar_t *) ws.str().c_str(), volumePath, sizeof(volumePath)))
+ if (ResolveSymbolicLink ((wchar_t *) partPath.str().c_str(), volumePath, sizeof(volumePath)))
{
wchar_t volumeName[TC_MAX_PATH];
HANDLE fh = FindFirstVolumeW (volumeName, array_capacity (volumeName));
@@ -794,32 +792,32 @@ namespace VeraCrypt
DISK_GEOMETRY BootEncryption::GetDriveGeometry (int driveNumber)
{
- stringstream devName;
- devName << "\\Device\\Harddisk" << driveNumber << "\\Partition0";
+ wstringstream devName;
+ devName << L"\\Device\\Harddisk" << driveNumber << L"\\Partition0";
DISK_GEOMETRY geometry;
- throw_sys_if (!::GetDriveGeometry ((char *) devName.str().c_str(), &geometry));
+ throw_sys_if (!::GetDriveGeometry (devName.str().c_str(), &geometry));
return geometry;
}
- string BootEncryption::GetWindowsDirectory ()
+ wstring BootEncryption::GetWindowsDirectory ()
{
- char buf[MAX_PATH];
- throw_sys_if (GetSystemDirectory (buf, sizeof (buf)) == 0);
+ wchar_t buf[MAX_PATH];
+ throw_sys_if (GetSystemDirectory (buf, ARRAYSIZE (buf)) == 0);
- return string (buf);
+ return wstring (buf);
}
- string BootEncryption::GetTempPath ()
+ wstring BootEncryption::GetTempPath ()
{
- char tempPath[MAX_PATH];
- DWORD tempLen = ::GetTempPath (sizeof (tempPath), tempPath);
- if (tempLen == 0 || tempLen > sizeof (tempPath))
+ wchar_t tempPath[MAX_PATH];
+ DWORD tempLen = ::GetTempPath (ARRAYSIZE (tempPath), tempPath);
+ if (tempLen == 0 || tempLen > ARRAYSIZE (tempPath))
throw ParameterIncorrect (SRC_POS);
- return string (tempPath);
+ return wstring (tempPath);
}
@@ -838,7 +836,7 @@ namespace VeraCrypt
}
// Note that this does not require admin rights (it just requires the driver to be running)
- bool BootEncryption::IsBootLoaderOnDrive (char *devicePath)
+ bool BootEncryption::IsBootLoaderOnDrive (wchar_t *devicePath)
{
try
{
@@ -846,8 +844,7 @@ namespace VeraCrypt
memset (&openTestStruct, 0, sizeof (openTestStruct));
DWORD dwResult;
- StringCbCopyA ((char *) &openTestStruct.wszFileName[0], sizeof(openTestStruct.wszFileName),devicePath);
- ToUNICODE ((char *) &openTestStruct.wszFileName[0], sizeof(openTestStruct.wszFileName));
+ StringCbCopyW (&openTestStruct.wszFileName[0], sizeof(openTestStruct.wszFileName),devicePath);
openTestStruct.bDetectTCBootLoader = TRUE;
@@ -949,7 +946,7 @@ namespace VeraCrypt
bool BootEncryption::SystemDriveIsDynamic ()
{
GetSystemDriveConfigurationRequest request;
- StringCbPrintfW (request.DevicePath, sizeof (request.DevicePath), L"%hs", GetSystemDriveConfiguration().DeviceKernelPath.c_str());
+ StringCbCopyW (request.DevicePath, sizeof (request.DevicePath), GetSystemDriveConfiguration().DeviceKernelPath.c_str());
CallDriver (TC_IOCTL_GET_SYSTEM_DRIVE_CONFIG, &request, sizeof (request), &request, sizeof (request));
return request.DriveIsDynamic ? true : false;
@@ -963,7 +960,7 @@ namespace VeraCrypt
SystemDriveConfiguration config;
- string winDir = GetWindowsDirectory();
+ wstring winDir = GetWindowsDirectory();
// Scan all drives
for (int driveNumber = 0; driveNumber < 32; ++driveNumber)
@@ -977,7 +974,7 @@ namespace VeraCrypt
foreach (const Partition &part, partitions)
{
if (!part.MountPoint.empty()
- && (_access ((part.MountPoint + "\\bootmgr").c_str(), 0) == 0 || _access ((part.MountPoint + "\\ntldr").c_str(), 0) == 0))
+ && (_waccess ((part.MountPoint + L"\\bootmgr").c_str(), 0) == 0 || _waccess ((part.MountPoint + L"\\ntldr").c_str(), 0) == 0))
{
config.SystemLoaderPresent = true;
}
@@ -1006,12 +1003,12 @@ namespace VeraCrypt
{
config.DriveNumber = driveNumber;
- stringstream ss;
- ss << "PhysicalDrive" << driveNumber;
+ wstringstream ss;
+ ss << L"PhysicalDrive" << driveNumber;
config.DevicePath = ss.str();
- stringstream kernelPath;
- kernelPath << "\\Device\\Harddisk" << driveNumber << "\\Partition0";
+ wstringstream kernelPath;
+ kernelPath << L"\\Device\\Harddisk" << driveNumber << L"\\Partition0";
config.DeviceKernelPath = kernelPath.str();
config.DrivePartition = partitions.front();
@@ -1187,7 +1184,7 @@ namespace VeraCrypt
// Boot sector
DWORD size;
- byte *bootSecResourceImg = MapResource ("BIN", bootSectorId, &size);
+ byte *bootSecResourceImg = MapResource (L"BIN", bootSectorId, &size);
if (!bootSecResourceImg || size != TC_SECTOR_SIZE_BIOS)
throw ParameterIncorrect (SRC_POS);
@@ -1215,14 +1212,14 @@ namespace VeraCrypt
}
// Decompressor
- byte *decompressor = MapResource ("BIN", IDR_BOOT_LOADER_DECOMPRESSOR, &size);
+ byte *decompressor = MapResource (L"BIN", IDR_BOOT_LOADER_DECOMPRESSOR, &size);
if (!decompressor || size > TC_BOOT_LOADER_DECOMPRESSOR_SECTOR_COUNT * TC_SECTOR_SIZE_BIOS)
throw ParameterIncorrect (SRC_POS);
memcpy (buffer + TC_SECTOR_SIZE_BIOS, decompressor, size);
// Compressed boot loader
- byte *bootLoader = MapResource ("BIN", bootLoaderId, &size);
+ byte *bootLoader = MapResource (L"BIN", bootLoaderId, &size);
if (!bootLoader || size > TC_MAX_BOOT_LOADER_SECTOR_COUNT * TC_SECTOR_SIZE_BIOS)
throw ParameterIncorrect (SRC_POS);
@@ -1254,7 +1251,7 @@ namespace VeraCrypt
throw ParameterIncorrect (SRC_POS);
GetSystemDriveConfigurationRequest request;
- StringCbPrintfW (request.DevicePath, sizeof (request.DevicePath), L"%hs", GetSystemDriveConfiguration().DeviceKernelPath.c_str());
+ StringCbCopyW (request.DevicePath, sizeof (request.DevicePath), GetSystemDriveConfiguration().DeviceKernelPath.c_str());
try
{
@@ -1584,35 +1581,35 @@ namespace VeraCrypt
}
#endif
- string BootEncryption::GetSystemLoaderBackupPath ()
+ wstring BootEncryption::GetSystemLoaderBackupPath ()
{
- char pathBuf[MAX_PATH];
+ WCHAR pathBuf[MAX_PATH];
throw_sys_if (!SUCCEEDED (SHGetFolderPath (NULL, CSIDL_COMMON_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, pathBuf)));
- string path = string (pathBuf) + "\\" TC_APP_NAME;
+ wstring path = wstring (pathBuf) + L"\\" _T(TC_APP_NAME);
CreateDirectory (path.c_str(), NULL);
- return path + '\\' + TC_SYS_BOOT_LOADER_BACKUP_NAME;
+ return path + L'\\' + TC_SYS_BOOT_LOADER_BACKUP_NAME;
}
void BootEncryption::RenameDeprecatedSystemLoaderBackup ()
{
- char pathBuf[MAX_PATH];
+ WCHAR pathBuf[MAX_PATH];
if (SUCCEEDED (SHGetFolderPath (NULL, CSIDL_COMMON_APPDATA, NULL, 0, pathBuf)))
{
- string path = string (pathBuf) + "\\" TC_APP_NAME + '\\' + TC_SYS_BOOT_LOADER_BACKUP_NAME_LEGACY;
+ wstring path = wstring (pathBuf) + L"\\" _T(TC_APP_NAME) + L'\\' + TC_SYS_BOOT_LOADER_BACKUP_NAME_LEGACY;
if (FileExists (path.c_str()) && !FileExists (GetSystemLoaderBackupPath().c_str()))
- throw_sys_if (rename (path.c_str(), GetSystemLoaderBackupPath().c_str()) != 0);
+ throw_sys_if (_wrename (path.c_str(), GetSystemLoaderBackupPath().c_str()) != 0);
}
}
#ifndef SETUP
- void BootEncryption::CreateRescueIsoImage (bool initialSetup, const string &isoImagePath)
+ void BootEncryption::CreateRescueIsoImage (bool initialSetup, const wstring &isoImagePath)
{
BootEncryptionStatus encStatus = GetStatus();
if (encStatus.SetupInProgress)
@@ -1764,12 +1761,12 @@ namespace VeraCrypt
if (!RescueIsoImage)
throw ParameterIncorrect (SRC_POS);
- for (char drive = 'Z'; drive >= 'C'; --drive)
+ for (WCHAR drive = L'Z'; drive >= L'C'; --drive)
{
try
{
- char rootPath[4] = { drive, ':', '\\', 0};
- UINT driveType = GetDriveTypeA (rootPath);
+ WCHAR rootPath[4] = { drive, L':', L'\\', 0};
+ UINT driveType = GetDriveType (rootPath);
// check that it is a CD/DVD drive or a removable media in case a bootable
// USB key was created from the rescue disk ISO file
if ((DRIVE_CDROM == driveType) || (DRIVE_REMOVABLE == driveType))
@@ -1795,7 +1792,7 @@ namespace VeraCrypt
return false;
}
- bool BootEncryption::VerifyRescueDiskIsoImage (const char* imageFile)
+ bool BootEncryption::VerifyRescueDiskIsoImage (const wchar_t* imageFile)
{
if (!RescueIsoImage)
throw ParameterIncorrect (SRC_POS);
@@ -1967,7 +1964,7 @@ namespace VeraCrypt
filter = "veracrypt.sys";
filterReg = "DumpFilters";
- SetLastError (RegOpenKeyEx (HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\CrashControl", 0, KEY_READ | KEY_WRITE, &regKey));
+ SetLastError (RegOpenKeyEx (HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\CrashControl", 0, KEY_READ | KEY_WRITE, &regKey));
throw_sys_if (GetLastError() != ERROR_SUCCESS);
break;
@@ -1989,18 +1986,18 @@ namespace VeraCrypt
// SetupInstallFromInfSection() does not support prepending of values so we have to modify the registry directly
StringCbCopyA ((char *) regKeyBuf, sizeof(regKeyBuf), filter.c_str());
- if (RegQueryValueEx (regKey, filterReg.c_str(), NULL, NULL, regKeyBuf + strSize, &size) != ERROR_SUCCESS)
+ if (RegQueryValueExA (regKey, filterReg.c_str(), NULL, NULL, regKeyBuf + strSize, &size) != ERROR_SUCCESS)
size = 1;
- SetLastError (RegSetValueEx (regKey, filterReg.c_str(), 0, REG_MULTI_SZ, regKeyBuf, (DWORD) strSize + size));
+ SetLastError (RegSetValueExA (regKey, filterReg.c_str(), 0, REG_MULTI_SZ, regKeyBuf, (DWORD) strSize + size));
throw_sys_if (GetLastError() != ERROR_SUCCESS);
}
else
{
- string infFileName = GetTempPath() + "\\veracrypt_driver_setup.inf";
+ wstring infFileName = GetTempPath() + L"\\veracrypt_driver_setup.inf";
File infFile (infFileName, false, true);
- finally_do_arg (string, infFileName, { DeleteFile (finally_arg.c_str()); });
+ finally_do_arg (wstring, infFileName, { DeleteFile (finally_arg.c_str()); });
string infTxt = "[veracrypt]\r\n"
+ string (registerFilter ? "Add" : "Del") + "Reg=veracrypt_reg\r\n\r\n"
@@ -2014,7 +2011,7 @@ namespace VeraCrypt
throw_sys_if (hInf == INVALID_HANDLE_VALUE);
finally_do_arg (HINF, hInf, { SetupCloseInfFile (finally_arg); });
- throw_sys_if (!SetupInstallFromInfSection (ParentWindow, hInf, "veracrypt", SPINST_REGISTRY, regKey, NULL, 0, NULL, NULL, NULL, NULL));
+ throw_sys_if (!SetupInstallFromInfSection (ParentWindow, hInf, L"veracrypt", SPINST_REGISTRY, regKey, NULL, 0, NULL, NULL, NULL, NULL));
}
}
@@ -2052,8 +2049,8 @@ namespace VeraCrypt
throw_sys_if (!scm);
finally_do_arg (SC_HANDLE, scm, { CloseServiceHandle (finally_arg); });
- string servicePath = GetServiceConfigPath (TC_APP_NAME ".exe", false);
- string serviceLegacyPath = GetServiceConfigPath (TC_APP_NAME ".exe", true);
+ wstring servicePath = GetServiceConfigPath (_T(TC_APP_NAME) L".exe", false);
+ wstring serviceLegacyPath = GetServiceConfigPath (_T(TC_APP_NAME) L".exe", true);
if (registerService)
{
@@ -2065,20 +2062,20 @@ namespace VeraCrypt
if (!noFileHandling)
{
- char appPath[TC_MAX_PATH];
- throw_sys_if (!GetModuleFileName (NULL, appPath, sizeof (appPath)));
+ wchar_t appPath[TC_MAX_PATH];
+ throw_sys_if (!GetModuleFileName (NULL, appPath, ARRAYSIZE (appPath)));
throw_sys_if (!CopyFile (appPath, servicePath.c_str(), FALSE));
}
SC_HANDLE service = CreateService (scm,
TC_SYSTEM_FAVORITES_SERVICE_NAME,
- TC_APP_NAME " System Favorites",
+ _T(TC_APP_NAME) L" System Favorites",
SERVICE_ALL_ACCESS,
SERVICE_WIN32_OWN_PROCESS,
SERVICE_AUTO_START,
SERVICE_ERROR_NORMAL,
- (string ("\"") + servicePath + "\" " TC_SYSTEM_FAVORITES_SERVICE_CMDLINE_OPTION).c_str(),
+ (wstring (L"\"") + servicePath + L"\" " TC_SYSTEM_FAVORITES_SERVICE_CMDLINE_OPTION).c_str(),
TC_SYSTEM_FAVORITES_SERVICE_LOAD_ORDER_GROUP,
NULL,
NULL,
@@ -2088,15 +2085,15 @@ namespace VeraCrypt
throw_sys_if (!service);
SERVICE_DESCRIPTION description;
- description.lpDescription = "Mounts VeraCrypt system favorite volumes.";
+ description.lpDescription = L"Mounts VeraCrypt system favorite volumes.";
ChangeServiceConfig2 (service, SERVICE_CONFIG_DESCRIPTION, &description);
CloseServiceHandle (service);
try
{
- WriteLocalMachineRegistryString ("SYSTEM\\CurrentControlSet\\Control\\SafeBoot\\Minimal\\" TC_SYSTEM_FAVORITES_SERVICE_NAME, NULL, "Service", FALSE);
- WriteLocalMachineRegistryString ("SYSTEM\\CurrentControlSet\\Control\\SafeBoot\\Network\\" TC_SYSTEM_FAVORITES_SERVICE_NAME, NULL, "Service", FALSE);
+ WriteLocalMachineRegistryString (L"SYSTEM\\CurrentControlSet\\Control\\SafeBoot\\Minimal\\" TC_SYSTEM_FAVORITES_SERVICE_NAME, NULL, L"Service", FALSE);
+ WriteLocalMachineRegistryString (L"SYSTEM\\CurrentControlSet\\Control\\SafeBoot\\Network\\" TC_SYSTEM_FAVORITES_SERVICE_NAME, NULL, L"Service", FALSE);
SetDriverConfigurationFlag (TC_DRIVER_CONFIG_CACHE_BOOT_PASSWORD_FOR_SYS_FAVORITES, true);
}
@@ -2115,8 +2112,8 @@ namespace VeraCrypt
{
SetDriverConfigurationFlag (TC_DRIVER_CONFIG_CACHE_BOOT_PASSWORD_FOR_SYS_FAVORITES, false);
- DeleteLocalMachineRegistryKey ("SYSTEM\\CurrentControlSet\\Control\\SafeBoot\\Minimal", TC_SYSTEM_FAVORITES_SERVICE_NAME);
- DeleteLocalMachineRegistryKey ("SYSTEM\\CurrentControlSet\\Control\\SafeBoot\\Network", TC_SYSTEM_FAVORITES_SERVICE_NAME);
+ DeleteLocalMachineRegistryKey (L"SYSTEM\\CurrentControlSet\\Control\\SafeBoot\\Minimal", TC_SYSTEM_FAVORITES_SERVICE_NAME);
+ DeleteLocalMachineRegistryKey (L"SYSTEM\\CurrentControlSet\\Control\\SafeBoot\\Network", TC_SYSTEM_FAVORITES_SERVICE_NAME);
SC_HANDLE service = OpenService (scm, TC_SYSTEM_FAVORITES_SERVICE_NAME, SERVICE_ALL_ACCESS);
throw_sys_if (!service);
@@ -2140,7 +2137,7 @@ namespace VeraCrypt
finally_do_arg (SC_HANDLE, scm, { CloseServiceHandle (finally_arg); });
- string servicePath = GetServiceConfigPath (TC_APP_NAME ".exe", false);
+ wstring servicePath = GetServiceConfigPath (_T(TC_APP_NAME) L".exe", false);
// check if service exists
SC_HANDLE service = OpenService (scm, TC_SYSTEM_FAVORITES_SERVICE_NAME, SERVICE_ALL_ACCESS);
@@ -2151,13 +2148,13 @@ namespace VeraCrypt
SERVICE_WIN32_OWN_PROCESS,
SERVICE_AUTO_START,
SERVICE_ERROR_NORMAL,
- (string ("\"") + servicePath + "\" " TC_SYSTEM_FAVORITES_SERVICE_CMDLINE_OPTION).c_str(),
+ (wstring (L"\"") + servicePath + L"\" " TC_SYSTEM_FAVORITES_SERVICE_CMDLINE_OPTION).c_str(),
TC_SYSTEM_FAVORITES_SERVICE_LOAD_ORDER_GROUP,
NULL,
NULL,
NULL,
NULL,
- TC_APP_NAME " System Favorites"));
+ _T(TC_APP_NAME) L" System Favorites"));
}
else
@@ -2175,9 +2172,9 @@ namespace VeraCrypt
else
configMap &= ~flag;
#ifdef SETUP
- WriteLocalMachineRegistryDword ("SYSTEM\\CurrentControlSet\\Services\\veracrypt", TC_DRIVER_CONFIG_REG_VALUE_NAME, configMap);
+ WriteLocalMachineRegistryDword (L"SYSTEM\\CurrentControlSet\\Services\\veracrypt", TC_DRIVER_CONFIG_REG_VALUE_NAME, configMap);
#else
- WriteLocalMachineRegistryDwordValue ("SYSTEM\\CurrentControlSet\\Services\\veracrypt", TC_DRIVER_CONFIG_REG_VALUE_NAME, configMap);
+ WriteLocalMachineRegistryDwordValue (L"SYSTEM\\CurrentControlSet\\Services\\veracrypt", TC_DRIVER_CONFIG_REG_VALUE_NAME, configMap);
#endif
}
@@ -2260,20 +2257,20 @@ namespace VeraCrypt
void BootEncryption::InitialSecurityChecksForHiddenOS ()
{
- char windowsDrive = (char) toupper (GetWindowsDirectory()[0]);
+ wchar_t windowsDrive = (wchar_t) towupper (GetWindowsDirectory()[0]);
// Paging files
bool pagingFilesOk = !IsPagingFileActive (TRUE);
- char pagingFileRegData[65536];
+ wchar_t pagingFileRegData[65536];
DWORD pagingFileRegDataSize = sizeof (pagingFileRegData);
- if (ReadLocalMachineRegistryMultiString ("System\\CurrentControlSet\\Control\\Session Manager\\Memory Management", "PagingFiles", pagingFileRegData, &pagingFileRegDataSize)
- && pagingFileRegDataSize > 4)
+ if (ReadLocalMachineRegistryMultiString (L"System\\CurrentControlSet\\Control\\Session Manager\\Memory Management", L"PagingFiles", pagingFileRegData, &pagingFileRegDataSize)
+ && pagingFileRegDataSize > 8)
{
- for (size_t i = 1; i < pagingFileRegDataSize - 2; ++i)
+ for (size_t i = 1; i < pagingFileRegDataSize/2 - 2; ++i)
{
- if (memcmp (pagingFileRegData + i, ":\\", 2) == 0 && toupper (pagingFileRegData[i - 1]) != windowsDrive)
+ if (wmemcmp (pagingFileRegData + i, L":\\", 2) == 0 && towupper (pagingFileRegData[i - 1]) != windowsDrive)
{
pagingFilesOk = false;
break;
@@ -2299,15 +2296,15 @@ namespace VeraCrypt
}
// User profile
- char *configPath = GetConfigPath ("dummy");
- if (configPath && toupper (configPath[0]) != windowsDrive)
+ wchar_t *configPath = GetConfigPath (L"dummy");
+ if (configPath && towupper (configPath[0]) != windowsDrive)
{
throw ErrorException (wstring (GetString ("USER_PROFILE_NOT_ON_SYS_PARTITION"))
+ GetString ("LEAKS_OUTSIDE_SYSPART_UNIVERSAL_EXPLANATION"), SRC_POS);
}
// Temporary files
- if (toupper (GetTempPath()[0]) != windowsDrive)
+ if (towupper (GetTempPath()[0]) != windowsDrive)
{
throw ErrorException (wstring (GetString ("TEMP_NOT_ON_SYS_PARTITION"))
+ GetString ("LEAKS_OUTSIDE_SYSPART_UNIVERSAL_EXPLANATION"), SRC_POS);
@@ -2602,7 +2599,7 @@ namespace VeraCrypt
}
- void BootEncryption::PrepareInstallation (bool systemPartitionOnly, Password &password, int ea, int mode, int pkcs5, int pim, const string &rescueIsoImagePath)
+ void BootEncryption::PrepareInstallation (bool systemPartitionOnly, Password &password, int ea, int mode, int pkcs5, int pim, const wstring &rescueIsoImagePath)
{
BootEncryptionStatus encStatus = GetStatus();
if (encStatus.DriveMounted)
@@ -2671,14 +2668,14 @@ namespace VeraCrypt
void BootEncryption::RestrictPagingFilesToSystemPartition ()
{
- char pagingFiles[128];
- StringCbCopyA (pagingFiles, sizeof(pagingFiles), "X:\\pagefile.sys 0 0");
+ wchar_t pagingFiles[128] = {0};
+ StringCbCopyW (pagingFiles, sizeof(pagingFiles), L"X:\\pagefile.sys 0 0");
pagingFiles[0] = GetWindowsDirectory()[0];
- throw_sys_if (!WriteLocalMachineRegistryMultiString ("System\\CurrentControlSet\\Control\\Session Manager\\Memory Management", "PagingFiles", pagingFiles, (DWORD) strlen (pagingFiles) + 2));
+ throw_sys_if (!WriteLocalMachineRegistryMultiString (L"System\\CurrentControlSet\\Control\\Session Manager\\Memory Management", L"PagingFiles", pagingFiles, (DWORD) (wcslen (pagingFiles) + 2) * sizeof (wchar_t)));
}
- void BootEncryption::WriteLocalMachineRegistryDwordValue (char *keyPath, char *valueName, DWORD value)
+ void BootEncryption::WriteLocalMachineRegistryDwordValue (wchar_t *keyPath, wchar_t *valueName, DWORD value)
{
if (!IsAdmin() && IsUacSupported())
{
@@ -2722,7 +2719,7 @@ namespace VeraCrypt
CallDriver (TC_IOCTL_BOOT_ENCRYPTION_SETUP, &request, sizeof (request), NULL, 0);
}
- void BootEncryption::CopyFileAdmin (const string &sourceFile, const string &destinationFile)
+ void BootEncryption::CopyFileAdmin (const wstring &sourceFile, const wstring &destinationFile)
{
if (!IsAdmin())
{
@@ -2738,7 +2735,7 @@ namespace VeraCrypt
throw_sys_if (!::CopyFile (sourceFile.c_str(), destinationFile.c_str(), FALSE));
}
- void BootEncryption::DeleteFileAdmin (const string &file)
+ void BootEncryption::DeleteFileAdmin (const wstring &file)
{
if (!IsAdmin() && IsUacSupported())
Elevator::DeleteFile (file);
@@ -2752,7 +2749,7 @@ namespace VeraCrypt
{
DWORD configMap;
- if (!ReadLocalMachineRegistryDword ("SYSTEM\\CurrentControlSet\\Services\\veracrypt", TC_DRIVER_CONFIG_REG_VALUE_NAME, &configMap))
+ if (!ReadLocalMachineRegistryDword (L"SYSTEM\\CurrentControlSet\\Services\\veracrypt", TC_DRIVER_CONFIG_REG_VALUE_NAME, &configMap))
configMap = 0;
return configMap;
diff --git a/src/Common/BootEncryption.h b/src/Common/BootEncryption.h
index c3eb3362..ae2d85ec 100644
--- a/src/Common/BootEncryption.h
+++ b/src/Common/BootEncryption.h
@@ -27,7 +27,7 @@ namespace VeraCrypt
{
public:
File () : Elevated (false), FileOpen (false), FilePointerPosition(0), Handle(INVALID_HANDLE_VALUE), IsDevice(false), LastError(0) { }
- File (string path,bool readOnly = false, bool create = false);
+ File (wstring path,bool readOnly = false, bool create = false);
virtual ~File () { Close(); }
void CheckOpened (const char* srcPos) { if (!FileOpen) { SetLastError (LastError); throw SystemException (srcPos);} }
@@ -42,7 +42,7 @@ namespace VeraCrypt
uint64 FilePointerPosition;
HANDLE Handle;
bool IsDevice;
- string Path;
+ wstring Path;
DWORD LastError;
};
@@ -50,7 +50,7 @@ namespace VeraCrypt
class Device : public File
{
public:
- Device (string path,bool readOnly = false);
+ Device (wstring path,bool readOnly = false);
virtual ~Device () {}
};
@@ -77,9 +77,9 @@ namespace VeraCrypt
struct Partition
{
- string DevicePath;
+ wstring DevicePath;
PARTITION_INFORMATION Info;
- string MountPoint;
+ wstring MountPoint;
size_t Number;
BOOL IsGPT;
wstring VolumeNameId;
@@ -119,8 +119,8 @@ namespace VeraCrypt
struct SystemDriveConfiguration
{
- string DeviceKernelPath;
- string DevicePath;
+ wstring DeviceKernelPath;
+ wstring DevicePath;
int DriveNumber;
Partition DrivePartition;
bool ExtraBootPartitionPresent;
@@ -154,19 +154,19 @@ namespace VeraCrypt
void CheckEncryptionSetupResult ();
void CheckRequirements ();
void CheckRequirementsHiddenOS ();
- void CopyFileAdmin (const string &sourceFile, const string &destinationFile);
- void CreateRescueIsoImage (bool initialSetup, const string &isoImagePath);
+ void CopyFileAdmin (const wstring &sourceFile, const wstring &destinationFile);
+ void CreateRescueIsoImage (bool initialSetup, const wstring &isoImagePath);
void Deinstall (bool displayWaitDialog = false);
- void DeleteFileAdmin (const string &file);
+ void DeleteFileAdmin (const wstring &file);
DecoySystemWipeStatus GetDecoyOSWipeStatus ();
DWORD GetDriverServiceStartType ();
unsigned int GetHiddenOSCreationPhase ();
uint16 GetInstalledBootLoaderVersion ();
void GetInstalledBootLoaderFingerprint (byte fingerprint[WHIRLPOOL_DIGESTSIZE + SHA512_DIGESTSIZE]);
Partition GetPartitionForHiddenOS ();
- bool IsBootLoaderOnDrive (char *devicePath);
+ bool IsBootLoaderOnDrive (wchar_t *devicePath);
BootEncryptionStatus GetStatus ();
- string GetTempPath ();
+ wstring GetTempPath ();
void GetVolumeProperties (VOLUME_PROPERTIES_STRUCT *properties);
SystemDriveConfiguration GetSystemDriveConfiguration ();
void Install (bool hiddenSystem);
@@ -178,7 +178,7 @@ namespace VeraCrypt
bool IsHiddenSystemRunning ();
bool IsPagingFileActive (BOOL checkNonWindowsPartitionsOnly);
void PrepareHiddenOSCreation (int ea, int mode, int pkcs5);
- void PrepareInstallation (bool systemPartitionOnly, Password &password, int ea, int mode, int pkcs5, int pim, const string &rescueIsoImagePath);
+ void PrepareInstallation (bool systemPartitionOnly, Password &password, int ea, int mode, int pkcs5, int pim, const wstring &rescueIsoImagePath);
void ProbeRealSystemDriveSize ();
void ReadBootSectorConfig (byte *config, size_t bufLength, byte *userConfig = nullptr, string *customUserMessage = nullptr, uint16 *bootLoaderVersion = nullptr);
uint32 ReadDriverConfigurationFlags ();
@@ -203,12 +203,12 @@ namespace VeraCrypt
bool SystemPartitionCoversWholeDrive ();
bool SystemDriveIsDynamic ();
bool VerifyRescueDisk ();
- bool VerifyRescueDiskIsoImage (const char* imageFile);
+ bool VerifyRescueDiskIsoImage (const wchar_t* imageFile);
void WipeHiddenOSCreationConfig ();
void WriteBootDriveSector (uint64 offset, byte *data);
void WriteBootSectorConfig (const byte newConfig[]);
void WriteBootSectorUserConfig (byte userConfig, const string &customUserMessage);
- void WriteLocalMachineRegistryDwordValue (char *keyPath, char *valueName, DWORD value);
+ void WriteLocalMachineRegistryDwordValue (wchar_t *keyPath, wchar_t *valueName, DWORD value);
protected:
static const uint32 RescueIsoImageSize = 1835008; // Size of ISO9660 image with bootable emulated 1.44MB floppy disk image
@@ -216,12 +216,12 @@ namespace VeraCrypt
void BackupSystemLoader ();
void CreateBootLoaderInMemory (byte *buffer, size_t bufferSize, bool rescueDisk, bool hiddenOSCreation = false);
void CreateVolumeHeader (uint64 volumeSize, uint64 encryptedAreaStart, Password *password, int ea, int mode, int pkcs5, int pim);
- string GetSystemLoaderBackupPath ();
+ wstring GetSystemLoaderBackupPath ();
uint32 GetChecksum (byte *data, size_t size);
DISK_GEOMETRY GetDriveGeometry (int driveNumber);
PartitionList GetDrivePartitions (int driveNumber);
wstring GetRemarksOnHiddenOS ();
- string GetWindowsDirectory ();
+ wstring GetWindowsDirectory ();
void RegisterFilter (bool registerFilter, FilterType filterType, const GUID *deviceClassGuid = nullptr);
void RestoreSystemLoader ();
void InstallVolumeHeader ();
@@ -246,11 +246,11 @@ namespace VeraCrypt
#define MIN_HIDDENOS_DECOY_PARTITION_SIZE_RATIO_NTFS 2.1
#define MIN_HIDDENOS_DECOY_PARTITION_SIZE_RATIO_FAT 1.05
-#define TC_SYS_BOOT_LOADER_BACKUP_NAME "Original System Loader"
-#define TC_SYS_BOOT_LOADER_BACKUP_NAME_LEGACY "Original System Loader.bak" // Deprecated to prevent removal by some "cleaners"
+#define TC_SYS_BOOT_LOADER_BACKUP_NAME L"Original System Loader"
+#define TC_SYS_BOOT_LOADER_BACKUP_NAME_LEGACY L"Original System Loader.bak" // Deprecated to prevent removal by some "cleaners"
-#define TC_SYSTEM_FAVORITES_SERVICE_NAME TC_APP_NAME "SystemFavorites"
-#define TC_SYSTEM_FAVORITES_SERVICE_LOAD_ORDER_GROUP "Event Log"
-#define TC_SYSTEM_FAVORITES_SERVICE_CMDLINE_OPTION "/systemFavoritesService"
+#define TC_SYSTEM_FAVORITES_SERVICE_NAME _T(TC_APP_NAME) L"SystemFavorites"
+#define TC_SYSTEM_FAVORITES_SERVICE_LOAD_ORDER_GROUP L"Event Log"
+#define TC_SYSTEM_FAVORITES_SERVICE_CMDLINE_OPTION L"/systemFavoritesService"
#endif // TC_HEADER_Common_BootEncryption
diff --git a/src/Common/Cmdline.c b/src/Common/Cmdline.c
index 4fca2dbe..f3609f9c 100644
--- a/src/Common/Cmdline.c
+++ b/src/Common/Cmdline.c
@@ -40,8 +40,8 @@ BOOL CALLBACK CommandHelpDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM
{
case WM_INITDIALOG:
{
- char * tmp = err_malloc(8192);
- char tmp2[MAX_PATH * 2];
+ wchar_t * tmp = err_malloc(8192 * sizeof (wchar_t));
+ wchar_t tmp2[MAX_PATH * 2];
argumentspec *as;
int i;
@@ -51,29 +51,29 @@ BOOL CALLBACK CommandHelpDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM
*tmp = 0;
- StringCbCopyA (tmp, 8192, "VeraCrypt " VERSION_STRING);
+ StringCchCopyW (tmp, 8192, L"VeraCrypt " _T(VERSION_STRING));
#ifdef _WIN64
- StringCbCatA (tmp, 8192, " (64-bit)");
+ StringCchCatW (tmp, 8192, L" (64-bit)");
#else
- StringCbCatA (tmp, 8192, " (32-bit)");
+ StringCchCatW (tmp, 8192, L" (32-bit)");
#endif
#if (defined(_DEBUG) || defined(DEBUG))
- StringCbCatA (tmp, 8192, " (debug)");
+ StringCchCatW (tmp, 8192, L" (debug)");
#endif
- StringCbCatA (tmp, 8192, "\n\nCommand line options:\n\n");
+ StringCchCatW (tmp, 8192, L"\n\nCommand line options:\n\n");
for (i = 0; i < as->arg_cnt; i ++)
{
if (!as->args[i].Internal)
{
- StringCchPrintf(tmp2, MAX_PATH * 2, "%s\t%s\n", as->args[i].short_name, as->args[i].long_name);
- StringCchCat(tmp, 8192, tmp2);
+ StringCchPrintfW(tmp2, MAX_PATH * 2, L"%s\t%s\n", as->args[i].short_name, as->args[i].long_name);
+ StringCchCatW(tmp, 8192, tmp2);
}
}
- StringCbCatA (tmp, 8192, "\nExamples:\n\nMount a volume as X:\tveracrypt.exe /q /v volume.hc /l X\nDismount a volume X:\tveracrypt.exe /q /d X");
+ StringCchCatW (tmp, 8192, L"\nExamples:\n\nMount a volume as X:\tveracrypt.exe /q /v volume.hc /l X\nDismount a volume X:\tveracrypt.exe /q /d X");
- SetWindowText (GetDlgItem (hwndDlg, IDC_COMMANDHELP_TEXT), (char*) tmp);
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_COMMANDHELP_TEXT), tmp);
TCfree(tmp);
return 1;
@@ -90,7 +90,7 @@ BOOL CALLBACK CommandHelpDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM
return 0;
}
-int Win32CommandLine (char *lpszCommandLine, char ***lpszArgs)
+int Win32CommandLine (wchar_t ***lpszArgs)
{
int argumentCount;
int i;
@@ -109,30 +109,16 @@ int Win32CommandLine (char *lpszCommandLine, char ***lpszArgs)
return 0;
}
- *lpszArgs = malloc (sizeof (char *) * argumentCount);
+ *lpszArgs = malloc (sizeof (wchar_t *) * argumentCount);
if (!*lpszArgs)
AbortProcess ("OUTOFMEMORY");
for (i = 0; i < argumentCount; ++i)
{
- size_t argLen = wcslen (arguments[i + 1]);
-
- char *arg = malloc (argLen + 1);
+ wchar_t *arg = _wcsdup (arguments[i + 1]);
if (!arg)
AbortProcess ("OUTOFMEMORY");
- if (argLen > 0)
- {
- int len = WideCharToMultiByte (CP_ACP, 0, arguments[i + 1], -1, arg, (int) argLen + 1, NULL, NULL);
- if (len == 0)
- {
- handleWin32Error (NULL, SRC_POS);
- AbortProcessSilent();
- }
- }
- else
- arg[0] = 0;
-
(*lpszArgs)[i] = arg;
}
@@ -140,21 +126,21 @@ int Win32CommandLine (char *lpszCommandLine, char ***lpszArgs)
return argumentCount;
}
-int GetArgSepPosOffset (char *lpszArgument)
+int GetArgSepPosOffset (wchar_t *lpszArgument)
{
- if (lpszArgument[0] == '/')
+ if (lpszArgument[0] == L'/')
return 1;
return 0;
}
-int GetArgumentID (argumentspec *as, char *lpszArgument)
+int GetArgumentID (argumentspec *as, wchar_t *lpszArgument)
{
int i;
for (i = 0; i < as->arg_cnt; i++)
{
- if (_stricmp (as->args[i].long_name, lpszArgument) == 0)
+ if (_wcsicmp (as->args[i].long_name, lpszArgument) == 0)
{
return as->args[i].Id;
}
@@ -165,7 +151,7 @@ int GetArgumentID (argumentspec *as, char *lpszArgument)
if (as->args[i].short_name[0] == 0)
continue;
- if (_stricmp (as->args[i].short_name, lpszArgument) == 0)
+ if (_wcsicmp (as->args[i].short_name, lpszArgument) == 0)
{
return as->args[i].Id;
}
@@ -175,8 +161,8 @@ int GetArgumentID (argumentspec *as, char *lpszArgument)
return -1;
}
-int GetArgumentValue (char **lpszCommandLineArgs, int *nArgIdx,
- int nNoCommandLineArgs, char *lpszValue, int nValueSize)
+int GetArgumentValue (wchar_t **lpszCommandLineArgs, int *nArgIdx,
+ int nNoCommandLineArgs, wchar_t *lpszValue, int nValueSize)
{
*lpszValue = 0;
@@ -187,7 +173,7 @@ int GetArgumentValue (char **lpszCommandLineArgs, int *nArgIdx,
{
/* Handles the case of space between parameter code
and value */
- StringCbCopyA (lpszValue, nValueSize, lpszCommandLineArgs[*nArgIdx + 1]);
+ StringCbCopyW (lpszValue, nValueSize, lpszCommandLineArgs[*nArgIdx + 1]);
lpszValue[nValueSize - 1] = 0;
(*nArgIdx)++;
return HAS_ARGUMENT;
diff --git a/src/Common/Cmdline.h b/src/Common/Cmdline.h
index a46a7c35..8f2c055c 100644
--- a/src/Common/Cmdline.h
+++ b/src/Common/Cmdline.h
@@ -21,8 +21,8 @@ extern "C" {
typedef struct argument_t
{
int Id;
- char long_name[32];
- char short_name[8];
+ wchar_t long_name[32];
+ wchar_t short_name[8];
BOOL Internal;
} argument;
@@ -33,10 +33,10 @@ typedef struct argumentspec_t
} argumentspec;
BOOL CALLBACK CommandHelpDlgProc ( HWND hwndDlg , UINT msg , WPARAM wParam , LPARAM lParam );
-int Win32CommandLine ( char *lpszCommandLine , char ***lpszArgs );
-int GetArgSepPosOffset ( char *lpszArgument );
-int GetArgumentID ( argumentspec *as , char *lpszArgument );
-int GetArgumentValue ( char **lpszCommandLineArgs , int *nArgIdx , int nNoCommandLineArgs , char *lpszValue , int nValueSize );
+int Win32CommandLine ( wchar_t ***lpszArgs );
+int GetArgSepPosOffset ( wchar_t *lpszArgument );
+int GetArgumentID ( argumentspec *as , wchar_t *lpszArgument );
+int GetArgumentValue ( wchar_t **lpszCommandLineArgs , int *nArgIdx , int nNoCommandLineArgs , wchar_t *lpszValue , int nValueSize );
#ifdef __cplusplus
}
diff --git a/src/Common/Combo.c b/src/Common/Combo.c
index 89e8315f..e5759bb3 100644
--- a/src/Common/Combo.c
+++ b/src/Common/Combo.c
@@ -20,7 +20,7 @@
#define SIZEOF_MRU_LIST 20
-void AddComboItem (HWND hComboBox, char *lpszFileName, BOOL saveHistory)
+void AddComboItem (HWND hComboBox, const wchar_t *lpszFileName, BOOL saveHistory)
{
LPARAM nIndex;
@@ -53,19 +53,19 @@ void AddComboItem (HWND hComboBox, char *lpszFileName, BOOL saveHistory)
LPARAM MoveEditToCombo (HWND hComboBox, BOOL saveHistory)
{
- char szTmp[TC_MAX_PATH] = {0};
+ wchar_t szTmp[TC_MAX_PATH] = {0};
if (!saveHistory)
{
- GetWindowText (hComboBox, szTmp, sizeof (szTmp));
+ GetWindowText (hComboBox, szTmp, ARRAYSIZE (szTmp));
SendMessage (hComboBox, CB_RESETCONTENT, 0, 0);
SetWindowText (hComboBox, szTmp);
return 0;
}
- GetWindowText (hComboBox, szTmp, sizeof (szTmp));
+ GetWindowText (hComboBox, szTmp, ARRAYSIZE (szTmp));
- if (strlen (szTmp) > 0)
+ if (wcslen (szTmp) > 0)
{
LPARAM nIndex = SendMessage (hComboBox, CB_FINDSTRINGEXACT, (WPARAM) - 1,
(LPARAM) & szTmp[0]);
@@ -169,19 +169,22 @@ void LoadCombo (HWND hComboBox, BOOL bEnabled, BOOL bOnlyCheckModified, BOOL *pb
i = 0;
while (xml = XmlFindElement (xml, "volume"))
{
- char szTmp[MAX_PATH] = { 0 };
+ wchar_t szTmp[MAX_PATH] = { 0 };
+ wchar_t wszVolume[MAX_PATH] = {0};
if (i < count)
{
- if (SendMessage (hComboBox, CB_GETLBTEXTLEN, nComboIdx[i], 0) < sizeof (szTmp))
+ if (SendMessage (hComboBox, CB_GETLBTEXTLEN, nComboIdx[i], 0) < ARRAYSIZE (szTmp))
SendMessage (hComboBox, CB_GETLBTEXT, nComboIdx[i], (LPARAM) & szTmp[0]);
}
XmlGetNodeText (xml, volume, sizeof (volume));
+ if (0 == MultiByteToWideChar (CP_UTF8, 0, volume, -1, wszVolume, MAX_PATH))
+ wszVolume [0] = 0;
if (!bOnlyCheckModified)
- AddComboItem (hComboBox, volume, TRUE);
+ AddComboItem (hComboBox, wszVolume, TRUE);
- if (pbModified && strcmp (volume, szTmp))
+ if (pbModified && wcscmp (wszVolume, szTmp))
*pbModified = TRUE;
xml++;
@@ -208,11 +211,11 @@ void DumpCombo (HWND hComboBox, int bClear)
return;
}
- f = fopen (GetConfigPath (TC_APPD_FILENAME_HISTORY), "w");
+ f = _wfopen (GetConfigPath (TC_APPD_FILENAME_HISTORY), L"w,ccs=UTF-8");
if (f == NULL) return;
XmlWriteHeader (f);
- fputs ("\n\t<history>", f);
+ fputws (L"\n\t<history>", f);
/* combo list part:- get mru items */
for (i = 0; i < SIZEOF_MRU_LIST; i++)
@@ -221,21 +224,21 @@ void DumpCombo (HWND hComboBox, int bClear)
/* combo list part:- write out mru items */
for (i = 0; i < SIZEOF_MRU_LIST; i++)
{
- char szTmp[MAX_PATH] = { 0 };
+ wchar_t szTmp[MAX_PATH] = { 0 };
- if (SendMessage (hComboBox, CB_GETLBTEXTLEN, nComboIdx[i], 0) < sizeof (szTmp))
+ if (SendMessage (hComboBox, CB_GETLBTEXTLEN, nComboIdx[i], 0) < ARRAYSIZE (szTmp))
SendMessage (hComboBox, CB_GETLBTEXT, nComboIdx[i], (LPARAM) & szTmp[0]);
if (szTmp[0] != 0)
{
- char q[MAX_PATH * 2] = { 0 };
- XmlQuoteText (szTmp, q, sizeof (q));
+ wchar_t q[MAX_PATH * 2] = { 0 };
+ XmlQuoteTextW (szTmp, q, sizeof (q));
- fprintf (f, "\n\t\t<volume>%s</volume>", q);
+ fwprintf (f, L"\n\t\t<volume>%s</volume>", q);
}
}
- fputs ("\n\t</history>", f);
+ fputws (L"\n\t</history>", f);
XmlWriteFooter (f);
fclose (f);
}
diff --git a/src/Common/Combo.h b/src/Common/Combo.h
index 9bd67a92..f4889fc5 100644
--- a/src/Common/Combo.h
+++ b/src/Common/Combo.h
@@ -15,7 +15,7 @@
extern "C" {
#endif
-void AddComboItem (HWND hComboBox, char *lpszFileName, BOOL saveHistory);
+void AddComboItem (HWND hComboBox, const wchar_t *lpszFileName, BOOL saveHistory);
LPARAM MoveEditToCombo (HWND hComboBox, BOOL saveHistory);
int GetOrderComboIdx ( HWND hComboBox , int *nIdxList , int nElems );
LPARAM UpdateComboOrder ( HWND hComboBox );
diff --git a/src/Common/Crypto.c b/src/Common/Crypto.c
index ead091db..e7a40a30 100644
--- a/src/Common/Crypto.c
+++ b/src/Common/Crypto.c
@@ -44,9 +44,15 @@ static Cipher Ciphers[] =
{
// Block Size Key Size Key Schedule Size
// ID Name (Bytes) (Bytes) (Bytes)
+#ifdef TC_WINDOWS_BOOT
{ AES, "AES", 16, 32, AES_KS },
{ SERPENT, "Serpent", 16, 32, 140*4 },
{ TWOFISH, "Twofish", 16, 32, TWOFISH_KS },
+#else
+ { AES, L"AES", 16, 32, AES_KS },
+ { SERPENT, L"Serpent", 16, 32, 140*4 },
+ { TWOFISH, L"Twofish", 16, 32, TWOFISH_KS },
+#endif
{ 0, 0, 0, 0, 0 }
};
@@ -88,18 +94,17 @@ static EncryptionAlgorithm EncryptionAlgorithms[] =
};
-
+#ifndef TC_WINDOWS_BOOT
// Hash algorithms
static Hash Hashes[] =
{ // ID Name Deprecated System Encryption
-#ifndef TC_WINDOWS_BOOT
- { SHA512, "SHA-512", FALSE, FALSE },
- { WHIRLPOOL, "Whirlpool", FALSE, FALSE },
-#endif
- { SHA256, "SHA-256", FALSE, TRUE },
- { RIPEMD160, "RIPEMD-160", TRUE, TRUE },
+ { SHA512, L"SHA-512", FALSE, FALSE },
+ { WHIRLPOOL, L"Whirlpool", FALSE, FALSE },
+ { SHA256, L"SHA-256", FALSE, TRUE },
+ { RIPEMD160, L"RIPEMD-160", TRUE, TRUE },
{ 0, 0, 0 }
};
+#endif
/* Return values: 0 = success, ERR_CIPHER_INIT_FAILURE (fatal), ERR_CIPHER_INIT_WEAK_KEY (non-fatal) */
int CipherInit (int cipher, unsigned char *key, unsigned __int8 *ks)
@@ -279,17 +284,12 @@ Cipher *CipherGet (int id)
}
#ifndef TC_WINDOWS_BOOT
-const
-#endif
-char *CipherGetName (int cipherId)
+const wchar_t *CipherGetName (int cipherId)
{
-#ifdef TC_WINDOWS_BOOT
- return CipherGet (cipherId) -> Name;
-#else
Cipher* pCipher = CipherGet (cipherId);
- return pCipher? pCipher -> Name : "";
-#endif
+ return pCipher? pCipher -> Name : L"";
}
+#endif
int CipherGetBlockSize (int cipherId)
{
@@ -410,19 +410,19 @@ BOOL EAInitMode (PCRYPTO_INFO ci)
return TRUE;
}
-static void EAGetDisplayName(char *buf, int ea, int i)
+static void EAGetDisplayName(wchar_t *buf, int ea, int i)
{
- strcpy (buf, CipherGetName (i));
+ wcscpy (buf, CipherGetName (i));
if (i = EAGetPreviousCipher(ea, i))
{
- strcat (buf, "(");
- EAGetDisplayName (&buf[strlen(buf)], ea, i);
- strcat (buf, ")");
+ wcscat (buf, L"(");
+ EAGetDisplayName (&buf[wcslen(buf)], ea, i);
+ wcscat (buf, L")");
}
}
// Returns name of EA, cascaded cipher names are separated by hyphens
-char *EAGetName (char *buf, int ea, int guiDisplay)
+wchar_t *EAGetName (wchar_t *buf, int ea, int guiDisplay)
{
if (guiDisplay)
{
@@ -431,27 +431,27 @@ char *EAGetName (char *buf, int ea, int guiDisplay)
else
{
int i = EAGetLastCipher(ea);
- strcpy (buf, (i != 0) ? CipherGetName (i) : "?");
+ wcscpy (buf, (i != 0) ? CipherGetName (i) : L"?");
while (i = EAGetPreviousCipher(ea, i))
{
- strcat (buf, "-");
- strcat (buf, CipherGetName (i));
+ wcscat (buf, L"-");
+ wcscat (buf, CipherGetName (i));
}
}
return buf;
}
-int EAGetByName (char *name)
+int EAGetByName (wchar_t *name)
{
int ea = EAGetFirst ();
- char n[128];
+ wchar_t n[128];
do
{
EAGetName (n, ea, 1);
- if (_stricmp (n, name) == 0)
+ if (_wcsicmp (n, name) == 0)
return ea;
}
while (ea = EAGetNext (ea));
@@ -499,16 +499,16 @@ int EAGetNextMode (int ea, int previousModeId)
#ifndef TC_WINDOWS_BOOT
// Returns the name of the mode of operation of the whole EA
-char *EAGetModeName (int ea, int mode, BOOL capitalLetters)
+wchar_t *EAGetModeName (int ea, int mode, BOOL capitalLetters)
{
switch (mode)
{
case XTS:
- return "XTS";
+ return L"XTS";
}
- return "[unknown]";
+ return L"[unknown]";
}
#endif // TC_WINDOWS_BOOT
@@ -635,7 +635,7 @@ BOOL EAIsModeSupported (int ea, int testedMode)
return FALSE;
}
-
+#ifndef TC_WINDOWS_BOOT
Hash *HashGet (int id)
{
int i;
@@ -647,37 +647,29 @@ Hash *HashGet (int id)
}
-int HashGetIdByName (char *name)
+int HashGetIdByName (wchar_t *name)
{
int i;
for (i = 0; Hashes[i].Id != 0; i++)
- if (strcmp (Hashes[i].Name, name) == 0)
+ if (wcscmp (Hashes[i].Name, name) == 0)
return Hashes[i].Id;
return 0;
}
-#ifndef TC_WINDOWS_BOOT
-const
-#endif
-char *HashGetName (int hashId)
+const wchar_t *HashGetName (int hashId)
{
-#ifdef TC_WINDOWS_BOOT
- return HashGet(hashId) -> Name;
-#else
Hash* pHash = HashGet(hashId);
- return pHash? pHash -> Name : "";
-#endif
+ return pHash? pHash -> Name : L"";
}
-#ifndef TC_WINDOWS_BOOT
-void HashGetName2 (char *buf, int hashId)
+void HashGetName2 (wchar_t *buf, int hashId)
{
Hash* pHash = HashGet(hashId);
if (pHash)
- strcpy(buf, pHash -> Name);
+ wcscpy(buf, pHash -> Name);
else
- buf[0] = '\0';
+ buf[0] = L'\0';
}
BOOL HashIsDeprecated (int hashId)
diff --git a/src/Common/Crypto.h b/src/Common/Crypto.h
index 073616cd..51539765 100644
--- a/src/Common/Crypto.h
+++ b/src/Common/Crypto.h
@@ -112,7 +112,11 @@ enum
typedef struct
{
int Id; // Cipher ID
+#ifdef TC_WINDOWS_BOOT
char *Name; // Name
+#else
+ wchar_t *Name; // Name
+#endif
int BlockSize; // Block size (bytes)
int KeySize; // Key size (bytes)
int KeyScheduleSize; // Scheduled key size (bytes)
@@ -125,13 +129,15 @@ typedef struct
int FormatEnabled;
} EncryptionAlgorithm;
+#ifndef TC_WINDOWS_BOOT
typedef struct
{
int Id; // Hash ID
- char *Name; // Name
+ wchar_t *Name; // Name
BOOL Deprecated;
BOOL SystemEncryption; // Available for system encryption
} Hash;
+#endif
// Maxium length of scheduled key
#if !defined (TC_WINDOWS_BOOT) || defined (TC_WINDOWS_BOOT_AES)
@@ -276,9 +282,8 @@ int CipherGetKeyScheduleSize (int cipher);
BOOL CipherSupportsIntraDataUnitParallelization (int cipher);
#ifndef TC_WINDOWS_BOOT
-const
+const wchar_t * CipherGetName (int cipher);
#endif
-char * CipherGetName (int cipher);
int CipherInit (int cipher, unsigned char *key, unsigned char *ks);
#ifndef TC_WINDOWS_BOOT_SINGLE_CIPHER_MODE
@@ -297,12 +302,16 @@ void DecipherBlocks (int cipher, void *dataPtr, void *ks, size_t blockCount);
int EAGetFirst ();
int EAGetCount (void);
int EAGetNext (int previousEA);
-char * EAGetName (char *buf, int ea, int guiDisplay);
-int EAGetByName (char *name);
+#ifndef TC_WINDOWS_BOOT
+wchar_t * EAGetName (wchar_t *buf, int ea, int guiDisplay);
+int EAGetByName (wchar_t *name);
+#endif
int EAGetKeySize (int ea);
int EAGetFirstMode (int ea);
int EAGetNextMode (int ea, int previousModeId);
-char * EAGetModeName (int ea, int mode, BOOL capitalLetters);
+#ifndef TC_WINDOWS_BOOT
+wchar_t * EAGetModeName (int ea, int mode, BOOL capitalLetters);
+#endif
int EAGetKeyScheduleSize (int ea);
int EAGetLargestKey ();
int EAGetLargestKeyForMode (int mode);
@@ -317,13 +326,10 @@ BOOL EAIsModeSupported (int ea, int testedMode);
#ifndef TC_WINDOWS_BOOT
-const
-#endif
-char *HashGetName (int hash_algo_id);
+const wchar_t *HashGetName (int hash_algo_id);
-#ifndef TC_WINDOWS_BOOT
Hash *HashGet (int id);
-void HashGetName2 (char *buf, int hashId);
+void HashGetName2 (wchar_t *buf, int hashId);
BOOL HashIsDeprecated (int hashId);
BOOL HashForSystemEncryption (int hashId);
int GetMaxPkcs5OutSize (void);
diff --git a/src/Common/Dlgcode.c b/src/Common/Dlgcode.c
index 65801bea..48dc1dd2 100644
--- a/src/Common/Dlgcode.c
+++ b/src/Common/Dlgcode.c
@@ -72,9 +72,9 @@ using namespace VeraCrypt;
LONG DriverVersion;
char *LastDialogId;
-char szHelpFile[TC_MAX_PATH];
-char szHelpFile2[TC_MAX_PATH];
-char SecurityTokenLibraryPath[TC_MAX_PATH];
+wchar_t szHelpFile[TC_MAX_PATH];
+wchar_t szHelpFile2[TC_MAX_PATH];
+wchar_t SecurityTokenLibraryPath[TC_MAX_PATH];
HFONT hFixedDigitFont = NULL;
HFONT hBoldFont = NULL;
@@ -170,9 +170,9 @@ BOOL bSysPartitionSelected = FALSE; /* TRUE if the user selected the system par
BOOL bSysDriveSelected = FALSE; /* TRUE if the user selected the system drive via the Select Device dialog */
/* To populate these arrays, call GetSysDevicePaths(). If they contain valid paths, bCachedSysDevicePathsValid is TRUE. */
-char SysPartitionDevicePath [TC_MAX_PATH];
-char SysDriveDevicePath [TC_MAX_PATH];
-string ExtraBootPartitionDevicePath;
+wchar_t SysPartitionDevicePath [TC_MAX_PATH];
+wchar_t SysDriveDevicePath [TC_MAX_PATH];
+wstring ExtraBootPartitionDevicePath;
char bCachedSysDevicePathsValid = FALSE;
BOOL bHyperLinkBeingTracked = FALSE;
@@ -219,7 +219,7 @@ enum
typedef struct
{
int id;
- char name[100];
+ wchar_t name[100];
unsigned __int64 encSpeed;
unsigned __int64 decSpeed;
unsigned __int64 meanBytesPerSec;
@@ -321,23 +321,23 @@ void cleanup ()
}
-void LowerCaseCopy (char *lpszDest, const char *lpszSource)
+void LowerCaseCopy (wchar_t *lpszDest, const wchar_t *lpszSource)
{
- size_t i = strlen (lpszSource) + 1;
+ size_t i = wcslen (lpszSource) + 1;
lpszDest[i - 1] = 0;
while (--i > 0)
{
- lpszDest[i - 1] = (char) tolower (lpszSource[i - 1]);
+ lpszDest[i - 1] = (wchar_t) towlower (lpszSource[i - 1]);
}
}
-void UpperCaseCopy (char *lpszDest, size_t cbDest, const char *lpszSource)
+void UpperCaseCopy (wchar_t *lpszDest, size_t cbDest, const wchar_t *lpszSource)
{
if (lpszDest && cbDest)
{
- size_t i = strlen (lpszSource);
+ size_t i = wcslen (lpszSource);
if (i >= cbDest)
i = cbDest - 1;
@@ -345,7 +345,7 @@ void UpperCaseCopy (char *lpszDest, size_t cbDest, const char *lpszSource)
i++;
while (--i > 0)
{
- lpszDest[i - 1] = (char) toupper (lpszSource[i - 1]);
+ lpszDest[i - 1] = (wchar_t) towupper (lpszSource[i - 1]);
}
}
}
@@ -362,16 +362,27 @@ std::string ToUpperCase (const std::string &str)
return u;
}
-size_t TrimWhiteSpace(char *str)
+std::wstring ToUpperCase (const std::wstring &str)
{
- char *end, *ptr = str;
+ wstring u;
+ foreach (wchar_t c, str)
+ {
+ u += (wchar_t) towupper (c);
+ }
+
+ return u;
+}
+
+size_t TrimWhiteSpace(wchar_t *str)
+{
+ wchar_t *end, *ptr = str;
size_t out_size;
if(!str || *str == 0)
return 0;
// Trim leading space
- while(isspace(*ptr)) ptr++;
+ while(iswspace(*ptr)) ptr++;
if(*ptr == 0) // All spaces?
{
@@ -380,32 +391,32 @@ size_t TrimWhiteSpace(char *str)
}
// Trim trailing space
- end = str + strlen(str) - 1;
- while(end > ptr && isspace(*end)) end--;
+ end = str + wcslen(str) - 1;
+ while(end > ptr && iswspace(*end)) end--;
end++;
// Set output size to trimmed string length
out_size = (end - ptr);
// Copy trimmed string and add null terminator
- memmove(str, ptr, out_size);
+ wmemmove(str, ptr, out_size);
str[out_size] = 0;
return out_size;
}
// check the validity of a file name
-BOOL IsValidFileName(const char* str)
+BOOL IsValidFileName(const wchar_t* str)
{
- static char invalidChars[9] = {'<', '>', ':', '"', '/', '\\', '|', '?', '*'};
- char c;
+ static wchar_t invalidChars[9] = {L'<', L'>', L':', L'"', L'/', L'\\', L'|', L'?', L'*'};
+ wchar_t c;
int i;
BOOL bNotDotOnly = FALSE;
while ((c = *str))
{
- if (c != '.')
+ if (c != L'.')
bNotDotOnly = TRUE;
- for (i= 0; i < sizeof(invalidChars); i++)
+ for (i= 0; i < ARRAYSIZE(invalidChars); i++)
if (c == invalidChars[i])
return FALSE;
str++;
@@ -414,38 +425,38 @@ BOOL IsValidFileName(const char* str)
return bNotDotOnly;
}
-BOOL IsVolumeDeviceHosted (const char *lpszDiskFile)
+BOOL IsVolumeDeviceHosted (const wchar_t *lpszDiskFile)
{
- return strstr (lpszDiskFile, "\\Device\\") == lpszDiskFile
- || strstr (lpszDiskFile, "\\DEVICE\\") == lpszDiskFile;
+ return wcsstr (lpszDiskFile, L"\\Device\\") == lpszDiskFile
+ || wcsstr (lpszDiskFile, L"\\DEVICE\\") == lpszDiskFile;
}
-void CreateFullVolumePath (char *lpszDiskFile, size_t cbDiskFile, const char *lpszFileName, BOOL * bDevice)
+void CreateFullVolumePath (wchar_t *lpszDiskFile, size_t cbDiskFile, const wchar_t *lpszFileName, BOOL * bDevice)
{
UpperCaseCopy (lpszDiskFile, cbDiskFile, lpszFileName);
*bDevice = FALSE;
- if (memcmp (lpszDiskFile, "\\DEVICE", sizeof (char) * 7) == 0)
+ if (wmemcmp (lpszDiskFile, L"\\DEVICE", 7) == 0)
{
*bDevice = TRUE;
}
- StringCbCopyA (lpszDiskFile, cbDiskFile, lpszFileName);
+ StringCbCopyW (lpszDiskFile, cbDiskFile, lpszFileName);
#if _DEBUG
- OutputDebugString ("CreateFullVolumePath: ");
+ OutputDebugString (L"CreateFullVolumePath: ");
OutputDebugString (lpszDiskFile);
- OutputDebugString ("\n");
+ OutputDebugString (L"\n");
#endif
}
-int FakeDosNameForDevice (const char *lpszDiskFile , char *lpszDosDevice , size_t cbDosDevice, char *lpszCFDevice , size_t cbCFDevice, BOOL bNameOnly)
+int FakeDosNameForDevice (const wchar_t *lpszDiskFile , wchar_t *lpszDosDevice , size_t cbDosDevice, wchar_t *lpszCFDevice , size_t cbCFDevice, BOOL bNameOnly)
{
BOOL bDosLinkCreated = TRUE;
- StringCbPrintfA (lpszDosDevice, cbDosDevice,"veracrypt%lu", GetCurrentProcessId ());
+ StringCbPrintfW (lpszDosDevice, cbDosDevice,L"veracrypt%lu", GetCurrentProcessId ());
if (bNameOnly == FALSE)
bDosLinkCreated = DefineDosDevice (DDD_RAW_TARGET_PATH, lpszDosDevice, lpszDiskFile);
@@ -453,12 +464,12 @@ int FakeDosNameForDevice (const char *lpszDiskFile , char *lpszDosDevice , size_
if (bDosLinkCreated == FALSE)
return ERR_OS_ERROR;
else
- StringCbPrintfA (lpszCFDevice, cbCFDevice,"\\\\.\\%s", lpszDosDevice);
+ StringCbPrintfW (lpszCFDevice, cbCFDevice,L"\\\\.\\%s", lpszDosDevice);
return 0;
}
-int RemoveFakeDosName (char *lpszDiskFile, char *lpszDosDevice)
+int RemoveFakeDosName (wchar_t *lpszDiskFile, wchar_t *lpszDosDevice)
{
BOOL bDosLinkRemoved = DefineDosDevice (DDD_RAW_TARGET_PATH | DDD_EXACT_MATCH_ON_REMOVE |
DDD_REMOVE_DEFINITION, lpszDosDevice, lpszDiskFile);
@@ -700,9 +711,9 @@ int GetTextGfxHeight (HWND hwndDlgItem, const wchar_t *text, HFONT hFont)
}
-std::string FitPathInGfxWidth (HWND hwnd, HFONT hFont, LONG width, const std::string &path)
+std::wstring FitPathInGfxWidth (HWND hwnd, HFONT hFont, LONG width, const std::wstring &path)
{
- string newPath;
+ wstring newPath;
RECT rect;
rect.left = 0;
@@ -713,8 +724,8 @@ std::string FitPathInGfxWidth (HWND hwnd, HFONT hFont, LONG width, const std::st
HDC hdc = GetDC (hwnd);
SelectObject (hdc, (HGDIOBJ) hFont);
- char pathBuf[TC_MAX_PATH];
- strcpy_s (pathBuf, sizeof (pathBuf), path.c_str());
+ wchar_t pathBuf[TC_MAX_PATH];
+ StringCbCopyW (pathBuf, sizeof (pathBuf), path.c_str());
if (DrawText (hdc, pathBuf, (int) path.size(), &rect, DT_CALCRECT | DT_MODIFYSTRING | DT_PATH_ELLIPSIS | DT_SINGLELINE) != 0)
newPath = pathBuf;
@@ -964,13 +975,13 @@ BOOL CALLBACK AboutDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam
{
case WM_INITDIALOG:
{
- char szTmp[100];
+ wchar_t szTmp[100];
RECT rec;
LocalizeDialog (hwndDlg, "IDD_ABOUT_DLG");
// Hyperlink
- SetWindowText (GetDlgItem (hwndDlg, IDC_HOMEPAGE), "www.idrix.fr");
+ SetWindowText (GetDlgItem (hwndDlg, IDC_HOMEPAGE), L"www.idrix.fr");
ToHyperlink (hwndDlg, IDC_HOMEPAGE);
// Logo area background (must not keep aspect ratio; must retain Windows-imposed distortion)
@@ -990,14 +1001,14 @@ BOOL CALLBACK AboutDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam
// Version
SendMessage (GetDlgItem (hwndDlg, IDT_ABOUT_VERSION), WM_SETFONT, (WPARAM) hUserBoldFont, 0);
- StringCbPrintfA (szTmp, sizeof(szTmp), "VeraCrypt %s", VERSION_STRING);
+ StringCbPrintfW (szTmp, sizeof(szTmp), L"VeraCrypt %s", _T(VERSION_STRING));
#ifdef _WIN64
- StringCbCatA (szTmp, sizeof(szTmp), " (64-bit)");
+ StringCbCatW (szTmp, sizeof(szTmp), L" (64-bit)");
#else
- StringCbCatA (szTmp, sizeof(szTmp), " (32-bit)");
+ StringCbCatW (szTmp, sizeof(szTmp), L" (32-bit)");
#endif
#if (defined(_DEBUG) || defined(DEBUG))
- StringCbCatA (szTmp, sizeof(szTmp), " (debug)");
+ StringCbCatW (szTmp, sizeof(szTmp), L" (debug)");
#endif
SetDlgItemText (hwndDlg, IDT_ABOUT_VERSION, szTmp);
SetDlgItemText (hwndDlg, IDT_ABOUT_RELEASE, TC_STR_RELEASED_BY);
@@ -1010,19 +1021,19 @@ BOOL CALLBACK AboutDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam
case WM_APP:
SetWindowText (GetDlgItem (hwndDlg, IDC_ABOUT_CREDITS),
- "Based on TrueCrypt 7.1a, freely available at http://www.truecrypt.org/ .\r\n\r\n"
+ L"Based on TrueCrypt 7.1a, freely available at http://www.truecrypt.org/ .\r\n\r\n"
- "Portions of this software:\r\n"
- "Copyright \xA9 2013-2015 IDRIX. All rights reserved.\r\n"
- "Copyright \xA9 2003-2012 TrueCrypt Developers Association. All Rights Reserved.\r\n"
- "Copyright \xA9 1998-2000 Paul Le Roux. All Rights Reserved.\r\n"
- "Copyright \xA9 1998-2008 Brian Gladman. All Rights Reserved.\r\n"
- "Copyright \xA9 2002-2004 Mark Adler. All Rights Reserved.\r\n\r\n"
+ L"Portions of this software:\r\n"
+ L"Copyright \xA9 2013-2015 IDRIX. All rights reserved.\r\n"
+ L"Copyright \xA9 2003-2012 TrueCrypt Developers Association. All Rights Reserved.\r\n"
+ L"Copyright \xA9 1998-2000 Paul Le Roux. All Rights Reserved.\r\n"
+ L"Copyright \xA9 1998-2008 Brian Gladman. All Rights Reserved.\r\n"
+ L"Copyright \xA9 2002-2004 Mark Adler. All Rights Reserved.\r\n\r\n"
- "This software as a whole:\r\n"
- "Copyright \xA9 2013-2015 IDRIX. All rights reserved.\r\n\r\n"
+ L"This software as a whole:\r\n"
+ L"Copyright \xA9 2013-2015 IDRIX. All rights reserved.\r\n\r\n"
- "An IDRIX Release");
+ L"An IDRIX Release");
return 1;
@@ -1137,7 +1148,7 @@ void CheckButton (HWND hButton)
}
-void LeftPadString (char *szTmp, int len, int targetLen, char filler)
+void LeftPadString (wchar_t *szTmp, int len, int targetLen, wchar_t filler)
{
int i;
@@ -1147,62 +1158,10 @@ void LeftPadString (char *szTmp, int len, int targetLen, char filler)
for (i = targetLen-1; i >= (targetLen-len); i--)
szTmp [i] = szTmp [i-(targetLen-len)];
- memset (szTmp, filler, targetLen-len);
+ wmemset (szTmp, filler, targetLen-len);
szTmp [targetLen] = 0;
}
-
-/*****************************************************************************
- ToSBCS: converts a unicode string to Single Byte Character String (SBCS).
- ***************************************************************************/
-
-void ToSBCS (LPWSTR lpszText, size_t cbSize)
-{
- if (lpszText)
- {
- int j = (int) wcslen (lpszText);
- if (j == 0)
- {
- *((char *) lpszText) = 0;
- return;
- }
- else
- {
- char *lpszNewText = (char *) err_malloc (j + 1);
- j = WideCharToMultiByte (CP_ACP, 0L, lpszText, -1, lpszNewText, j + 1, NULL, NULL);
- if (j > 0)
- StringCbCopyA ((char *) lpszText, cbSize, lpszNewText);
- else
- *((char *) lpszText) = 0;
- free (lpszNewText);
- }
- }
-}
-
-/*****************************************************************************
- ToUNICODE: converts a SBCS string to a UNICODE string.
- ***************************************************************************/
-
-void ToUNICODE (char *lpszText, size_t cbSize)
-{
- int j = (int) strlen (lpszText);
- if (j == 0)
- {
- StringCbCopyW ((LPWSTR) lpszText, cbSize, (LPWSTR) WIDE (""));
- return;
- }
- else
- {
- LPWSTR lpszNewText = (LPWSTR) err_malloc ((j + 1) * 2);
- j = MultiByteToWideChar (CP_ACP, 0L, lpszText, -1, lpszNewText, j + 1);
- if (j > 0)
- StringCbCopyW ((LPWSTR) lpszText, cbSize, lpszNewText);
- else
- StringCbCopyW ((LPWSTR) lpszText, cbSize, (LPWSTR) WIDE (""));
- free (lpszNewText);
- }
-}
-
/* InitDialog - initialize the applications main dialog, this function should
be called only once in the dialogs WM_INITDIALOG message handler */
void InitDialog (HWND hwndDlg)
@@ -1333,7 +1292,7 @@ void InitDialog (HWND hwndDlg)
if (!aboutMenuAppended)
{
hMenu = GetSystemMenu (hwndDlg, FALSE);
- AppendMenu (hMenu, MF_SEPARATOR, 0, "");
+ AppendMenu (hMenu, MF_SEPARATOR, 0, L"");
AppendMenuW (hMenu, MF_ENABLED | MF_STRING, IDC_ABOUT, GetString ("ABOUTBOX"));
aboutMenuAppended = TRUE;
@@ -1354,7 +1313,7 @@ void ProcessPaintMessages (HWND hwnd, int maxMessagesToProcess)
}
-HDC CreateMemBitmap (HINSTANCE hInstance, HWND hwnd, char *resource)
+HDC CreateMemBitmap (HINSTANCE hInstance, HWND hwnd, wchar_t *resource)
{
HBITMAP picture = LoadBitmap (hInstance, resource);
HDC viewDC = GetDC (hwnd), dcMem;
@@ -1384,7 +1343,7 @@ deleted by calling DeleteObject() with the handle passed as the parameter.
Known Windows issues:
- For some reason, anti-aliasing is not applied if the source bitmap contains less than 16K pixels.
- Windows 2000 may produce slightly inaccurate colors even when source, buffer, and target are 24-bit true color. */
-HBITMAP RenderBitmap (char *resource, HWND hwndDest, int x, int y, int nWidth, int nHeight, BOOL bDirectRender, BOOL bKeepAspectRatio)
+HBITMAP RenderBitmap (wchar_t *resource, HWND hwndDest, int x, int y, int nWidth, int nHeight, BOOL bDirectRender, BOOL bKeepAspectRatio)
{
LRESULT lResult = 0;
@@ -1711,15 +1670,15 @@ wchar_t *GetWipeModeName (WipeAlgorithmId modeId)
}
}
-wchar_t *GetPathType (const char *path, BOOL bUpperCase, BOOL *bIsPartition)
+wchar_t *GetPathType (const wchar_t *path, BOOL bUpperCase, BOOL *bIsPartition)
{
- if (strstr (path, "Partition")
- && strstr (path, "Partition0") == NULL)
+ if (wcsstr (path, L"Partition")
+ && wcsstr (path, L"Partition0") == NULL)
{
*bIsPartition = TRUE;
return GetString (bUpperCase ? "PARTITION_UPPER_CASE" : "PARTITION_LOWER_CASE");
}
- else if (strstr (path, "HarddiskVolume"))
+ else if (wcsstr (path, L"HarddiskVolume"))
{
*bIsPartition = TRUE;
return GetString (bUpperCase ? "VOLUME_UPPER_CASE" : "VOLUME_LOWER_CASE");
@@ -2088,7 +2047,7 @@ BOOL IsTrueCryptInstallerRunning (void)
// Returns TRUE if the mutex is (or had been) successfully acquired (otherwise FALSE).
-BOOL TCCreateMutex (volatile HANDLE *hMutex, char *name)
+BOOL TCCreateMutex (volatile HANDLE *hMutex, wchar_t *name)
{
if (*hMutex != NULL)
return TRUE; // This instance already has the mutex
@@ -2128,7 +2087,7 @@ void TCCloseMutex (volatile HANDLE *hMutex)
// Returns TRUE if a process running on the system has the specified mutex (otherwise FALSE).
-BOOL MutexExistsOnSystem (char *name)
+BOOL MutexExistsOnSystem (wchar_t *name)
{
if (name[0] == 0)
return FALSE;
@@ -2156,7 +2115,7 @@ uint32 ReadDriverConfigurationFlags ()
{
DWORD configMap;
- if (!ReadLocalMachineRegistryDword ("SYSTEM\\CurrentControlSet\\Services\\veracrypt", TC_DRIVER_CONFIG_REG_VALUE_NAME, &configMap))
+ if (!ReadLocalMachineRegistryDword (L"SYSTEM\\CurrentControlSet\\Services\\veracrypt", TC_DRIVER_CONFIG_REG_VALUE_NAME, &configMap))
configMap = 0;
return configMap;
@@ -2167,7 +2126,7 @@ uint32 ReadEncryptionThreadPoolFreeCpuCountLimit ()
{
DWORD count;
- if (!ReadLocalMachineRegistryDword ("SYSTEM\\CurrentControlSet\\Services\\veracrypt", TC_ENCRYPTION_FREE_CPU_COUNT_REG_VALUE_NAME, &count))
+ if (!ReadLocalMachineRegistryDword (L"SYSTEM\\CurrentControlSet\\Services\\veracrypt", TC_ENCRYPTION_FREE_CPU_COUNT_REG_VALUE_NAME, &count))
count = 0;
return count;
@@ -2260,13 +2219,13 @@ int LoadNonSysInPlaceEncSettings (WipeAlgorithmId *wipeAlgorithm)
void RemoveNonSysInPlaceEncNotifications (void)
{
if (FileExists (GetConfigPath (TC_APPD_FILENAME_NONSYS_INPLACE_ENC)))
- remove (GetConfigPath (TC_APPD_FILENAME_NONSYS_INPLACE_ENC));
+ _wremove (GetConfigPath (TC_APPD_FILENAME_NONSYS_INPLACE_ENC));
if (FileExists (GetConfigPath (TC_APPD_FILENAME_NONSYS_INPLACE_ENC_WIPE)))
- remove (GetConfigPath (TC_APPD_FILENAME_NONSYS_INPLACE_ENC_WIPE));
+ _wremove (GetConfigPath (TC_APPD_FILENAME_NONSYS_INPLACE_ENC_WIPE));
if (!IsNonInstallMode () && SystemEncryptionStatus == SYSENC_STATUS_NONE)
- ManageStartupSeqWiz (TRUE, "");
+ ManageStartupSeqWiz (TRUE, L"");
}
@@ -2280,16 +2239,16 @@ void SavePostInstallTasksSettings (int command)
switch (command)
{
case TC_POST_INSTALL_CFG_REMOVE_ALL:
- remove (GetConfigPath (TC_APPD_FILENAME_POST_INSTALL_TASK_TUTORIAL));
- remove (GetConfigPath (TC_APPD_FILENAME_POST_INSTALL_TASK_RELEASE_NOTES));
+ _wremove (GetConfigPath (TC_APPD_FILENAME_POST_INSTALL_TASK_TUTORIAL));
+ _wremove (GetConfigPath (TC_APPD_FILENAME_POST_INSTALL_TASK_RELEASE_NOTES));
break;
case TC_POST_INSTALL_CFG_TUTORIAL:
- f = fopen (GetConfigPath (TC_APPD_FILENAME_POST_INSTALL_TASK_TUTORIAL), "w");
+ f = _wfopen (GetConfigPath (TC_APPD_FILENAME_POST_INSTALL_TASK_TUTORIAL), L"w");
break;
case TC_POST_INSTALL_CFG_RELEASE_NOTES:
- f = fopen (GetConfigPath (TC_APPD_FILENAME_POST_INSTALL_TASK_RELEASE_NOTES), "w");
+ f = _wfopen (GetConfigPath (TC_APPD_FILENAME_POST_INSTALL_TASK_RELEASE_NOTES), L"w");
break;
default:
@@ -2299,7 +2258,7 @@ void SavePostInstallTasksSettings (int command)
if (f == NULL)
return;
- if (fputs ("1", f) < 0)
+ if (fputws (L"1", f) < 0)
{
// Error
fclose (f);
@@ -2357,7 +2316,7 @@ void InitOSVersionInfo ()
OSVERSIONINFOEX osEx;
osEx.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEX);
- GetVersionEx ((LPOSVERSIONINFOA) &osEx);
+ GetVersionEx ((LPOSVERSIONINFOW) &osEx);
if (osEx.wProductType == VER_NT_SERVER || osEx.wProductType == VER_NT_DOMAIN_CONTROLLER)
nCurrentOS = WIN_SERVER_2003;
@@ -2369,7 +2328,7 @@ void InitOSVersionInfo ()
OSVERSIONINFOEX osEx;
osEx.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEX);
- GetVersionEx ((LPOSVERSIONINFOA) &osEx);
+ GetVersionEx ((LPOSVERSIONINFOW) &osEx);
if (osEx.wProductType == VER_NT_SERVER || osEx.wProductType == VER_NT_DOMAIN_CONTROLLER)
nCurrentOS = WIN_SERVER_2008;
@@ -2395,11 +2354,11 @@ void InitOSVersionInfo ()
/* InitApp - initialize the application, this function is called once in the
applications WinMain function, but before the main dialog has been created */
-void InitApp (HINSTANCE hInstance, char *lpszCommandLine)
+void InitApp (HINSTANCE hInstance, wchar_t *lpszCommandLine)
{
WNDCLASSW wc;
char langId[6];
- char dllPath[MAX_PATH];
+ wchar_t dllPath[MAX_PATH];
/* Save the instance handle for later */
hInst = hInstance;
@@ -2412,7 +2371,7 @@ void InitApp (HINSTANCE hInstance, char *lpszCommandLine)
#ifndef SETUP
// Application ID
typedef HRESULT (WINAPI *SetAppId_t) (PCWSTR appID);
- SetAppId_t setAppId = (SetAppId_t) GetProcAddress (GetModuleHandle ("shell32.dll"), "SetCurrentProcessExplicitAppUserModelID");
+ SetAppId_t setAppId = (SetAppId_t) GetProcAddress (GetModuleHandle (L"shell32.dll"), "SetCurrentProcessExplicitAppUserModelID");
if (setAppId)
setAppId (TC_APPLICATION_ID);
@@ -2446,11 +2405,11 @@ void InitApp (HINSTANCE hInstance, char *lpszCommandLine)
// A new instance of the application must be created with elevated privileges.
if (IsNonInstallMode () && !IsAdmin () && IsUacSupported ())
{
- char modPath[MAX_PATH], newCmdLine[4096];
+ wchar_t modPath[MAX_PATH], newCmdLine[4096];
WNDCLASSEXW wcex;
HWND hWnd;
- if (strstr (lpszCommandLine, "/q UAC ") == lpszCommandLine)
+ if (wcsstr (lpszCommandLine, L"/q UAC ") == lpszCommandLine)
{
Error ("UAC_INIT_ERROR", NULL);
exit (1);
@@ -2473,12 +2432,12 @@ void InitApp (HINSTANCE hInstance, char *lpszCommandLine)
SetLayeredWindowAttributes (hWnd, 0, 0, LWA_ALPHA);
ShowWindow (hWnd, SW_SHOWNORMAL);
- GetModuleFileName (NULL, modPath, sizeof (modPath));
+ GetModuleFileNameW (NULL, modPath, ARRAYSIZE (modPath));
- StringCbCopyA (newCmdLine, sizeof(newCmdLine), "/q UAC ");
- StringCbCatA (newCmdLine, sizeof (newCmdLine), lpszCommandLine);
+ StringCbCopyW (newCmdLine, sizeof(newCmdLine), L"/q UAC ");
+ StringCbCatW (newCmdLine, sizeof (newCmdLine), lpszCommandLine);
- if ((int)ShellExecute (hWnd, "runas", modPath, newCmdLine, NULL, SW_SHOWNORMAL) <= 32)
+ if ((int)ShellExecuteW (hWnd, L"runas", modPath, newCmdLine, NULL, SW_SHOWNORMAL) <= 32)
exit (1);
Sleep (2000);
@@ -2503,7 +2462,7 @@ void InitApp (HINSTANCE hInstance, char *lpszCommandLine)
// Service pack check & warnings about critical MS issues
osEx.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEX);
- if (GetVersionEx ((LPOSVERSIONINFOA) &osEx) != 0)
+ if (GetVersionEx ((LPOSVERSIONINFOW) &osEx) != 0)
{
CurrentOSServicePack = osEx.wServicePackMajor;
switch (nCurrentOS)
@@ -2516,9 +2475,9 @@ void InitApp (HINSTANCE hInstance, char *lpszCommandLine)
DWORD val = 0, size = sizeof(val);
HKEY hkey;
- if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\Atapi\\Parameters", 0, KEY_READ, &hkey) == ERROR_SUCCESS)
+ if (RegOpenKeyExW (HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Services\\Atapi\\Parameters", 0, KEY_READ, &hkey) == ERROR_SUCCESS)
{
- if (RegQueryValueEx (hkey, "EnableBigLba", 0, 0, (LPBYTE) &val, &size) != ERROR_SUCCESS
+ if (RegQueryValueExW (hkey, L"EnableBigLba", 0, 0, (LPBYTE) &val, &size) != ERROR_SUCCESS
|| val != 1)
{
Warning ("LARGE_IDE_WARNING_2K_REGISTRY", NULL);
@@ -2533,7 +2492,7 @@ void InitApp (HINSTANCE hInstance, char *lpszCommandLine)
{
HKEY k;
// PE environment does not report version of SP
- if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, "System\\CurrentControlSet\\Control\\minint", 0, KEY_READ, &k) != ERROR_SUCCESS)
+ if (RegOpenKeyExW (HKEY_LOCAL_MACHINE, L"System\\CurrentControlSet\\Control\\minint", 0, KEY_READ, &k) != ERROR_SUCCESS)
Warning ("LARGE_IDE_WARNING_XP", NULL);
else
RegCloseKey (k);
@@ -2581,9 +2540,9 @@ void InitApp (HINSTANCE hInstance, char *lpszCommandLine)
}
if (GetSystemDirectory(dllPath, MAX_PATH))
- StringCbCatA(dllPath, sizeof(dllPath), "\\Riched20.dll");
+ StringCbCatW(dllPath, sizeof(dllPath), L"\\Riched20.dll");
else
- StringCbCopyA(dllPath, sizeof(dllPath), "c:\\Windows\\System32\\Riched20.dll");
+ StringCbCopyW(dllPath, sizeof(dllPath), L"c:\\Windows\\System32\\Riched20.dll");
// Required for RichEdit text fields to work
if ((hRichEditDll = LoadLibrary(dllPath)) == NULL)
{
@@ -2623,13 +2582,13 @@ void FinalizeApp (void)
void InitHelpFileName (void)
{
- char *lpszTmp;
+ wchar_t *lpszTmp;
- GetModuleFileName (NULL, szHelpFile, sizeof (szHelpFile));
- lpszTmp = strrchr (szHelpFile, '\\');
+ GetModuleFileNameW (NULL, szHelpFile, ARRAYSIZE (szHelpFile));
+ lpszTmp = wcsrchr (szHelpFile, L'\\');
if (lpszTmp)
{
- char szTemp[TC_MAX_PATH];
+ wchar_t szTemp[TC_MAX_PATH];
++lpszTmp;
*lpszTmp = 0; // add null terminating character to prepare for append operations
@@ -2638,34 +2597,33 @@ void InitHelpFileName (void)
if (strcmp (GetPreferredLangId(), "en") == 0
|| strlen(GetPreferredLangId()) == 0)
{
- StringCbCatA (szHelpFile, sizeof(szHelpFile), "VeraCrypt User Guide.pdf");
+ StringCbCatW (szHelpFile, sizeof(szHelpFile), L"VeraCrypt User Guide.pdf");
}
else
{
- StringCbPrintfA (szTemp, sizeof(szTemp), "VeraCrypt User Guide.%s.pdf", GetPreferredLangId());
- StringCbCatA (szHelpFile, sizeof(szHelpFile), szTemp);
+ StringCbPrintfW (szTemp, sizeof(szTemp), L"VeraCrypt User Guide.%S.pdf", GetPreferredLangId());
+ StringCbCatW (szHelpFile, sizeof(szHelpFile), szTemp);
}
// Secondary file name (used when localized documentation is not found).
- GetModuleFileName (NULL, szHelpFile2, sizeof (szHelpFile2));
- lpszTmp = strrchr (szHelpFile2, '\\');
+ GetModuleFileNameW (NULL, szHelpFile2, ARRAYSIZE (szHelpFile2));
+ lpszTmp = wcsrchr (szHelpFile2, L'\\');
if (lpszTmp)
{
++lpszTmp;
*lpszTmp = 0;
- StringCbCatA (szHelpFile2, sizeof(szHelpFile2), "VeraCrypt User Guide.pdf");
+ StringCbCatW (szHelpFile2, sizeof(szHelpFile2), L"VeraCrypt User Guide.pdf");
}
}
}
-BOOL OpenDevice (const char *lpszPath, OPEN_TEST_STRUCT *driver, BOOL detectFilesystem)
+BOOL OpenDevice (const wchar_t *lpszPath, OPEN_TEST_STRUCT *driver, BOOL detectFilesystem)
{
DWORD dwResult;
BOOL bResult;
wchar_t wszFileName[TC_MAX_PATH];
- StringCbCopyA ((char *) &wszFileName[0], sizeof(wszFileName), lpszPath);
- ToUNICODE ((char *) &wszFileName[0], sizeof(wszFileName));
+ StringCbCopyW (wszFileName, sizeof(wszFileName), lpszPath);
memset (driver, 0, sizeof (OPEN_TEST_STRUCT));
memcpy (driver->wszFileName, wszFileName, sizeof (wszFileName));
@@ -2743,13 +2701,13 @@ executions complete very fast. Returns TRUE if successful (otherwise FALSE). */
BOOL GetSysDevicePaths (HWND hwndDlg)
{
if (!bCachedSysDevicePathsValid
- || strlen (SysPartitionDevicePath) <= 1
- || strlen (SysDriveDevicePath) <= 1)
+ || wcslen (SysPartitionDevicePath) <= 1
+ || wcslen (SysDriveDevicePath) <= 1)
{
foreach (const HostDevice &device, GetAvailableHostDevices (false, true))
{
if (device.ContainsSystem)
- strcpy_s (device.IsPartition ? SysPartitionDevicePath : SysDriveDevicePath, TC_MAX_PATH, device.Path.c_str());
+ StringCchCopyW (device.IsPartition ? SysPartitionDevicePath : SysDriveDevicePath, TC_MAX_PATH, device.Path.c_str());
}
if (IsOSAtLeast (WIN_7))
@@ -2777,8 +2735,8 @@ BOOL GetSysDevicePaths (HWND hwndDlg)
}
return (bCachedSysDevicePathsValid
- && strlen (SysPartitionDevicePath) > 1
- && strlen (SysDriveDevicePath) > 1);
+ && wcslen (SysPartitionDevicePath) > 1
+ && wcslen (SysDriveDevicePath) > 1);
}
/* Determines whether the device path is the path of the system partition or of the system drive (or neither).
@@ -2800,7 +2758,7 @@ Return codes:
3 - it is the extra boot partition path
0 - it's not the system partition/drive path
-1 - the result can't be determined, isn't reliable, or there was an error. */
-int IsSystemDevicePath (const char *path, HWND hwndDlg, BOOL bReliableRequired)
+int IsSystemDevicePath (const wchar_t *path, HWND hwndDlg, BOOL bReliableRequired)
{
if (!bCachedSysDevicePathsValid
&& bReliableRequired)
@@ -2809,15 +2767,15 @@ int IsSystemDevicePath (const char *path, HWND hwndDlg, BOOL bReliableRequired)
return -1;
}
- if (strlen (SysPartitionDevicePath) <= 1 || strlen (SysDriveDevicePath) <= 1)
+ if (wcslen (SysPartitionDevicePath) <= 1 || wcslen (SysDriveDevicePath) <= 1)
return -1;
if (!path)
return -1;
- if (strncmp (path, SysPartitionDevicePath, max (strlen(path), strlen(SysPartitionDevicePath))) == 0)
+ if (wcsncmp (path, SysPartitionDevicePath, max (wcslen(path), wcslen(SysPartitionDevicePath))) == 0)
return 1;
- else if (strncmp (path, SysDriveDevicePath, max (strlen(path), strlen(SysDriveDevicePath))) == 0)
+ else if (wcsncmp (path, SysDriveDevicePath, max (wcslen(path), wcslen(SysDriveDevicePath))) == 0)
return 2;
else if (ExtraBootPartitionDevicePath == path)
return 3;
@@ -2833,42 +2791,43 @@ Return codes:
0 - it isn't a non-system partition on the system drive
1 - it's a non-system partition on the system drive
-1 - the result can't be determined, isn't reliable, or there was an error. */
-int IsNonSysPartitionOnSysDrive (const char *path)
+int IsNonSysPartitionOnSysDrive (const wchar_t *path)
{
- char tmpPath [TC_MAX_PATH + 1];
+ wchar_t tmpPath [TC_MAX_PATH + 1];
int pos;
if (!GetSysDevicePaths (MainDlg))
return -1;
- if (strlen (SysPartitionDevicePath) <= 1 || strlen (SysDriveDevicePath) <= 1)
+ if (wcslen (SysPartitionDevicePath) <= 1 || wcslen (SysDriveDevicePath) <= 1)
return -1;
- if (strncmp (path, SysPartitionDevicePath, max (strlen(path), strlen(SysPartitionDevicePath))) == 0
- || strncmp (path, SysDriveDevicePath, max (strlen(path), strlen(SysDriveDevicePath))) == 0)
+ if (wcsncmp (path, SysPartitionDevicePath, max (wcslen(path), wcslen(SysPartitionDevicePath))) == 0
+ || wcsncmp (path, SysDriveDevicePath, max (wcslen(path), wcslen(SysDriveDevicePath))) == 0)
{
// It is the system partition/drive path (it isn't a non-system partition)
return 0;
}
memset (tmpPath, 0, sizeof (tmpPath));
- strncpy (tmpPath, path, sizeof (tmpPath) - 1);
+ wcsncpy (tmpPath, path, ARRAYSIZE (tmpPath) - 1);
- pos = (int) FindString (tmpPath, "Partition", (int) strlen (tmpPath), (int) strlen ("Partition"), 0);
+ pos = (int) FindString ((const char*) tmpPath, (const char*) L"Partition", (int) wcslen (tmpPath) * 2, (int) wcslen (L"Partition") * 2, 0);
if (pos < 0)
return -1;
+ pos /= 2;
pos += (int) strlen ("Partition");
- if (pos + 1 > sizeof (tmpPath) - 1)
+ if (pos + 1 > ARRAYSIZE (tmpPath) - 1)
return -1;
- tmpPath [pos] = '0';
+ tmpPath [pos] = L'0';
tmpPath [pos + 1] = 0;
- if (strncmp (tmpPath, SysDriveDevicePath, max (strlen(tmpPath), strlen(SysDriveDevicePath))) == 0)
+ if (wcsncmp (tmpPath, SysDriveDevicePath, max (wcslen(tmpPath), wcslen(SysDriveDevicePath))) == 0)
{
// It is a non-system partition on the system drive
return 1;
@@ -3004,19 +2963,19 @@ BOOL CALLBACK TextInfoDialogBoxDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, L
switch (nID)
{
case TC_TBXID_SYS_ENCRYPTION_PRETEST:
- PrintHardCopyTextUTF16 ((wchar_t *) GetSysEncryptionPretestInfo2String ().c_str(), "Pre-Boot Troubleshooting", GetSysEncryptionPretestInfo2String ().length () * 2);
+ PrintHardCopyTextUTF16 ((wchar_t *) GetSysEncryptionPretestInfo2String ().c_str(), L"Pre-Boot Troubleshooting", GetSysEncryptionPretestInfo2String ().length () * 2);
break;
case TC_TBXID_SYS_ENC_RESCUE_DISK:
- PrintHardCopyTextUTF16 ((wchar_t *) GetRescueDiskHelpString ().c_str(), "VeraCrypt Rescue Disk Help", GetRescueDiskHelpString ().length () * 2);
+ PrintHardCopyTextUTF16 ((wchar_t *) GetRescueDiskHelpString ().c_str(), L"VeraCrypt Rescue Disk Help", GetRescueDiskHelpString ().length () * 2);
break;
case TC_TBXID_DECOY_OS_INSTRUCTIONS:
- PrintHardCopyTextUTF16 ((wchar_t *) GetDecoyOsInstructionsString ().c_str(), "How to Create Decoy OS", GetDecoyOsInstructionsString ().length () * 2);
+ PrintHardCopyTextUTF16 ((wchar_t *) GetDecoyOsInstructionsString ().c_str(), L"How to Create Decoy OS", GetDecoyOsInstructionsString ().length () * 2);
break;
case TC_TBXID_EXTRA_BOOT_PARTITION_REMOVAL_INSTRUCTIONS:
- PrintHardCopyTextUTF16 (GetString ("EXTRA_BOOT_PARTITION_REMOVAL_INSTRUCTIONS"), "How to Remove Extra Boot Partition", wcslen (GetString ("EXTRA_BOOT_PARTITION_REMOVAL_INSTRUCTIONS")) * 2);
+ PrintHardCopyTextUTF16 (GetString ("EXTRA_BOOT_PARTITION_REMOVAL_INSTRUCTIONS"), L"How to Remove Extra Boot Partition", wcslen (GetString ("EXTRA_BOOT_PARTITION_REMOVAL_INSTRUCTIONS")) * 2);
break;
}
return 1;
@@ -3035,7 +2994,7 @@ BOOL CALLBACK TextInfoDialogBoxDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, L
r = GetLegalNotices ();
if (r != NULL)
{
- SetWindowText (GetDlgItem (hwndDlg, IDC_INFO_BOX_TEXT), r);
+ SetWindowTextA (GetDlgItem (hwndDlg, IDC_INFO_BOX_TEXT), r);
free (r);
}
break;
@@ -3080,7 +3039,7 @@ char * GetLegalNotices ()
char *buf = NULL;
if (resource == NULL)
- resource = (char *) MapResource ("Text", IDR_LICENSE, &size);
+ resource = (char *) MapResource (L"Text", IDR_LICENSE, &size);
if (resource != NULL)
{
@@ -3098,7 +3057,7 @@ char * GetLegalNotices ()
BOOL CALLBACK RawDevicesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
- static char *lpszFileName; // This is actually a pointer to a GLOBAL array
+ static wchar_t *lpszFileName; // This is actually a pointer to a GLOBAL array
static vector <HostDevice> devices;
static map <int, HostDevice> itemToDeviceMap;
@@ -3171,9 +3130,9 @@ BOOL CALLBACK RawDevicesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l
if (device.ContainsSystem)
{
if (device.IsPartition)
- strcpy_s (SysPartitionDevicePath, sizeof (SysPartitionDevicePath), device.Path.c_str());
+ StringCbCopyW (SysPartitionDevicePath, sizeof (SysPartitionDevicePath), device.Path.c_str());
else
- strcpy_s (SysDriveDevicePath, sizeof (SysDriveDevicePath), device.Path.c_str());
+ StringCbCopyW (SysDriveDevicePath, sizeof (SysDriveDevicePath), device.Path.c_str());
}
// Path
@@ -3184,13 +3143,13 @@ BOOL CALLBACK RawDevicesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l
if (line > 1)
{
- ListItemAdd (hList, item.iItem, "");
+ ListItemAdd (hList, item.iItem, L"");
item.iItem = line++;
}
if (device.Floppy || device.DynamicVolume)
{
- ListItemAdd (hList, item.iItem, (char *) device.Path.c_str());
+ ListItemAdd (hList, item.iItem, (wchar_t *) device.Path.c_str());
}
else
{
@@ -3203,12 +3162,12 @@ BOOL CALLBACK RawDevicesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l
if (!device.Partitions.empty())
StringCbCatW (s, sizeof(s), L":");
- ListItemAddW (hList, item.iItem, s);
+ ListItemAdd (hList, item.iItem, s);
}
}
else
{
- ListItemAdd (hList, item.iItem, (char *) device.Path.c_str());
+ ListItemAdd (hList, item.iItem, (wchar_t *) device.Path.c_str());
}
itemToDeviceMap[item.iItem] = device;
@@ -3218,23 +3177,23 @@ BOOL CALLBACK RawDevicesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l
{
wchar_t size[100] = { 0 };
GetSizeString (device.Size, size, sizeof(size));
- ListSubItemSetW (hList, item.iItem, 2, size);
+ ListSubItemSet (hList, item.iItem, 2, size);
}
// Mount point
if (!device.MountPoint.empty())
- ListSubItemSet (hList, item.iItem, 1, (char *) device.MountPoint.c_str());
+ ListSubItemSet (hList, item.iItem, 1, (wchar_t *) device.MountPoint.c_str());
// Label
if (!device.Name.empty())
- ListSubItemSetW (hList, item.iItem, 3, (wchar_t *) device.Name.c_str());
+ ListSubItemSet (hList, item.iItem, 3, (wchar_t *) device.Name.c_str());
#ifdef TCMOUNT
else
{
bool useInExplorer = false;
wstring favoriteLabel = GetFavoriteVolumeLabel (device.Path, useInExplorer);
if (!favoriteLabel.empty())
- ListSubItemSetW (hList, item.iItem, 3, (wchar_t *) favoriteLabel.c_str());
+ ListSubItemSet (hList, item.iItem, 3, (wchar_t *) favoriteLabel.c_str());
}
#endif
@@ -3298,7 +3257,7 @@ BOOL CALLBACK RawDevicesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l
return 1; // non-device line selected
const HostDevice selectedDevice = itemToDeviceMap[selectedItem];
- strcpy_s (lpszFileName, TC_MAX_PATH, selectedDevice.Path.c_str());
+ StringCchCopyW (lpszFileName, TC_MAX_PATH, selectedDevice.Path.c_str());
#ifdef VOLFORMAT
if (selectedDevice.ContainsSystem && selectedDevice.IsPartition)
@@ -3470,9 +3429,9 @@ BOOL DoDriverInstall (HWND hwndDlg)
StatusMessage (hwndDlg, "INSTALLING_DRIVER");
#endif
- hService = CreateService (hManager, "veracrypt", "veracrypt",
+ hService = CreateService (hManager, L"veracrypt", L"veracrypt",
SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER, SERVICE_SYSTEM_START, SERVICE_ERROR_NORMAL,
- "System32\\drivers\\veracrypt.sys",
+ L"System32\\drivers\\veracrypt.sys",
NULL, NULL, NULL, NULL, NULL);
if (hService == NULL)
@@ -3480,7 +3439,7 @@ BOOL DoDriverInstall (HWND hwndDlg)
else
CloseServiceHandle (hService);
- hService = OpenService (hManager, "veracrypt", SERVICE_ALL_ACCESS);
+ hService = OpenService (hManager, L"veracrypt", SERVICE_ALL_ACCESS);
if (hService == NULL)
goto error;
@@ -3519,25 +3478,25 @@ static int DriverLoad ()
HANDLE file;
WIN32_FIND_DATA find;
SC_HANDLE hManager, hService = NULL;
- char driverPath[TC_MAX_PATH*2];
+ wchar_t driverPath[TC_MAX_PATH*2];
BOOL res;
- char *tmp;
+ wchar_t *tmp;
DWORD startType;
- if (ReadLocalMachineRegistryDword ("SYSTEM\\CurrentControlSet\\Services\\veracrypt", "Start", &startType) && startType == SERVICE_BOOT_START)
+ if (ReadLocalMachineRegistryDword (L"SYSTEM\\CurrentControlSet\\Services\\veracrypt", L"Start", &startType) && startType == SERVICE_BOOT_START)
return ERR_PARAMETER_INCORRECT;
- GetModuleFileName (NULL, driverPath, sizeof (driverPath));
- tmp = strrchr (driverPath, '\\');
+ GetModuleFileName (NULL, driverPath, ARRAYSIZE (driverPath));
+ tmp = wcsrchr (driverPath, L'\\');
if (!tmp)
{
- driverPath[0] = '.';
+ driverPath[0] = L'.';
driverPath[1] = 0;
}
else
*tmp = 0;
- StringCbCatA (driverPath, sizeof(driverPath), !Is64BitOs () ? "\\veracrypt.sys" : "\\veracrypt-x64.sys");
+ StringCbCatW (driverPath, sizeof(driverPath), !Is64BitOs () ? L"\\veracrypt.sys" : L"\\veracrypt-x64.sys");
file = FindFirstFile (driverPath, &find);
@@ -3561,7 +3520,7 @@ static int DriverLoad ()
return ERR_OS_ERROR;
}
- hService = OpenService (hManager, "veracrypt", SERVICE_ALL_ACCESS);
+ hService = OpenService (hManager, L"veracrypt", SERVICE_ALL_ACCESS);
if (hService != NULL)
{
// Remove stale service (driver is not loaded but service exists)
@@ -3570,7 +3529,7 @@ static int DriverLoad ()
Sleep (500);
}
- hService = CreateService (hManager, "veracrypt", "veracrypt",
+ hService = CreateService (hManager, L"veracrypt", L"veracrypt",
SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL,
driverPath, NULL, NULL, NULL, NULL, NULL);
@@ -3647,7 +3606,7 @@ BOOL DriverUnload ()
if (hManager == NULL)
goto error;
- hService = OpenService (hManager, "veracrypt", SERVICE_ALL_ACCESS);
+ hService = OpenService (hManager, L"veracrypt", SERVICE_ALL_ACCESS);
if (hService == NULL)
goto error;
@@ -3821,30 +3780,29 @@ load:
void ResetCurrentDirectory ()
{
- char p[MAX_PATH];
+ wchar_t p[MAX_PATH];
if (!IsNonInstallMode () && SHGetFolderPath (NULL, CSIDL_PROFILE, NULL, 0, p) == ERROR_SUCCESS)
{
SetCurrentDirectory (p);
}
else
{
- GetModPath (p, sizeof (p));
+ GetModPath (p, ARRAYSIZE (p));
SetCurrentDirectory (p);
}
}
-BOOL BrowseFiles (HWND hwndDlg, char *stringId, char *lpszFileName, BOOL keepHistory, BOOL saveMode, wchar_t *browseFilter)
+BOOL BrowseFiles (HWND hwndDlg, char *stringId, wchar_t *lpszFileName, BOOL keepHistory, BOOL saveMode, wchar_t *browseFilter)
{
return BrowseFilesInDir (hwndDlg, stringId, NULL, lpszFileName, keepHistory, saveMode, browseFilter);
}
-BOOL BrowseFilesInDir (HWND hwndDlg, char *stringId, char *initialDir, char *lpszFileName, BOOL keepHistory, BOOL saveMode, wchar_t *browseFilter, const wchar_t *initialFileName, const wchar_t *defaultExtension)
+BOOL BrowseFilesInDir (HWND hwndDlg, char *stringId, wchar_t *initialDir, wchar_t *lpszFileName, BOOL keepHistory, BOOL saveMode, wchar_t *browseFilter, const wchar_t *initialFileName, const wchar_t *defaultExtension)
{
OPENFILENAMEW ofn;
wchar_t file[TC_MAX_PATH] = { 0 };
- wchar_t wInitialDir[TC_MAX_PATH] = { 0 };
wchar_t filter[1024];
BOOL status = FALSE;
@@ -3855,12 +3813,11 @@ BOOL BrowseFilesInDir (HWND hwndDlg, char *stringId, char *initialDir, char *lps
if (initialDir)
{
- swprintf_s (wInitialDir, sizeof (wInitialDir) / 2, L"%hs", initialDir);
- ofn.lpstrInitialDir = wInitialDir;
+ ofn.lpstrInitialDir = initialDir;
}
if (initialFileName)
- wcscpy_s (file, array_capacity (file), initialFileName);
+ StringCchCopyW (file, array_capacity (file), initialFileName);
ofn.lStructSize = sizeof (ofn);
ofn.hwndOwner = hwndDlg;
@@ -3897,7 +3854,7 @@ BOOL BrowseFilesInDir (HWND hwndDlg, char *stringId, char *initialDir, char *lps
SystemFileSelectorCallPending = FALSE;
- WideCharToMultiByte (CP_ACP, 0, file, -1, lpszFileName, MAX_PATH, NULL, NULL);
+ StringCchCopyW (lpszFileName, MAX_PATH, file);
if (!keepHistory)
CleanLastVisitedMRU ();
@@ -3913,13 +3870,12 @@ ret:
}
-static char SelectMultipleFilesPath[131072];
+static wchar_t SelectMultipleFilesPath[131072];
static int SelectMultipleFilesOffset;
-BOOL SelectMultipleFiles (HWND hwndDlg, const char *stringId, char *lpszFileName, size_t cbFileName,BOOL keepHistory)
+BOOL SelectMultipleFiles (HWND hwndDlg, const char *stringId, wchar_t *lpszFileName, size_t cbFileName,BOOL keepHistory)
{
OPENFILENAMEW ofn;
- wchar_t file[0xffff * 2] = { 0 }; // The size must not exceed 0xffff*2 due to a bug in Windows 2000 and XP SP1
wchar_t filter[1024];
BOOL status = FALSE;
@@ -3934,8 +3890,8 @@ BOOL SelectMultipleFiles (HWND hwndDlg, const char *stringId, char *lpszFileName
GetString ("ALL_FILES"), 0, 0, GetString ("TC_VOLUMES"), 0, 0, 0);
ofn.lpstrFilter = filter;
ofn.nFilterIndex = 1;
- ofn.lpstrFile = file;
- ofn.nMaxFile = sizeof (file) / sizeof (file[0]);
+ ofn.lpstrFile = SelectMultipleFilesPath;
+ ofn.nMaxFile = 0xffff * 2; // The size must not exceed 0xffff*2 due to a bug in Windows 2000 and XP SP1
ofn.lpstrTitle = GetString (stringId);
ofn.Flags = OFN_HIDEREADONLY
| OFN_EXPLORER
@@ -3954,24 +3910,15 @@ BOOL SelectMultipleFiles (HWND hwndDlg, const char *stringId, char *lpszFileName
SystemFileSelectorCallPending = FALSE;
- if (file[ofn.nFileOffset - 1] != 0)
+ if (SelectMultipleFilesPath[ofn.nFileOffset - 1] != 0)
{
// Single file selected
- WideCharToMultiByte (CP_ACP, 0, file, -1, lpszFileName, MAX_PATH, NULL, NULL);
+ StringCbCopyW (lpszFileName, cbFileName, SelectMultipleFilesPath);
SelectMultipleFilesOffset = 0;
}
else
{
// Multiple files selected
- int n;
- wchar_t *f = file;
- char *s = SelectMultipleFilesPath;
- while ((n = WideCharToMultiByte (CP_ACP, 0, f, -1, s, MAX_PATH, NULL, NULL)) > 1)
- {
- f += n;
- s += n;
- }
-
SelectMultipleFilesOffset = ofn.nFileOffset;
SelectMultipleFilesNext (lpszFileName, cbFileName);
}
@@ -3990,20 +3937,20 @@ ret:
}
-BOOL SelectMultipleFilesNext (char *lpszFileName, size_t cbFileName)
+BOOL SelectMultipleFilesNext (wchar_t *lpszFileName, size_t cbFileName)
{
if (SelectMultipleFilesOffset == 0)
return FALSE;
- StringCbCopyA (lpszFileName, cbFileName,SelectMultipleFilesPath);
+ StringCbCopyW (lpszFileName, cbFileName,SelectMultipleFilesPath);
lpszFileName[TC_MAX_PATH - 1] = 0;
- if (lpszFileName[strlen (lpszFileName) - 1] != '\\')
- StringCbCatA (lpszFileName, cbFileName,"\\");
+ if (lpszFileName[wcslen (lpszFileName) - 1] != L'\\')
+ StringCbCatW (lpszFileName, cbFileName,L"\\");
- StringCbCatA (lpszFileName, cbFileName,SelectMultipleFilesPath + SelectMultipleFilesOffset);
+ StringCbCatW (lpszFileName, cbFileName,SelectMultipleFilesPath + SelectMultipleFilesOffset);
- SelectMultipleFilesOffset += (int) strlen (SelectMultipleFilesPath + SelectMultipleFilesOffset) + 1;
+ SelectMultipleFilesOffset += (int) wcslen (SelectMultipleFilesPath + SelectMultipleFilesOffset) + 1;
if (SelectMultipleFilesPath[SelectMultipleFilesOffset] == 0)
SelectMultipleFilesOffset = 0;
@@ -4018,13 +3965,13 @@ static int CALLBACK BrowseCallbackProc(HWND hwnd,UINT uMsg,LPARAM lp, LPARAM pDa
{
/* WParam is TRUE since we are passing a path.
It would be FALSE if we were passing a pidl. */
- SendMessage (hwnd,BFFM_SETSELECTION,TRUE,(LPARAM)pData);
+ SendMessageW (hwnd,BFFM_SETSELECTION,TRUE,(LPARAM)pData);
break;
}
case BFFM_SELCHANGED:
{
- char szDir[TC_MAX_PATH];
+ wchar_t szDir[TC_MAX_PATH];
/* Set the status window to the currently selected path. */
if (SHGetPathFromIDList((LPITEMIDLIST) lp ,szDir))
@@ -4042,7 +3989,7 @@ static int CALLBACK BrowseCallbackProc(HWND hwnd,UINT uMsg,LPARAM lp, LPARAM pDa
}
-BOOL BrowseDirectories (HWND hwndDlg, char *lpszTitle, char *dirName)
+BOOL BrowseDirectories (HWND hwndDlg, char *lpszTitle, wchar_t *dirName)
{
BROWSEINFOW bi;
LPITEMIDLIST pidl;
@@ -4090,8 +4037,8 @@ std::wstring GetWrongPasswordErrorMessage (HWND hwndDlg)
StringCbCatW (szTmp, sizeof(szTmp), GetString ("PASSWORD_WRONG_CAPSLOCK_ON"));
#ifdef TCMOUNT
- char szDevicePath [TC_MAX_PATH+1] = {0};
- GetWindowText (GetDlgItem (MainDlg, IDC_VOLUME), szDevicePath, sizeof (szDevicePath));
+ wchar_t szDevicePath [TC_MAX_PATH+1] = {0};
+ GetWindowText (GetDlgItem (MainDlg, IDC_VOLUME), szDevicePath, ARRAYSIZE (szDevicePath));
if (TCBootLoaderOnInactiveSysEncDrive (szDevicePath))
{
@@ -4241,7 +4188,7 @@ void handleError (HWND hwndDlg, int code, const char* srcPos)
}
-BOOL CheckFileStreamWriteErrors (HWND hwndDlg, FILE *file, const char *fileName)
+BOOL CheckFileStreamWriteErrors (HWND hwndDlg, FILE *file, const wchar_t *fileName)
{
if (ferror (file))
{
@@ -4300,15 +4247,15 @@ void LocalizeDialog (HWND hwnd, char *stringId)
void OpenVolumeExplorerWindow (int driveNo)
{
- char dosName[5];
+ wchar_t dosName[5];
SHFILEINFO fInfo;
- StringCbPrintfA (dosName, sizeof(dosName), "%c:\\", (char) driveNo + 'A');
+ StringCbPrintfW (dosName, sizeof(dosName), L"%c:\\", (wchar_t) driveNo + L'A');
// Force explorer to discover the drive
SHGetFileInfo (dosName, 0, &fInfo, sizeof (fInfo), 0);
- ShellExecute (NULL, "open", dosName, NULL, NULL, SW_SHOWNORMAL);
+ ShellExecute (NULL, L"open", dosName, NULL, NULL, SW_SHOWNORMAL);
}
static BOOL explorerCloseSent;
@@ -4417,16 +4364,16 @@ BOOL UpdateDriveCustomLabel (int driveNo, wchar_t* effectiveLabel, BOOL bSetValu
return (ERROR_SUCCESS == lStatus)? TRUE : FALSE;
}
-string GetUserFriendlyVersionString (int version)
+wstring GetUserFriendlyVersionString (int version)
{
- char szTmp [64];
- StringCbPrintfA (szTmp, sizeof(szTmp), "%x", version);
+ wchar_t szTmp [64];
+ StringCbPrintfW (szTmp, sizeof(szTmp), L"%x", version);
- string versionString (szTmp);
+ wstring versionString (szTmp);
- versionString.insert (version > 0xfff ? 2 : 1,".");
+ versionString.insert (version > 0xfff ? 2 : 1,L".");
- if (versionString[versionString.length()-1] == '0')
+ if (versionString[versionString.length()-1] == L'0')
versionString.erase (versionString.length()-1, 1);
return (versionString);
@@ -4808,7 +4755,7 @@ static BOOL PerformBenchmark(HWND hBenchDlg, HWND hwndDlg)
benchmarkTable[benchmarkTotalItems].encSpeed = performanceCountEnd.QuadPart - performanceCountStart.QuadPart;
benchmarkTable[benchmarkTotalItems].id = thid;
- StringCbPrintfA (benchmarkTable[benchmarkTotalItems].name, sizeof(benchmarkTable[benchmarkTable[benchmarkTotalItems].name),"%s", get_pkcs5_prf_name (thid));
+ StringCbPrintfW (benchmarkTable[benchmarkTotalItems].name, sizeof(benchmarkTable[benchmarkTable[benchmarkTotalItems].name),L"%s", get_pkcs5_prf_name (thid));
benchmarkTotalItems++;
}
@@ -5113,7 +5060,7 @@ static BOOL CALLBACK RandomPoolEnrichementDlgProc (HWND hwndDlg, UINT msg, WPARA
WORD hw = HIWORD (wParam);
static unsigned char randPool [RNG_POOL_SIZE];
static unsigned char lastRandPool [RNG_POOL_SIZE];
- static char outputDispBuffer [RNG_POOL_SIZE * 3 + RANDPOOL_DISPLAY_ROWS + 2];
+ static wchar_t outputDispBuffer [RNG_POOL_SIZE * 3 + RANDPOOL_DISPLAY_ROWS + 2];
static BOOL bDisplayPoolContents = TRUE;
static BOOL bRandPoolDispAscii = FALSE;
int hash_algo = RandGetHashFunction();
@@ -5135,7 +5082,7 @@ static BOOL CALLBACK RandomPoolEnrichementDlgProc (HWND hwndDlg, UINT msg, WPARA
for (hid = FIRST_PRF_ID; hid <= LAST_PRF_ID; hid++)
{
if (!HashIsDeprecated (hid))
- AddComboPair (hComboBox, HashGetName(hid), hid);
+ AddComboPairW (hComboBox, HashGetName(hid), hid);
}
SelectAlgo (hComboBox, &hash_algo);
@@ -5148,7 +5095,7 @@ static BOOL CALLBACK RandomPoolEnrichementDlgProc (HWND hwndDlg, UINT msg, WPARA
case WM_TIMER:
{
- char tmp[4];
+ wchar_t tmp[4];
unsigned char tmpByte;
int col, row;
@@ -5166,10 +5113,10 @@ static BOOL CALLBACK RandomPoolEnrichementDlgProc (HWND hwndDlg, UINT msg, WPARA
{
tmpByte = randPool[row * RANDPOOL_DISPLAY_COLUMNS + col];
- StringCbPrintfA (tmp, sizeof(tmp), bRandPoolDispAscii ? ((tmpByte >= 32 && tmpByte < 255 && tmpByte != '&') ? " %c " : " . ") : "%02X ", tmpByte);
- StringCbCatA (outputDispBuffer, sizeof(outputDispBuffer), tmp);
+ StringCbPrintfW (tmp, sizeof(tmp), bRandPoolDispAscii ? ((tmpByte >= 32 && tmpByte < 255 && tmpByte != L'&') ? L" %c " : L" . ") : L"%02X ", tmpByte);
+ StringCbCatW (outputDispBuffer, sizeof(outputDispBuffer), tmp);
}
- StringCbCatA (outputDispBuffer, sizeof(outputDispBuffer), "\n");
+ StringCbCatW (outputDispBuffer, sizeof(outputDispBuffer), L"\n");
}
SetWindowText (GetDlgItem (hwndDlg, IDC_POOL_CONTENTS), outputDispBuffer);
@@ -5200,9 +5147,9 @@ static BOOL CALLBACK RandomPoolEnrichementDlgProc (HWND hwndDlg, UINT msg, WPARA
{
if (!(bDisplayPoolContents = GetCheckBox (hwndDlg, IDC_DISPLAY_POOL_CONTENTS)))
{
- char tmp[RNG_POOL_SIZE+1];
+ wchar_t tmp[RNG_POOL_SIZE+1];
- memset (tmp, ' ', sizeof(tmp));
+ wmemset (tmp, L' ', ARRAYSIZE(tmp));
tmp [RNG_POOL_SIZE] = 0;
SetWindowText (GetDlgItem (hwndDlg, IDC_POOL_CONTENTS), tmp);
}
@@ -5214,7 +5161,7 @@ static BOOL CALLBACK RandomPoolEnrichementDlgProc (HWND hwndDlg, UINT msg, WPARA
case WM_CLOSE:
{
- char tmp[RNG_POOL_SIZE+1];
+ wchar_t tmp[RNG_POOL_SIZE+1];
exit:
KillTimer (hwndDlg, 0xfd);
@@ -5223,7 +5170,7 @@ exit:
burn (outputDispBuffer, sizeof(outputDispBuffer));
// Attempt to wipe the pool contents in the GUI text area
- memset (tmp, ' ', RNG_POOL_SIZE);
+ wmemset (tmp, L' ', RNG_POOL_SIZE);
tmp [RNG_POOL_SIZE] = 0;
SetWindowText (GetDlgItem (hwndDlg, IDC_POOL_CONTENTS), tmp);
@@ -5261,7 +5208,7 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
WORD hw = HIWORD (wParam);
static unsigned char randPool [RNG_POOL_SIZE];
static unsigned char lastRandPool [RNG_POOL_SIZE];
- static char outputDispBuffer [RNG_POOL_SIZE * 3 + RANDPOOL_DISPLAY_ROWS + 2];
+ static wchar_t outputDispBuffer [RNG_POOL_SIZE * 3 + RANDPOOL_DISPLAY_ROWS + 2];
static BOOL bDisplayPoolContents = TRUE;
static BOOL bRandPoolDispAscii = FALSE;
int hash_algo = RandGetHashFunction();
@@ -5283,7 +5230,7 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
for (hid = FIRST_PRF_ID; hid <= LAST_PRF_ID; hid++)
{
if (!HashIsDeprecated (hid))
- AddComboPair (hComboBox, HashGetName(hid), hid);
+ AddComboPairW (hComboBox, HashGetName(hid), hid);
}
SelectAlgo (hComboBox, &hash_algo);
@@ -5300,10 +5247,10 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
SendMessage (GetDlgItem (hwndDlg, IDC_POOL_CONTENTS), WM_SETFONT, (WPARAM) hFixedDigitFont, (LPARAM) TRUE);
// 9-digit limit for the number of keyfiles (more than enough!)
SendMessage (GetDlgItem (hwndDlg, IDC_NUMBER_KEYFILES), EM_SETLIMITTEXT, (WPARAM) 9, 0);
- SetWindowText(GetDlgItem (hwndDlg, IDC_NUMBER_KEYFILES), "1");
+ SetWindowText(GetDlgItem (hwndDlg, IDC_NUMBER_KEYFILES), L"1");
// maximum keyfile size is 1048576, so limit the edit control to 7 characters
SendMessage (GetDlgItem (hwndDlg, IDC_KEYFILES_SIZE), EM_SETLIMITTEXT, (WPARAM) 7, 0);
- SetWindowText(GetDlgItem (hwndDlg, IDC_KEYFILES_SIZE), "64");
+ SetWindowText(GetDlgItem (hwndDlg, IDC_KEYFILES_SIZE), L"64");
// set the maximum length of the keyfile base name to (TC_MAX_PATH - 1)
SendMessage (GetDlgItem (hwndDlg, IDC_KEYFILES_BASE_NAME), EM_SETLIMITTEXT, (WPARAM) (TC_MAX_PATH - 1), 0);
return 1;
@@ -5311,7 +5258,7 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
case WM_TIMER:
{
- char tmp[4];
+ wchar_t tmp[4];
unsigned char tmpByte;
int col, row;
@@ -5329,10 +5276,10 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
{
tmpByte = randPool[row * RANDPOOL_DISPLAY_COLUMNS + col];
- StringCbPrintfA (tmp, sizeof(tmp), bRandPoolDispAscii ? ((tmpByte >= 32 && tmpByte < 255 && tmpByte != '&') ? " %c " : " . ") : "%02X ", tmpByte);
- StringCbCatA (outputDispBuffer, sizeof(outputDispBuffer), tmp);
+ StringCbPrintfW (tmp, sizeof(tmp), bRandPoolDispAscii ? ((tmpByte >= 32 && tmpByte < 255 && tmpByte != L'&') ? L" %c " : L" . ") : L"%02X ", tmpByte);
+ StringCbCatW (outputDispBuffer, sizeof(outputDispBuffer), tmp);
}
- StringCbCatA (outputDispBuffer, sizeof(outputDispBuffer), "\n");
+ StringCbCatW (outputDispBuffer, sizeof(outputDispBuffer), L"\n");
}
SetWindowText (GetDlgItem (hwndDlg, IDC_POOL_CONTENTS), outputDispBuffer);
@@ -5361,9 +5308,9 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
{
if (!(bDisplayPoolContents = GetCheckBox (hwndDlg, IDC_DISPLAY_POOL_CONTENTS)))
{
- char tmp[RNG_POOL_SIZE+1];
+ wchar_t tmp[RNG_POOL_SIZE+1];
- memset (tmp, ' ', sizeof(tmp));
+ wmemset (tmp, L' ', ARRAYSIZE(tmp));
tmp [RNG_POOL_SIZE] = 0;
SetWindowText (GetDlgItem (hwndDlg, IDC_POOL_CONTENTS), tmp);
}
@@ -5377,21 +5324,21 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
if (lw == IDC_GENERATE_AND_SAVE_KEYFILE)
{
- char szNumber[16] = {0};
- char szFileBaseName[TC_MAX_PATH];
- char szDirName[TC_MAX_PATH];
- char szFileName [2*TC_MAX_PATH + 16];
+ wchar_t szNumber[16] = {0};
+ wchar_t szFileBaseName[TC_MAX_PATH];
+ wchar_t szDirName[TC_MAX_PATH];
+ wchar_t szFileName [2*TC_MAX_PATH + 16];
unsigned char *keyfile = NULL;
int fhKeyfile = -1, status;
long keyfilesCount = 0, keyfilesSize = 0, i;
- char* fileExtensionPtr = 0;
- char szSuffix[32];
+ wchar_t* fileExtensionPtr = 0;
+ wchar_t szSuffix[32];
BOOL bRandomSize = GetCheckBox (hwndDlg, IDC_KEYFILES_RANDOM_SIZE);
- if (!GetWindowText(GetDlgItem (hwndDlg, IDC_NUMBER_KEYFILES), szNumber, sizeof(szNumber)))
+ if (!GetWindowText(GetDlgItem (hwndDlg, IDC_NUMBER_KEYFILES), szNumber, ARRAYSIZE(szNumber)))
szNumber[0] = 0;
- keyfilesCount = strtoul(szNumber, NULL, 0);
+ keyfilesCount = wcstoul(szNumber, NULL, 0);
if (keyfilesCount <= 0 || keyfilesCount == LONG_MAX)
{
Warning("KEYFILE_INCORRECT_NUMBER", hwndDlg);
@@ -5401,10 +5348,10 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
if (!bRandomSize)
{
- if (!GetWindowText(GetDlgItem (hwndDlg, IDC_KEYFILES_SIZE), szNumber, sizeof(szNumber)))
+ if (!GetWindowText(GetDlgItem (hwndDlg, IDC_KEYFILES_SIZE), szNumber, ARRAYSIZE(szNumber)))
szNumber[0] = 0;
- keyfilesSize = strtoul(szNumber, NULL, 0);
+ keyfilesSize = wcstoul(szNumber, NULL, 0);
if (keyfilesSize < 64 || keyfilesSize > 1024*1024)
{
Warning("KEYFILE_INCORRECT_SIZE", hwndDlg);
@@ -5431,14 +5378,14 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
return 1;
}
- fileExtensionPtr = strrchr(szFileBaseName, '.');
+ fileExtensionPtr = wcsrchr(szFileBaseName, L'.');
/* Select directory */
if (!BrowseDirectories (hwndDlg, "SELECT_KEYFILE_GENERATION_DIRECTORY", szDirName))
return 1;
- if (szDirName[strlen(szDirName) - 1] != '\\' && szDirName[strlen(szDirName) - 1] != '/')
- StringCbCat(szDirName, sizeof(szDirName), "\\");
+ if (szDirName[wcslen(szDirName) - 1] != L'\\' && szDirName[wcslen(szDirName) - 1] != L'/')
+ StringCbCat(szDirName, sizeof(szDirName), L"\\");
WaitCursor();
@@ -5446,15 +5393,15 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
for (i= 0; i < keyfilesCount; i++)
{
- StringCbCopy(szFileName, sizeof(szFileName), szDirName);
+ StringCbCopyW(szFileName, sizeof(szFileName), szDirName);
if (i > 0)
{
- StringCbPrintfA(szSuffix, sizeof(szSuffix), "_%d", i);
+ StringCbPrintfW(szSuffix, sizeof(szSuffix), L"_%d", i);
// Append the counter to the name
if (fileExtensionPtr)
{
- StringCbCatN(szFileName, sizeof(szFileName), szFileBaseName, (size_t) (fileExtensionPtr - szFileBaseName));
+ StringCchCatN(szFileName, ARRAYSIZE(szFileName), szFileBaseName, (size_t) (fileExtensionPtr - szFileBaseName));
StringCbCat(szFileName, sizeof(szFileName), szSuffix);
StringCbCat(szFileName, sizeof(szFileName), fileExtensionPtr);
}
@@ -5468,16 +5415,13 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
StringCbCat(szFileName, sizeof(szFileName), szFileBaseName);
// check if the file exists
- if ((fhKeyfile = _open(szFileName, _O_RDONLY|_O_BINARY, _S_IREAD|_S_IWRITE)) != -1)
+ if ((fhKeyfile = _wopen(szFileName, _O_RDONLY|_O_BINARY, _S_IREAD|_S_IWRITE)) != -1)
{
WCHAR s[4*TC_MAX_PATH] = {0};
- WCHAR wszFileName[3*TC_MAX_PATH] = {0};
_close (fhKeyfile);
- MultiByteToWideChar(CP_ACP, 0, szFileName, -1, wszFileName, sizeof(wszFileName) / sizeof(WCHAR));
-
- StringCbPrintfW (s, sizeof(s), GetString ("KEYFILE_ALREADY_EXISTS"), wszFileName);
+ StringCbPrintfW (s, sizeof(s), GetString ("KEYFILE_ALREADY_EXISTS"), szFileName);
status = AskWarnNoYesString (s, hwndDlg);
if (status == IDNO)
{
@@ -5488,7 +5432,7 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
}
/* Conceive the file */
- if ((fhKeyfile = _open(szFileName, _O_CREAT|_O_TRUNC|_O_WRONLY|_O_BINARY, _S_IREAD|_S_IWRITE)) == -1)
+ if ((fhKeyfile = _wopen(szFileName, _O_CREAT|_O_TRUNC|_O_WRONLY|_O_BINARY, _S_IREAD|_S_IWRITE)) == -1)
{
TCfree(keyfile);
NormalCursor();
@@ -5550,7 +5494,7 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
case WM_CLOSE:
{
- char tmp[RNG_POOL_SIZE+1];
+ wchar_t tmp[RNG_POOL_SIZE+1];
exit:
WaitCursor();
KillTimer (hwndDlg, 0xfd);
@@ -5565,7 +5509,7 @@ exit:
burn (outputDispBuffer, sizeof(outputDispBuffer));
// Attempt to wipe the pool contents in the GUI text area
- memset (tmp, ' ', RNG_POOL_SIZE);
+ wmemset (tmp, L' ', RNG_POOL_SIZE);
tmp [RNG_POOL_SIZE] = 0;
SetWindowText (GetDlgItem (hwndDlg, IDC_POOL_CONTENTS), tmp);
@@ -5597,7 +5541,7 @@ CipherTestDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
case WM_INITDIALOG:
{
int ea;
- char buf[100];
+ wchar_t buf[100];
LocalizeDialog (hwndDlg, "IDD_CIPHER_TEST_DLG");
@@ -5627,7 +5571,7 @@ CipherTestDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
for (ea = EAGetFirst (); ea != 0; ea = EAGetNext (ea))
{
if (EAGetCipherCount (ea) == 1 && EAIsFormatEnabled (ea))
- AddComboPair (GetDlgItem (hwndDlg, IDC_CIPHER), EAGetName (buf, ea, 1), EAGetFirstCipher (ea));
+ AddComboPairW (GetDlgItem (hwndDlg, IDC_CIPHER), EAGetName (buf, ea, 1), EAGetFirstCipher (ea));
}
ResetCipherTest(hwndDlg, idTestCipher);
@@ -5695,7 +5639,8 @@ CipherTestDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
if (lw == IDOK || lw == IDC_ENCRYPT || lw == IDC_DECRYPT)
{
- char key[128+1], inputtext[128+1], secondaryKey[64+1], dataUnitNo[16+1], szTmp[128+1];
+ char key[128+1], inputtext[128+1], secondaryKey[64+1], dataUnitNo[16+1];
+ wchar_t szTmp[128+1];
int ks, pt, n, tlen, blockNo = 0;
BOOL bEncrypt;
@@ -5710,7 +5655,7 @@ CipherTestDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
memset(key,0,sizeof(key));
memset(szTmp,0,sizeof(szTmp));
- n = GetWindowText(GetDlgItem(hwndDlg, IDC_KEY), szTmp, sizeof(szTmp));
+ n = GetWindowText(GetDlgItem(hwndDlg, IDC_KEY), szTmp, ARRAYSIZE(szTmp));
if (n != ks * 2)
{
Warning ("TEST_KEY_SIZE", hwndDlg);
@@ -5719,14 +5664,14 @@ CipherTestDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
for (n = 0; n < ks; n ++)
{
- char szTmp2[3], *ptr;
+ wchar_t szTmp2[3], *ptr;
long x;
szTmp2[2] = 0;
szTmp2[0] = szTmp[n * 2];
szTmp2[1] = szTmp[n * 2 + 1];
- x = strtol(szTmp2, &ptr, 16);
+ x = wcstol(szTmp2, &ptr, 16);
key[n] = (char) x;
}
@@ -5738,11 +5683,11 @@ CipherTestDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
if (bEncrypt)
{
- n = GetWindowText(GetDlgItem(hwndDlg, IDC_PLAINTEXT), szTmp, sizeof(szTmp));
+ n = GetWindowText(GetDlgItem(hwndDlg, IDC_PLAINTEXT), szTmp, ARRAYSIZE(szTmp));
}
else
{
- n = GetWindowText(GetDlgItem(hwndDlg, IDC_CIPHERTEXT), szTmp, sizeof(szTmp));
+ n = GetWindowText(GetDlgItem(hwndDlg, IDC_CIPHERTEXT), szTmp, ARRAYSIZE(szTmp));
}
if (n != pt * 2)
@@ -5761,14 +5706,14 @@ CipherTestDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
for (n = 0; n < pt; n ++)
{
- char szTmp2[3], *ptr;
+ wchar_t szTmp2[3], *ptr;
long x;
szTmp2[2] = 0;
szTmp2[0] = szTmp[n * 2];
szTmp2[1] = szTmp[n * 2 + 1];
- x = strtol(szTmp2, &ptr, 16);
+ x = wcstol(szTmp2, &ptr, 16);
inputtext[n] = (char) x;
}
@@ -5778,7 +5723,7 @@ CipherTestDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
// Secondary key
- if (GetWindowText(GetDlgItem(hwndDlg, IDC_SECONDARY_KEY), szTmp, sizeof(szTmp)) != 64)
+ if (GetWindowText(GetDlgItem(hwndDlg, IDC_SECONDARY_KEY), szTmp, ARRAYSIZE(szTmp)) != 64)
{
Warning ("TEST_INCORRECT_SECONDARY_KEY_SIZE", hwndDlg);
return 1;
@@ -5786,21 +5731,21 @@ CipherTestDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
for (n = 0; n < 64; n ++)
{
- char szTmp2[3], *ptr;
+ wchar_t szTmp2[3], *ptr;
long x;
szTmp2[2] = 0;
szTmp2[0] = szTmp[n * 2];
szTmp2[1] = szTmp[n * 2 + 1];
- x = strtol(szTmp2, &ptr, 16);
+ x = wcstol(szTmp2, &ptr, 16);
secondaryKey[n] = (char) x;
}
// Data unit number
- tlen = GetWindowText(GetDlgItem(hwndDlg, IDC_TEST_DATA_UNIT_NUMBER), szTmp, sizeof(szTmp));
+ tlen = GetWindowText(GetDlgItem(hwndDlg, IDC_TEST_DATA_UNIT_NUMBER), szTmp, ARRAYSIZE(szTmp));
if (tlen > 16 || tlen < 1)
{
@@ -5808,18 +5753,18 @@ CipherTestDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
return 1;
}
- LeftPadString (szTmp, tlen, 16, '0');
+ LeftPadString (szTmp, tlen, 16, L'0');
for (n = 0; n < 16; n ++)
{
- char szTmp2[3], *ptr;
+ wchar_t szTmp2[3], *ptr;
long x;
szTmp2[2] = 0;
szTmp2[0] = szTmp[n * 2];
szTmp2[1] = szTmp[n * 2 + 1];
- x = strtol(szTmp2, &ptr, 16);
+ x = wcstol(szTmp2, &ptr, 16);
dataUnitNo[n] = (char) x;
}
@@ -5898,9 +5843,9 @@ CipherTestDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
for (n = 0; n < pt; n ++)
{
- char szTmp2[3];
- StringCbPrintfA(szTmp2, sizeof(szTmp2), "%02x", (int)((unsigned char)tmp[n]));
- StringCbCatA(szTmp, sizeof(szTmp), szTmp2);
+ wchar_t szTmp2[3];
+ StringCbPrintfW(szTmp2, sizeof(szTmp2), L"%02x", (int)((unsigned char)tmp[n]));
+ StringCbCatW(szTmp, sizeof(szTmp), szTmp2);
}
if (bEncrypt)
@@ -5961,26 +5906,26 @@ ResetCipherTest(HWND hwndDlg, int idTestCipher)
SendMessage(GetDlgItem(hwndDlg, IDC_TEST_BLOCK_NUMBER), CB_SETCURSEL, 0, 0);
- SetWindowText(GetDlgItem(hwndDlg, IDC_SECONDARY_KEY), "0000000000000000000000000000000000000000000000000000000000000000");
- SetWindowText(GetDlgItem(hwndDlg, IDC_TEST_DATA_UNIT_NUMBER), "0");
+ SetWindowText(GetDlgItem(hwndDlg, IDC_SECONDARY_KEY), L"0000000000000000000000000000000000000000000000000000000000000000");
+ SetWindowText(GetDlgItem(hwndDlg, IDC_TEST_DATA_UNIT_NUMBER), L"0");
- SetWindowText(GetDlgItem(hwndDlg, IDC_PLAINTEXT), "0000000000000000");
- SetWindowText(GetDlgItem(hwndDlg, IDC_CIPHERTEXT), "0000000000000000");
+ SetWindowText(GetDlgItem(hwndDlg, IDC_PLAINTEXT), L"0000000000000000");
+ SetWindowText(GetDlgItem(hwndDlg, IDC_CIPHERTEXT), L"0000000000000000");
if (idTestCipher == AES || idTestCipher == SERPENT || idTestCipher == TWOFISH)
{
- ndx = (int) SendMessage (GetDlgItem(hwndDlg, IDC_KEY_SIZE), CB_ADDSTRING, 0,(LPARAM) "256");
+ ndx = (int) SendMessage (GetDlgItem(hwndDlg, IDC_KEY_SIZE), CB_ADDSTRING, 0,(LPARAM) L"256");
SendMessage(GetDlgItem(hwndDlg, IDC_KEY_SIZE), CB_SETITEMDATA, ndx,(LPARAM) 32);
SendMessage(GetDlgItem(hwndDlg, IDC_KEY_SIZE), CB_SETCURSEL, ndx,0);
SendMessage (GetDlgItem(hwndDlg, IDC_PLAINTEXT_SIZE), CB_RESETCONTENT, 0,0);
- ndx = (int) SendMessage (GetDlgItem(hwndDlg, IDC_PLAINTEXT_SIZE), CB_ADDSTRING, 0,(LPARAM) "128");
+ ndx = (int) SendMessage (GetDlgItem(hwndDlg, IDC_PLAINTEXT_SIZE), CB_ADDSTRING, 0,(LPARAM) L"128");
SendMessage(GetDlgItem(hwndDlg, IDC_PLAINTEXT_SIZE), CB_SETITEMDATA, ndx,(LPARAM) 16);
SendMessage(GetDlgItem(hwndDlg, IDC_PLAINTEXT_SIZE), CB_SETCURSEL, ndx,0);
- SetWindowText(GetDlgItem(hwndDlg, IDC_KEY), "0000000000000000000000000000000000000000000000000000000000000000");
- SetWindowText(GetDlgItem(hwndDlg, IDC_PLAINTEXT), "00000000000000000000000000000000");
- SetWindowText(GetDlgItem(hwndDlg, IDC_CIPHERTEXT), "00000000000000000000000000000000");
+ SetWindowText(GetDlgItem(hwndDlg, IDC_KEY), L"0000000000000000000000000000000000000000000000000000000000000000");
+ SetWindowText(GetDlgItem(hwndDlg, IDC_PLAINTEXT), L"00000000000000000000000000000000");
+ SetWindowText(GetDlgItem(hwndDlg, IDC_CIPHERTEXT), L"00000000000000000000000000000000");
}
}
@@ -6228,48 +6173,48 @@ BOOL CheckCapsLock (HWND hwnd, BOOL quiet)
// Checks whether the file extension is not used for executable files or similarly problematic, which often
// causes Windows and antivirus software to interfere with the container.
-BOOL CheckFileExtension (char *fileName)
+BOOL CheckFileExtension (wchar_t *fileName)
{
int i = 0;
- char *ext = strrchr (fileName, '.');
- static char *problemFileExt[] = {
+ wchar_t *ext = wcsrchr (fileName, L'.');
+ static wchar_t *problemFileExt[] = {
// These are protected by the Windows Resource Protection
- ".asa", ".asp", ".aspx", ".ax", ".bas", ".bat", ".bin", ".cer", ".chm", ".clb", ".cmd", ".cnt", ".cnv",
- ".com", ".cpl", ".cpx", ".crt", ".csh", ".dll", ".drv", ".dtd", ".exe", ".fxp", ".grp", ".h1s", ".hlp",
- ".hta", ".ime", ".inf", ".ins", ".isp", ".its", ".js", ".jse", ".ksh", ".lnk", ".mad", ".maf", ".mag",
- ".mam", ".man", ".maq", ".mar", ".mas", ".mat", ".mau", ".mav", ".maw", ".mda", ".mdb", ".mde", ".mdt",
- ".mdw", ".mdz", ".msc", ".msi", ".msp", ".mst", ".mui", ".nls", ".ocx", ".ops", ".pal", ".pcd", ".pif",
- ".prf", ".prg", ".pst", ".reg", ".scf", ".scr", ".sct", ".shb", ".shs", ".sys", ".tlb", ".tsp", ".url",
- ".vb", ".vbe", ".vbs", ".vsmacros", ".vss", ".vst", ".vsw", ".ws", ".wsc", ".wsf", ".wsh", ".xsd", ".xsl",
+ L".asa", L".asp", L".aspx", L".ax", L".bas", L".bat", L".bin", L".cer", L".chm", L".clb", L".cmd", L".cnt", L".cnv",
+ L".com", L".cpl", L".cpx", L".crt", L".csh", L".dll", L".drv", L".dtd", L".exe", L".fxp", L".grp", L".h1s", L".hlp",
+ L".hta", L".ime", L".inf", L".ins", L".isp", L".its", L".js", L".jse", L".ksh", L".lnk", L".mad", L".maf", L".mag",
+ L".mam", L".man", L".maq", L".mar", L".mas", L".mat", L".mau", L".mav", L".maw", L".mda", L".mdb", L".mde", L".mdt",
+ L".mdw", L".mdz", L".msc", L".msi", L".msp", L".mst", L".mui", L".nls", L".ocx", L".ops", L".pal", L".pcd", L".pif",
+ L".prf", L".prg", L".pst", L".reg", L".scf", L".scr", L".sct", L".shb", L".shs", L".sys", L".tlb", L".tsp", L".url",
+ L".vb", L".vbe", L".vbs", L".vsmacros", L".vss", L".vst", L".vsw", L".ws", L".wsc", L".wsf", L".wsh", L".xsd", L".xsl",
// These additional file extensions are usually watched by antivirus programs
- ".386", ".acm", ".ade", ".adp", ".ani", ".app", ".asd", ".asf", ".asx", ".awx", ".ax", ".boo", ".bz2", ".cdf",
- ".class", ".dhtm", ".dhtml",".dlo", ".emf", ".eml", ".flt", ".fot", ".gz", ".hlp", ".htm", ".html", ".ini",
- ".j2k", ".jar", ".jff", ".jif", ".jmh", ".jng", ".jp2", ".jpe", ".jpeg", ".jpg", ".lsp", ".mod", ".nws",
- ".obj", ".olb", ".osd", ".ov1", ".ov2", ".ov3", ".ovl", ".ovl", ".ovr", ".pdr", ".pgm", ".php", ".pkg",
- ".pl", ".png", ".pot", ".pps", ".ppt", ".ps1", ".ps1xml", ".psc1", ".rar", ".rpl", ".rtf", ".sbf", ".script", ".sh", ".sha", ".shtm",
- ".shtml", ".spl", ".swf", ".tar", ".tgz", ".tmp", ".ttf", ".vcs", ".vlm", ".vxd", ".vxo", ".wiz", ".wll", ".wmd",
- ".wmf", ".wms", ".wmz", ".wpc", ".wsc", ".wsh", ".wwk", ".xhtm", ".xhtml", ".xl", ".xml", ".zip", ".7z", 0};
+ L".386", L".acm", L".ade", L".adp", L".ani", L".app", L".asd", L".asf", L".asx", L".awx", L".ax", L".boo", L".bz2", L".cdf",
+ L".class", L".dhtm", L".dhtml",L".dlo", L".emf", L".eml", L".flt", L".fot", L".gz", L".hlp", L".htm", L".html", L".ini",
+ L".j2k", L".jar", L".jff", L".jif", L".jmh", L".jng", L".jp2", L".jpe", L".jpeg", L".jpg", L".lsp", L".mod", L".nws",
+ L".obj", L".olb", L".osd", L".ov1", L".ov2", L".ov3", L".ovl", L".ovl", L".ovr", L".pdr", L".pgm", L".php", L".pkg",
+ L".pl", L".png", L".pot", L".pps", L".ppt", L".ps1", L".ps1xml", L".psc1", L".rar", L".rpl", L".rtf", L".sbf", L".script", L".sh", L".sha", L".shtm",
+ L".shtml", L".spl", L".swf", L".tar", L".tgz", L".tmp", L".ttf", L".vcs", L".vlm", L".vxd", L".vxo", L".wiz", L".wll", L".wmd",
+ L".wmf", L".wms", L".wmz", L".wpc", L".wsc", L".wsh", L".wwk", L".xhtm", L".xhtml", L".xl", L".xml", L".zip", L".7z", 0};
if (!ext)
return FALSE;
while (problemFileExt[i])
{
- if (!_stricmp (ext, problemFileExt[i++]))
+ if (!_wcsicmp (ext, problemFileExt[i++]))
return TRUE;
}
return FALSE;
}
-void CorrectFileName (char* fileName)
+void CorrectFileName (wchar_t* fileName)
{
/* replace '/' by '\' */
- size_t i, len = strlen (fileName);
+ size_t i, len = wcslen (fileName);
for (i = 0; i < len; i++)
{
- if (fileName [i] == '/')
- fileName [i] = '\\';
+ if (fileName [i] == L'/')
+ fileName [i] = L'\\';
}
}
@@ -6327,7 +6272,7 @@ BOOL IsDriveAvailable (int driveNo)
}
-BOOL IsDeviceMounted (char *deviceName)
+BOOL IsDeviceMounted (wchar_t *deviceName)
{
BOOL bResult = FALSE;
DWORD dwResult;
@@ -6392,7 +6337,7 @@ int DriverUnmountVolume (HWND hwndDlg, int nDosDriveNo, BOOL forced)
wchar_t msg[4096];
VolumeNotificationsList.bHidVolDamagePrevReported [nDosDriveNo] = TRUE;
- StringCbPrintfW (msg, sizeof(msg), GetString ("DAMAGE_TO_HIDDEN_VOLUME_PREVENTED"), nDosDriveNo + 'A');
+ StringCbPrintfW (msg, sizeof(msg), GetString ("DAMAGE_TO_HIDDEN_VOLUME_PREVENTED"), nDosDriveNo + L'A');
SetForegroundWindow (hwndDlg);
MessageBoxW (hwndDlg, msg, lpszTitle, MB_ICONWARNING | MB_SETFOREGROUND | MB_TOPMOST);
}
@@ -6429,21 +6374,10 @@ void BroadcastDeviceChange (WPARAM message, int nDosDriveNo, DWORD driveMap)
{
if (driveMap & (1 << i))
{
- char root[] = { (char) i + 'A', ':', '\\', 0 };
+ wchar_t root[] = { (wchar_t) i + L'A', L':', L'\\', 0 };
SHChangeNotify (eventId, SHCNF_PATH, root, NULL);
- if (nCurrentOS == WIN_2000 && RemoteSession)
- {
- char target[32];
- StringCbPrintfA (target, sizeof(target), "%ls%c", TC_MOUNT_PREFIX, i + 'A');
- root[2] = 0;
-
- if (message == DBT_DEVICEARRIVAL)
- DefineDosDevice (DDD_RAW_TARGET_PATH, root, target);
- else if (message == DBT_DEVICEREMOVECOMPLETE)
- DefineDosDevice (DDD_RAW_TARGET_PATH| DDD_REMOVE_DEFINITION
- | DDD_EXACT_MATCH_ON_REMOVE, root, target);
- }
+
}
}
}
@@ -6516,7 +6450,7 @@ BOOL GetPhysicalDriveAlignment(UINT nDriveNumber, STORAGE_ACCESS_ALIGNMENT_DESCR
// implementation of the generic wait dialog mechanism
-static UINT g_wmWaitDlg = ::RegisterWindowMessage("VeraCryptWaitDlgMessage");
+static UINT g_wmWaitDlg = ::RegisterWindowMessage(L"VeraCryptWaitDlgMessage");
typedef struct
{
@@ -6700,7 +6634,7 @@ void CALLBACK MountWaitThreadProc(void* pArg, HWND )
int MountVolume (HWND hwndDlg,
int driveNo,
- char *volumePath,
+ wchar_t *volumePath,
Password *password,
int pkcs5,
int pim,
@@ -6714,7 +6648,7 @@ int MountVolume (HWND hwndDlg,
MOUNT_STRUCT mount;
DWORD dwResult, dwLastError = ERROR_SUCCESS;
BOOL bResult, bDevice;
- char root[MAX_PATH];
+ wchar_t root[MAX_PATH];
int favoriteMountOnArrivalRetryCount = 0;
#ifdef TCMOUNT
@@ -6785,33 +6719,33 @@ retry:
if (CurrentOSMajor == 5 && CurrentOSMinor == 0)
mount.bMountManager = FALSE;
- string path = volumePath;
- if (path.find ("\\\\?\\") == 0)
+ wstring path = volumePath;
+ if (path.find (L"\\\\?\\") == 0)
{
// Remove \\?\ prefix
path = path.substr (4);
- strcpy_s (volumePath, TC_MAX_PATH, path.c_str());
+ StringCchCopyW (volumePath, TC_MAX_PATH, path.c_str());
}
- if (path.find ("Volume{") == 0 && path.rfind ("}\\") == path.size() - 2)
+ if (path.find (L"Volume{") == 0 && path.rfind (L"}\\") == path.size() - 2)
{
- string resolvedPath = VolumeGuidPathToDevicePath (path);
+ wstring resolvedPath = VolumeGuidPathToDevicePath (path);
if (!resolvedPath.empty())
- strcpy_s (volumePath, TC_MAX_PATH, resolvedPath.c_str());
+ StringCchCopyW (volumePath, TC_MAX_PATH, resolvedPath.c_str());
}
- CreateFullVolumePath ((char *) mount.wszVolume, sizeof(mount.wszVolume), volumePath, &bDevice);
+ CreateFullVolumePath (mount.wszVolume, sizeof(mount.wszVolume), volumePath, &bDevice);
if (!bDevice)
{
// UNC path
- if (path.find ("\\\\") == 0)
+ if (path.find (L"\\\\") == 0)
{
- strcpy_s ((char *)mount.wszVolume, array_capacity (mount.wszVolume), ("UNC" + path.substr (1)).c_str());
+ StringCbCopyW (mount.wszVolume, sizeof (mount.wszVolume), (L"UNC" + path.substr (1)).c_str());
}
- if (GetVolumePathName (volumePath, root, sizeof (root) - 1))
+ if (GetVolumePathName (volumePath, root, ARRAYSIZE (root) - 1))
{
DWORD bps, flags, d;
if (GetDiskFreeSpace (root, &d, &bps, &d, &d))
@@ -6822,12 +6756,12 @@ retry:
if (IsOSAtLeast (WIN_VISTA))
{
- if ( (strlen(root) >= 2)
- && (root[1] == ':')
- && (toupper(root[0]) >= 'A' && toupper(root[0]) <= 'Z')
+ if ( (wcslen(root) >= 2)
+ && (root[1] == L':')
+ && (towupper(root[0]) >= L'A' && towupper(root[0]) <= L'Z')
)
{
- string drivePath = "\\\\.\\X:";
+ wstring drivePath = L"\\\\.\\X:";
HANDLE dev = INVALID_HANDLE_VALUE;
VOLUME_DISK_EXTENTS extents = {0};
DWORD dwResult = 0;
@@ -6858,8 +6792,6 @@ retry:
}
}
- ToUNICODE ((char *) mount.wszVolume, sizeof(mount.wszVolume));
-
if (mountOptions->PartitionInInactiveSysEncScope)
{
if (mount.wszVolume == NULL || swscanf_s ((const wchar_t *) mount.wszVolume,
@@ -6965,7 +6897,7 @@ retry:
{
int driveNo;
- if (sscanf (volumePath, "\\Device\\Harddisk%d\\Partition", &driveNo) == 1)
+ if (swscanf (volumePath, L"\\Device\\Harddisk%d\\Partition", &driveNo) == 1)
{
OPEN_TEST_STRUCT openTestStruct;
memset (&openTestStruct, 0, sizeof (openTestStruct));
@@ -7040,7 +6972,7 @@ retry:
if (mount.VolumeMountedReadOnlyAfterDeviceWriteProtected
&& !Silent
- && strstr (volumePath, "\\Device\\Harddisk") == volumePath)
+ && wcsstr (volumePath, L"\\Device\\Harddisk") == volumePath)
{
wchar_t msg[1024];
wchar_t mountPoint[] = { L'A' + (wchar_t) driveNo, L':', 0 };
@@ -7049,7 +6981,7 @@ retry:
WarningDirect (msg, hwndDlg);
if (CurrentOSMajor >= 6
- && strstr (volumePath, "\\Device\\HarddiskVolume") != volumePath
+ && wcsstr (volumePath, L"\\Device\\HarddiskVolume") != volumePath
&& AskNoYes ("ASK_REMOVE_DEVICE_WRITE_PROTECTION", hwndDlg) == IDYES)
{
RemoveDeviceWriteProtection (hwndDlg, volumePath);
@@ -7143,7 +7075,7 @@ retry:
if (IsOSAtLeast (WIN_7))
{
// Undo SHCNE_DRIVEREMOVED
- char root[] = { (char) nDosDriveNo + 'A', ':', '\\', 0 };
+ wchar_t root[] = { (wchar_t) nDosDriveNo + L'A', L':', L'\\', 0 };
SHChangeNotify (SHCNE_DRIVEADD, SHCNF_PATH, root, NULL);
}
@@ -7178,23 +7110,21 @@ BOOL IsPasswordCacheEmpty (void)
}
-BOOL IsMountedVolume (const char *volname)
+BOOL IsMountedVolume (const wchar_t *volname)
{
MOUNT_LIST_STRUCT mlist;
DWORD dwResult;
int i;
- char volume[TC_MAX_PATH*2+16];
+ wchar_t volume[TC_MAX_PATH*2+16];
- StringCbCopyA (volume, sizeof(volume), volname);
+ StringCbCopyW (volume, sizeof(volume), volname);
- if (strstr (volname, "\\Device\\") != volname)
- StringCbPrintfA(volume, sizeof(volume), "\\??\\%s", volname);
+ if (wcsstr (volname, L"\\Device\\") != volname)
+ StringCbPrintfW(volume, sizeof(volume), L"\\??\\%s", volname);
- string resolvedPath = VolumeGuidPathToDevicePath (volname);
+ wstring resolvedPath = VolumeGuidPathToDevicePath (volname);
if (!resolvedPath.empty())
- StringCbCopyA (volume, sizeof (volume), resolvedPath.c_str());
-
- ToUNICODE (volume, sizeof(volume));
+ StringCbCopyW (volume, sizeof (volume), resolvedPath.c_str());
memset (&mlist, 0, sizeof (mlist));
DeviceIoControl (hDriver, TC_IOCTL_GET_MOUNTED_VOLUMES, &mlist,
@@ -7202,33 +7132,31 @@ BOOL IsMountedVolume (const char *volname)
NULL);
for (i=0 ; i<26; i++)
- if (0 == _wcsicmp ((wchar_t *) mlist.wszVolume[i], (WCHAR *)volume))
+ if (0 == _wcsicmp ((wchar_t *) mlist.wszVolume[i], volume))
return TRUE;
return FALSE;
}
-int GetMountedVolumeDriveNo (char *volname)
+int GetMountedVolumeDriveNo (wchar_t *volname)
{
MOUNT_LIST_STRUCT mlist;
DWORD dwResult;
int i;
- char volume[TC_MAX_PATH*2+16];
+ wchar_t volume[TC_MAX_PATH*2+16];
if (volname == NULL)
return -1;
- StringCbCopyA (volume, sizeof(volume), volname);
+ StringCbCopyW (volume, sizeof(volume), volname);
- if (strstr (volname, "\\Device\\") != volname)
- StringCbPrintfA (volume, sizeof(volume), "\\??\\%s", volname);
+ if (wcsstr (volname, L"\\Device\\") != volname)
+ StringCbPrintfW (volume, sizeof(volume), L"\\??\\%s", volname);
- string resolvedPath = VolumeGuidPathToDevicePath (volname);
+ wstring resolvedPath = VolumeGuidPathToDevicePath (volname);
if (!resolvedPath.empty())
- StringCbCopyA (volume, sizeof (volume), resolvedPath.c_str());
-
- ToUNICODE (volume, sizeof(volume));
+ StringCbCopyW (volume, sizeof (volume), resolvedPath.c_str());
memset (&mlist, 0, sizeof (mlist));
DeviceIoControl (hDriver, TC_IOCTL_GET_MOUNTED_VOLUMES, &mlist,
@@ -7283,9 +7211,9 @@ BOOL IsUacSupported ()
if (!IsOSAtLeast (WIN_VISTA))
return FALSE;
- if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", 0, KEY_READ, &hkey) == ERROR_SUCCESS)
+ if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", 0, KEY_READ, &hkey) == ERROR_SUCCESS)
{
- if (RegQueryValueEx (hkey, "EnableLUA", 0, 0, (LPBYTE) &value, &size) != ERROR_SUCCESS)
+ if (RegQueryValueEx (hkey, L"EnableLUA", 0, 0, (LPBYTE) &value, &size) != ERROR_SUCCESS)
value = 1;
RegCloseKey (hkey);
@@ -7314,14 +7242,14 @@ BOOL ResolveSymbolicLink (const wchar_t *symLinkName, PWSTR targetName, size_t c
}
-BOOL GetPartitionInfo (const char *deviceName, PPARTITION_INFORMATION rpartInfo)
+BOOL GetPartitionInfo (const wchar_t *deviceName, PPARTITION_INFORMATION rpartInfo)
{
BOOL bResult;
DWORD dwResult;
DISK_PARTITION_INFO_STRUCT dpi;
memset (&dpi, 0, sizeof(dpi));
- StringCbPrintfW ((PWSTR) &dpi.deviceName, sizeof(dpi.deviceName), L"%hs", deviceName);
+ StringCbCopyW ((PWSTR) &dpi.deviceName, sizeof(dpi.deviceName), deviceName);
bResult = DeviceIoControl (hDriver, TC_IOCTL_GET_DRIVE_PARTITION_INFO, &dpi,
sizeof (dpi), &dpi, sizeof (dpi), &dwResult, NULL);
@@ -7331,25 +7259,25 @@ BOOL GetPartitionInfo (const char *deviceName, PPARTITION_INFORMATION rpartInfo)
}
-BOOL GetDeviceInfo (const char *deviceName, DISK_PARTITION_INFO_STRUCT *info)
+BOOL GetDeviceInfo (const wchar_t *deviceName, DISK_PARTITION_INFO_STRUCT *info)
{
DWORD dwResult;
memset (info, 0, sizeof(*info));
- StringCbPrintfW ((PWSTR) &info->deviceName, sizeof(info->deviceName), L"%hs", deviceName);
+ StringCbCopyW ((PWSTR) &info->deviceName, sizeof(info->deviceName), deviceName);
return DeviceIoControl (hDriver, TC_IOCTL_GET_DRIVE_PARTITION_INFO, info, sizeof (*info), info, sizeof (*info), &dwResult, NULL);
}
-BOOL GetDriveGeometry (const char *deviceName, PDISK_GEOMETRY diskGeometry)
+BOOL GetDriveGeometry (const wchar_t *deviceName, PDISK_GEOMETRY diskGeometry)
{
BOOL bResult;
DWORD dwResult;
DISK_GEOMETRY_STRUCT dg;
memset (&dg, 0, sizeof(dg));
- StringCbPrintfW ((PWSTR) &dg.deviceName, sizeof(dg.deviceName), L"%hs", deviceName);
+ StringCbCopyW ((PWSTR) &dg.deviceName, sizeof(dg.deviceName), deviceName);
bResult = DeviceIoControl (hDriver, TC_IOCTL_GET_DRIVE_GEOMETRY, &dg,
sizeof (dg), &dg, sizeof (dg), &dwResult, NULL);
@@ -7377,7 +7305,7 @@ int GetDiskDeviceDriveLetter (PWSTR deviceName)
for (i = 0; i < 26; i++)
{
- WCHAR drive[] = { (WCHAR) i + 'A', ':', 0 };
+ WCHAR drive[] = { (WCHAR) i + L'A', L':', 0 };
StringCchCopyW (link, MAX_PATH, L"\\DosDevices\\");
StringCchCatW (link, MAX_PATH, drive);
@@ -7396,7 +7324,7 @@ int GetDiskDeviceDriveLetter (PWSTR deviceName)
// WARNING: This function does NOT provide 100% reliable results -- do NOT use it for critical/dangerous operations!
// Return values: 0 - filesystem does not appear empty, 1 - filesystem appears empty, -1 - an error occurred
-int FileSystemAppearsEmpty (const char *devicePath)
+int FileSystemAppearsEmpty (const wchar_t *devicePath)
{
float percentFreeSpace = 0.0;
__int64 occupiedBytes = 0;
@@ -7420,20 +7348,19 @@ int FileSystemAppearsEmpty (const char *devicePath)
// is not NULL, size of occupied space (in bytes) is written to the pointed location. In addition, if the
// 'percent' pointer is not NULL, % of free space is stored in the pointed location. If there's an error,
// returns -1.
-__int64 GetStatsFreeSpaceOnPartition (const char *devicePath, float *percentFree, __int64 *occupiedBytes, BOOL silent)
+__int64 GetStatsFreeSpaceOnPartition (const wchar_t *devicePath, float *percentFree, __int64 *occupiedBytes, BOOL silent)
{
WCHAR devPath [MAX_PATH];
int driveLetterNo = -1;
- char szRootPath[4] = {0, ':', '\\', 0};
+ wchar_t szRootPath[4] = {0, L':', L'\\', 0};
ULARGE_INTEGER freeSpaceSize;
ULARGE_INTEGER totalNumberOfBytes;
ULARGE_INTEGER totalNumberOfFreeBytes;
- StringCbCopyA ((char *) devPath, sizeof(devPath), devicePath);
- ToUNICODE ((char *) devPath, sizeof(devPath));
+ StringCbCopyW (devPath, sizeof(devPath), devicePath);
driveLetterNo = GetDiskDeviceDriveLetter (devPath);
- szRootPath[0] = (char) driveLetterNo + 'A';
+ szRootPath[0] = (wchar_t) driveLetterNo + L'A';
if (!GetDiskFreeSpaceEx (szRootPath, &freeSpaceSize, &totalNumberOfBytes, &totalNumberOfFreeBytes))
@@ -7476,7 +7403,7 @@ __int64 GetStatsFreeSpaceOnPartition (const char *devicePath, float *percentFree
// Returns -1 if there's an error.
-__int64 GetDeviceSize (const char *devicePath)
+__int64 GetDeviceSize (const wchar_t *devicePath)
{
PARTITION_INFORMATION partitionInfo;
@@ -7487,7 +7414,7 @@ __int64 GetDeviceSize (const char *devicePath)
}
-HANDLE DismountDrive (char *devName, char *devicePath)
+HANDLE DismountDrive (wchar_t *devName, wchar_t *devicePath)
{
DWORD dwResult;
HANDLE hVolume;
@@ -7496,8 +7423,7 @@ HANDLE DismountDrive (char *devName, char *devicePath)
int driveLetterNo = -1;
WCHAR devPath [MAX_PATH];
- StringCbCopyA ((char *) devPath, sizeof(devPath), devicePath);
- ToUNICODE ((char *) devPath, sizeof(devPath));
+ StringCbCopyW (devPath, sizeof(devPath), devicePath);
driveLetterNo = GetDiskDeviceDriveLetter (devPath);
@@ -7563,32 +7489,32 @@ int64 FindString (const char *buf, const char *str, int64 bufLen, int64 strLen,
}
// Returns TRUE if the file or directory exists (both may be enclosed in quotation marks).
-BOOL FileExists (const char *filePathPtr)
+BOOL FileExists (const wchar_t *filePathPtr)
{
- char filePath [TC_MAX_PATH * 2 + 1];
+ wchar_t filePath [TC_MAX_PATH * 2 + 1];
// Strip quotation marks (if any)
- if (filePathPtr [0] == '"')
+ if (filePathPtr [0] == L'"')
{
- StringCbCopyA (filePath, sizeof(filePath), filePathPtr + 1);
+ StringCbCopyW (filePath, sizeof(filePath), filePathPtr + 1);
}
else
{
- StringCbCopyA (filePath, sizeof(filePath), filePathPtr);
+ StringCbCopyW (filePath, sizeof(filePath), filePathPtr);
}
// Strip quotation marks (if any)
- if (filePath [strlen (filePath) - 1] == '"')
- filePath [strlen (filePath) - 1] = 0;
+ if (filePath [wcslen (filePath) - 1] == L'"')
+ filePath [wcslen (filePath) - 1] = 0;
- return (_access (filePath, 0) != -1);
+ return (_waccess (filePath, 0) != -1);
}
// Searches the file from its end for the LAST occurrence of the string str.
// The string may contain zeroes, which do NOT terminate the string.
// If the string is found, its offset from the start of the file is returned.
// If the string isn't found or if any error occurs, -1 is returned.
-__int64 FindStringInFile (const char *filePath, const char* str, int strLen)
+__int64 FindStringInFile (const wchar_t *filePath, const char* str, int strLen)
{
int bufSize = 64 * BYTES_PER_KB;
char *buffer = (char *) err_malloc (bufSize);
@@ -7706,31 +7632,7 @@ BOOL TCCopyFileBase (HANDLE src, HANDLE dst)
return res != 0;
}
-BOOL TCCopyFile (char *sourceFileName, char *destinationFile)
-{
- HANDLE src, dst;
-
- src = CreateFile (sourceFileName,
- GENERIC_READ,
- FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
-
- if (src == INVALID_HANDLE_VALUE)
- return FALSE;
-
- dst = CreateFile (destinationFile,
- GENERIC_WRITE,
- 0, NULL, CREATE_ALWAYS, 0, NULL);
-
- if (dst == INVALID_HANDLE_VALUE)
- {
- CloseHandle (src);
- return FALSE;
- }
-
- return TCCopyFileBase (src, dst);
-}
-
-BOOL TCCopyFileW (wchar_t *sourceFileName, wchar_t *destinationFile)
+BOOL TCCopyFile (wchar_t *sourceFileName, wchar_t *destinationFile)
{
HANDLE src, dst;
@@ -7756,7 +7658,7 @@ BOOL TCCopyFileW (wchar_t *sourceFileName, wchar_t *destinationFile)
// If bAppend is TRUE, the buffer is appended to an existing file. If bAppend is FALSE, any existing file
// is replaced. If an error occurs, the incomplete file is deleted (provided that bAppend is FALSE).
-BOOL SaveBufferToFile (const char *inputBuffer, const char *destinationFile, DWORD inputLength, BOOL bAppend, BOOL bRenameIfFailed)
+BOOL SaveBufferToFile (const char *inputBuffer, const wchar_t *destinationFile, DWORD inputLength, BOOL bAppend, BOOL bRenameIfFailed)
{
HANDLE dst;
DWORD bytesWritten;
@@ -7770,9 +7672,9 @@ BOOL SaveBufferToFile (const char *inputBuffer, const char *destinationFile, DWO
dwLastError = GetLastError();
if (!bAppend && bRenameIfFailed && (dst == INVALID_HANDLE_VALUE) && (GetLastError () == ERROR_SHARING_VIOLATION))
{
- char renamedPath[TC_MAX_PATH + 1];
- StringCbCopyA (renamedPath, sizeof(renamedPath), destinationFile);
- StringCbCatA (renamedPath, sizeof(renamedPath), VC_FILENAME_RENAMED_SUFFIX);
+ wchar_t renamedPath[TC_MAX_PATH + 1];
+ StringCbCopyW (renamedPath, sizeof(renamedPath), destinationFile);
+ StringCbCatW (renamedPath, sizeof(renamedPath), VC_FILENAME_RENAMED_SUFFIX);
/* rename the locked file in order to be able to create a new one */
if (MoveFileEx (destinationFile, renamedPath, MOVEFILE_REPLACE_EXISTING))
@@ -7821,7 +7723,7 @@ BOOL SaveBufferToFile (const char *inputBuffer, const char *destinationFile, DWO
CloseHandle (dst);
if (!res && !bAppend)
- remove (destinationFile);
+ _wremove (destinationFile);
return res;
}
@@ -7844,62 +7746,62 @@ BOOL TCFlushFile (FILE *f)
// Prints a UTF-16 text (note that this involves a real printer, not a screen).
// textByteLen - length of the text in bytes
// title - printed as part of the page header and used as the filename for a temporary file
-BOOL PrintHardCopyTextUTF16 (wchar_t *text, char *title, size_t textByteLen)
+BOOL PrintHardCopyTextUTF16 (wchar_t *text, wchar_t *title, size_t textByteLen)
{
- char cl [MAX_PATH*3] = {"/p \""};
- char path [MAX_PATH * 2] = { 0 };
- char filename [MAX_PATH + 1] = { 0 };
+ wchar_t cl [MAX_PATH*3] = {L"/p \""};
+ wchar_t path [MAX_PATH * 2] = { 0 };
+ wchar_t filename [MAX_PATH + 1] = { 0 };
- StringCbCopyA (filename, sizeof(filename), title);
+ StringCbCopyW (filename, sizeof(filename), title);
//strcat (filename, ".txt");
- GetTempPath (sizeof (path), path);
+ GetTempPath (ARRAYSIZE (path), path);
if (!FileExists (path))
{
- StringCbCopyA (path, sizeof(path), GetConfigPath (filename));
+ StringCbCopyW (path, sizeof(path), GetConfigPath (filename));
- if (strlen(path) < 2)
+ if (wcslen(path) < 2)
return FALSE;
}
else
{
- StringCbCatA (path, sizeof(path), filename);
+ StringCbCatW (path, sizeof(path), filename);
}
// Write the Unicode signature
if (!SaveBufferToFile ("\xFF\xFE", path, 2, FALSE, FALSE))
{
- remove (path);
+ _wremove (path);
return FALSE;
}
// Write the actual text
if (!SaveBufferToFile ((char *) text, path, (DWORD) textByteLen, TRUE, FALSE))
{
- remove (path);
+ _wremove (path);
return FALSE;
}
- StringCbCatA (cl, sizeof(cl), path);
- StringCbCatA (cl, sizeof(cl), "\"");
+ StringCbCatW (cl, sizeof(cl), path);
+ StringCbCatW (cl, sizeof(cl), L"\"");
// Get the absolute path for notepad
if (GetWindowsDirectory(filename, MAX_PATH))
{
- if (filename[strlen (filename) - 1] != '\\')
- StringCbCatA (filename, sizeof(filename), "\\");
- StringCbCatA(filename, sizeof(filename), PRINT_TOOL);
+ if (filename[wcslen (filename) - 1] != L'\\')
+ StringCbCatW (filename, sizeof(filename), L"\\");
+ StringCbCatW(filename, sizeof(filename), PRINT_TOOL);
}
else
- StringCbCopyA(filename, sizeof(filename), "C:\\Windows\\" PRINT_TOOL);
+ StringCbCopyW(filename, sizeof(filename), L"C:\\Windows\\" PRINT_TOOL);
WaitCursor ();
- ShellExecute (NULL, "open", filename, cl, NULL, SW_HIDE);
+ ShellExecute (NULL, L"open", filename, cl, NULL, SW_HIDE);
Sleep (6000);
NormalCursor();
- remove (path);
+ _wremove (path);
return TRUE;
}
@@ -7937,13 +7839,13 @@ BOOL IsNonInstallMode ()
{
// The driver was not found in the system path
- char path[MAX_PATH * 2] = { 0 };
+ wchar_t path[MAX_PATH * 2] = { 0 };
// We can't use GetConfigPath() here because it would call us back (indirect recursion)
if (SUCCEEDED(SHGetFolderPath (NULL, CSIDL_APPDATA, NULL, 0, path)))
{
- StringCbCatA (path, MAX_PATH * 2, "\\VeraCrypt\\");
- StringCbCatA (path, MAX_PATH * 2, TC_APPD_FILENAME_SYSTEM_ENCRYPTION);
+ StringCbCatW (path, MAX_PATH * 2, L"\\VeraCrypt\\");
+ StringCbCatW (path, MAX_PATH * 2, TC_APPD_FILENAME_SYSTEM_ENCRYPTION);
if (FileExists (path))
{
@@ -7968,7 +7870,7 @@ BOOL IsNonInstallMode ()
// The following test may be unreliable in some cases (e.g. after the user selects restore "Last Known Good
// Configuration" from the Windows boot menu).
- if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\VeraCrypt", 0, KEY_READ | KEY_WOW64_32KEY, &hkey) == ERROR_SUCCESS)
+ if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\VeraCrypt", 0, KEY_READ | KEY_WOW64_32KEY, &hkey) == ERROR_SUCCESS)
{
RegCloseKey (hkey);
return FALSE;
@@ -8008,79 +7910,79 @@ void ManageStartupSeq (void)
{
if (!IsNonInstallMode ())
{
- char regk [64];
+ wchar_t regk [64];
GetStartupRegKeyName (regk, sizeof(regk));
if (bStartOnLogon || bMountDevicesOnLogon || bMountFavoritesOnLogon)
{
- char exe[MAX_PATH * 2] = { '"' };
+ wchar_t exe[MAX_PATH * 2] = { L'"' };
- GetModuleFileName (NULL, exe + 1, sizeof (exe) - 1);
+ GetModuleFileName (NULL, exe + 1, ARRAYSIZE (exe) - 1);
#ifdef VOLFORMAT
{
- char *tmp = NULL;
+ wchar_t *tmp = NULL;
- if (tmp = strrchr (exe, '\\'))
+ if (tmp = wcsrchr (exe, L'\\'))
{
*tmp = 0;
- StringCbCatA (exe, MAX_PATH * 2, "\\VeraCrypt.exe");
+ StringCbCatW (exe, MAX_PATH * 2, L"\\VeraCrypt.exe");
}
}
#endif
- StringCbCatA (exe, MAX_PATH * 2, "\" /q preferences /a logon");
+ StringCbCatW (exe, MAX_PATH * 2, L"\" /q preferences /a logon");
- if (bMountDevicesOnLogon) StringCbCatA (exe, MAX_PATH * 2, " /a devices");
- if (bMountFavoritesOnLogon) StringCbCatA (exe, MAX_PATH * 2, " /a favorites");
+ if (bMountDevicesOnLogon) StringCbCatW (exe, MAX_PATH * 2, L" /a devices");
+ if (bMountFavoritesOnLogon) StringCbCatW (exe, MAX_PATH * 2, L" /a favorites");
- WriteRegistryString (regk, "VeraCrypt", exe);
+ WriteRegistryString (regk, L"VeraCrypt", exe);
}
else
- DeleteRegistryValue (regk, "VeraCrypt");
+ DeleteRegistryValue (regk, L"VeraCrypt");
}
}
// Adds or removes the VeraCrypt Volume Creation Wizard to/from the system startup sequence
-void ManageStartupSeqWiz (BOOL bRemove, const char *arg)
+void ManageStartupSeqWiz (BOOL bRemove, const wchar_t *arg)
{
- char regk [64];
+ wchar_t regk [64];
GetStartupRegKeyName (regk, sizeof(regk));
if (!bRemove)
{
- size_t exeSize = (MAX_PATH * 2) + 3 + 20 + strlen (arg); // enough room for all concatenation operations
- char* exe = (char*) calloc(1, exeSize);
- exe[0] = '"';
+ size_t exeSize = (MAX_PATH * 2) + 3 + 20 + wcslen (arg); // enough room for all concatenation operations
+ wchar_t* exe = (wchar_t*) calloc(1, exeSize * sizeof (wchar_t));
+ exe[0] = L'"';
GetModuleFileName (NULL, exe + 1, (DWORD) (exeSize - 1));
#ifndef VOLFORMAT
{
- char *tmp = NULL;
+ wchar_t *tmp = NULL;
- if (tmp = strrchr (exe, '\\'))
+ if (tmp = wcsrchr (exe, L'\\'))
{
*tmp = 0;
- StringCbCatA (exe, exeSize, "\\VeraCrypt Format.exe");
+ StringCchCatW (exe, exeSize, L"\\VeraCrypt Format.exe");
}
}
#endif
- if (strlen (arg) > 0)
+ if (wcslen (arg) > 0)
{
- StringCbCatA (exe, exeSize, "\" ");
- StringCbCatA (exe, exeSize, arg);
+ StringCchCatW (exe, exeSize, L"\" ");
+ StringCchCatW (exe, exeSize, arg);
}
- WriteRegistryString (regk, "VeraCrypt Format", exe);
+ WriteRegistryString (regk, L"VeraCrypt Format", exe);
free(exe);
}
else
- DeleteRegistryValue (regk, "VeraCrypt Format");
+ DeleteRegistryValue (regk, L"VeraCrypt Format");
}
@@ -8091,19 +7993,19 @@ void CleanLastVisitedMRU (void)
WCHAR *strToMatch;
WCHAR strTmp[4096];
- char regPath[128];
- char key[64];
+ WCHAR regPath[128];
+ WCHAR key[64];
int id, len;
GetModuleFileNameW (NULL, exeFilename, sizeof (exeFilename) / sizeof(exeFilename[0]));
- strToMatch = wcsrchr (exeFilename, '\\') + 1;
+ strToMatch = wcsrchr (exeFilename, L'\\') + 1;
- StringCbPrintfA (regPath, sizeof(regPath), "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ComDlg32\\LastVisited%sMRU", IsOSAtLeast (WIN_VISTA) ? "Pidl" : "");
+ StringCbPrintfW (regPath, sizeof(regPath), L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ComDlg32\\LastVisited%sMRU", IsOSAtLeast (WIN_VISTA) ? L"Pidl" : L"");
- for (id = (IsOSAtLeast (WIN_VISTA) ? 0 : 'a'); id <= (IsOSAtLeast (WIN_VISTA) ? 1000 : 'z'); id++)
+ for (id = (IsOSAtLeast (WIN_VISTA) ? 0 : L'a'); id <= (IsOSAtLeast (WIN_VISTA) ? 1000 : L'z'); id++)
{
*strTmp = 0;
- StringCbPrintfA (key, sizeof(key), (IsOSAtLeast (WIN_VISTA) ? "%d" : "%c"), id);
+ StringCbPrintfW (key, sizeof(key), (IsOSAtLeast (WIN_VISTA) ? L"%d" : L"%c"), id);
if ((len = ReadRegistryBytes (regPath, key, (char *) strTmp, sizeof (strTmp))) > 0)
{
@@ -8125,7 +8027,7 @@ void CleanLastVisitedMRU (void)
int *pout = (int *)bufout;
int l;
- l = len = ReadRegistryBytes ("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ComDlg32\\LastVisitedPidlMRU", "MRUListEx", buf, sizeof (buf));
+ l = len = ReadRegistryBytes (L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ComDlg32\\LastVisitedPidlMRU", L"MRUListEx", buf, sizeof (buf));
while (l > 0)
{
l -= sizeof (int);
@@ -8139,14 +8041,14 @@ void CleanLastVisitedMRU (void)
*pout++ = *p++;
}
- WriteRegistryBytes ("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ComDlg32\\LastVisitedPidlMRU", "MRUListEx", bufout, len);
+ WriteRegistryBytes (L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ComDlg32\\LastVisitedPidlMRU", L"MRUListEx", bufout, len);
}
else
{
- char *p = buf;
- char *pout = bufout;
+ wchar_t *p = (wchar_t*) buf;
+ wchar_t *pout = (wchar_t*) bufout;
- ReadRegistryString ("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ComDlg32\\LastVisitedMRU", "MRUList", "", buf, sizeof (buf));
+ ReadRegistryString (L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ComDlg32\\LastVisitedMRU", L"MRUList", L"", (wchar_t*) buf, sizeof (buf));
while (*p)
{
if (*p == id)
@@ -8158,7 +8060,7 @@ void CleanLastVisitedMRU (void)
}
*pout++ = 0;
- WriteRegistryString ("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ComDlg32\\LastVisitedMRU", "MRUList", bufout);
+ WriteRegistryString (L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ComDlg32\\LastVisitedMRU", L"MRUList", (wchar_t*) bufout);
}
break;
@@ -8183,58 +8085,32 @@ void ClearHistory (HWND hwndDlgItem)
#endif // #ifndef SETUP
-LRESULT ListItemAdd (HWND list, int index, char *string)
+LRESULT ListItemAdd (HWND list, int index, const wchar_t *string)
{
LVITEM li;
memset (&li, 0, sizeof(li));
li.mask = LVIF_TEXT;
- li.pszText = string;
+ li.pszText = (wchar_t*) string;
li.iItem = index;
li.iSubItem = 0;
return ListView_InsertItem (list, &li);
}
-LRESULT ListItemAddW (HWND list, int index, wchar_t *string)
-{
- LVITEMW li;
- memset (&li, 0, sizeof(li));
-
- li.mask = LVIF_TEXT;
- li.pszText = string;
- li.iItem = index;
- li.iSubItem = 0;
- return SendMessageW (list, LVM_INSERTITEMW, 0, (LPARAM)(&li));
-}
-
-
-LRESULT ListSubItemSet (HWND list, int index, int subIndex, char *string)
+LRESULT ListSubItemSet (HWND list, int index, int subIndex, const wchar_t *string)
{
LVITEM li;
memset (&li, 0, sizeof(li));
li.mask = LVIF_TEXT;
- li.pszText = string;
+ li.pszText = (wchar_t*) string;
li.iItem = index;
li.iSubItem = subIndex;
return ListView_SetItem (list, &li);
}
-LRESULT ListSubItemSetW (HWND list, int index, int subIndex, wchar_t *string)
-{
- LVITEMW li;
- memset (&li, 0, sizeof(li));
-
- li.mask = LVIF_TEXT;
- li.pszText = string;
- li.iItem = index;
- li.iSubItem = subIndex;
- return SendMessageW (list, LVM_SETITEMW, 0, (LPARAM)(&li));
-}
-
-
BOOL GetMountList (MOUNT_LIST_STRUCT *list)
{
DWORD dwResult;
@@ -8263,7 +8139,7 @@ int GetDriverRefCount ()
// Loads a 32-bit integer from the file at the specified file offset. The saved value is assumed to have been
// processed by mputLong(). The result is stored in *result. Returns TRUE if successful (otherwise FALSE).
-BOOL LoadInt32 (char *filePath, unsigned __int32 *result, __int64 fileOffset)
+BOOL LoadInt32 (const wchar_t *filePath, unsigned __int32 *result, __int64 fileOffset)
{
DWORD bufSize = sizeof(__int32);
unsigned char *buffer = (unsigned char *) malloc (bufSize);
@@ -8307,7 +8183,7 @@ fsif_end:
// Loads a 16-bit integer from the file at the specified file offset. The saved value is assumed to have been
// processed by mputWord(). The result is stored in *result. Returns TRUE if successful (otherwise FALSE).
-BOOL LoadInt16 (char *filePath, int *result, __int64 fileOffset)
+BOOL LoadInt16 (const wchar_t *filePath, int *result, __int64 fileOffset)
{
DWORD bufSize = sizeof(__int16);
unsigned char *buffer = (unsigned char *) malloc (bufSize);
@@ -8350,7 +8226,7 @@ fsif_end:
}
// Returns NULL if there's any error. Although the buffer can contain binary data, it is always null-terminated.
-char *LoadFile (const char *fileName, DWORD *size)
+char *LoadFile (const wchar_t *fileName, DWORD *size)
{
char *buf;
DWORD fileSize = INVALID_FILE_SIZE;
@@ -8385,7 +8261,7 @@ char *LoadFile (const char *fileName, DWORD *size)
// Returns NULL if there's any error.
-char *LoadFileBlock (char *fileName, __int64 fileOffset, DWORD count)
+char *LoadFileBlock (const wchar_t *fileName, __int64 fileOffset, DWORD count)
{
char *buf;
DWORD bytesRead = 0;
@@ -8427,7 +8303,7 @@ char *LoadFileBlock (char *fileName, __int64 fileOffset, DWORD count)
// Returns -1 if there is an error, or the size of the file.
-__int64 GetFileSize64 (const char *path)
+__int64 GetFileSize64 (const wchar_t *path)
{
HANDLE h = CreateFile (path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
LARGE_INTEGER size;
@@ -8447,33 +8323,33 @@ __int64 GetFileSize64 (const char *path)
}
-char *GetModPath (char *path, int maxSize)
+wchar_t *GetModPath (wchar_t *path, int maxSize)
{
GetModuleFileName (NULL, path, maxSize);
- char* ptr = strrchr (path, '\\');
+ wchar_t* ptr = wcsrchr (path, L'\\');
if (ptr)
ptr[1] = 0;
return path;
}
-char *GetConfigPath (char *fileName)
+wchar_t *GetConfigPath (wchar_t *fileName)
{
- static char path[MAX_PATH * 2] = { 0 };
+ static wchar_t path[MAX_PATH * 2] = { 0 };
if (IsNonInstallMode ())
{
- GetModPath (path, sizeof (path));
- StringCbCatA (path, (MAX_PATH * 2), fileName);
+ GetModPath (path, ARRAYSIZE (path));
+ StringCchCatW (path, (MAX_PATH * 2), fileName);
return path;
}
if (SUCCEEDED(SHGetFolderPath (NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, path)))
{
- StringCbCatA (path, (MAX_PATH * 2), "\\VeraCrypt\\");
+ StringCchCatW (path, (MAX_PATH * 2), L"\\VeraCrypt\\");
CreateDirectory (path, NULL);
- StringCbCatA (path, (MAX_PATH * 2), fileName);
+ StringCchCatW (path, (MAX_PATH * 2), fileName);
}
else
path[0] = 0;
@@ -8482,15 +8358,15 @@ char *GetConfigPath (char *fileName)
}
-char *GetProgramConfigPath (char *fileName)
+wchar_t *GetProgramConfigPath (wchar_t *fileName)
{
- static char path[MAX_PATH * 2] = { 0 };
+ static wchar_t path[MAX_PATH * 2] = { 0 };
if (SUCCEEDED (SHGetFolderPath (NULL, CSIDL_COMMON_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, path)))
{
- StringCbCatA (path, (MAX_PATH * 2), "\\VeraCrypt\\");
+ StringCchCatW (path, (MAX_PATH * 2), L"\\VeraCrypt\\");
CreateDirectory (path, NULL);
- StringCbCatA (path, (MAX_PATH * 2), fileName);
+ StringCchCatW (path, (MAX_PATH * 2), fileName);
}
else
path[0] = 0;
@@ -8499,31 +8375,31 @@ char *GetProgramConfigPath (char *fileName)
}
-std::string GetServiceConfigPath (const char *fileName, bool useLegacy)
+std::wstring GetServiceConfigPath (const wchar_t *fileName, bool useLegacy)
{
- char sysPath[TC_MAX_PATH];
+ wchar_t sysPath[TC_MAX_PATH];
if (Is64BitOs() && useLegacy)
{
- typedef UINT (WINAPI *GetSystemWow64Directory_t) (LPTSTR lpBuffer, UINT uSize);
+ typedef UINT (WINAPI *GetSystemWow64Directory_t) (LPWSTR lpBuffer, UINT uSize);
- GetSystemWow64Directory_t getSystemWow64Directory = (GetSystemWow64Directory_t) GetProcAddress (GetModuleHandle ("kernel32"), "GetSystemWow64DirectoryA");
- getSystemWow64Directory (sysPath, sizeof (sysPath));
+ GetSystemWow64Directory_t getSystemWow64Directory = (GetSystemWow64Directory_t) GetProcAddress (GetModuleHandle (L"kernel32"), "GetSystemWow64DirectoryW");
+ getSystemWow64Directory (sysPath, ARRAYSIZE (sysPath));
}
else
- GetSystemDirectory (sysPath, sizeof (sysPath));
+ GetSystemDirectory (sysPath, ARRAYSIZE (sysPath));
- return string (sysPath) + "\\" + fileName;
+ return wstring (sysPath) + L"\\" + fileName;
}
// Returns 0 if an error occurs or the drive letter (as an upper-case char) of the system partition (e.g. 'C');
-char GetSystemDriveLetter (void)
+wchar_t GetSystemDriveLetter (void)
{
- char systemDir [MAX_PATH];
+ wchar_t systemDir [MAX_PATH];
- if (GetSystemDirectory (systemDir, sizeof (systemDir)))
- return (char) (toupper (systemDir [0]));
+ if (GetSystemDirectory (systemDir, ARRAYSIZE (systemDir)))
+ return (wchar_t) (towupper (systemDir [0]));
else
return 0;
}
@@ -8826,7 +8702,7 @@ BOOL ConfigWriteBegin ()
if (ConfigBuffer == NULL)
ConfigBuffer = LoadFile (GetConfigPath (TC_APPD_FILENAME_CONFIGURATION), &size);
- ConfigFileHandle = fopen (GetConfigPath (TC_APPD_FILENAME_CONFIGURATION), "w");
+ ConfigFileHandle = _wfopen (GetConfigPath (TC_APPD_FILENAME_CONFIGURATION), L"w,ccs=UTF-8");
if (ConfigFileHandle == NULL)
{
free (ConfigBuffer);
@@ -8834,7 +8710,7 @@ BOOL ConfigWriteBegin ()
return FALSE;
}
XmlWriteHeader (ConfigFileHandle);
- fputs ("\n\t<configuration>", ConfigFileHandle);
+ fputws (L"\n\t<configuration>", ConfigFileHandle);
return TRUE;
}
@@ -8853,11 +8729,11 @@ BOOL ConfigWriteEnd (HWND hwnd)
XmlGetAttributeText (xml, "key", key, sizeof (key));
XmlGetNodeText (xml, value, sizeof (value));
- fprintf (ConfigFileHandle, "\n\t\t<config key=\"%s\">%s</config>", key, value);
+ fwprintf (ConfigFileHandle, L"\n\t\t<config key=\"%hs\">%hs</config>", key, value);
xml++;
}
- fputs ("\n\t</configuration>", ConfigFileHandle);
+ fputws (L"\n\t</configuration>", ConfigFileHandle);
XmlWriteFooter (ConfigFileHandle);
TCFlushFile (ConfigFileHandle);
@@ -8892,11 +8768,29 @@ BOOL ConfigWriteString (char *configKey, char *configValue)
c[1] = '!';
}
- return 0 != fprintf (
- ConfigFileHandle, "\n\t\t<config key=\"%s\">%s</config>",
+ return 0 != fwprintf (
+ ConfigFileHandle, L"\n\t\t<config key=\"%hs\">%hs</config>",
configKey, configValue);
}
+BOOL ConfigWriteStringW (char *configKey, wchar_t *configValue)
+{
+ char *c;
+ if (ConfigFileHandle == NULL)
+ return FALSE;
+
+ // Mark previous config value as updated
+ if (ConfigBuffer != NULL)
+ {
+ c = XmlFindElementByAttributeValue (ConfigBuffer, "config", "key", configKey);
+ if (c != NULL)
+ c[1] = '!';
+ }
+
+ return 0 != fwprintf (
+ ConfigFileHandle, L"\n\t\t<config key=\"%hs\">%ls</config>",
+ configKey, configValue);
+}
BOOL ConfigWriteInt (char *configKey, int configValue)
{
@@ -8992,12 +8886,12 @@ void ConfigReadCompareString (char *configKey, char *defaultValue, char *str, in
void OpenPageHelp (HWND hwndDlg, int nPage)
{
- int r = (int)ShellExecute (NULL, "open", szHelpFile, NULL, NULL, SW_SHOWNORMAL);
+ int r = (int)ShellExecuteW (NULL, L"open", szHelpFile, NULL, NULL, SW_SHOWNORMAL);
if (r == ERROR_FILE_NOT_FOUND)
{
// Try the secondary help file
- r = (int)ShellExecute (NULL, "open", szHelpFile2, NULL, NULL, SW_SHOWNORMAL);
+ r = (int)ShellExecuteW (NULL, L"open", szHelpFile2, NULL, NULL, SW_SHOWNORMAL);
if (r == ERROR_FILE_NOT_FOUND)
{
@@ -9053,8 +8947,13 @@ BOOL LoadDefaultKeyFilesParam (void)
kf = (KeyFile *) malloc (sizeof (KeyFile));
if (kf)
{
- if (XmlGetNodeText (xml, kf->FileName, sizeof (kf->FileName)) != NULL)
+ char fileName [MAX_PATH + 1];
+ if (XmlGetNodeText (xml, fileName, sizeof (fileName)) != NULL)
+ {
+ std::wstring wszFileName = Utf8StringToWide(fileName);
+ StringCbCopyW (kf->FileName, sizeof (kf->FileName), wszFileName.c_str ());
defaultKeyFilesParam.FirstKeyFile = KeyFileAdd (defaultKeyFilesParam.FirstKeyFile, kf);
+ }
else
free (kf);
}
@@ -9087,7 +8986,7 @@ void Debug (char *format, ...)
StringCbVPrintfA (buf, sizeof (buf), format, val);
va_end(val);
- OutputDebugString (buf);
+ OutputDebugStringA (buf);
}
@@ -9100,7 +8999,7 @@ void DebugMsgBox (char *format, ...)
StringCbVPrintfA (buf, sizeof (buf), format, val);
va_end(val);
- MessageBox (MainDlg, buf, "VeraCrypt debug", 0);
+ MessageBoxA (MainDlg, buf, "VeraCrypt debug", 0);
}
@@ -9154,7 +9053,7 @@ BOOL Is64BitOs ()
if (valid)
return isWow64;
- fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress (GetModuleHandle("kernel32"), "IsWow64Process");
+ fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress (GetModuleHandle(L"kernel32"), "IsWow64Process");
if (fnIsWow64Process != NULL)
if (!fnIsWow64Process (GetCurrentProcess(), &isWow64))
@@ -9204,7 +9103,7 @@ BOOL IsHiddenOSRunning (void)
BOOL EnableWow64FsRedirection (BOOL enable)
{
typedef BOOLEAN (__stdcall *Wow64EnableWow64FsRedirection_t) (BOOL enable);
- Wow64EnableWow64FsRedirection_t wow64EnableWow64FsRedirection = (Wow64EnableWow64FsRedirection_t) GetProcAddress (GetModuleHandle ("kernel32"), "Wow64EnableWow64FsRedirection");
+ Wow64EnableWow64FsRedirection_t wow64EnableWow64FsRedirection = (Wow64EnableWow64FsRedirection_t) GetProcAddress (GetModuleHandle (L"kernel32"), "Wow64EnableWow64FsRedirection");
if (!wow64EnableWow64FsRedirection)
return FALSE;
@@ -9246,23 +9145,23 @@ BOOL RestartComputer (void)
}
-std::string GetWindowsEdition ()
+std::wstring GetWindowsEdition ()
{
- string osname = "win";
+ wstring osname = L"win";
- OSVERSIONINFOEXA osVer;
+ OSVERSIONINFOEXW osVer;
osVer.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEXA);
- GetVersionExA ((LPOSVERSIONINFOA) &osVer);
+ GetVersionExW ((LPOSVERSIONINFOW) &osVer);
BOOL home = (osVer.wSuiteMask & VER_SUITE_PERSONAL);
BOOL server = (osVer.wProductType == VER_NT_SERVER || osVer.wProductType == VER_NT_DOMAIN_CONTROLLER);
HKEY hkey;
- char productName[300] = {0};
+ wchar_t productName[300] = {0};
DWORD productNameSize = sizeof (productName);
- if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_QUERY_VALUE, &hkey) == ERROR_SUCCESS)
+ if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_QUERY_VALUE, &hkey) == ERROR_SUCCESS)
{
- if (RegQueryValueEx (hkey, "ProductName", 0, 0, (LPBYTE) &productName, &productNameSize) != ERROR_SUCCESS || productNameSize < 1)
+ if (RegQueryValueEx (hkey, L"ProductName", 0, 0, (LPBYTE) &productName, &productNameSize) != ERROR_SUCCESS || productNameSize < 1)
productName[0] = 0;
RegCloseKey (hkey);
@@ -9271,75 +9170,75 @@ std::string GetWindowsEdition ()
switch (nCurrentOS)
{
case WIN_2000:
- osname += "2000";
+ osname += L"2000";
break;
case WIN_XP:
case WIN_XP64:
- osname += "xp";
- osname += home ? "-home" : "-pro";
+ osname += L"xp";
+ osname += home ? L"-home" : L"-pro";
break;
case WIN_SERVER_2003:
- osname += "2003";
+ osname += L"2003";
break;
case WIN_VISTA:
- osname += "vista";
+ osname += L"vista";
break;
case WIN_SERVER_2008:
- osname += "2008";
+ osname += L"2008";
break;
case WIN_7:
- osname += "7";
+ osname += L"7";
break;
case WIN_SERVER_2008_R2:
- osname += "2008r2";
+ osname += L"2008r2";
break;
default:
- stringstream s;
- s << CurrentOSMajor << "." << CurrentOSMinor;
+ wstringstream s;
+ s << CurrentOSMajor << L"." << CurrentOSMinor;
osname += s.str();
break;
}
if (server)
- osname += "-server";
+ osname += L"-server";
if (IsOSAtLeast (WIN_VISTA))
{
if (home)
- osname += "-home";
- else if (strstr (productName, "Standard") != 0)
- osname += "-standard";
- else if (strstr (productName, "Professional") != 0)
- osname += "-pro";
- else if (strstr (productName, "Business") != 0)
- osname += "-business";
- else if (strstr (productName, "Enterprise") != 0)
- osname += "-enterprise";
- else if (strstr (productName, "Datacenter") != 0)
- osname += "-datacenter";
- else if (strstr (productName, "Ultimate") != 0)
- osname += "-ultimate";
+ osname += L"-home";
+ else if (wcsstr (productName, L"Standard") != 0)
+ osname += L"-standard";
+ else if (wcsstr (productName, L"Professional") != 0)
+ osname += L"-pro";
+ else if (wcsstr (productName, L"Business") != 0)
+ osname += L"-business";
+ else if (wcsstr (productName, L"Enterprise") != 0)
+ osname += L"-enterprise";
+ else if (wcsstr (productName, L"Datacenter") != 0)
+ osname += L"-datacenter";
+ else if (wcsstr (productName, L"Ultimate") != 0)
+ osname += L"-ultimate";
}
if (GetSystemMetrics (SM_STARTER))
- osname += "-starter";
- else if (strstr (productName, "Basic") != 0)
- osname += "-basic";
+ osname += L"-starter";
+ else if (wcsstr (productName, L"Basic") != 0)
+ osname += L"-basic";
if (Is64BitOs())
- osname += "-x64";
+ osname += L"-x64";
if (CurrentOSServicePack > 0)
{
- stringstream s;
- s << "-sp" << CurrentOSServicePack;
+ wstringstream s;
+ s << L"-sp" << CurrentOSServicePack;
osname += s.str();
}
@@ -9470,27 +9369,27 @@ void Applink (char *dest, BOOL bSendOS, char *extraOutput)
{
StringCbCopyA (url, sizeof (url),TC_APPLINK);
}
- ShellExecute (NULL, "open", url, NULL, NULL, SW_SHOWNORMAL);
+ ShellExecuteA (NULL, "open", url, NULL, NULL, SW_SHOWNORMAL);
Sleep (200);
NormalCursor ();
}
-char *RelativePath2Absolute (char *szFileName)
+wchar_t *RelativePath2Absolute (wchar_t *szFileName)
{
- if (szFileName[0] != '\\'
- && strchr (szFileName, ':') == 0
- && strstr (szFileName, "Volume{") != szFileName)
+ if (szFileName[0] != L'\\'
+ && wcschr (szFileName, L':') == 0
+ && wcsstr (szFileName, L"Volume{") != szFileName)
{
- char path[MAX_PATH*2];
+ wchar_t path[MAX_PATH*2];
GetCurrentDirectory (MAX_PATH, path);
- if (path[strlen (path) - 1] != '\\')
- StringCbCatA (path, (MAX_PATH * 2), "\\");
+ if (path[wcslen (path) - 1] != L'\\')
+ StringCbCatW (path, (MAX_PATH * 2), L"\\");
- StringCbCatA (path, (MAX_PATH * 2), szFileName);
- StringCbCopyA (szFileName, MAX_PATH + 1, path); // szFileName size is always at least (MAX_PATH + 1)
+ StringCbCatW (path, (MAX_PATH * 2), szFileName);
+ StringCbCopyW (szFileName, MAX_PATH + 1, path); // szFileName size is always at least (MAX_PATH + 1)
}
return szFileName;
@@ -9502,11 +9401,11 @@ void HandleDriveNotReadyError (HWND hwnd)
HKEY hkey = 0;
DWORD value = 0, size = sizeof (DWORD);
- if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\MountMgr",
+ if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Services\\MountMgr",
0, KEY_READ, &hkey) != ERROR_SUCCESS)
return;
- if (RegQueryValueEx (hkey, "NoAutoMount", 0, 0, (LPBYTE) &value, &size) == ERROR_SUCCESS
+ if (RegQueryValueEx (hkey, L"NoAutoMount", 0, 0, (LPBYTE) &value, &size) == ERROR_SUCCESS
&& value != 0)
{
Warning ("SYS_AUTOMOUNT_DISABLED", hwnd);
@@ -9525,9 +9424,9 @@ BOOL CALLBACK CloseTCWindowsEnum (HWND hwnd, LPARAM lParam)
LONG_PTR userDataVal = GetWindowLongPtrW (hwnd, GWLP_USERDATA);
if ((userDataVal == (LONG_PTR) 'VERA') || (userDataVal == (LONG_PTR) 'TRUE')) // Prior to 1.0e, 'TRUE' was used for VeraCrypt dialogs
{
- char name[1024] = { 0 };
- GetWindowText (hwnd, name, sizeof (name) - 1);
- if (hwnd != MainDlg && strstr (name, "VeraCrypt"))
+ wchar_t name[1024] = { 0 };
+ GetWindowText (hwnd, name, ARRAYSIZE (name) - 1);
+ if (hwnd != MainDlg && wcsstr (name, L"VeraCrypt"))
{
PostMessage (hwnd, TC_APPMSG_CLOSE_BKG_TASK, 0, 0);
@@ -9548,9 +9447,9 @@ BOOL CALLBACK FindTCWindowEnum (HWND hwnd, LPARAM lParam)
LONG_PTR userDataVal = GetWindowLongPtrW (hwnd, GWLP_USERDATA);
if ((userDataVal == (LONG_PTR) 'VERA') || (userDataVal == (LONG_PTR) 'TRUE')) // Prior to 1.0e, 'TRUE' was used for VeraCrypt dialogs
{
- char name[32] = { 0 };
- GetWindowText (hwnd, name, sizeof (name) - 1);
- if (hwnd != MainDlg && strcmp (name, "VeraCrypt") == 0)
+ wchar_t name[32] = { 0 };
+ GetWindowText (hwnd, name, ARRAYSIZE (name) - 1);
+ if (hwnd != MainDlg && wcscmp (name, L"VeraCrypt") == 0)
{
if (lParam != 0)
*((HWND *)lParam) = hwnd;
@@ -9560,7 +9459,7 @@ BOOL CALLBACK FindTCWindowEnum (HWND hwnd, LPARAM lParam)
}
-BYTE *MapResource (char *resourceType, int resourceId, PDWORD size)
+BYTE *MapResource (wchar_t *resourceType, int resourceId, PDWORD size)
{
HGLOBAL hResL;
HRSRC hRes;
@@ -9595,12 +9494,12 @@ void ReportUnexpectedState (char *techInfo)
#ifndef SETUP
-int OpenVolume (OpenVolumeContext *context, const char *volumePath, Password *password, int pkcs5_prf, int pim, BOOL truecryptMode, BOOL write, BOOL preserveTimestamps, BOOL useBackupHeader)
+int OpenVolume (OpenVolumeContext *context, const wchar_t *volumePath, Password *password, int pkcs5_prf, int pim, BOOL truecryptMode, BOOL write, BOOL preserveTimestamps, BOOL useBackupHeader)
{
int status = ERR_PARAMETER_INCORRECT;
int volumeType;
- char szDiskFile[TC_MAX_PATH], szCFDevice[TC_MAX_PATH];
- char szDosDevice[TC_MAX_PATH];
+ wchar_t szDiskFile[TC_MAX_PATH], szCFDevice[TC_MAX_PATH];
+ wchar_t szDosDevice[TC_MAX_PATH];
char buffer[TC_VOLUME_HEADER_EFFECTIVE_SIZE];
LARGE_INTEGER headerOffset;
DWORD dwResult;
@@ -9628,7 +9527,7 @@ int OpenVolume (OpenVolumeContext *context, const char *volumePath, Password *pa
}
}
else
- StringCbCopyA (szCFDevice, sizeof(szCFDevice), szDiskFile);
+ StringCbCopyW (szCFDevice, sizeof(szCFDevice), szDiskFile);
if (preserveTimestamps)
write = TRUE;
@@ -9837,29 +9736,29 @@ BOOL IsPagingFileActive (BOOL checkNonWindowsPartitionsOnly)
{
// GlobalMemoryStatusEx() cannot be used to determine if a paging file is active
- char data[65536];
+ wchar_t data[65536];
DWORD size = sizeof (data);
if (IsPagingFileWildcardActive())
return TRUE;
- if (ReadLocalMachineRegistryMultiString ("System\\CurrentControlSet\\Control\\Session Manager\\Memory Management", "PagingFiles", data, &size)
- && size > 12 && !checkNonWindowsPartitionsOnly)
+ if (ReadLocalMachineRegistryMultiString (L"System\\CurrentControlSet\\Control\\Session Manager\\Memory Management", L"PagingFiles", data, &size)
+ && size > 24 && !checkNonWindowsPartitionsOnly)
return TRUE;
if (!IsAdmin())
AbortProcess ("UAC_INIT_ERROR");
- for (char drive = 'C'; drive <= 'Z'; ++drive)
+ for (wchar_t drive = L'C'; drive <= L'Z'; ++drive)
{
// Query geometry of the drive first to prevent "no medium" pop-ups
- string drivePath = "\\\\.\\X:";
+ wstring drivePath = L"\\\\.\\X:";
drivePath[4] = drive;
if (checkNonWindowsPartitionsOnly)
{
- char sysDir[MAX_PATH];
- if (GetSystemDirectory (sysDir, sizeof (sysDir)) != 0 && toupper (sysDir[0]) == drive)
+ wchar_t sysDir[MAX_PATH];
+ if (GetSystemDirectory (sysDir, ARRAYSIZE (sysDir)) != 0 && towupper (sysDir[0]) == drive)
continue;
}
@@ -9880,7 +9779,7 @@ BOOL IsPagingFileActive (BOOL checkNonWindowsPartitionsOnly)
CloseHandle (handle);
// Test if a paging file exists and is locked by another process
- string path = "X:\\pagefile.sys";
+ wstring path = L"X:\\pagefile.sys";
path[0] = drive;
handle = CreateFile (path.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
@@ -9897,25 +9796,25 @@ BOOL IsPagingFileActive (BOOL checkNonWindowsPartitionsOnly)
BOOL IsPagingFileWildcardActive ()
{
- char pagingFiles[65536];
+ wchar_t pagingFiles[65536];
DWORD size = sizeof (pagingFiles);
- char *mmKey = "System\\CurrentControlSet\\Control\\Session Manager\\Memory Management";
+ wchar_t *mmKey = L"System\\CurrentControlSet\\Control\\Session Manager\\Memory Management";
- if (!ReadLocalMachineRegistryString (mmKey, "PagingFiles", pagingFiles, &size))
+ if (!ReadLocalMachineRegistryString (mmKey, L"PagingFiles", pagingFiles, &size))
{
size = sizeof (pagingFiles);
- if (!ReadLocalMachineRegistryMultiString (mmKey, "PagingFiles", pagingFiles, &size))
+ if (!ReadLocalMachineRegistryMultiString (mmKey, L"PagingFiles", pagingFiles, &size))
size = 0;
}
- return size > 0 && strstr (pagingFiles, "?:\\") == pagingFiles;
+ return size > 0 && wcsstr (pagingFiles, L"?:\\") == pagingFiles;
}
BOOL DisablePagingFile ()
{
- char empty[] = { 0, 0 };
- return WriteLocalMachineRegistryMultiString ("System\\CurrentControlSet\\Control\\Session Manager\\Memory Management", "PagingFiles", empty, sizeof (empty));
+ wchar_t empty[] = { 0, 0 };
+ return WriteLocalMachineRegistryMultiString (L"System\\CurrentControlSet\\Control\\Session Manager\\Memory Management", L"PagingFiles", empty, sizeof (empty));
}
@@ -10035,8 +9934,8 @@ BOOL CALLBACK SecurityTokenPasswordDlgProc (HWND hwndDlg, UINT msg, WPARAM wPara
}
// Attempt to wipe password stored in the input field buffer
- char tmp[SecurityToken::MaxPasswordLength+1];
- memset (tmp, 'X', SecurityToken::MaxPasswordLength);
+ wchar_t tmp[SecurityToken::MaxPasswordLength+1];
+ wmemset (tmp, 'X', SecurityToken::MaxPasswordLength);
tmp[SecurityToken::MaxPasswordLength] = 0;
SetWindowText (GetDlgItem (hwndDlg, IDC_TOKEN_PASSWORD), tmp);
@@ -10162,12 +10061,12 @@ static void SecurityTokenKeyfileDlgFillList (HWND hwndDlg, const vector <Securit
lvItem.mask = LVIF_TEXT;
lvItem.iItem = line++;
- stringstream s;
+ wstringstream s;
s << keyfile.SlotId;
- ListItemAdd (tokenListControl, lvItem.iItem, (char *) s.str().c_str());
- ListSubItemSetW (tokenListControl, lvItem.iItem, 1, (wchar_t *) keyfile.Token.Label.c_str());
- ListSubItemSetW (tokenListControl, lvItem.iItem, 2, (wchar_t *) keyfile.Id.c_str());
+ ListItemAdd (tokenListControl, lvItem.iItem, (wchar_t *) s.str().c_str());
+ ListSubItemSet (tokenListControl, lvItem.iItem, 1, (wchar_t *) keyfile.Token.Label.c_str());
+ ListSubItemSet (tokenListControl, lvItem.iItem, 2, (wchar_t *) keyfile.Id.c_str());
}
BOOL selected = (ListView_GetNextItem (GetDlgItem (hwndDlg, IDC_TOKEN_FILE_LIST), -1, LVIS_SELECTED) != -1);
@@ -10293,7 +10192,7 @@ BOOL CALLBACK SecurityTokenKeyfileDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam
case IDC_IMPORT_KEYFILE:
{
- char keyfilePath[TC_MAX_PATH];
+ wchar_t keyfilePath[TC_MAX_PATH];
if (BrowseFiles (hwndDlg, "SELECT_KEYFILE", keyfilePath, bHistory, FALSE, NULL))
{
@@ -10308,7 +10207,7 @@ BOOL CALLBACK SecurityTokenKeyfileDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam
if (keyfileSize != 0)
{
NewSecurityTokenKeyfileDlgProcParams newParams;
- newParams.Name = WideToUtf8String (SingleStringToWide (keyfilePath));
+ newParams.Name = WideToUtf8String (keyfilePath);
size_t lastBackSlash = newParams.Name.find_last_of ('\\');
if (lastBackSlash != string::npos)
@@ -10356,7 +10255,7 @@ BOOL CALLBACK SecurityTokenKeyfileDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam
{
foreach (const SecurityTokenKeyfile &keyfile, SecurityTokenKeyfileDlgGetSelected (hwndDlg, keyfiles))
{
- char keyfilePath[TC_MAX_PATH];
+ wchar_t keyfilePath[TC_MAX_PATH];
if (!BrowseFiles (hwndDlg, "OPEN_TITLE", keyfilePath, bHistory, TRUE, NULL))
break;
@@ -10489,10 +10388,10 @@ std::vector <HostDevice> GetAvailableHostDevices (bool noDeviceProperties, bool
{
for (int partNumber = 0; partNumber < MAX_HOST_PARTITION_NUMBER; partNumber++)
{
- stringstream strm;
- strm << "\\Device\\Harddisk" << devNumber << "\\Partition" << partNumber;
- string devPathStr (strm.str());
- const char *devPath = devPathStr.c_str();
+ wstringstream strm;
+ strm << L"\\Device\\Harddisk" << devNumber << L"\\Partition" << partNumber;
+ wstring devPathStr (strm.str());
+ const wchar_t *devPath = devPathStr.c_str();
OPEN_TEST_STRUCT openTest = {0};
if (!OpenDevice (devPath, &openTest, detectUnencryptedFilesystems && partNumber != 0))
@@ -10521,20 +10420,18 @@ std::vector <HostDevice> GetAvailableHostDevices (bool noDeviceProperties, bool
{
DISK_GEOMETRY geometry;
- wstringstream ws;
- ws << devPathStr.c_str();
- int driveNumber = GetDiskDeviceDriveLetter ((wchar_t *) ws.str().c_str());
+ int driveNumber = GetDiskDeviceDriveLetter ((wchar_t *) devPathStr.c_str());
if (driveNumber >= 0)
{
- device.MountPoint += (char) (driveNumber + 'A');
- device.MountPoint += ":";
+ device.MountPoint += (wchar_t) (driveNumber + L'A');
+ device.MountPoint += L":";
wchar_t name[64];
if (GetDriveLabel (driveNumber, name, sizeof (name)))
device.Name = name;
- if (GetSystemDriveLetter() == 'A' + driveNumber)
+ if (GetSystemDriveLetter() == L'A' + driveNumber)
device.ContainsSystem = true;
}
@@ -10584,10 +10481,10 @@ std::vector <HostDevice> GetAvailableHostDevices (bool noDeviceProperties, bool
{
for (int devNumber = 0; devNumber < 256; devNumber++)
{
- stringstream strm;
- strm << "\\Device\\HarddiskVolume" << devNumber;
- string devPathStr (strm.str());
- const char *devPath = devPathStr.c_str();
+ wstringstream strm;
+ strm << L"\\Device\\HarddiskVolume" << devNumber;
+ wstring devPathStr (strm.str());
+ const wchar_t *devPath = devPathStr.c_str();
OPEN_TEST_STRUCT openTest = {0};
if (!OpenDevice (devPath, &openTest, detectUnencryptedFilesystems))
@@ -10606,20 +10503,18 @@ std::vector <HostDevice> GetAvailableHostDevices (bool noDeviceProperties, bool
if (!noDeviceProperties)
{
- wstringstream ws;
- ws << devPathStr.c_str();
- int driveNumber = GetDiskDeviceDriveLetter ((wchar_t *) ws.str().c_str());
+ int driveNumber = GetDiskDeviceDriveLetter ((wchar_t *) devPathStr.c_str());
if (driveNumber >= 0)
{
- device.MountPoint += (char) (driveNumber + 'A');
- device.MountPoint += ":";
+ device.MountPoint += (wchar_t) (driveNumber + L'A');
+ device.MountPoint += L":";
wchar_t name[64];
if (GetDriveLabel (driveNumber, name, sizeof (name)))
device.Name = name;
- if (GetSystemDriveLetter() == 'A' + driveNumber)
+ if (GetSystemDriveLetter() == L'A' + driveNumber)
device.ContainsSystem = true;
}
}
@@ -10633,17 +10528,17 @@ std::vector <HostDevice> GetAvailableHostDevices (bool noDeviceProperties, bool
}
-BOOL FileHasReadOnlyAttribute (const char *path)
+BOOL FileHasReadOnlyAttribute (const wchar_t *path)
{
DWORD attributes = GetFileAttributes (path);
return attributes != INVALID_FILE_ATTRIBUTES && (attributes & FILE_ATTRIBUTE_READONLY) != 0;
}
-BOOL IsFileOnReadOnlyFilesystem (const char *path)
+BOOL IsFileOnReadOnlyFilesystem (const wchar_t *path)
{
- char root[MAX_PATH];
- if (!GetVolumePathName (path, root, sizeof (root)))
+ wchar_t root[MAX_PATH];
+ if (!GetVolumePathName (path, root, ARRAYSIZE (root)))
return FALSE;
DWORD flags, d;
@@ -10657,13 +10552,13 @@ BOOL IsFileOnReadOnlyFilesystem (const char *path)
void CheckFilesystem (HWND hwndDlg, int driveNo, BOOL fixErrors)
{
wchar_t msg[1024], param[1024], cmdPath[MAX_PATH];
- char driveRoot[] = { 'A' + (char) driveNo, ':', 0 };
+ wchar_t driveRoot[] = { L'A' + (wchar_t) driveNo, L':', 0 };
if (fixErrors && AskWarnYesNo ("FILESYS_REPAIR_CONFIRM_BACKUP", hwndDlg) == IDNO)
return;
StringCbPrintfW (msg, sizeof(msg), GetString (fixErrors ? "REPAIRING_FS" : "CHECKING_FS"), driveRoot);
- StringCbPrintfW (param, sizeof(param), fixErrors ? L"/C echo %s & chkdsk %hs /F /X & pause" : L"/C echo %s & chkdsk %hs & pause", msg, driveRoot);
+ StringCbPrintfW (param, sizeof(param), fixErrors ? L"/C echo %s & chkdsk %s /F /X & pause" : L"/C echo %s & chkdsk %s & pause", msg, driveRoot);
if (GetSystemDirectoryW(cmdPath, MAX_PATH))
{
@@ -10741,37 +10636,37 @@ int AskNonSysInPlaceEncryptionResume (HWND hwndDlg, BOOL *pbDecrypt)
#endif // !SETUP
-BOOL RemoveDeviceWriteProtection (HWND hwndDlg, char *devicePath)
+BOOL RemoveDeviceWriteProtection (HWND hwndDlg, wchar_t *devicePath)
{
int driveNumber;
int partitionNumber;
- char temp[MAX_PATH*2];
- char cmdBatch[MAX_PATH*2];
- char diskpartScript[MAX_PATH*2];
+ wchar_t temp[MAX_PATH*2];
+ wchar_t cmdBatch[MAX_PATH*2];
+ wchar_t diskpartScript[MAX_PATH*2];
- if (sscanf (devicePath, "\\Device\\Harddisk%d\\Partition%d", &driveNumber, &partitionNumber) != 2)
+ if (swscanf (devicePath, L"\\Device\\Harddisk%d\\Partition%d", &driveNumber, &partitionNumber) != 2)
return FALSE;
- if (GetTempPath (sizeof (temp), temp) == 0)
+ if (GetTempPath (ARRAYSIZE (temp), temp) == 0)
return FALSE;
- StringCbPrintfA (cmdBatch, sizeof (cmdBatch), "%s\\VeraCrypt_Write_Protection_Removal.cmd", temp);
- StringCbPrintfA (diskpartScript, sizeof (diskpartScript), "%s\\VeraCrypt_Write_Protection_Removal.diskpart", temp);
+ StringCbPrintfW (cmdBatch, sizeof (cmdBatch), L"%s\\VeraCrypt_Write_Protection_Removal.cmd", temp);
+ StringCbPrintfW (diskpartScript, sizeof (diskpartScript), L"%s\\VeraCrypt_Write_Protection_Removal.diskpart", temp);
- FILE *f = fopen (cmdBatch, "w");
+ FILE *f = _wfopen (cmdBatch, L"w");
if (!f)
{
handleWin32Error (hwndDlg, SRC_POS);
return FALSE;
}
- fprintf (f, "@diskpart /s \"%s\"\n@pause\n@del \"%s\" \"%s\"", diskpartScript, diskpartScript, cmdBatch);
+ fwprintf (f, L"@diskpart /s \"%s\"\n@pause\n@del \"%s\" \"%s\"", diskpartScript, diskpartScript, cmdBatch);
CheckFileStreamWriteErrors (hwndDlg, f, cmdBatch);
fclose (f);
- f = fopen (diskpartScript, "w");
+ f = _wfopen (diskpartScript, L"w");
if (!f)
{
handleWin32Error (hwndDlg, SRC_POS);
@@ -10779,17 +10674,17 @@ BOOL RemoveDeviceWriteProtection (HWND hwndDlg, char *devicePath)
return FALSE;
}
- fprintf (f, "select disk %d\nattributes disk clear readonly\n", driveNumber);
+ fwprintf (f, L"select disk %d\nattributes disk clear readonly\n", driveNumber);
if (partitionNumber != 0)
- fprintf (f, "select partition %d\nattributes volume clear readonly\n", partitionNumber);
+ fwprintf (f, L"select partition %d\nattributes volume clear readonly\n", partitionNumber);
- fprintf (f, "exit\n");
+ fwprintf (f, L"exit\n");
CheckFileStreamWriteErrors (hwndDlg, f, diskpartScript);
fclose (f);
- ShellExecute (NULL, (!IsAdmin() && IsUacSupported()) ? "runas" : "open", cmdBatch, NULL, NULL, SW_SHOW);
+ ShellExecute (NULL, (!IsAdmin() && IsUacSupported()) ? L"runas" : L"open", cmdBatch, NULL, NULL, SW_SHOW);
return TRUE;
}
@@ -10846,25 +10741,25 @@ BOOL DisableFileCompression (HANDLE file)
}
-BOOL VolumePathExists (const char *volumePath)
+BOOL VolumePathExists (const wchar_t *volumePath)
{
OPEN_TEST_STRUCT openTest = {0};
- char upperCasePath[TC_MAX_PATH + 1];
+ wchar_t upperCasePath[TC_MAX_PATH + 1];
UpperCaseCopy (upperCasePath, sizeof(upperCasePath), volumePath);
- if (strstr (upperCasePath, "\\DEVICE\\") == upperCasePath)
+ if (wcsstr (upperCasePath, L"\\DEVICE\\") == upperCasePath)
return OpenDevice (volumePath, &openTest, FALSE);
- string path = volumePath;
- if (path.find ("\\\\?\\Volume{") == 0 && path.rfind ("}\\") == path.size() - 2)
+ wstring path = volumePath;
+ if (path.find (L"\\\\?\\Volume{") == 0 && path.rfind (L"}\\") == path.size() - 2)
{
- char devicePath[TC_MAX_PATH];
+ wchar_t devicePath[TC_MAX_PATH];
if (QueryDosDevice (path.substr (4, path.size() - 5).c_str(), devicePath, TC_MAX_PATH) != 0)
return TRUE;
}
- if (_access (volumePath, 0) == 0)
+ if (_waccess (volumePath, 0) == 0)
return TRUE;
else
{
@@ -10879,7 +10774,7 @@ BOOL VolumePathExists (const char *volumePath)
BOOL IsWindowsIsoBurnerAvailable ()
{
- char path[MAX_PATH*2] = { 0 };
+ wchar_t path[MAX_PATH*2] = { 0 };
if (!IsOSAtLeast (WIN_7))
{
@@ -10888,7 +10783,7 @@ BOOL IsWindowsIsoBurnerAvailable ()
if (SUCCEEDED(SHGetFolderPath (NULL, CSIDL_SYSTEM, NULL, 0, path)))
{
- StringCbCatA (path, MAX_PATH*2, "\\" ISO_BURNER_TOOL);
+ StringCbCatW (path, MAX_PATH*2, L"\\" ISO_BURNER_TOOL);
return (FileExists (path));
}
@@ -10897,17 +10792,17 @@ BOOL IsWindowsIsoBurnerAvailable ()
}
-BOOL LaunchWindowsIsoBurner (HWND hwnd, const char *isoPath)
+BOOL LaunchWindowsIsoBurner (HWND hwnd, const wchar_t *isoPath)
{
- char path[MAX_PATH*2] = { 0 };
+ wchar_t path[MAX_PATH*2] = { 0 };
int r;
if (SUCCEEDED(SHGetFolderPath (NULL, CSIDL_SYSTEM, NULL, 0, path)))
- StringCbCatA (path, MAX_PATH*2, "\\" ISO_BURNER_TOOL);
+ StringCbCatW (path, MAX_PATH*2, L"\\" ISO_BURNER_TOOL);
else
- StringCbCopyA (path, MAX_PATH*2, "C:\\Windows\\System32\\" ISO_BURNER_TOOL);
+ StringCbCopyW (path, MAX_PATH*2, L"C:\\Windows\\System32\\" ISO_BURNER_TOOL);
- r = (int) ShellExecute (hwnd, "open", path, (string ("\"") + isoPath + "\"").c_str(), NULL, SW_SHOWNORMAL);
+ r = (int) ShellExecute (hwnd, L"open", path, (wstring (L"\"") + isoPath + L"\"").c_str(), NULL, SW_SHOWNORMAL);
if (r <= 32)
{
@@ -10921,53 +10816,51 @@ BOOL LaunchWindowsIsoBurner (HWND hwnd, const char *isoPath)
}
-std::string VolumeGuidPathToDevicePath (std::string volumeGuidPath)
+std::wstring VolumeGuidPathToDevicePath (std::wstring volumeGuidPath)
{
- if (volumeGuidPath.find ("\\\\?\\") == 0)
+ if (volumeGuidPath.find (L"\\\\?\\") == 0)
volumeGuidPath = volumeGuidPath.substr (4);
- if (volumeGuidPath.find ("Volume{") != 0 || volumeGuidPath.rfind ("}\\") != volumeGuidPath.size() - 2)
- return string();
+ if (volumeGuidPath.find (L"Volume{") != 0 || volumeGuidPath.rfind (L"}\\") != volumeGuidPath.size() - 2)
+ return wstring();
- char volDevPath[TC_MAX_PATH];
+ wchar_t volDevPath[TC_MAX_PATH];
if (QueryDosDevice (volumeGuidPath.substr (0, volumeGuidPath.size() - 1).c_str(), volDevPath, TC_MAX_PATH) == 0)
- return string();
+ return wstring();
- string partitionPath = HarddiskVolumePathToPartitionPath (volDevPath);
+ wstring partitionPath = HarddiskVolumePathToPartitionPath (volDevPath);
return partitionPath.empty() ? volDevPath : partitionPath;
}
-std::string HarddiskVolumePathToPartitionPath (const std::string &harddiskVolumePath)
+std::wstring HarddiskVolumePathToPartitionPath (const std::wstring &harddiskVolumePath)
{
- wstring volPath = SingleStringToWide (harddiskVolumePath);
-
for (int driveNumber = 0; driveNumber < MAX_HOST_DRIVE_NUMBER; driveNumber++)
{
for (int partNumber = 0; partNumber < MAX_HOST_PARTITION_NUMBER; partNumber++)
{
wchar_t partitionPath[TC_MAX_PATH];
- swprintf_s (partitionPath, ARRAYSIZE (partitionPath), L"\\Device\\Harddisk%d\\Partition%d", driveNumber, partNumber);
+ StringCchPrintfW (partitionPath, ARRAYSIZE (partitionPath), L"\\Device\\Harddisk%d\\Partition%d", driveNumber, partNumber);
wchar_t resolvedPath[TC_MAX_PATH];
if (ResolveSymbolicLink (partitionPath, resolvedPath, sizeof(resolvedPath)))
{
- if (volPath == resolvedPath)
- return WideToSingleString (partitionPath);
+ if (harddiskVolumePath == resolvedPath)
+ return partitionPath;
}
else if (partNumber == 0)
break;
}
}
- return string();
+ return wstring();
}
-BOOL IsApplicationInstalled (const char *appName, BOOL b32bitApp)
+BOOL IsApplicationInstalled (const wchar_t *appName, BOOL b32bitApp)
{
- const char *uninstallRegName = "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall";
+ const wchar_t *uninstallRegName = L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall";
BOOL installed = FALSE;
HKEY unistallKey;
LONG res = RegOpenKeyEx (HKEY_LOCAL_MACHINE, uninstallRegName, 0, KEY_READ | b32bitApp? KEY_WOW64_32KEY: KEY_WOW64_64KEY, &unistallKey);
@@ -10977,19 +10870,19 @@ BOOL IsApplicationInstalled (const char *appName, BOOL b32bitApp)
return FALSE;
}
- char regName[1024];
+ wchar_t regName[1024];
DWORD regNameSize = sizeof (regName);
DWORD index = 0;
while (RegEnumKeyEx (unistallKey, index++, regName, &regNameSize, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
{
- if (strstr (regName, "{") == regName)
+ if (wcsstr (regName, L"{") == regName)
{
regNameSize = sizeof (regName);
- if (!ReadLocalMachineRegistryStringNonReflected ((string (uninstallRegName) + "\\" + regName).c_str(), "DisplayName", regName, &regNameSize, b32bitApp))
+ if (!ReadLocalMachineRegistryStringNonReflected ((wstring (uninstallRegName) + L"\\" + regName).c_str(), L"DisplayName", regName, &regNameSize, b32bitApp))
regName[0] = 0;
}
- if (_stricmp (regName, appName) == 0)
+ if (_wcsicmp (regName, appName) == 0)
{
installed = TRUE;
break;
@@ -11003,19 +10896,19 @@ BOOL IsApplicationInstalled (const char *appName, BOOL b32bitApp)
}
-std::string FindLatestFileOrDirectory (const std::string &directory, const char *namePattern, bool findDirectory, bool findFile)
+std::wstring FindLatestFileOrDirectory (const std::wstring &directory, const wchar_t *namePattern, bool findDirectory, bool findFile)
{
- string name;
+ wstring name;
ULARGE_INTEGER latestTime;
latestTime.QuadPart = 0;
WIN32_FIND_DATA findData;
- HANDLE find = FindFirstFile ((directory + "\\" + namePattern).c_str(), &findData);
+ HANDLE find = FindFirstFile ((directory + L"\\" + namePattern).c_str(), &findData);
if (find != INVALID_HANDLE_VALUE)
{
do
{
- if (strcmp (findData.cFileName, ".") == 0 || strcmp (findData.cFileName, "..") == 0)
+ if (wcscmp (findData.cFileName, L".") == 0 || wcscmp (findData.cFileName, L"..") == 0)
continue;
ULARGE_INTEGER writeTime;
@@ -11040,7 +10933,7 @@ std::string FindLatestFileOrDirectory (const std::string &directory, const char
if (name.empty())
return name;
- return string (directory) + "\\" + name;
+ return wstring (directory) + L"\\" + name;
}
int GetPim (HWND hwndDlg, UINT ctrlId)
@@ -11049,12 +10942,12 @@ int GetPim (HWND hwndDlg, UINT ctrlId)
HWND hCtrl = GetDlgItem (hwndDlg, ctrlId);
if (IsWindowEnabled (hCtrl) && IsWindowVisible (hCtrl))
{
- char szTmp[MAX_PIM + 1] = {0};
+ wchar_t szTmp[MAX_PIM + 1] = {0};
if (GetDlgItemText (hwndDlg, ctrlId, szTmp, MAX_PIM + 1) > 0)
{
- char* endPtr = NULL;
- pim = strtol(szTmp, &endPtr, 10);
- if (pim < 0 || endPtr == szTmp || !endPtr || *endPtr != '\0')
+ wchar_t* endPtr = NULL;
+ pim = wcstol(szTmp, &endPtr, 10);
+ if (pim < 0 || endPtr == szTmp || !endPtr || *endPtr != L'\0')
pim = 0;
}
}
@@ -11065,12 +10958,49 @@ void SetPim (HWND hwndDlg, UINT ctrlId, int pim)
{
if (pim > 0)
{
- char szTmp[MAX_PIM + 1];
- StringCbPrintfA (szTmp, sizeof(szTmp), "%d", pim);
+ wchar_t szTmp[MAX_PIM + 1];
+ StringCbPrintfW (szTmp, sizeof(szTmp), L"%d", pim);
SetDlgItemText (hwndDlg, ctrlId, szTmp);
}
else
- SetDlgItemText (hwndDlg, ctrlId, "");
+ SetDlgItemText (hwndDlg, ctrlId, L"");
+}
+
+BOOL GetPassword (HWND hwndDlg, UINT ctrlID, char* passValue, int bufSize, BOOL bShowError)
+{
+ wchar_t tmp [MAX_PASSWORD + 1];
+ int utf8Len;
+ BOOL bRet = FALSE;
+
+ GetWindowText (GetDlgItem (hwndDlg, ctrlID), tmp, ARRAYSIZE (tmp));
+ utf8Len = WideCharToMultiByte (CP_UTF8, 0, tmp, -1, passValue, bufSize, NULL, NULL);
+ burn (tmp, sizeof (tmp));
+ if (utf8Len > 0)
+ {
+ bRet = TRUE;
+ }
+ else
+ {
+ passValue [0] = 0;
+ if (bShowError)
+ {
+ SetFocus (GetDlgItem(hwndDlg, ctrlID));
+ if (GetLastError () == ERROR_INSUFFICIENT_BUFFER)
+ Error ("PASSWORD_UTF8_TOO_LONG", hwndDlg);
+ else
+ Error ("PASSWORD_UTF8_INVALID", hwndDlg);
+ }
+ }
+
+ return bRet;
+}
+
+void SetPassword (HWND hwndDlg, UINT ctrlID, char* passValue)
+{
+ wchar_t tmp [MAX_PASSWORD + 1] = {0};
+ MultiByteToWideChar (CP_UTF8, 0, passValue, -1, tmp, MAX_PASSWORD + 1);
+ SetWindowText ( GetDlgItem (hwndDlg, ctrlID), tmp);
+ burn (tmp, sizeof (tmp));
}
void HandleShowPasswordFieldAction (HWND hwndDlg, UINT checkBoxId, UINT edit1Id, UINT edit2Id)
diff --git a/src/Common/Dlgcode.h b/src/Common/Dlgcode.h
index a7f4affd..2b6aee18 100644
--- a/src/Common/Dlgcode.h
+++ b/src/Common/Dlgcode.h
@@ -48,10 +48,10 @@ enum
#define TC_APPLICATION_ID L"IDRIX.VeraCrypt"
-#define TC_MUTEX_NAME_SYSENC "Global\\VeraCrypt System Encryption Wizard"
-#define TC_MUTEX_NAME_NONSYS_INPLACE_ENC "Global\\VeraCrypt In-Place Encryption Wizard"
-#define TC_MUTEX_NAME_APP_SETUP "Global\\VeraCrypt Setup"
-#define TC_MUTEX_NAME_DRIVER_SETUP "Global\\VeraCrypt Driver Setup"
+#define TC_MUTEX_NAME_SYSENC L"Global\\VeraCrypt System Encryption Wizard"
+#define TC_MUTEX_NAME_NONSYS_INPLACE_ENC L"Global\\VeraCrypt In-Place Encryption Wizard"
+#define TC_MUTEX_NAME_APP_SETUP L"Global\\VeraCrypt Setup"
+#define TC_MUTEX_NAME_DRIVER_SETUP L"Global\\VeraCrypt Driver Setup"
#define IDC_ABOUT 0x7fff /* ID for AboutBox on system menu in wm_user range */
@@ -68,18 +68,18 @@ enum
#define MAX_MULTI_CHOICES 10 /* Maximum number of options for mutliple-choice dialog */
-#define TC_APPD_FILENAME_CONFIGURATION "Configuration.xml"
-#define TC_APPD_FILENAME_SYSTEM_ENCRYPTION "System Encryption.xml"
-#define TC_APPD_FILENAME_DEFAULT_KEYFILES "Default Keyfiles.xml"
-#define TC_APPD_FILENAME_HISTORY "History.xml"
-#define TC_APPD_FILENAME_FAVORITE_VOLUMES "Favorite Volumes.xml"
-#define TC_APPD_FILENAME_SYSTEM_FAVORITE_VOLUMES TC_APP_NAME " System Favorite Volumes.xml"
-#define TC_APPD_FILENAME_NONSYS_INPLACE_ENC "In-Place Encryption"
-#define TC_APPD_FILENAME_NONSYS_INPLACE_ENC_WIPE "In-Place Encryption Wipe Algo"
-#define TC_APPD_FILENAME_POST_INSTALL_TASK_TUTORIAL "Post-Install Task - Tutorial"
-#define TC_APPD_FILENAME_POST_INSTALL_TASK_RELEASE_NOTES "Post-Install Task - Release Notes"
+#define TC_APPD_FILENAME_CONFIGURATION L"Configuration.xml"
+#define TC_APPD_FILENAME_SYSTEM_ENCRYPTION L"System Encryption.xml"
+#define TC_APPD_FILENAME_DEFAULT_KEYFILES L"Default Keyfiles.xml"
+#define TC_APPD_FILENAME_HISTORY L"History.xml"
+#define TC_APPD_FILENAME_FAVORITE_VOLUMES L"Favorite Volumes.xml"
+#define TC_APPD_FILENAME_SYSTEM_FAVORITE_VOLUMES _T(TC_APP_NAME) L" System Favorite Volumes.xml"
+#define TC_APPD_FILENAME_NONSYS_INPLACE_ENC L"In-Place Encryption"
+#define TC_APPD_FILENAME_NONSYS_INPLACE_ENC_WIPE L"In-Place Encryption Wipe Algo"
+#define TC_APPD_FILENAME_POST_INSTALL_TASK_TUTORIAL L"Post-Install Task - Tutorial"
+#define TC_APPD_FILENAME_POST_INSTALL_TASK_RELEASE_NOTES L"Post-Install Task - Release Notes"
-#define VC_FILENAME_RENAMED_SUFFIX "_old"
+#define VC_FILENAME_RENAMED_SUFFIX L"_old"
#ifndef USER_DEFAULT_SCREEN_DPI
#define USER_DEFAULT_SCREEN_DPI 96
@@ -98,9 +98,9 @@ enum
extern char *LastDialogId;
extern char *ConfigBuffer;
-extern char szHelpFile[TC_MAX_PATH];
-extern char szHelpFile2[TC_MAX_PATH];
-extern char SecurityTokenLibraryPath[TC_MAX_PATH];
+extern wchar_t szHelpFile[TC_MAX_PATH];
+extern wchar_t szHelpFile2[TC_MAX_PATH];
+extern wchar_t SecurityTokenLibraryPath[TC_MAX_PATH];
extern HFONT hFixedDigitFont;
extern HFONT hBoldFont;
extern HFONT hTitleFont;
@@ -132,8 +132,8 @@ extern WipeAlgorithmId nWipeMode;
extern BOOL bSysPartitionSelected;
extern BOOL bSysDriveSelected;
-extern char SysPartitionDevicePath [TC_MAX_PATH];
-extern char SysDriveDevicePath [TC_MAX_PATH];
+extern wchar_t SysPartitionDevicePath [TC_MAX_PATH];
+extern wchar_t SysDriveDevicePath [TC_MAX_PATH];
extern char bCachedSysDevicePathsValid;
extern BOOL bHyperLinkBeingTracked;
@@ -226,15 +226,15 @@ typedef struct
#define ICON_HAND MB_ICONHAND
#define YES_NO MB_YESNO
-#define ISO_BURNER_TOOL "isoburn.exe"
-#define PRINT_TOOL "notepad.exe"
+#define ISO_BURNER_TOOL L"isoburn.exe"
+#define PRINT_TOOL L"notepad.exe"
void cleanup ( void );
-void LowerCaseCopy ( char *lpszDest , const char *lpszSource );
-void UpperCaseCopy ( char *lpszDest , size_t cbDest, const char *lpszSource );
-void CreateFullVolumePath ( char *lpszDiskFile , size_t cbDiskFile, const char *lpszFileName , BOOL *bDevice );
-int FakeDosNameForDevice ( const char *lpszDiskFile , char *lpszDosDevice , size_t cbDosDevice, char *lpszCFDevice , size_t cbCFDevice, BOOL bNameOnly );
-int RemoveFakeDosName ( char *lpszDiskFile , char *lpszDosDevice );
+void LowerCaseCopy ( wchar_t *lpszDest , const wchar_t *lpszSource );
+void UpperCaseCopy ( wchar_t *lpszDest , size_t cbDest, const wchar_t *lpszSource );
+void CreateFullVolumePath ( wchar_t *lpszDiskFile , size_t cbDiskFile, const wchar_t *lpszFileName , BOOL *bDevice );
+int FakeDosNameForDevice ( const wchar_t *lpszDiskFile , wchar_t *lpszDosDevice , size_t cbDosDevice, wchar_t *lpszCFDevice , size_t cbCFDevice, BOOL bNameOnly );
+int RemoveFakeDosName ( wchar_t *lpszDiskFile , wchar_t *lpszDosDevice );
void AbortProcessDirect ( wchar_t *abortMsg );
void AbortProcess ( char *stringId );
void AbortProcessSilent ( void );
@@ -251,13 +251,11 @@ void DisplayStaticModelessWaitDlg (HWND parent);
void CloseStaticModelessWaitDlg (void);
BOOL IsButtonChecked ( HWND hButton );
void CheckButton ( HWND hButton );
-void LeftPadString (char *szTmp, int len, int targetLen, char filler);
-void ToSBCS ( LPWSTR lpszText, size_t cbSize );
-void ToUNICODE ( char *lpszText , size_t cbSize);
+void LeftPadString (wchar_t *szTmp, int len, int targetLen, wchar_t filler);
void InitDialog ( HWND hwndDlg );
void ProcessPaintMessages (HWND hwnd, int maxMessagesToProcess);
-HDC CreateMemBitmap ( HINSTANCE hInstance , HWND hwnd , char *resource );
-HBITMAP RenderBitmap ( char *resource , HWND hwndDest , int x , int y , int nWidth , int nHeight , BOOL bDirectRender , BOOL bKeepAspectRatio);
+HDC CreateMemBitmap ( HINSTANCE hInstance , HWND hwnd , wchar_t *resource );
+HBITMAP RenderBitmap ( wchar_t *resource , HWND hwndDest , int x , int y , int nWidth , int nHeight , BOOL bDirectRender , BOOL bKeepAspectRatio);
LRESULT CALLBACK RedTick ( HWND hwnd , UINT uMsg , WPARAM wParam , LPARAM lParam );
BOOL RegisterRedTick ( HINSTANCE hInstance );
BOOL UnregisterRedTick ( HINSTANCE hInstance );
@@ -271,11 +269,11 @@ void AddComboPairW (HWND hComboBox, const wchar_t *lpszItem, int value);
void SelectAlgo ( HWND hComboBox , int *nCipher );
void PopulateWipeModeCombo (HWND hComboBox, BOOL bNA, BOOL bInPlaceEncryption, BOOL bHeaderWipe);
wchar_t *GetWipeModeName (WipeAlgorithmId modeId);
-wchar_t *GetPathType (const char *path, BOOL bUpperCase, BOOL *bIsPartition);
+wchar_t *GetPathType (const wchar_t *path, BOOL bUpperCase, BOOL *bIsPartition);
LRESULT CALLBACK CustomDlgProc ( HWND hwnd , UINT uMsg , WPARAM wParam , LPARAM lParam );
-BOOL TCCreateMutex (volatile HANDLE *hMutex, char *name);
+BOOL TCCreateMutex (volatile HANDLE *hMutex, wchar_t *name);
void TCCloseMutex (volatile HANDLE *hMutex);
-BOOL MutexExistsOnSystem (char *name);
+BOOL MutexExistsOnSystem (wchar_t *name);
BOOL CreateSysEncMutex (void);
BOOL InstanceHasSysEncMutex (void);
void CloseSysEncMutex (void);
@@ -297,15 +295,15 @@ void RemoveNonSysInPlaceEncNotifications (void);
void SavePostInstallTasksSettings (int command);
void DoPostInstallTasks (HWND hwndDlg);
void InitOSVersionInfo ();
-void InitApp ( HINSTANCE hInstance, char *lpszCommandLine );
+void InitApp ( HINSTANCE hInstance, wchar_t *lpszCommandLine );
void FinalizeApp (void);
void InitHelpFileName (void);
-BOOL OpenDevice (const char *lpszPath, OPEN_TEST_STRUCT *driver, BOOL detectFilesystem);
+BOOL OpenDevice (const wchar_t *lpszPath, OPEN_TEST_STRUCT *driver, BOOL detectFilesystem);
void NotifyDriverOfPortableMode (void);
int GetAvailableFixedDisks ( HWND hComboBox , char *lpszRootPath );
int GetAvailableRemovables ( HWND hComboBox , char *lpszRootPath );
-int IsSystemDevicePath (const char *path, HWND hwndDlg, BOOL bReliableRequired);
-int IsNonSysPartitionOnSysDrive (const char *path);
+int IsSystemDevicePath (const wchar_t *path, HWND hwndDlg, BOOL bReliableRequired);
+int IsNonSysPartitionOnSysDrive (const wchar_t *path);
BOOL CALLBACK RawDevicesDlgProc ( HWND hwndDlg , UINT msg , WPARAM wParam , LPARAM lParam );
INT_PTR TextInfoDialogBox (int nID);
BOOL CALLBACK TextInfoDialogBoxDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
@@ -318,50 +316,49 @@ int DriverAttach ( void );
BOOL CALLBACK CipherTestDialogProc ( HWND hwndDlg , UINT uMsg , WPARAM wParam , LPARAM lParam );
void ResetCipherTest ( HWND hwndDlg , int idTestCipher );
void ResetCurrentDirectory ();
-BOOL BrowseFiles (HWND hwndDlg, char *stringId, char *lpszFileName, BOOL keepHistory, BOOL saveMode, wchar_t *browseFilter);
-BOOL BrowseDirectories (HWND hWnd, char *lpszTitle, char *dirName);
+BOOL BrowseFiles (HWND hwndDlg, char *stringId, wchar_t *lpszFileName, BOOL keepHistory, BOOL saveMode, wchar_t *browseFilter);
+BOOL BrowseDirectories (HWND hWnd, char *lpszTitle, wchar_t *dirName);
void handleError ( HWND hwndDlg , int code, const char* srcPos );
-BOOL CheckFileStreamWriteErrors (HWND hwndDlg, FILE *file, const char *fileName);
+BOOL CheckFileStreamWriteErrors (HWND hwndDlg, FILE *file, const wchar_t *fileName);
void LocalizeDialog ( HWND hwnd, char *stringId );
void OpenVolumeExplorerWindow (int driveNo);
static BOOL CALLBACK CloseVolumeExplorerWindowsEnum( HWND hwnd, LPARAM driveNo);
BOOL CloseVolumeExplorerWindows (HWND hwnd, int driveNo);
BOOL UpdateDriveCustomLabel (int driveNo, wchar_t* effectiveLabel, BOOL bSetValue);
BOOL CheckCapsLock (HWND hwnd, BOOL quiet);
-BOOL CheckFileExtension (char *fileName);
-void CorrectFileName (char* fileName);
+BOOL CheckFileExtension (wchar_t *fileName);
+void CorrectFileName (wchar_t* fileName);
void IncreaseWrongPwdRetryCount (int count);
void ResetWrongPwdRetryCount (void);
BOOL WrongPwdRetryCountOverLimit (void);
int GetFirstAvailableDrive ();
int GetLastAvailableDrive ();
BOOL IsDriveAvailable (int driveNo);
-BOOL IsDeviceMounted (char *deviceName);
+BOOL IsDeviceMounted (wchar_t *deviceName);
int DriverUnmountVolume (HWND hwndDlg, int nDosDriveNo, BOOL forced);
void BroadcastDeviceChange (WPARAM message, int nDosDriveNo, DWORD driveMap);
-int MountVolume (HWND hwndDlg, int driveNo, char *volumePath, Password *password, int pkcs5, int pim, BOOL truecryptMode, BOOL cachePassword, BOOL sharedAccess, const MountOptions* const mountOptions, BOOL quiet, BOOL bReportWrongPassword);
+int MountVolume (HWND hwndDlg, int driveNo, wchar_t *volumePath, Password *password, int pkcs5, int pim, BOOL truecryptMode, BOOL cachePassword, BOOL sharedAccess, const MountOptions* const mountOptions, BOOL quiet, BOOL bReportWrongPassword);
BOOL UnmountVolume (HWND hwndDlg , int nDosDriveNo, BOOL forceUnmount);
BOOL UnmountVolumeAfterFormatExCall (HWND hwndDlg, int nDosDriveNo);
BOOL IsPasswordCacheEmpty (void);
-BOOL IsMountedVolume (const char *volname);
-int GetMountedVolumeDriveNo (char *volname);
+BOOL IsMountedVolume (const wchar_t *volname);
+int GetMountedVolumeDriveNo (wchar_t *volname);
BOOL IsAdmin (void);
BOOL IsBuiltInAdmin ();
BOOL IsUacSupported ();
BOOL ResolveSymbolicLink (const wchar_t *symLinkName, PWSTR targetName, size_t cbTargetName);
int GetDiskDeviceDriveLetter (PWSTR deviceName);
-int FileSystemAppearsEmpty (const char *devicePath);
-__int64 GetStatsFreeSpaceOnPartition (const char *devicePath, float *percent, __int64 *occupiedBytes, BOOL silent);
-__int64 GetDeviceSize (const char *devicePath);
-HANDLE DismountDrive (char *devName, char *devicePath);
+int FileSystemAppearsEmpty (const wchar_t *devicePath);
+__int64 GetStatsFreeSpaceOnPartition (const wchar_t *devicePath, float *percent, __int64 *occupiedBytes, BOOL silent);
+__int64 GetDeviceSize (const wchar_t *devicePath);
+HANDLE DismountDrive (wchar_t *devName, wchar_t *devicePath);
int64 FindString (const char *buf, const char *str, int64 bufLen, int64 strLen, int64 startOffset);
-BOOL FileExists (const char *filePathPtr);
-__int64 FindStringInFile (const char *filePath, const char *str, int strLen);
-BOOL TCCopyFile (char *sourceFileName, char *destinationFile);
-BOOL TCCopyFileW (wchar_t *sourceFileName, wchar_t *destinationFile);
-BOOL SaveBufferToFile (const char *inputBuffer, const char *destinationFile, DWORD inputLength, BOOL bAppend, BOOL bRenameIfFailed);
+BOOL FileExists (const wchar_t *filePathPtr);
+__int64 FindStringInFile (const wchar_t *filePath, const char *str, int strLen);
+BOOL TCCopyFile (wchar_t *sourceFileName, wchar_t *destinationFile);
+BOOL SaveBufferToFile (const char *inputBuffer, const wchar_t *destinationFile, DWORD inputLength, BOOL bAppend, BOOL bRenameIfFailed);
BOOL TCFlushFile (FILE *f);
-BOOL PrintHardCopyTextUTF16 (wchar_t *text, char *title, size_t byteLen);
+BOOL PrintHardCopyTextUTF16 (wchar_t *text, wchar_t *title, size_t byteLen);
void GetSpeedString (unsigned __int64 speed, wchar_t *str, size_t cbStr);
BOOL IsNonInstallMode ();
BOOL DriverUnload ();
@@ -369,25 +366,23 @@ LRESULT SetCheckBox (HWND hwndDlg, int dlgItem, BOOL state);
BOOL GetCheckBox (HWND hwndDlg, int dlgItem);
void SetListScrollHPos (HWND hList, int topMostVisibleItem);
void ManageStartupSeq (void);
-void ManageStartupSeqWiz (BOOL bRemove, const char *arg);
+void ManageStartupSeqWiz (BOOL bRemove, const wchar_t *arg);
void CleanLastVisitedMRU (void);
void ClearHistory (HWND hwndDlgItem);
-LRESULT ListItemAdd (HWND list, int index, char *string);
-LRESULT ListItemAddW (HWND list, int index, wchar_t *string);
-LRESULT ListSubItemSet (HWND list, int index, int subIndex, char *string);
-LRESULT ListSubItemSetW (HWND list, int index, int subIndex, wchar_t *string);
+LRESULT ListItemAdd (HWND list, int index, const wchar_t *string);
+LRESULT ListSubItemSet (HWND list, int index, int subIndex, const wchar_t *string);
BOOL GetMountList (MOUNT_LIST_STRUCT *list);
int GetDriverRefCount ();
void GetSizeString (unsigned __int64 size, wchar_t *str, size_t cbStr);
-__int64 GetFileSize64 (const char *path);
-BOOL LoadInt16 (char *filePath, int *result, __int64 fileOffset);
-BOOL LoadInt32 (char *filePath, unsigned __int32 *result, __int64 fileOffset);
-char *LoadFile (const char *fileName, DWORD *size);
-char *LoadFileBlock (char *fileName, __int64 fileOffset, DWORD count);
-char *GetModPath (char *path, int maxSize);
-char *GetConfigPath (char *fileName);
-char *GetProgramConfigPath (char *fileName);
-char GetSystemDriveLetter (void);
+__int64 GetFileSize64 (const wchar_t *path);
+BOOL LoadInt16 (const wchar_t *filePath, int *result, __int64 fileOffset);
+BOOL LoadInt32 (const wchar_t *filePath, unsigned __int32 *result, __int64 fileOffset);
+char *LoadFile (const wchar_t *fileName, DWORD *size);
+char *LoadFileBlock (const wchar_t *fileName, __int64 fileOffset, DWORD count);
+wchar_t *GetModPath (wchar_t *path, int maxSize);
+wchar_t *GetConfigPath (wchar_t *fileName);
+wchar_t *GetProgramConfigPath (wchar_t *fileName);
+wchar_t GetSystemDriveLetter (void);
void OpenPageHelp (HWND hwndDlg, int nPage);
void TaskBarIconDisplayBalloonTooltip (HWND hwnd, wchar_t *headline, wchar_t *text, BOOL warning);
void InfoBalloon (char *headingStringId, char *textStringId, HWND hwnd);
@@ -425,6 +420,7 @@ int AskMultiChoice (void *strings[], BOOL bBold, HWND hwnd);
BOOL ConfigWriteBegin ();
BOOL ConfigWriteEnd (HWND hwnd);
BOOL ConfigWriteString (char *configKey, char *configValue);
+BOOL ConfigWriteStringW (char *configKey, wchar_t *configValue);
BOOL ConfigWriteInt (char *configKey, int configValue);
int ConfigReadInt (char *configKey, int defaultValue);
char *ConfigReadString (char *configKey, char *defaultValue, char *str, int maxLen);
@@ -442,20 +438,20 @@ BOOL IsHiddenOSRunning (void);
BOOL EnableWow64FsRedirection (BOOL enable);
BOOL RestartComputer (void);
void Applink (char *dest, BOOL bSendOS, char *extraOutput);
-char *RelativePath2Absolute (char *szFileName);
+wchar_t *RelativePath2Absolute (wchar_t *szFileName);
void HandleDriveNotReadyError (HWND hwnd);
BOOL CALLBACK CloseTCWindowsEnum( HWND hwnd, LPARAM lParam);
BOOL CALLBACK FindTCWindowEnum (HWND hwnd, LPARAM lParam);
-BYTE *MapResource (char *resourceType, int resourceId, PDWORD size);
+BYTE *MapResource (wchar_t *resourceType, int resourceId, PDWORD size);
void InconsistencyResolved (char *msg);
void ReportUnexpectedState (char *techInfo);
-BOOL SelectMultipleFiles (HWND hwndDlg, const char *stringId, char *lpszFileName, size_t cbFileName, BOOL keepHistory);
-BOOL SelectMultipleFilesNext (char *lpszFileName, size_t cbFileName);
+BOOL SelectMultipleFiles (HWND hwndDlg, const char *stringId, wchar_t *lpszFileName, size_t cbFileName, BOOL keepHistory);
+BOOL SelectMultipleFilesNext (wchar_t *lpszFileName, size_t cbFileName);
void OpenOnlineHelp ();
-BOOL GetPartitionInfo (const char *deviceName, PPARTITION_INFORMATION rpartInfo);
-BOOL GetDeviceInfo (const char *deviceName, DISK_PARTITION_INFO_STRUCT *info);
-BOOL GetDriveGeometry (const char *deviceName, PDISK_GEOMETRY diskGeometry);
-BOOL IsVolumeDeviceHosted (const char *lpszDiskFile);
+BOOL GetPartitionInfo (const wchar_t *deviceName, PPARTITION_INFORMATION rpartInfo);
+BOOL GetDeviceInfo (const wchar_t *deviceName, DISK_PARTITION_INFO_STRUCT *info);
+BOOL GetDriveGeometry (const wchar_t *deviceName, PDISK_GEOMETRY diskGeometry);
+BOOL IsVolumeDeviceHosted (const wchar_t *lpszDiskFile);
int CompensateXDPI (int val);
int CompensateYDPI (int val);
int CompensateDPIFont (int val);
@@ -470,7 +466,7 @@ void AccommodateTextField (HWND hwndDlg, UINT ctrlId, BOOL bFirstUpdate, HFONT h
BOOL GetDriveLabel (int driveNo, wchar_t *label, int labelSize);
BOOL GetSysDevicePaths (HWND hwndDlg);
BOOL DoDriverInstall (HWND hwndDlg);
-int OpenVolume (OpenVolumeContext *context, const char *volumePath, Password *password, int pkcs5_prf, int pim, BOOL truecryptMode, BOOL write, BOOL preserveTimestamps, BOOL useBackupHeader);
+int OpenVolume (OpenVolumeContext *context, const wchar_t *volumePath, Password *password, int pkcs5_prf, int pim, BOOL truecryptMode, BOOL write, BOOL preserveTimestamps, BOOL useBackupHeader);
void CloseVolume (OpenVolumeContext *context);
int ReEncryptVolumeHeader (HWND hwndDlg, char *buffer, BOOL bBoot, CRYPTO_INFO *cryptoInfo, Password *password, int pim, BOOL wipeMode);
BOOL IsPagingFileActive (BOOL checkNonWindowsPartitionsOnly);
@@ -479,20 +475,22 @@ BOOL DisablePagingFile ();
BOOL CALLBACK SecurityTokenPasswordDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK SecurityTokenKeyfileDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
BOOL InitSecurityTokenLibrary (HWND hwndDlg);
-BOOL FileHasReadOnlyAttribute (const char *path);
-BOOL IsFileOnReadOnlyFilesystem (const char *path);
+BOOL FileHasReadOnlyAttribute (const wchar_t *path);
+BOOL IsFileOnReadOnlyFilesystem (const wchar_t *path);
void CheckFilesystem (HWND hwndDlg, int driveNo, BOOL fixErrors);
BOOL BufferContainsString (const byte *buffer, size_t bufferSize, const char *str);
int AskNonSysInPlaceEncryptionResume (HWND hwndDlg, BOOL* pbDecrypt);
-BOOL RemoveDeviceWriteProtection (HWND hwndDlg, char *devicePath);
+BOOL RemoveDeviceWriteProtection (HWND hwndDlg, wchar_t *devicePath);
void EnableElevatedCursorChange (HWND parent);
BOOL DisableFileCompression (HANDLE file);
-BOOL VolumePathExists (const char *volumePath);
+BOOL VolumePathExists (const wchar_t *volumePath);
BOOL IsWindowsIsoBurnerAvailable ();
-BOOL LaunchWindowsIsoBurner (HWND hwnd, const char *isoPath);
-BOOL IsApplicationInstalled (const char *appName);
+BOOL LaunchWindowsIsoBurner (HWND hwnd, const wchar_t *isoPath);
+BOOL IsApplicationInstalled (const wchar_t *appName);
int GetPim (HWND hwndDlg, UINT ctrlId);
void SetPim (HWND hwndDlg, UINT ctrlId, int pim);
+BOOL GetPassword (HWND hwndDlg, UINT ctrlID, char* passValue, int bufSize, BOOL bShowError);
+void SetPassword (HWND hwndDlg, UINT ctrlID, char* passValue);
void HandleShowPasswordFieldAction (HWND hwndDlg, UINT checkBoxId, UINT edit1Id, UINT edit2Id);
#ifdef __cplusplus
@@ -527,9 +525,9 @@ struct HostDevice
bool IsPartition;
bool IsVirtualPartition;
bool HasUnencryptedFilesystem;
- std::string MountPoint;
+ std::wstring MountPoint;
std::wstring Name;
- std::string Path;
+ std::wstring Path;
bool Removable;
uint64 Size;
uint32 SystemNumber;
@@ -540,10 +538,10 @@ struct HostDevice
struct RawDevicesDlgParam
{
std::vector <HostDevice> devices;
- char *pszFileName;
+ wchar_t *pszFileName;
};
-BOOL BrowseFilesInDir (HWND hwndDlg, char *stringId, char *initialDir, char *lpszFileName, BOOL keepHistory, BOOL saveMode, wchar_t *browseFilter, const wchar_t *initialFileName = NULL, const wchar_t *defaultExtension = NULL);
+BOOL BrowseFilesInDir (HWND hwndDlg, char *stringId, wchar_t *initialDir, wchar_t *lpszFileName, BOOL keepHistory, BOOL saveMode, wchar_t *browseFilter, const wchar_t *initialFileName = NULL, const wchar_t *defaultExtension = NULL);
std::wstring SingleStringToWide (const std::string &singleString);
std::wstring Utf8StringToWide (const std::string &utf8String);
std::string WideToSingleString (const std::wstring &wideString);
@@ -551,14 +549,15 @@ std::string WideToUtf8String (const std::wstring &wideString);
std::string StringToUpperCase (const std::string &str);
std::vector <HostDevice> GetAvailableHostDevices (bool noDeviceProperties = false, bool singleList = false, bool noFloppy = true, bool detectUnencryptedFilesystems = false);
std::string ToUpperCase (const std::string &str);
+std::wstring ToUpperCase (const std::wstring &str);
std::wstring GetWrongPasswordErrorMessage (HWND hwndDlg);
-std::string GetWindowsEdition ();
-std::string FitPathInGfxWidth (HWND hwnd, HFONT hFont, LONG width, const std::string &path);
-std::string GetServiceConfigPath (const char *fileName, bool useLegacy);
-std::string VolumeGuidPathToDevicePath (std::string volumeGuidPath);
-std::string HarddiskVolumePathToPartitionPath (const std::string &harddiskVolumePath);
-std::string FindLatestFileOrDirectory (const std::string &directory, const char *namePattern, bool findDirectory, bool findFile);
-std::string GetUserFriendlyVersionString (int version);
+std::wstring GetWindowsEdition ();
+std::wstring FitPathInGfxWidth (HWND hwnd, HFONT hFont, LONG width, const std::wstring &path);
+std::wstring GetServiceConfigPath (const wchar_t *fileName, bool useLegacy);
+std::wstring VolumeGuidPathToDevicePath (std::wstring volumeGuidPath);
+std::wstring HarddiskVolumePathToPartitionPath (const std::wstring &harddiskVolumePath);
+std::wstring FindLatestFileOrDirectory (const std::wstring &directory, const wchar_t *namePattern, bool findDirectory, bool findFile);
+std::wstring GetUserFriendlyVersionString (int version);
std::string IntToString (int val);
std::wstring IntToWideString (int val);
inline std::wstring AppendSrcPos (const wchar_t* msg, const char* srcPos)
diff --git a/src/Common/Exception.h b/src/Common/Exception.h
index d5958b26..cac6ddd2 100644
--- a/src/Common/Exception.h
+++ b/src/Common/Exception.h
@@ -64,7 +64,7 @@ namespace VeraCrypt
void Show (HWND parent) const
{
string msgBody = "Parameter incorrect.\n\n\n(If you report a bug in connection with this, please include the following technical information in the bug report:\n" + string (SrcPos) + ")";
- MessageBox (parent, msgBody.c_str(), "VeraCrypt", MB_ICONERROR | MB_SETFOREGROUND);
+ MessageBoxA (parent, msgBody.c_str(), "VeraCrypt", MB_ICONERROR | MB_SETFOREGROUND);
}
const char *SrcPos;
@@ -77,9 +77,9 @@ namespace VeraCrypt
void Show (HWND parent) const
{
char szErrCode[16];
- StringCbPrintf (szErrCode, sizeof(szErrCode), "0x%.8X", LastError);
+ StringCbPrintfA (szErrCode, sizeof(szErrCode), "0x%.8X", LastError);
string msgBody = "The Random Generator initialization failed.\n\n\n(If you report a bug in connection with this, please include the following technical information in the bug report:\n" + string (SrcPos) + "\nLast Error = " + string (szErrCode) + ")";
- MessageBox (parent, msgBody.c_str(), "VeraCrypt", MB_ICONERROR | MB_SETFOREGROUND);
+ MessageBoxA (parent, msgBody.c_str(), "VeraCrypt", MB_ICONERROR | MB_SETFOREGROUND);
}
const char *SrcPos;
@@ -93,9 +93,9 @@ namespace VeraCrypt
void Show (HWND parent) const
{
char szErrCode[16];
- StringCbPrintf (szErrCode, sizeof(szErrCode), "0x%.8X", LastError);
+ StringCbPrintfA (szErrCode, sizeof(szErrCode), "0x%.8X", LastError);
string msgBody = "Windows Crypto API failed.\n\n\n(If you report a bug in connection with this, please include the following technical information in the bug report:\n" + string (SrcPos) + "\nLast Error = " + string (szErrCode) + ")";
- MessageBox (parent, msgBody.c_str(), "VeraCrypt", MB_ICONERROR | MB_SETFOREGROUND);
+ MessageBoxA (parent, msgBody.c_str(), "VeraCrypt", MB_ICONERROR | MB_SETFOREGROUND);
}
const char *SrcPos;
diff --git a/src/Common/Format.c b/src/Common/Format.c
index 3fede6d5..43916273 100644
--- a/src/Common/Format.c
+++ b/src/Common/Format.c
@@ -92,8 +92,8 @@ int TCFormatVolume (volatile FORMAT_VOL_PARAMETERS *volParams)
FILETIME ftLastAccessTime;
BOOL bTimeStampValid = FALSE;
BOOL bInstantRetryOtherFilesys = FALSE;
- char dosDev[TC_MAX_PATH] = { 0 };
- char devName[MAX_PATH] = { 0 };
+ WCHAR dosDev[TC_MAX_PATH] = { 0 };
+ WCHAR devName[MAX_PATH] = { 0 };
int driveLetter = -1;
WCHAR deviceName[MAX_PATH];
uint64 dataOffset, dataAreaSize;
@@ -138,8 +138,7 @@ int TCFormatVolume (volatile FORMAT_VOL_PARAMETERS *volParams)
if (volParams->bDevice)
{
- StringCbCopyA ((char *)deviceName, sizeof(deviceName), volParams->volumePath);
- ToUNICODE ((char *)deviceName, sizeof(deviceName));
+ StringCbCopyW (deviceName, sizeof(deviceName), volParams->volumePath);
driveLetter = GetDiskDeviceDriveLetter (deviceName);
}
@@ -213,9 +212,9 @@ begin_format:
// to which no drive letter has been assigned under the system. This problem can be worked
// around by assigning a drive letter to the partition temporarily.
- char szDriveLetter[] = { 'A', ':', 0 };
- char rootPath[] = { 'A', ':', '\\', 0 };
- char uniqVolName[MAX_PATH+1] = { 0 };
+ wchar_t szDriveLetter[] = { L'A', L':', 0 };
+ wchar_t rootPath[] = { L'A', L':', L'\\', 0 };
+ wchar_t uniqVolName[MAX_PATH+1] = { 0 };
int tmpDriveLetter = -1;
BOOL bResult = FALSE;
@@ -223,8 +222,8 @@ begin_format:
if (tmpDriveLetter != -1)
{
- rootPath[0] += (char) tmpDriveLetter;
- szDriveLetter[0] += (char) tmpDriveLetter;
+ rootPath[0] += (wchar_t) tmpDriveLetter;
+ szDriveLetter[0] += (wchar_t) tmpDriveLetter;
if (DefineDosDevice (DDD_RAW_TARGET_PATH, szDriveLetter, volParams->volumePath))
{
@@ -863,25 +862,25 @@ BOOLEAN __stdcall FormatExCallback (int command, DWORD subCommand, PVOID paramet
BOOL FormatNtfs (int driveNo, int clusterSize)
{
- char dllPath[MAX_PATH] = {0};
- WCHAR dir[8] = { (WCHAR) driveNo + 'A', 0 };
+ wchar_t dllPath[MAX_PATH] = {0};
+ WCHAR dir[8] = { (WCHAR) driveNo + L'A', 0 };
PFORMATEX FormatEx;
HMODULE hModule;
int i;
if (GetSystemDirectory (dllPath, MAX_PATH))
{
- StringCbCatA(dllPath, sizeof(dllPath), "\\fmifs.dll");
+ StringCbCatW(dllPath, sizeof(dllPath), L"\\fmifs.dll");
}
else
- StringCbCopyA(dllPath, sizeof(dllPath), "C:\\Windows\\System32\\fmifs.dll");
+ StringCbCopyW(dllPath, sizeof(dllPath), L"C:\\Windows\\System32\\fmifs.dll");
hModule = LoadLibrary (dllPath);
if (hModule == NULL)
return FALSE;
- if (!(FormatEx = (PFORMATEX) GetProcAddress (GetModuleHandle ("fmifs.dll"), "FormatEx")))
+ if (!(FormatEx = (PFORMATEX) GetProcAddress (GetModuleHandle (L"fmifs.dll"), "FormatEx")))
{
FreeLibrary (hModule);
return FALSE;
diff --git a/src/Common/Format.h b/src/Common/Format.h
index 3c39bec4..97eeabea 100644
--- a/src/Common/Format.h
+++ b/src/Common/Format.h
@@ -28,7 +28,7 @@ typedef struct
{
BOOL bDevice;
BOOL hiddenVol;
- char *volumePath;
+ wchar_t *volumePath;
unsigned __int64 size;
unsigned __int64 hiddenVolHostSize;
int ea;
diff --git a/src/Common/Keyfiles.c b/src/Common/Keyfiles.c
index 428821b5..5cde6b30 100644
--- a/src/Common/Keyfiles.c
+++ b/src/Common/Keyfiles.c
@@ -112,7 +112,7 @@ KeyFile *KeyFileClone (KeyFile *keyFile)
clone = (KeyFile *) malloc (sizeof (KeyFile));
if (clone)
{
- StringCbCopyA (clone->FileName, sizeof(clone->FileName), keyFile->FileName);
+ StringCbCopyW (clone->FileName, sizeof(clone->FileName), keyFile->FileName);
clone->Next = NULL;
}
return clone;
@@ -170,7 +170,7 @@ static BOOL KeyFileProcess (unsigned __int8 *keyPool, KeyFile *keyFile)
CloseHandle (finally_arg);
});
- f = fopen (keyFile->FileName, "rb");
+ f = _wfopen (keyFile->FileName, L"rb");
if (f == NULL) return FALSE;
while ((bytesRead = fread (buffer, 1, sizeof (buffer), f)) > 0)
@@ -225,7 +225,7 @@ close:
}
-BOOL KeyFilesApply (HWND hwndDlg, Password *password, KeyFile *firstKeyFile, const char* volumeFileName)
+BOOL KeyFilesApply (HWND hwndDlg, Password *password, KeyFile *firstKeyFile, const wchar_t* volumeFileName)
{
BOOL status = TRUE;
KeyFile kfSubStruct;
@@ -234,8 +234,8 @@ BOOL KeyFilesApply (HWND hwndDlg, Password *password, KeyFile *firstKeyFile, con
static unsigned __int8 keyPool [KEYFILE_POOL_SIZE];
size_t i;
struct stat statStruct;
- char searchPath [TC_MAX_PATH*2];
- struct _finddata_t fBuf;
+ wchar_t searchPath [TC_MAX_PATH*2];
+ struct _wfinddata_t fBuf;
intptr_t searchHandle;
HiddenFilesPresentInKeyfilePath = FALSE;
@@ -250,11 +250,12 @@ BOOL KeyFilesApply (HWND hwndDlg, Password *password, KeyFile *firstKeyFile, con
// Determine whether it's a security token path
try
{
- if (SecurityToken::IsKeyfilePathValid (SingleStringToWide (kf->FileName)))
+ if (SecurityToken::IsKeyfilePathValid (kf->FileName))
{
// Apply security token keyfile
vector <byte> keyfileData;
- SecurityToken::GetKeyfileData (SecurityTokenKeyfile (SingleStringToWide (kf->FileName)), keyfileData);
+ SecurityTokenKeyfilePath secPath (kf->FileName);
+ SecurityToken::GetKeyfileData (SecurityTokenKeyfile (secPath), keyfileData);
if (keyfileData.empty())
{
@@ -296,7 +297,7 @@ BOOL KeyFilesApply (HWND hwndDlg, Password *password, KeyFile *firstKeyFile, con
}
// Determine whether it's a path or a file
- if (stat (kf->FileName, &statStruct) != 0)
+ if (_wstat (kf->FileName, &statStruct) != 0)
{
handleWin32Error (hwndDlg, SRC_POS);
Error ("ERR_PROCESS_KEYFILE", hwndDlg);
@@ -309,8 +310,8 @@ BOOL KeyFilesApply (HWND hwndDlg, Password *password, KeyFile *firstKeyFile, con
/* Find and process all keyfiles in the directory */
int keyfileCount = 0;
- StringCbPrintfA (searchPath, sizeof (searchPath), "%s\\*.*", kf->FileName);
- if ((searchHandle = _findfirst (searchPath, &fBuf)) == -1)
+ StringCbPrintfW (searchPath, sizeof (searchPath), L"%s\\*.*", kf->FileName);
+ if ((searchHandle = _wfindfirst (searchPath, &fBuf)) == -1)
{
handleWin32Error (hwndDlg, SRC_POS);
Error ("ERR_PROCESS_KEYFILE_PATH", hwndDlg);
@@ -322,13 +323,13 @@ BOOL KeyFilesApply (HWND hwndDlg, Password *password, KeyFile *firstKeyFile, con
{
WIN32_FILE_ATTRIBUTE_DATA fileAttributes;
- StringCbPrintfA (kfSub->FileName, sizeof(kfSub->FileName), "%s%c%s", kf->FileName,
- '\\',
+ StringCbPrintfW (kfSub->FileName, sizeof(kfSub->FileName), L"%s%c%s", kf->FileName,
+ L'\\',
fBuf.name
);
// Determine whether it's a path or a file
- if (stat (kfSub->FileName, &statStruct) != 0)
+ if (_wstat (kfSub->FileName, &statStruct) != 0)
{
handleWin32Error (hwndDlg, SRC_POS);
Error ("ERR_PROCESS_KEYFILE", hwndDlg);
@@ -342,7 +343,7 @@ BOOL KeyFilesApply (HWND hwndDlg, Password *password, KeyFile *firstKeyFile, con
}
// Skip hidden files
- if (GetFileAttributesEx (kfSub->FileName, GetFileExInfoStandard, &fileAttributes)
+ if (GetFileAttributesExW (kfSub->FileName, GetFileExInfoStandard, &fileAttributes)
&& (fileAttributes.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) != 0)
{
HiddenFilesPresentInKeyfilePath = TRUE;
@@ -350,7 +351,7 @@ BOOL KeyFilesApply (HWND hwndDlg, Password *password, KeyFile *firstKeyFile, con
}
CorrectFileName (kfSub->FileName);
- if (volumeFileName && (_stricmp (volumeFileName, kfSub->FileName) == 0))
+ if (volumeFileName && (_wcsicmp (volumeFileName, kfSub->FileName) == 0))
{
// skip if it is the current container file name
continue;
@@ -366,14 +367,14 @@ BOOL KeyFilesApply (HWND hwndDlg, Password *password, KeyFile *firstKeyFile, con
status = FALSE;
}
- } while (_findnext (searchHandle, &fBuf) != -1);
+ } while (_wfindnext (searchHandle, &fBuf) != -1);
_findclose (searchHandle);
burn (&kfSubStruct, sizeof (kfSubStruct));
if (keyfileCount == 0)
{
- ErrorDirect ((wstring (GetString ("ERR_KEYFILE_PATH_EMPTY")) + L"\n\n" + SingleStringToWide (kf->FileName)).c_str(), hwndDlg);
+ ErrorDirect ((wstring (GetString ("ERR_KEYFILE_PATH_EMPTY")) + L"\n\n" + wstring (kf->FileName)).c_str(), hwndDlg);
status = FALSE;
}
}
@@ -499,7 +500,7 @@ BOOL CALLBACK KeyFilesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
do
{
CorrectFileName (kf->FileName);
- if (_stricmp (param->VolumeFileName, kf->FileName) == 0)
+ if (_wcsicmp (param->VolumeFileName, kf->FileName) == 0)
containerFileSkipped = true;
else
{
@@ -547,7 +548,7 @@ BOOL CALLBACK KeyFilesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
KeyFile *kf = (KeyFile *) malloc (sizeof (KeyFile));
if (kf)
{
- strcpy_s (kf->FileName, sizeof (kf->FileName), WideToSingleString (keyPath).c_str());
+ StringCbCopyW (kf->FileName, sizeof (kf->FileName), wstring(keyPath).c_str ());
param->FirstKeyFile = KeyFileAdd (param->FirstKeyFile, kf);
LoadKeyList (hwndDlg, param->FirstKeyFile);
@@ -741,7 +742,7 @@ BOOL KeyfilesPopupMenu (HWND hwndDlg, POINT popupPosition, KeyFilesDlgParam *par
KeyFile *kf = (KeyFile *) malloc (sizeof (KeyFile));
if (kf)
{
- strcpy_s (kf->FileName, sizeof (kf->FileName), WideToSingleString (keyPath).c_str());
+ StringCbCopyW (kf->FileName, sizeof (kf->FileName), wstring (keyPath).c_str());
param->FirstKeyFile = KeyFileAdd (param->FirstKeyFile, kf);
param->EnableKeyFiles = TRUE;
diff --git a/src/Common/Keyfiles.h b/src/Common/Keyfiles.h
index 8400ebc3..dcdfdde8 100644
--- a/src/Common/Keyfiles.h
+++ b/src/Common/Keyfiles.h
@@ -24,13 +24,13 @@ extern "C" {
typedef struct KeyFileStruct
{
- char FileName[MAX_PATH + 1];
+ wchar_t FileName[MAX_PATH + 1];
struct KeyFileStruct *Next;
} KeyFile;
typedef struct
{
- char VolumeFileName[MAX_PATH + 1];
+ wchar_t VolumeFileName[MAX_PATH + 1];
BOOL EnableKeyFiles;
KeyFile *FirstKeyFile;
} KeyFilesDlgParam;
@@ -39,7 +39,7 @@ KeyFile *KeyFileAdd (KeyFile *firstKeyFile, KeyFile *keyFile);
void KeyFileRemoveAll (KeyFile **firstKeyFile);
KeyFile *KeyFileClone (KeyFile *keyFile);
KeyFile *KeyFileCloneAll (KeyFile *firstKeyFile);
-BOOL KeyFilesApply (HWND hwndDlg, Password *password, KeyFile *firstKeyFilem, const char* volumeFileName);
+BOOL KeyFilesApply (HWND hwndDlg, Password *password, KeyFile *firstKeyFilem, const wchar_t* volumeFileName);
BOOL CALLBACK KeyFilesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
BOOL KeyfilesPopupMenu (HWND hwndDlg, POINT popupPosition, KeyFilesDlgParam *dialogParam);
diff --git a/src/Common/Language.c b/src/Common/Language.c
index dbad2d5e..757f0508 100644
--- a/src/Common/Language.c
+++ b/src/Common/Language.c
@@ -62,7 +62,7 @@ static char *MapFirstLanguageFile ()
if (LanguageResource == NULL)
{
DWORD size;
- LanguageResource = MapResource ("Xml", IDR_LANGUAGE, &size);
+ LanguageResource = MapResource (L"Xml", IDR_LANGUAGE, &size);
if (LanguageResource)
LanguageResourceSize = size;
}
@@ -287,7 +287,7 @@ BOOL LoadLanguageFile ()
case 't': *out++ = '\t'; break;
case 'n': *out++ = 13; *out++ = 10; break;
default:
- MessageBox (0, key, "VeraCrypt: Unknown '\\' escape sequence in string", MB_ICONERROR);
+ MessageBoxA (0, key, "VeraCrypt: Unknown '\\' escape sequence in string", MB_ICONERROR);
return FALSE;
}
}
@@ -301,7 +301,7 @@ BOOL LoadLanguageFile ()
len = MultiByteToWideChar (CP_UTF8, 0, attr, -1, wattr, sizeof (wattr) / sizeof(wattr[0]));
if (len == 0)
{
- MessageBox (0, key, "VeraCrypt: Error while decoding UTF-8 string", MB_ICONERROR);
+ MessageBoxA (0, key, "VeraCrypt: Error while decoding UTF-8 string", MB_ICONERROR);
return FALSE;
}
@@ -343,7 +343,7 @@ BOOL LoadLanguageFile ()
{
if (HeaderResource[i] == NULL)
{
- HeaderResource[i] = MapResource ("Header", headers[i], &size);
+ HeaderResource[i] = MapResource (L"Header", headers[i], &size);
if (HeaderResource[i])
HeaderResourceSize[i] = size;
}
diff --git a/src/Common/Language.xml b/src/Common/Language.xml
index 250bf3ad..3c8fbfcf 100644
--- a/src/Common/Language.xml
+++ b/src/Common/Language.xml
@@ -416,13 +416,13 @@
<string lang="en" key="CIPHER_TITLE">Encryption Options</string>
<string lang="en" key="CLEAN_WINMRU_FAILED">WARNING: Failed to clear the path of the last selected volume/keyfile (remembered by file selector)!</string>
<string lang="en" key="COMPRESSION_NOT_SUPPORTED">Error: The container has been compressed at the filesystem level. VeraCrypt does not support compressed containers (note that compression of encrypted data is ineffective and redundant).\n\nPlease disable compression for the container by following these steps:\n1) Right-click the container in Windows Explorer (not in VeraCrypt).\n2) Select 'Properties'.\n3) In the 'Properties' dialog box, click 'Advanced'.\n4) In the 'Advanced Attributes' dialog box, disable the option 'Compress contents to save disk space' and click 'OK'.\n5) In the 'Properties' dialog box, click 'OK'.</string>
- <string lang="en" key="CREATE_FAILED">Failed to create volume %hs</string>
- <string lang="en" key="DEVICE_FREE_BYTES">Size of %hs is %.2f bytes</string>
- <string lang="en" key="DEVICE_FREE_KB">Size of %hs is %.2f KB</string>
- <string lang="en" key="DEVICE_FREE_MB">Size of %hs is %.2f MB</string>
- <string lang="en" key="DEVICE_FREE_GB">Size of %hs is %.2f GB</string>
- <string lang="en" key="DEVICE_FREE_TB">Size of %hs is %.2f TB</string>
- <string lang="en" key="DEVICE_FREE_PB">Size of %hs is %.2f PB</string>
+ <string lang="en" key="CREATE_FAILED">Failed to create volume %s</string>
+ <string lang="en" key="DEVICE_FREE_BYTES">Size of %s is %.2f bytes</string>
+ <string lang="en" key="DEVICE_FREE_KB">Size of %s is %.2f KB</string>
+ <string lang="en" key="DEVICE_FREE_MB">Size of %s is %.2f MB</string>
+ <string lang="en" key="DEVICE_FREE_GB">Size of %s is %.2f GB</string>
+ <string lang="en" key="DEVICE_FREE_TB">Size of %s is %.2f TB</string>
+ <string lang="en" key="DEVICE_FREE_PB">Size of %s is %.2f PB</string>
<string lang="en" key="DEVICE_IN_USE_FORMAT">WARNING: The device/partition is in use by the operating system or applications. Formatting the device/partition might cause data corruption and system instability.\n\nContinue?</string>
<string lang="en" key="DEVICE_IN_USE_INPLACE_ENC">Warning: The partition is in use by the operating system or applications. You should close any applications that might be using the partition (including antivirus software).\n\nContinue?</string>
<string lang="en" key="FORMAT_CANT_DISMOUNT_FILESYS">Error: The device/partition contains a file system that could not be dismounted. The file system may be in use by the operating system. Formatting the device/partition would very likely cause data corruption and system instability.\n\nTo solve this issue, we recommend that you first delete the partition and then recreate it without formatting. To do so, follow these steps:\n1) Right-click the 'Computer' (or 'My Computer') icon in the 'Start Menu' and select 'Manage'. The 'Computer Management' window should appear.\n2) In the 'Computer Management' window, select 'Storage' > 'Disk Management'.\n3) Right-click the partition you want to encrypt and select either 'Delete Partition', or 'Delete Volume', or 'Delete Logical Drive'.\n4) Click 'Yes'. If Windows asks you to restart the computer, do so. Then repeat the steps 1 and 2 and continue from the step 5.\n5) Right-click the unallocated/free space area and select either 'New Partition', or 'New Simple Volume', or 'New Logical Drive'.\n6) The 'New Partition Wizard' or 'New Simple Volume Wizard' window should appear now; follow its instructions. On the wizard page entitled 'Format Partition', select either 'Do not format this partition' or 'Do not format this volume'. In the same wizard, click 'Next' and then 'Finish'.\n7) Note that the device path you have selected in VeraCrypt may be wrong now. Therefore, exit the VeraCrypt Volume Creation Wizard (if it is still running) and then start it again.\n8) Try encrypting the device/partition again.\n\nIf VeraCrypt repeatedly fails to encrypt the device/partition, you may want to consider creating a file container instead.</string>
@@ -441,12 +441,12 @@
<string lang="en" key="INPLACE_ENC_INVALID_PATH">Error: VeraCrypt can in-place encrypt only a partition, a dynamic volume, or an entire system drive. Please make sure the specified path is valid.</string>
<string lang="en" key="CANNOT_RESIZE_FILESYS">Error: Cannot shrink the filesystem (the filesystem needs to be shrunk to make space for the volume header and backup header).\n\nPossible causes and solutions:\n\n- Not enough free space on the volume. Please make sure no other application is writing to the filesystem.\n\n- Corrupted file system. Try to check it and fix any errors (right-click the corresponding drive letter in the 'Computer' list, then select Properties > Tools > 'Check Now', make sure the option 'Automatically fix file system errors' is enabled and click Start).\n\nIf the above steps do not help, please follow the below steps.</string>
<string lang="en" key="NOT_ENOUGH_FREE_FILESYS_SPACE_FOR_SHRINK">Error: There is not enough free space on the volume and so the filesystem cannot be shrunk (the filesystem needs to be shrunk to make space for the volume header and backup header).\n\nPlease delete any redundant files and empty the Recycle Bin so as to free at least 256 KB of space and then try again. Note that due to a Windows issue, the amount of free space reported by the Windows Explorer may be incorrect until the operating system is restarted. If restarting the system does not help, the file system may be corrupted. Try to check it and fix any errors (right-click the corresponding drive letter in the 'Computer' list, then select Properties > Tools > 'Check Now', make sure the option 'Automatically fix file system errors' is enabled and click Start).\n\nIf the above steps do not help, please follow the below steps.</string>
- <string lang="en" key="DISK_FREE_BYTES">Free space on drive %hs is %.2f bytes.</string>
- <string lang="en" key="DISK_FREE_KB">Free space on drive %hs is %.2f KB</string>
- <string lang="en" key="DISK_FREE_MB">Free space on drive %hs is %.2f MB</string>
- <string lang="en" key="DISK_FREE_GB">Free space on drive %hs is %.2f GB</string>
- <string lang="en" key="DISK_FREE_TB">Free space on drive %hs is %.2f TB</string>
- <string lang="en" key="DISK_FREE_PB">Free space on drive %hs is %.2f PB</string>
+ <string lang="en" key="DISK_FREE_BYTES">Free space on drive %s is %.2f bytes.</string>
+ <string lang="en" key="DISK_FREE_KB">Free space on drive %s is %.2f KB</string>
+ <string lang="en" key="DISK_FREE_MB">Free space on drive %s is %.2f MB</string>
+ <string lang="en" key="DISK_FREE_GB">Free space on drive %s is %.2f GB</string>
+ <string lang="en" key="DISK_FREE_TB">Free space on drive %s is %.2f TB</string>
+ <string lang="en" key="DISK_FREE_PB">Free space on drive %s is %.2f PB</string>
<string lang="en" key="DRIVELETTERS">Could not get available drive letters.</string>
<string lang="en" key="DRIVER_NOT_FOUND">Error: VeraCrypt driver not found.\n\nPlease copy the files 'veracrypt.sys' and 'veracrypt-x64.sys' to the directory where the main VeraCrypt application (VeraCrypt.exe) is located.</string>
<string lang="en" key="DRIVER_VERSION">Error: An incompatible version of the VeraCrypt driver is currently running.\n\nIf you are trying to run VeraCrypt in portable mode (i.e. without installing it) and a different version of VeraCrypt is already installed, you must uninstall it first (or upgrade it using the VeraCrypt installer). To uninstall it, follow these steps: On Windows Vista or later, select 'Start Menu' > Computer > 'Uninstall or change a program' > VeraCrypt > Uninstall; on Windows XP, select 'Start Menu' > Settings > 'Control Panel' > 'Add Or Remove Programs' > VeraCrypt > Remove.\n\nSimilarly, if you are trying to run VeraCrypt in portable mode (i.e. without installing it) and a different version of VeraCrypt is already running in portable mode, you must restart the system first and then run only this new version.</string>
@@ -598,12 +598,12 @@
<string lang="en" key="SELECT_PKCS11_MODULE">Select PKCS #11 Library</string>
<string lang="en" key="OUTOFMEMORY">Out of Memory</string>
<string lang="en" key="FORMAT_DEVICE_FOR_ADVANCED_ONLY">IMPORTANT: We strongly recommend that inexperienced users create a VeraCrypt file container on the selected device/partition, instead of attempting to encrypt the entire device/partition.\n\nWhen you create a VeraCrypt file container (as opposed to encrypting a device or partition) there is, for example, no risk of destroying a large number of files. Note that a VeraCrypt file container (even though it contains a virtual encrypted disk) is actually just like any normal file. For more information, see the chapter Beginner's Tutorial in the VeraCrypt User Guide.\n\nAre you sure you want to encrypt the entire device/partition?</string>
- <string lang="en" key="OVERWRITEPROMPT">WARNING: The file '%hs' already exists!\n\nIMPORTANT: VERACRYPT WILL NOT ENCRYPT THE FILE, BUT IT WILL DELETE IT. Are you sure you want to delete the file and replace it with a new VeraCrypt container?</string>
- <string lang="en" key="OVERWRITEPROMPT_DEVICE">CAUTION: ALL FILES CURRENTLY STORED ON THE SELECTED %s '%hs'%s WILL BE ERASED AND LOST (THEY WILL NOT BE ENCRYPTED)!\n\nAre you sure you want to proceed with format?</string>
- <string lang="en" key="NONSYS_INPLACE_ENC_CONFIRM">WARNING: You will not be able to mount the volume or access any files stored on it until it has been fully encrypted.\n\nAre you sure you want to start encrypting the selected %s '%hs'%s?</string>
- <string lang="en" key="NONSYS_INPLACE_DEC_CONFIRM">WARNING: You will not be able to mount the volume or access any files stored on it until it has been fully decrypted.\n\nAre you sure you want to start decrypting the selected %s '%hs'%s?</string>
+ <string lang="en" key="OVERWRITEPROMPT">WARNING: The file '%s' already exists!\n\nIMPORTANT: VERACRYPT WILL NOT ENCRYPT THE FILE, BUT IT WILL DELETE IT. Are you sure you want to delete the file and replace it with a new VeraCrypt container?</string>
+ <string lang="en" key="OVERWRITEPROMPT_DEVICE">CAUTION: ALL FILES CURRENTLY STORED ON THE SELECTED %s '%s'%s WILL BE ERASED AND LOST (THEY WILL NOT BE ENCRYPTED)!\n\nAre you sure you want to proceed with format?</string>
+ <string lang="en" key="NONSYS_INPLACE_ENC_CONFIRM">WARNING: You will not be able to mount the volume or access any files stored on it until it has been fully encrypted.\n\nAre you sure you want to start encrypting the selected %s '%s'%s?</string>
+ <string lang="en" key="NONSYS_INPLACE_DEC_CONFIRM">WARNING: You will not be able to mount the volume or access any files stored on it until it has been fully decrypted.\n\nAre you sure you want to start decrypting the selected %s '%s'%s?</string>
<string lang="en" key="NONSYS_INPLACE_ENC_CONFIRM_BACKUP">WARNING: Please note that if power supply is suddenly interrupted while encrypting/decrypting existing data in place, or when the operating system crashes due to a software error or hardware malfunction while VeraCrypt is encrypting/decrypting existing data in place, portions of the data will be corrupted or lost. Therefore, before you start encrypting/decrypting, please make sure that you have backup copies of the files you want to encrypt/decrypt.\n\nDo you have such a backup?</string>
- <string lang="en" key="OVERWRITEPROMPT_DEVICE_HIDDEN_OS_PARTITION">CAUTION: ANY FILES CURRENTLY STORED ON THE PARTITION '%hs'%s (I.E. ON THE FIRST PARTITION BEHIND THE SYSTEM PARTITION) WILL BE ERASED AND LOST (THEY WILL NOT BE ENCRYPTED)!\n\nAre you sure you want to proceed with format?</string>
+ <string lang="en" key="OVERWRITEPROMPT_DEVICE_HIDDEN_OS_PARTITION">CAUTION: ANY FILES CURRENTLY STORED ON THE PARTITION '%s'%s (I.E. ON THE FIRST PARTITION BEHIND THE SYSTEM PARTITION) WILL BE ERASED AND LOST (THEY WILL NOT BE ENCRYPTED)!\n\nAre you sure you want to proceed with format?</string>
<string lang="en" key="OVERWRITEPROMPT_DEVICE_SECOND_WARNING_LOTS_OF_DATA">WARNING: THE SELECTED PARTITION CONTAINS A LARGE AMOUNT OF DATA! Any files stored on the partition will be erased and lost (they will NOT be encrypted)!</string>
<string lang="en" key="ERASE_FILES_BY_CREATING_VOLUME">Erase any files stored on the partition by creating a VeraCrypt volume within it</string>
<string lang="en" key="PASSWORD">Password</string>
@@ -641,6 +641,8 @@
<string lang="en" key="PASSWORD_WRONG_AUTOMOUNT">Auto-mount failed due to one or more of the following:\n - Incorrect password.\n - Incorrect Volume PIM number.\n - Incorrect PRF (hash).\n - No valid volume found.</string>
<string lang="en" key="PASSWORD_OR_KEYFILE_WRONG_AUTOMOUNT">Auto-mount failed due to one or more of the following:\n - Incorrect keyfile(s).\n - Incorrect password.\n - Incorrect Volume PIM number.\n - Incorrect PRF (hash).\n - No valid volume found.</string>
<string lang="en" key="PASSWORD_WRONG_CAPSLOCK_ON">\n\nWarning: Caps Lock is on. This may cause you to enter your password incorrectly.</string>
+ <string lang="en" key="PASSWORD_UTF8_TOO_LONG">The entered password is too long: its UTF-8 representation exceeds 64 bytes.</string>
+ <string lang="en" key="PASSWORD_UTF8_INVALID">The entered password contains Unicode characters that couldn't be converted to UTF-8 representation.</string>
<string lang="en" key="PIM_CHANGE_WARNING">Remember Number to Mount Volume</string>
<string lang="en" key="PIM_HIDVOL_HOST_TITLE">Outer Volume PIM</string>
<string lang="en" key="PIM_HIDVOL_TITLE">Hidden Volume PIM</string>
@@ -663,7 +665,7 @@
<string lang="en" key="CANT_DECRYPT_PARTITION_ON_ENTIRELY_ENCRYPTED_SYS_DRIVE_UNSURE">Warning: As the drive contains the VeraCrypt Boot Loader, it may be an entirely encrypted system drive. If it is, please note that VeraCrypt cannot decrypt an individual partition on an entirely encrypted system drive (you can decrypt only the entire system drive). If that is the case, you will be able to continue now but you will receive the 'Incorrect password' error message later.</string>
<string lang="en" key="PREV">&lt; &amp;Back</string>
<string lang="en" key="RAWDEVICES">Unable to list raw devices installed on your system!</string>
- <string lang="en" key="READONLYPROMPT">The volume '%hs' exists, and is read-only. Are you sure you want to replace it?</string>
+ <string lang="en" key="READONLYPROMPT">The volume '%s' exists, and is read-only. Are you sure you want to replace it?</string>
<string lang="en" key="SELECT_DEST_DIR">Select destination directory</string>
<string lang="en" key="SELECT_KEYFILE">Select Keyfile</string>
<string lang="en" key="SELECT_KEYFILE_PATH">Select a keyfile search path. WARNING: Note that only the path will be remembered, not the filenames!</string>
@@ -687,13 +689,13 @@
<string lang="en" key="TEST_CIPHERTEXT_SIZE">The test ciphertext you have supplied is too long or short.</string>
<string lang="en" key="TEST_KEY_SIZE">The test key you have supplied is too long or short.</string>
<string lang="en" key="TEST_PLAINTEXT_SIZE">The test plaintext you have supplied is too long or short.</string>
- <string lang="en" key="TWO_LAYER_CASCADE_HELP">Two ciphers in a cascade operating in XTS mode. Each block is first encrypted with %hs (%d-bit key) and then with %hs (%d-bit key). Each cipher uses its own key. All keys are mutually independent.</string>
- <string lang="en" key="THREE_LAYER_CASCADE_HELP">Three ciphers in a cascade operating in XTS mode. Each block is first encrypted with %hs (%d-bit key), then with %hs (%d-bit key), and finally with %hs (%d-bit key). Each cipher uses its own key. All keys are mutually independent.</string>
+ <string lang="en" key="TWO_LAYER_CASCADE_HELP">Two ciphers in a cascade operating in XTS mode. Each block is first encrypted with %s (%d-bit key) and then with %s (%d-bit key). Each cipher uses its own key. All keys are mutually independent.</string>
+ <string lang="en" key="THREE_LAYER_CASCADE_HELP">Three ciphers in a cascade operating in XTS mode. Each block is first encrypted with %s (%d-bit key), then with %s (%d-bit key), and finally with %s (%d-bit key). Each cipher uses its own key. All keys are mutually independent.</string>
<string lang="en" key="AUTORUN_MAY_NOT_ALWAYS_WORK">Note that, depending on the operating system configuration, these auto-run and auto-mount features may work only when the traveler disk files are created on a non-writable CD/DVD-like medium. Also note that this is not a bug in VeraCrypt (it is a limitation of Windows).</string>
<string lang="en" key="TRAVELER_DISK_CREATED">VeraCrypt traveler disk has been successfully created.\n\nNote that you need administrator privileges to run VeraCrypt in portable mode. Also note that, after examining the registry file, it may be possible to tell that VeraCrypt was run on a Windows system even if it is run in portable mode.</string>
<string lang="en" key="TC_TRAVELER_DISK">VeraCrypt Traveler Disk</string>
<string lang="en" key="TWOFISH_HELP">Designed by Bruce Schneier, John Kelsey, Doug Whiting, David Wagner, Chris Hall, and Niels Ferguson. Published in 1998. 256-bit key, 128-bit block. Mode of operation is XTS. Twofish was one of the AES finalists.</string>
- <string lang="en" key="MORE_INFO_ABOUT">More information on %hs</string>
+ <string lang="en" key="MORE_INFO_ABOUT">More information on %s</string>
<string lang="en" key="UNKNOWN">Unknown</string>
<string lang="en" key="ERR_UNKNOWN">An unspecified or unknown error occurred (%d).</string>
<string lang="en" key="UNMOUNTALL_LOCK_FAILED">Some volumes contain files or folders being used by applications or system.\n\nForce dismount?</string>
@@ -858,7 +860,7 @@
<string lang="en" key="INSTALL_FAILED">Installation failed.</string>
<string lang="en" key="UNINSTALL_FAILED">Uninstallation failed.</string>
<string lang="en" key="DIST_PACKAGE_CORRUPTED">This distribution package is damaged. Please try downloading it again (preferably from the official VeraCrypt website at https://veracrypt.codeplex.com).</string>
- <string lang="en" key="CANNOT_WRITE_FILE_X">Cannot write file %hs</string>
+ <string lang="en" key="CANNOT_WRITE_FILE_X">Cannot write file %s</string>
<string lang="en" key="EXTRACTING_VERB">Extracting</string>
<string lang="en" key="CANNOT_READ_FROM_PACKAGE">Cannot read data from the package.</string>
<string lang="en" key="CANT_VERIFY_PACKAGE_INTEGRITY">Cannot verify the integrity of this distribution package.</string>
@@ -868,7 +870,7 @@
<string lang="en" key="SETUP_UPDATE_OK">VeraCrypt has been successfully updated.</string>
<string lang="en" key="UPGRADE_OK_REBOOT_REQUIRED">VeraCrypt has been successfully upgraded. However, before you can start using it, the computer must be restarted.\n\nDo you want to restart it now?</string>
<string lang="en" key="SYS_ENC_UPGRADE_FAILED">Failed to upgrade VeraCrypt!\n\nIMPORTANT: Before you shut down or restart the system, we strongly recommend that you use System Restore (Windows Start menu > All programs > Accessories > System Tools > System Restore) to restore your system to the restore point named 'VeraCrypt installation'. If System Restore is not available, you should try installing the original or the new version of VeraCrypt again before you shut down or restart the system.</string>
- <string lang="en" key="UNINSTALL_OK">VeraCrypt has been successfully uninstalled.\n\nClick 'Finish' to remove the VeraCrypt installer and the folder %hs. Note that the folder will not be removed if it contains any files that were not installed by the VeraCrypt installer or created by VeraCrypt.</string>
+ <string lang="en" key="UNINSTALL_OK">VeraCrypt has been successfully uninstalled.\n\nClick 'Finish' to remove the VeraCrypt installer and the folder %s. Note that the folder will not be removed if it contains any files that were not installed by the VeraCrypt installer or created by VeraCrypt.</string>
<string lang="en" key="REMOVING_REG">Removing VeraCrypt registry entries</string>
<string lang="en" key="ADDING_REG">Adding registry entry</string>
<string lang="en" key="REMOVING_APPDATA">Removing application-specific data</string>
@@ -879,10 +881,10 @@
<string lang="en" key="CREATING_SYS_RESTORE">Creating System Restore point</string>
<string lang="en" key="FAILED_SYS_RESTORE">Failed to create System Restore point!</string>
<string lang="en" key="INSTALLER_UPDATING_BOOT_LOADER">Updating boot loader</string>
- <string lang="en" key="INSTALL_OF_FAILED">Failed to install '%hs'. %hs\nDo you want to continue installing?</string>
- <string lang="en" key="UNINSTALL_OF_FAILED">Failed to uninstall '%hs'. %hs\nDo you want to continue uninstalling?</string>
+ <string lang="en" key="INSTALL_OF_FAILED">Failed to install '%s'. %s\nDo you want to continue installing?</string>
+ <string lang="en" key="UNINSTALL_OF_FAILED">Failed to uninstall '%s'. %s\nDo you want to continue uninstalling?</string>
<string lang="en" key="INSTALL_COMPLETED">Installation completed.</string>
- <string lang="en" key="CANT_CREATE_FOLDER">The folder '%hs' could not be created</string>
+ <string lang="en" key="CANT_CREATE_FOLDER">The folder '%s' could not be created</string>
<string lang="en" key="CLOSE_TC_FIRST">The VeraCrypt device driver cannot be unloaded.\n\nPlease close all open VeraCrypt windows first. If it does not help, please restart Windows and then try again.</string>
<string lang="en" key="DISMOUNT_ALL_FIRST">All VeraCrypt volumes must be dismounted before installing or uninstalling VeraCrypt.</string>
<string lang="en" key="UNINSTALL_OLD_VERSION_FIRST">An obsolete version of VeraCrypt is currently installed on this system. It needs to be uninstalled before you can install this new version of VeraCrypt.\n\nAs soon as you close this message box, the uninstaller of the old version will be launched. Note that no volume will be decrypted when you uninstall VeraCrypt. After you uninstall the old version of VeraCrypt, run the installer of the new version of VeraCrypt again.</string>
@@ -935,7 +937,7 @@
<string lang="en" key="FAVORITE_LABEL_DEVICE_PATH_ERR">The device displayed below is neither a partition nor a dynamic volume. Therefore, no label can be assigned to it.</string>
<string lang="en" key="FAVORITE_LABEL_PARTITION_TYPE_ERR">Please set the type of the partition displayed below to a type recognized by Windows (use the SETID command of the Windows 'diskpart' tool). Then remove the partition from favorites and add it again. This will enable VeraCrypt to assign a label to the partition.</string>
<string lang="en" key="SYSTEM_FAVORITE_NETWORK_PATH_ERR">Due to a Windows limitation, a container stored in a remote filesystem shared over a network cannot be mounted as a system favorite volume (however, it can be mounted as a non-system favorite volume when a user logs on).</string>
- <string lang="en" key="ENTER_PASSWORD_FOR">Enter password for %hs</string>
+ <string lang="en" key="ENTER_PASSWORD_FOR">Enter password for %s</string>
<string lang="en" key="ENTER_PASSWORD_FOR_LABEL">Enter password for '%s'</string>
<string lang="en" key="ENTER_NORMAL_VOL_PASSWORD">Enter password for the normal/outer volume</string>
<string lang="en" key="ENTER_HIDDEN_VOL_PASSWORD">Enter password for the hidden volume</string>
@@ -950,8 +952,8 @@
<string lang="en" key="VOL_HEADER_BACKED_UP">Volume header backup has been successfully created.\n\nIMPORTANT: Restoring the volume header using this backup will also restore the current volume password. Moreover, if keyfile(s) are/is necessary to mount the volume, the same keyfile(s) will be necessary to mount the volume again when the volume header is restored.\n\nWARNING: This volume header backup may be used to restore the header ONLY of this particular volume. If you use this header backup to restore a header of a different volume, you will be able to mount the volume, but you will NOT be able to decrypt any data stored in the volume (because you will change its master key).</string>
<string lang="en" key="VOL_HEADER_RESTORED">The volume header has been successfully restored.\n\nIMPORTANT: Please note that an old password may have been restored as well. Moreover, if keyfile(s) were/was necessary to mount the volume when the backup was created, the same keyfile(s) are now necessary to mount the volume again.</string>
<string lang="en" key="EXTERNAL_VOL_HEADER_BAK_FIRST_INFO">For security reasons, you will have to enter the correct password (and/or supply the correct keyfiles) for the volume.\n\nNote: If the volume contains a hidden volume, you will have to enter the correct password (and/or supply the correct keyfiles) for the outer volume first. Afterwards, if you choose to back up the header of the hidden volume, you will have to enter the correct password (and/or supply the correct keyfiles) for the hidden volume.</string>
- <string lang="en" key="CONFIRM_VOL_HEADER_BAK">Are you sure you want to create volume header backup for %hs?\n\nAfter you click Yes, you will prompted for a filename for the header backup.\n\nNote: Both the standard and the hidden volume headers will be re-encrypted using a new salt and stored in the backup file. If there is no hidden volume within this volume, the area reserved for the hidden volume header in the backup file will be filled with random data (to preserve plausible deniability). When restoring a volume header from the backup file, you will need to enter the correct password (and/or to supply the correct keyfiles) that was/were valid when the volume header backup was created. The password (and/or keyfiles) will also automatically determine the type of the volume header to restore, i.e. standard or hidden (note that VeraCrypt determines the type through the process of trial and error).</string>
- <string lang="en" key="CONFIRM_VOL_HEADER_RESTORE">Are you sure you want to restore volume header of %hs?\n\nWARNING: Restoring a volume header also restores the volume password that was valid when the backup was created. Moreover, if keyfile(s) were/was necessary to mount the volume when the backup was created, the same keyfile(s) will be necessary to mount the volume again after the volume header is restored.\n\nAfter you click Yes, you will select the header backup file.</string>
+ <string lang="en" key="CONFIRM_VOL_HEADER_BAK">Are you sure you want to create volume header backup for %s?\n\nAfter you click Yes, you will prompted for a filename for the header backup.\n\nNote: Both the standard and the hidden volume headers will be re-encrypted using a new salt and stored in the backup file. If there is no hidden volume within this volume, the area reserved for the hidden volume header in the backup file will be filled with random data (to preserve plausible deniability). When restoring a volume header from the backup file, you will need to enter the correct password (and/or to supply the correct keyfiles) that was/were valid when the volume header backup was created. The password (and/or keyfiles) will also automatically determine the type of the volume header to restore, i.e. standard or hidden (note that VeraCrypt determines the type through the process of trial and error).</string>
+ <string lang="en" key="CONFIRM_VOL_HEADER_RESTORE">Are you sure you want to restore volume header of %s?\n\nWARNING: Restoring a volume header also restores the volume password that was valid when the backup was created. Moreover, if keyfile(s) were/was necessary to mount the volume when the backup was created, the same keyfile(s) will be necessary to mount the volume again after the volume header is restored.\n\nAfter you click Yes, you will select the header backup file.</string>
<string lang="en" key="DOES_VOLUME_CONTAIN_HIDDEN">Does the volume contain a hidden volume?</string>
<string lang="en" key="VOLUME_CONTAINS_HIDDEN">The volume contains a hidden volume</string>
<string lang="en" key="VOLUME_DOES_NOT_CONTAIN_HIDDEN">The volume does not contain a hidden volume</string>
@@ -963,8 +965,8 @@
<string lang="en" key="BACKUP_HEADER_NOT_FOR_SYS_DEVICE">You are attempting to back up the header of the system partition/drive. This is not allowed. Backup/restore operations pertaining to the system partition/drive can be performed only using the VeraCrypt Rescue Disk.\n\nDo you want to create a VeraCrypt Rescue Disk?</string>
<string lang="en" key="RESTORE_HEADER_NOT_FOR_SYS_DEVICE">You are attempting to restore the header of a virtual VeraCrypt volume but you selected the system partition/drive. This is not allowed. Backup/restore operations pertaining to the system partition/drive can be performed only using the VeraCrypt Rescue Disk.\n\nDo you want to create a VeraCrypt Rescue Disk?</string>
<string lang="en" key="RESCUE_DISK_NON_WIZARD_CREATION_SELECT_PATH">After you click OK, you will select a filename for the new VeraCrypt Rescue Disk ISO image and the location where you wish to place it.</string>
- <string lang="en" key="RESCUE_DISK_NON_WIZARD_CREATION_BURN">The Rescue Disk image has been created and stored in this file:\n%hs\n\nNow you need to burn the Rescue Disk image to a CD or DVD.\n\nIMPORTANT: Note that the file must be written to the CD/DVD as an ISO disk image (not as an individual file). For information on how to do so, please refer to the documentation of your CD/DVD recording software.\n\nAfter you burn the Rescue Disk, select 'System' > 'Verify Rescue Disk' to verify that it has been correctly burned.</string>
- <string lang="en" key="RESCUE_DISK_NON_WIZARD_CREATION_WIN_ISOBURN">The Rescue Disk image has been created and stored in this file:\n%hs\n\nNow you need to burn the Rescue Disk image to a CD or DVD.\n\nDo you want to launch the Microsoft Windows Disc Image Burner now?\n\nNote: After you burn the Rescue Disk, select 'System' > 'Verify Rescue Disk' to verify that it has been correctly burned.</string>
+ <string lang="en" key="RESCUE_DISK_NON_WIZARD_CREATION_BURN">The Rescue Disk image has been created and stored in this file:\n%s\n\nNow you need to burn the Rescue Disk image to a CD or DVD.\n\nIMPORTANT: Note that the file must be written to the CD/DVD as an ISO disk image (not as an individual file). For information on how to do so, please refer to the documentation of your CD/DVD recording software.\n\nAfter you burn the Rescue Disk, select 'System' > 'Verify Rescue Disk' to verify that it has been correctly burned.</string>
+ <string lang="en" key="RESCUE_DISK_NON_WIZARD_CREATION_WIN_ISOBURN">The Rescue Disk image has been created and stored in this file:\n%s\n\nNow you need to burn the Rescue Disk image to a CD or DVD.\n\nDo you want to launch the Microsoft Windows Disc Image Burner now?\n\nNote: After you burn the Rescue Disk, select 'System' > 'Verify Rescue Disk' to verify that it has been correctly burned.</string>
<string lang="en" key="RESCUE_DISK_NON_WIZARD_CHECK_INSERT">Please insert your VeraCrypt Rescue Disk into your CD/DVD drive and click OK to verify it.</string>
<string lang="en" key="RESCUE_DISK_NON_WIZARD_CHECK_PASSED">The VeraCrypt Rescue Disk has been successfully verified.</string>
<string lang="en" key="RESCUE_DISK_NON_WIZARD_CHECK_FAILED">Cannot verify that the Rescue Disk has been correctly burned.\n\nIf you have burned the Rescue Disk, please eject and reinsert the CD/DVD; then try again. If this does not help, please try other CD/DVD recording software and/or medium.\n\nIf you attempted to verify a VeraCrypt Rescue Disk created for a different master key, password, salt, etc., please note that such Rescue Disk will always fail this verification. To create a new Rescue Disk fully compatible with your current configuration, select 'System' > 'Create Rescue Disk'.</string>
@@ -1059,8 +1061,8 @@
<string lang="en" key="NO_SYS_ENC_PROCESS_TO_RESUME">There is no interrupted process of encryption/decryption of the system partition/drive to resume.\n\nNote: If you want to resume an interrupted process of encryption/decryption of a non-system partition/volume, select 'Volumes' &gt; 'Resume Interrupted Process'.</string>
<string lang="en" key="HIDVOL_PROT_BKG_TASK_WARNING">WARNING: VeraCrypt Background Task is disabled. After you exit VeraCrypt, you will not be notified if damage to hidden volume is prevented.\n\nNote: You may shut down the Background Task anytime by right-clicking the VeraCrypt tray icon and selecting 'Exit'.\n\nEnable VeraCrypt Background Task?</string>
<string lang="en" key="LANG_PACK_VERSION">Language pack version: %s</string>
- <string lang="en" key="CHECKING_FS">Checking the file system on the VeraCrypt volume mounted as %hs...</string>
- <string lang="en" key="REPAIRING_FS">Attempting to repair the file system on the VeraCrypt volume mounted as %hs...</string>
+ <string lang="en" key="CHECKING_FS">Checking the file system on the VeraCrypt volume mounted as %s...</string>
+ <string lang="en" key="REPAIRING_FS">Attempting to repair the file system on the VeraCrypt volume mounted as %s...</string>
<string lang="en" key="WARN_64_BIT_BLOCK_CIPHER">Warning: This volume is encrypted with a legacy encryption algorithm.\n\nAll 64-bit-block encryption algorithms (e.g., Blowfish, CAST-128, or Triple DES) are deprecated. It will be possible to mount this volume using future versions of VeraCrypt. However, there will be no further enhancements to the implementations of these legacy encryption algorithms. We recommend that you create a new VeraCrypt volume encrypted with a 128-bit-block encryption algorithm (e.g., AES, Serpent, Twofish, etc.) and that you move all files from this volume to the new volume.</string>
<string lang="en" key="SYS_AUTOMOUNT_DISABLED">Your system is not configured to auto-mount new volumes. It may be impossible to mount device-hosted VeraCrypt volumes. Auto-mounting can be enabled by executing the following command and restarting the system.\n\nmountvol.exe /E</string>
<string lang="en" key="SYS_ASSIGN_DRIVE_LETTER">Please assign a drive letter to the partition/device before proceeding ('Control Panel' > 'System and Maintenance' > 'Administrative Tools' - 'Create and format hard disk partitions').\n\nNote that this is a requirement of the operating system.</string>
@@ -1116,8 +1118,8 @@
<string lang="en" key="KEYB_LAYOUT_SYS_ENC_EXPLANATION">Note: The password will need to be typed in the pre-boot environment (before Windows starts) where non-US Windows keyboard layouts are not available. Therefore, the password must always be typed using the standard US keyboard layout. However, it is important to note that you do NOT need a real US keyboard. VeraCrypt automatically ensures that you can safely type the password (right now and in the pre-boot environment) even if you do NOT have a real US keyboard.</string>
<string lang="en" key="RESCUE_DISK_INFO">Before you can encrypt the partition/drive, you must create a VeraCrypt Rescue Disk (VRD), which serves the following purposes:\n\n- If the VeraCrypt Boot Loader, master key, or other critical data gets damaged, the VRD allows you to restore it (note, however, that you will still have to enter the correct password then).\n\n- If Windows gets damaged and cannot start, the VRD allows you to permanently decrypt the partition/drive before Windows starts.\n\n- The VRD will contain a backup of the present content of the first drive track (which typically contains a system loader or boot manager) and will allow you to restore it if necessary.\n\nThe VeraCrypt Rescue Disk ISO image will be created in the location specified below.</string>
<string lang="en" key="RESCUE_DISK_WIN_ISOBURN_PRELAUNCH_NOTE">After you click OK, Microsoft Windows Disc Image Burner will be launched. Please use it to burn the VeraCrypt Rescue Disk ISO image to a CD or DVD.\n\nAfter you do so, return to the VeraCrypt Volume Creation Wizard and follow its instructions.</string>
- <string lang="en" key="RESCUE_DISK_BURN_INFO">The Rescue Disk image has been created and stored in this file:\n%hs\n\nNow you need to burn it to a CD or DVD.\n\n%lsAfter you burn the Rescue Disk, click Next to verify that it has been correctly burned.</string>
- <string lang="en" key="RESCUE_DISK_BURN_INFO_NO_CHECK">The Rescue Disk image has been created and stored in this file:\n%hs\n\nNow you should either burn the image to a CD/DVD or move it to a safe location for later use.\n\n%lsClick Next to continue.</string>
+ <string lang="en" key="RESCUE_DISK_BURN_INFO">The Rescue Disk image has been created and stored in this file:\n%s\n\nNow you need to burn it to a CD or DVD.\n\n%lsAfter you burn the Rescue Disk, click Next to verify that it has been correctly burned.</string>
+ <string lang="en" key="RESCUE_DISK_BURN_INFO_NO_CHECK">The Rescue Disk image has been created and stored in this file:\n%s\n\nNow you should either burn the image to a CD/DVD or move it to a safe location for later use.\n\n%lsClick Next to continue.</string>
<string lang="en" key="RESCUE_DISK_BURN_INFO_NONWIN_ISO_BURNER">IMPORTANT: Note that the file must be written to the CD/DVD as an ISO disk image (not as an individual file). For information on how to do so, please refer to the documentation of your CD/DVD recording software. If you do not have any CD/DVD recording software that can write the ISO disk image to a CD/DVD, click the link below to download such free software.\n\n</string>
<string lang="en" key="LAUNCH_WIN_ISOBURN">Launch Microsoft Windows Disc Image Burner</string>
<string lang="en" key="RESCUE_DISK_BURN_NO_CHECK_WARN">WARNING: If you already created a VeraCrypt Rescue Disk in the past, it cannot be reused for this system partition/drive because it was created for a different master key! Every time you encrypt a system partition/drive, you must create a new VeraCrypt Rescue Disk for it even if you use the same password.</string>
diff --git a/src/Common/Password.c b/src/Common/Password.c
index 8b44e7d5..e22e71ab 100644
--- a/src/Common/Password.c
+++ b/src/Common/Password.c
@@ -33,17 +33,25 @@ void VerifyPasswordAndUpdate (HWND hwndDlg, HWND hButton, HWND hPassword,
char *szVerify,
BOOL keyFilesEnabled)
{
- char szTmp1[MAX_PASSWORD + 1];
- char szTmp2[MAX_PASSWORD + 1];
+ wchar_t szTmp1[MAX_PASSWORD + 1];
+ wchar_t szTmp2[MAX_PASSWORD + 1];
+ char szTmp1Utf8[MAX_PASSWORD + 1];
+ char szTmp2Utf8[MAX_PASSWORD + 1];
int k = GetWindowTextLength (hPassword);
BOOL bEnable = FALSE;
+ int utf8Len1, utf8Len2;
UNREFERENCED_PARAMETER (hwndDlg); /* Remove warning */
GetWindowText (hPassword, szTmp1, sizeof (szTmp1));
GetWindowText (hVerify, szTmp2, sizeof (szTmp2));
- if (strcmp (szTmp1, szTmp2) != 0)
+ utf8Len1 = WideCharToMultiByte (CP_UTF8, 0, szTmp1, -1, szTmp1Utf8, MAX_PASSWORD + 1, NULL, NULL);
+ utf8Len2 = WideCharToMultiByte (CP_UTF8, 0, szTmp2, -1, szTmp2Utf8, MAX_PASSWORD + 1, NULL, NULL);
+
+ if (wcscmp (szTmp1, szTmp2) != 0)
+ bEnable = FALSE;
+ else if (utf8Len1 <= 0)
bEnable = FALSE;
else
{
@@ -54,13 +62,25 @@ void VerifyPasswordAndUpdate (HWND hwndDlg, HWND hButton, HWND hPassword,
}
if (szPassword != NULL)
- memcpy (szPassword, szTmp1, sizeof (szTmp1));
+ {
+ if (utf8Len1 > 0)
+ memcpy (szPassword, szTmp1Utf8, sizeof (szTmp1Utf8));
+ else
+ szPassword [0] = 0;
+ }
if (szVerify != NULL)
- memcpy (szVerify, szTmp2, sizeof (szTmp2));
+ {
+ if (utf8Len2 > 0)
+ memcpy (szVerify, szTmp2Utf8, sizeof (szTmp2Utf8));
+ else
+ szVerify [0] = 0;
+ }
burn (szTmp1, sizeof (szTmp1));
burn (szTmp2, sizeof (szTmp2));
+ burn (szTmp1Utf8, sizeof (szTmp1Utf8));
+ burn (szTmp2Utf8, sizeof (szTmp2Utf8));
EnableWindow (hButton, bEnable);
}
@@ -146,11 +166,11 @@ BOOL CheckPasswordLength (HWND hwndDlg, unsigned __int32 passwordLength, int pim
return TRUE;
}
-int ChangePwd (const char *lpszVolume, Password *oldPassword, int old_pkcs5, int old_pim, BOOL truecryptMode, Password *newPassword, int pkcs5, int pim, int wipePassCount, HWND hwndDlg)
+int ChangePwd (const wchar_t *lpszVolume, Password *oldPassword, int old_pkcs5, int old_pim, BOOL truecryptMode, Password *newPassword, int pkcs5, int pim, int wipePassCount, HWND hwndDlg)
{
int nDosLinkCreated = 1, nStatus = ERR_OS_ERROR;
- char szDiskFile[TC_MAX_PATH], szCFDevice[TC_MAX_PATH];
- char szDosDevice[TC_MAX_PATH];
+ wchar_t szDiskFile[TC_MAX_PATH], szCFDevice[TC_MAX_PATH];
+ wchar_t szDosDevice[TC_MAX_PATH];
char buffer[TC_VOLUME_HEADER_EFFECTIVE_SIZE];
PCRYPTO_INFO cryptoInfo = NULL, ci = NULL;
void *dev = INVALID_HANDLE_VALUE;
@@ -190,7 +210,7 @@ int ChangePwd (const char *lpszVolume, Password *oldPassword, int old_pkcs5, int
if (bDevice == FALSE)
{
- strcpy (szCFDevice, szDiskFile);
+ wcscpy (szCFDevice, szDiskFile);
}
else
{
diff --git a/src/Common/Password.h b/src/Common/Password.h
index 6523e88d..5d8b79e9 100644
--- a/src/Common/Password.h
+++ b/src/Common/Password.h
@@ -40,7 +40,7 @@ typedef struct
void VerifyPasswordAndUpdate ( HWND hwndDlg , HWND hButton , HWND hPassword , HWND hVerify , unsigned char *szPassword , char *szVerify, BOOL keyFilesEnabled );
BOOL CheckPasswordLength (HWND hwndDlg, unsigned __int32 passwordLength, int pim, BOOL bForBoot, BOOL bSkipPasswordWarning, BOOL bSkipPimWarning);
BOOL CheckPasswordCharEncoding (HWND hPassword, Password *ptrPw);
-int ChangePwd (const char *lpszVolume, Password *oldPassword, int old_pkcs5, int old_pim, BOOL truecryptMode, Password *newPassword, int pkcs5, int pim, int wipePassCount, HWND hwndDlg);
+int ChangePwd (const wchar_t *lpszVolume, Password *oldPassword, int old_pkcs5, int old_pim, BOOL truecryptMode, Password *newPassword, int pkcs5, int pim, int wipePassCount, HWND hwndDlg);
#endif // defined(_WIN32) && !defined(TC_WINDOWS_DRIVER)
diff --git a/src/Common/Pkcs5.c b/src/Common/Pkcs5.c
index e7859ccb..d1bc6027 100644
--- a/src/Common/Pkcs5.c
+++ b/src/Common/Pkcs5.c
@@ -736,24 +736,24 @@ void derive_key_whirlpool (char *pwd, int pwd_len, char *salt, int salt_len, uin
}
-char *get_pkcs5_prf_name (int pkcs5_prf_id)
+wchar_t *get_pkcs5_prf_name (int pkcs5_prf_id)
{
switch (pkcs5_prf_id)
{
case SHA512:
- return "HMAC-SHA-512";
+ return L"HMAC-SHA-512";
case SHA256:
- return "HMAC-SHA-256";
+ return L"HMAC-SHA-256";
case RIPEMD160:
- return "HMAC-RIPEMD-160";
+ return L"HMAC-RIPEMD-160";
case WHIRLPOOL:
- return "HMAC-Whirlpool";
+ return L"HMAC-Whirlpool";
default:
- return "(Unknown)";
+ return L"(Unknown)";
}
}
diff --git a/src/Common/Pkcs5.h b/src/Common/Pkcs5.h
index e9c9ee02..ab42a4b7 100644
--- a/src/Common/Pkcs5.h
+++ b/src/Common/Pkcs5.h
@@ -20,24 +20,26 @@
extern "C"
{
#endif
+/* output written to input_digest which must be at lease 20 bytes long */
+void hmac_ripemd160 (char *key, int keylen, char *input_digest, int len);
+void derive_key_ripemd160 (char *pwd, int pwd_len, char *salt, int salt_len, uint32 iterations, char *dk, int dklen);
+
/* output written to d which must be at lease 32 bytes long */
void hmac_sha256 (char *k, int lk, char *d, int ld);
void derive_key_sha256 (char *pwd, int pwd_len, char *salt, int salt_len, uint32 iterations, char *dk, int dklen);
+#ifndef TC_WINDOWS_BOOT
/* output written to d which must be at lease 64 bytes long */
void hmac_sha512 (char *k, int lk, char *d, int ld);
void derive_key_sha512 (char *pwd, int pwd_len, char *salt, int salt_len, uint32 iterations, char *dk, int dklen);
-/* output written to input_digest which must be at lease 20 bytes long */
-void hmac_ripemd160 (char *key, int keylen, char *input_digest, int len);
-void derive_key_ripemd160 (char *pwd, int pwd_len, char *salt, int salt_len, uint32 iterations, char *dk, int dklen);
-
/* output written to d which must be at lease 64 bytes long */
void hmac_whirlpool (char *k, int lk, char *d, int ld);
void derive_key_whirlpool (char *pwd, int pwd_len, char *salt, int salt_len, uint32 iterations, char *dk, int dklen);
int get_pkcs5_iteration_count (int pkcs5_prf_id, int pim, BOOL truecryptMode, BOOL bBoot);
-char *get_pkcs5_prf_name (int pkcs5_prf_id);
+wchar_t *get_pkcs5_prf_name (int pkcs5_prf_id);
+#endif
#if defined(__cplusplus)
}
diff --git a/src/Common/Random.c b/src/Common/Random.c
index f3f94899..84c10e66 100644
--- a/src/Common/Random.c
+++ b/src/Common/Random.c
@@ -631,17 +631,17 @@ BOOL SlowPoll (void)
HKEY hKey;
if (RegOpenKeyEx (HKEY_LOCAL_MACHINE,
- "SYSTEM\\CurrentControlSet\\Control\\ProductOptions",
+ L"SYSTEM\\CurrentControlSet\\Control\\ProductOptions",
0, KEY_READ, &hKey) == ERROR_SUCCESS)
{
- unsigned char szValue[32];
+ wchar_t szValue[32];
dwSize = sizeof (szValue);
isWorkstation = TRUE;
- status = RegQueryValueEx (hKey, "ProductType", 0, NULL,
- szValue, &dwSize);
+ status = RegQueryValueEx (hKey, L"ProductType", 0, NULL,
+ (LPBYTE) szValue, &dwSize);
- if (status == ERROR_SUCCESS && _stricmp ((char *) szValue, "WinNT"))
+ if (status == ERROR_SUCCESS && _wcsicmp (szValue, L"WinNT"))
/* Note: There are (at least) three cases for
ProductType: WinNT = NT Workstation,
ServerNT = NT Server, LanmanNT = NT Server
@@ -656,13 +656,13 @@ BOOL SlowPoll (void)
{
/* Obtain a handle to the module containing the Lan Manager
functions */
- char dllPath[MAX_PATH];
+ wchar_t dllPath[MAX_PATH];
if (GetSystemDirectory (dllPath, MAX_PATH))
{
- StringCbCatA(dllPath, sizeof(dllPath), "\\NETAPI32.DLL");
+ StringCbCatW(dllPath, sizeof(dllPath), L"\\NETAPI32.DLL");
}
else
- StringCbCopyA(dllPath, sizeof(dllPath), "C:\\Windows\\System32\\NETAPI32.DLL");
+ StringCbCopyW(dllPath, sizeof(dllPath), L"C:\\Windows\\System32\\NETAPI32.DLL");
hNetAPI32 = LoadLibrary (dllPath);
if (hNetAPI32 != NULL)
@@ -710,10 +710,10 @@ BOOL SlowPoll (void)
for (nDrive = 0;; nDrive++)
{
DISK_PERFORMANCE diskPerformance;
- char szDevice[24];
+ wchar_t szDevice[24];
/* Check whether we can access this device */
- StringCbPrintfA (szDevice, sizeof(szDevice), "\\\\.\\PhysicalDrive%d", nDrive);
+ StringCbPrintfW (szDevice, sizeof(szDevice), L"\\\\.\\PhysicalDrive%d", nDrive);
hDevice = CreateFile (szDevice, 0, FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, NULL);
if (hDevice == INVALID_HANDLE_VALUE)
diff --git a/src/Common/Registry.c b/src/Common/Registry.c
index 42162906..f66e4f0d 100644
--- a/src/Common/Registry.c
+++ b/src/Common/Registry.c
@@ -14,7 +14,7 @@
#include "Registry.h"
#include <Strsafe.h>
-BOOL ReadLocalMachineRegistryDword (char *subKey, char *name, DWORD *value)
+BOOL ReadLocalMachineRegistryDword (wchar_t *subKey, wchar_t *name, DWORD *value)
{
HKEY hkey = 0;
DWORD size = sizeof (*value);
@@ -33,7 +33,7 @@ BOOL ReadLocalMachineRegistryDword (char *subKey, char *name, DWORD *value)
return type == REG_DWORD;
}
-BOOL ReadLocalMachineRegistryMultiString (char *subKey, char *name, char *value, DWORD *size)
+BOOL ReadLocalMachineRegistryMultiString (wchar_t *subKey, wchar_t *name, wchar_t *value, DWORD *size)
{
HKEY hkey = 0;
DWORD type;
@@ -51,7 +51,7 @@ BOOL ReadLocalMachineRegistryMultiString (char *subKey, char *name, char *value,
return type == REG_MULTI_SZ;
}
-BOOL ReadLocalMachineRegistryString (const char *subKey, char *name, char *str, DWORD *size)
+BOOL ReadLocalMachineRegistryString (const wchar_t *subKey, wchar_t *name, wchar_t *str, DWORD *size)
{
HKEY hkey = 0;
DWORD type;
@@ -69,7 +69,7 @@ BOOL ReadLocalMachineRegistryString (const char *subKey, char *name, char *str,
return type == REG_SZ;
}
-BOOL ReadLocalMachineRegistryStringNonReflected (const char *subKey, char *name, char *str, DWORD *size, BOOL b32bitApp)
+BOOL ReadLocalMachineRegistryStringNonReflected (const wchar_t *subKey, wchar_t *name, wchar_t *str, DWORD *size, BOOL b32bitApp)
{
HKEY hkey = 0;
DWORD type;
@@ -87,7 +87,7 @@ BOOL ReadLocalMachineRegistryStringNonReflected (const char *subKey, char *name,
return type == REG_SZ;
}
-int ReadRegistryInt (char *subKey, char *name, int defaultValue)
+int ReadRegistryInt (wchar_t *subKey, wchar_t *name, int defaultValue)
{
HKEY hkey = 0;
DWORD value, size = sizeof (DWORD);
@@ -103,27 +103,27 @@ int ReadRegistryInt (char *subKey, char *name, int defaultValue)
return value;
}
-char *ReadRegistryString (char *subKey, char *name, char *defaultValue, char *str, int maxLen)
+wchar_t *ReadRegistryString (wchar_t *subKey, wchar_t *name, wchar_t *defaultValue, wchar_t *str, int maxLen)
{
HKEY hkey = 0;
- char value[MAX_PATH*4];
+ wchar_t value[MAX_PATH*4];
DWORD size = sizeof (value);
- str[maxLen-1] = 0;
- StringCbCopyA (str, maxLen, defaultValue);
+ str[maxLen/2-1] = 0;
+ StringCbCopyW (str, maxLen, defaultValue);
ZeroMemory (value, sizeof value);
if (RegOpenKeyEx (HKEY_CURRENT_USER, subKey,
0, KEY_READ, &hkey) == ERROR_SUCCESS)
if (RegQueryValueEx (hkey, name, 0, 0, (LPBYTE) value, &size) == ERROR_SUCCESS)
- StringCbCopyA (str, maxLen,value);
+ StringCbCopyW (str, maxLen,value);
if (hkey)
RegCloseKey (hkey);
return str;
}
-DWORD ReadRegistryBytes (char *path, char *name, char *value, int maxLen)
+DWORD ReadRegistryBytes (wchar_t *path, wchar_t *name, char *value, int maxLen)
{
HKEY hkey = 0;
DWORD size = maxLen;
@@ -138,7 +138,7 @@ DWORD ReadRegistryBytes (char *path, char *name, char *value, int maxLen)
return success ? size : 0;
}
-void WriteRegistryInt (char *subKey, char *name, int value)
+void WriteRegistryInt (wchar_t *subKey, wchar_t *name, int value)
{
HKEY hkey = 0;
DWORD disp;
@@ -151,7 +151,7 @@ void WriteRegistryInt (char *subKey, char *name, int value)
RegCloseKey (hkey);
}
-BOOL WriteLocalMachineRegistryDword (char *subKey, char *name, DWORD value)
+BOOL WriteLocalMachineRegistryDword (wchar_t *subKey, wchar_t *name, DWORD value)
{
HKEY hkey = 0;
DWORD disp;
@@ -175,31 +175,7 @@ BOOL WriteLocalMachineRegistryDword (char *subKey, char *name, DWORD value)
return TRUE;
}
-BOOL WriteLocalMachineRegistryDwordW (WCHAR *subKey, WCHAR *name, DWORD value)
-{
- HKEY hkey = 0;
- DWORD disp;
- LONG status;
-
- if ((status = RegCreateKeyExW (HKEY_LOCAL_MACHINE, subKey,
- 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &disp)) != ERROR_SUCCESS)
- {
- SetLastError (status);
- return FALSE;
- }
-
- if ((status = RegSetValueExW (hkey, name, 0, REG_DWORD, (BYTE *) &value, sizeof value)) != ERROR_SUCCESS)
- {
- RegCloseKey (hkey);
- SetLastError (status);
- return FALSE;
- }
-
- RegCloseKey (hkey);
- return TRUE;
-}
-
-BOOL WriteLocalMachineRegistryMultiString (char *subKey, char *name, char *multiString, DWORD size)
+BOOL WriteLocalMachineRegistryMultiString (wchar_t *subKey, wchar_t *name, wchar_t *multiString, DWORD size)
{
HKEY hkey = 0;
DWORD disp;
@@ -223,7 +199,7 @@ BOOL WriteLocalMachineRegistryMultiString (char *subKey, char *name, char *multi
return TRUE;
}
-BOOL WriteLocalMachineRegistryString (char *subKey, char *name, char *str, BOOL expandable)
+BOOL WriteLocalMachineRegistryString (wchar_t *subKey, wchar_t *name, wchar_t *str, BOOL expandable)
{
HKEY hkey = 0;
DWORD disp;
@@ -236,7 +212,7 @@ BOOL WriteLocalMachineRegistryString (char *subKey, char *name, char *str, BOOL
return FALSE;
}
- if ((status = RegSetValueEx (hkey, name, 0, expandable ? REG_EXPAND_SZ : REG_SZ, (BYTE *) str, (DWORD) strlen (str) + 1)) != ERROR_SUCCESS)
+ if ((status = RegSetValueEx (hkey, name, 0, expandable ? REG_EXPAND_SZ : REG_SZ, (BYTE *) str, (DWORD) (wcslen (str) + 1) * sizeof (wchar_t))) != ERROR_SUCCESS)
{
RegCloseKey (hkey);
SetLastError (status);
@@ -247,7 +223,7 @@ BOOL WriteLocalMachineRegistryString (char *subKey, char *name, char *str, BOOL
return TRUE;
}
-void WriteRegistryString (char *subKey, char *name, char *str)
+void WriteRegistryString (wchar_t *subKey, wchar_t *name, wchar_t *str)
{
HKEY hkey = 0;
DWORD disp;
@@ -256,11 +232,11 @@ void WriteRegistryString (char *subKey, char *name, char *str)
0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &disp) != ERROR_SUCCESS)
return;
- RegSetValueEx (hkey, name, 0, REG_SZ, (BYTE *) str, (DWORD) strlen (str) + 1);
+ RegSetValueEx (hkey, name, 0, REG_SZ, (BYTE *) str, (DWORD) (wcslen (str) + 1) * sizeof (wchar_t));
RegCloseKey (hkey);
}
-BOOL WriteRegistryBytes (char *path, char *name, char *str, DWORD size)
+BOOL WriteRegistryBytes (wchar_t *path, wchar_t *name, char *str, DWORD size)
{
HKEY hkey = 0;
DWORD disp;
@@ -275,7 +251,7 @@ BOOL WriteRegistryBytes (char *path, char *name, char *str, DWORD size)
return res == ERROR_SUCCESS;
}
-BOOL DeleteLocalMachineRegistryKey (char *parentKey, char *subKeyToDelete)
+BOOL DeleteLocalMachineRegistryKey (wchar_t *parentKey, wchar_t *subKeyToDelete)
{
LONG status;
HKEY hkey = 0;
@@ -297,7 +273,7 @@ BOOL DeleteLocalMachineRegistryKey (char *parentKey, char *subKeyToDelete)
return TRUE;
}
-void DeleteRegistryValue (char *subKey, char *name)
+void DeleteRegistryValue (wchar_t *subKey, wchar_t *name)
{
HKEY hkey = 0;
@@ -309,16 +285,16 @@ void DeleteRegistryValue (char *subKey, char *name)
}
-void GetStartupRegKeyName (char *regk, size_t cbRegk)
+void GetStartupRegKeyName (wchar_t *regk, size_t cbRegk)
{
// The string is split in order to prevent some antivirus packages from falsely reporting
// VeraCrypt.exe to contain a possible Trojan horse because of this string (heuristic scan).
- StringCbPrintfA (regk, cbRegk,"%s%s", "Software\\Microsoft\\Windows\\Curren", "tVersion\\Run");
+ StringCbPrintfW (regk, cbRegk,L"%s%s", L"Software\\Microsoft\\Windows\\Curren", L"tVersion\\Run");
}
-void GetRestorePointRegKeyName (char *regk, size_t cbRegk)
+void GetRestorePointRegKeyName (wchar_t *regk, size_t cbRegk)
{
// The string is split in order to prevent some antivirus packages from falsely reporting
// VeraCrypt.exe to contain a possible Trojan horse because of this string (heuristic scan).
- StringCbPrintfA (regk, cbRegk,"%s%s%s%s", "Software\\Microsoft\\Windows", " NT\\Curren", "tVersion\\Sy", "stemRestore");
+ StringCbPrintfW (regk, cbRegk,L"%s%s%s%s", L"Software\\Microsoft\\Windows", L" NT\\Curren", L"tVersion\\Sy", L"stemRestore");
} \ No newline at end of file
diff --git a/src/Common/Registry.h b/src/Common/Registry.h
index 99396771..c485ac05 100644
--- a/src/Common/Registry.h
+++ b/src/Common/Registry.h
@@ -14,24 +14,23 @@
extern "C" {
#endif
-BOOL ReadLocalMachineRegistryDword (char *subKey, char *name, DWORD *value);
-BOOL ReadLocalMachineRegistryMultiString (char *subKey, char *name, char *value, DWORD *size);
-BOOL ReadLocalMachineRegistryString (const char *subKey, char *name, char *value, DWORD *size);
-BOOL ReadLocalMachineRegistryStringNonReflected (const char *subKey, char *name, char *str, DWORD *size, BOOL b32bitApp);
-int ReadRegistryInt (char *subKey, char *name, int defaultValue);
-char *ReadRegistryString (char *subKey, char *name, char *defaultValue, char *str, int maxLen);
-DWORD ReadRegistryBytes (char *path, char *name, char *value, int maxLen);
-void WriteRegistryInt (char *subKey, char *name, int value);
-BOOL WriteLocalMachineRegistryDword (char *subKey, char *name, DWORD value);
-BOOL WriteLocalMachineRegistryDwordW (WCHAR *subKey, WCHAR *name, DWORD value);
-BOOL WriteLocalMachineRegistryMultiString (char *subKey, char *name, char *multiString, DWORD size);
-BOOL WriteLocalMachineRegistryString (char *subKey, char *name, char *str, BOOL expandable);
-void WriteRegistryString (char *subKey, char *name, char *str);
-BOOL WriteRegistryBytes (char *path, char *name, char *str, DWORD size);
-BOOL DeleteLocalMachineRegistryKey (char *parentKey, char *subKeyToDelete);
-void DeleteRegistryValue (char *subKey, char *name);
-void GetStartupRegKeyName (char *regk, size_t cbRegk);
-void GetRestorePointRegKeyName (char *regk, size_t cbRegk);
+BOOL ReadLocalMachineRegistryDword (wchar_t *subKey, wchar_t *name, DWORD *value);
+BOOL ReadLocalMachineRegistryMultiString (wchar_t *subKey, wchar_t *name, wchar_t *value, DWORD *size);
+BOOL ReadLocalMachineRegistryString (const wchar_t *subKey, wchar_t *name, wchar_t *value, DWORD *size);
+BOOL ReadLocalMachineRegistryStringNonReflected (const wchar_t *subKey, wchar_t *name, wchar_t *str, DWORD *size, BOOL b32bitApp);
+int ReadRegistryInt (wchar_t *subKey, wchar_t *name, int defaultValue);
+wchar_t *ReadRegistryString (wchar_t *subKey, wchar_t *name, wchar_t *defaultValue, wchar_t *str, int maxLen);
+DWORD ReadRegistryBytes (wchar_t *path, wchar_t *name, char *value, int maxLen);
+void WriteRegistryInt (wchar_t *subKey, wchar_t *name, int value);
+BOOL WriteLocalMachineRegistryDword (wchar_t *subKey, wchar_t *name, DWORD value);
+BOOL WriteLocalMachineRegistryMultiString (wchar_t *subKey, wchar_t *name, wchar_t *multiString, DWORD size);
+BOOL WriteLocalMachineRegistryString (wchar_t *subKey, wchar_t *name, wchar_t *str, BOOL expandable);
+void WriteRegistryString (wchar_t *subKey, wchar_t *name, wchar_t *str);
+BOOL WriteRegistryBytes (wchar_t *path, wchar_t *name, char *str, DWORD size);
+BOOL DeleteLocalMachineRegistryKey (wchar_t *parentKey, wchar_t *subKeyToDelete);
+void DeleteRegistryValue (wchar_t *subKey, wchar_t *name);
+void GetStartupRegKeyName (wchar_t *regk, size_t cbRegk);
+void GetRestorePointRegKeyName (wchar_t *regk, size_t cbRegk);
#ifdef __cplusplus
}
diff --git a/src/Common/SecurityToken.cpp b/src/Common/SecurityToken.cpp
index 4d2e9c63..d7dacf57 100644
--- a/src/Common/SecurityToken.cpp
+++ b/src/Common/SecurityToken.cpp
@@ -47,7 +47,7 @@ namespace VeraCrypt
SlotId = slotId;
size_t keyIdPos = pathStr.find (L"/" TC_SECURITY_TOKEN_KEYFILE_URL_FILE L"/");
- if (keyIdPos == string::npos)
+ if (keyIdPos == wstring::npos)
throw InvalidSecurityTokenKeyfilePath();
Id = pathStr.substr (keyIdPos + wstring (L"/" TC_SECURITY_TOKEN_KEYFILE_URL_FILE L"/").size());
@@ -510,13 +510,17 @@ namespace VeraCrypt
}
}
+#ifdef TC_WINDOWS
+ void SecurityToken::InitLibrary (const wstring &pkcs11LibraryPath, auto_ptr <GetPinFunctor> pinCallback, auto_ptr <SendExceptionFunctor> warningCallback)
+#else
void SecurityToken::InitLibrary (const string &pkcs11LibraryPath, auto_ptr <GetPinFunctor> pinCallback, auto_ptr <SendExceptionFunctor> warningCallback)
+#endif
{
if (Initialized)
CloseLibrary();
#ifdef TC_WINDOWS
- Pkcs11LibraryHandle = LoadLibraryA (pkcs11LibraryPath.c_str());
+ Pkcs11LibraryHandle = LoadLibraryW (pkcs11LibraryPath.c_str());
#else
Pkcs11LibraryHandle = dlopen (pkcs11LibraryPath.c_str(), RTLD_NOW | RTLD_LOCAL);
#endif
diff --git a/src/Common/SecurityToken.h b/src/Common/SecurityToken.h
index ba680c4a..53292c9f 100644
--- a/src/Common/SecurityToken.h
+++ b/src/Common/SecurityToken.h
@@ -189,7 +189,11 @@ namespace VeraCrypt
static void GetKeyfileData (const SecurityTokenKeyfile &keyfile, vector <byte> &keyfileData);
static list <SecurityTokenInfo> GetAvailableTokens ();
static SecurityTokenInfo GetTokenInfo (CK_SLOT_ID slotId);
+#ifdef TC_WINDOWS
+ static void InitLibrary (const wstring &pkcs11LibraryPath, auto_ptr <GetPinFunctor> pinCallback, auto_ptr <SendExceptionFunctor> warningCallback);
+#else
static void InitLibrary (const string &pkcs11LibraryPath, auto_ptr <GetPinFunctor> pinCallback, auto_ptr <SendExceptionFunctor> warningCallback);
+#endif
static bool IsInitialized () { return Initialized; }
static bool IsKeyfilePathValid (const wstring &securityTokenKeyfilePath);
diff --git a/src/Common/Tcdefs.h b/src/Common/Tcdefs.h
index bef6beef..5725c135 100644
--- a/src/Common/Tcdefs.h
+++ b/src/Common/Tcdefs.h
@@ -175,6 +175,7 @@ typedef int BOOL;
#include <process.h> /* Process control */
#include <winioctl.h>
#include <stdio.h> /* For sprintf */
+#include <tchar.h>
#endif /* _WIN32 */
@@ -254,7 +255,7 @@ void EraseMemory (void *memory, int size);
#define TC_MAX_PATH 260 /* Includes the null terminator */
#endif
-#define TC_STR_RELEASED_BY "Released by IDRIX on " TC_STR_RELEASE_DATE
+#define TC_STR_RELEASED_BY L"Released by IDRIX on " TC_STR_RELEASE_DATE
#define MAX_URL_LENGTH 2084 /* Internet Explorer limit. Includes the terminating null character. */
diff --git a/src/Common/Tests.c b/src/Common/Tests.c
index ff536e20..3d1f6d8c 100644
--- a/src/Common/Tests.c
+++ b/src/Common/Tests.c
@@ -265,7 +265,7 @@ BOOL XTSAesTest (PCRYPTO_INFO ci)
for (i = 0; i < XTS_TEST_COUNT; i++)
{
- ci->ea = EAGetByName ("AES");
+ ci->ea = EAGetByName (L"AES");
if (ci->ea == 0)
return FALSE;
@@ -476,7 +476,7 @@ BOOL TestSectorBufEncryption (PCRYPTO_INFO ci)
{
unsigned char buf [ENCRYPTION_DATA_UNIT_SIZE * 4];
unsigned int i;
- char name[64];
+ wchar_t name[64];
unsigned __int32 crc;
UINT64_STRUCT unitNo;
uint32 nbrUnits;
@@ -538,7 +538,7 @@ BOOL TestSectorBufEncryption (PCRYPTO_INFO ci)
crc = GetCrc32 (buf, sizeof (buf));
- if (strcmp (name, "AES") == 0)
+ if (wcscmp (name, L"AES") == 0)
{
// Verify the ciphertext of the "moving" data unit using the IEEE test vector #14
if (memcmp (XTS_vectors[XTS_TEST_COUNT-1].ciphertext,
@@ -573,7 +573,7 @@ BOOL TestSectorBufEncryption (PCRYPTO_INFO ci)
break;
}
}
- else if (strcmp (name, "Serpent") == 0)
+ else if (wcscmp (name, L"Serpent") == 0)
{
switch (testCase)
{
@@ -599,7 +599,7 @@ BOOL TestSectorBufEncryption (PCRYPTO_INFO ci)
break;
}
}
- else if (strcmp (name, "Twofish") == 0)
+ else if (wcscmp (name, L"Twofish") == 0)
{
switch (testCase)
{
@@ -625,7 +625,7 @@ BOOL TestSectorBufEncryption (PCRYPTO_INFO ci)
break;
}
}
- else if (strcmp (name, "AES-Twofish") == 0)
+ else if (wcscmp (name, L"AES-Twofish") == 0)
{
switch (testCase)
{
@@ -651,7 +651,7 @@ BOOL TestSectorBufEncryption (PCRYPTO_INFO ci)
break;
}
}
- else if (strcmp (name, "AES-Twofish-Serpent") == 0)
+ else if (wcscmp (name, L"AES-Twofish-Serpent") == 0)
{
switch (testCase)
{
@@ -677,7 +677,7 @@ BOOL TestSectorBufEncryption (PCRYPTO_INFO ci)
break;
}
}
- else if (strcmp (name, "Serpent-AES") == 0)
+ else if (wcscmp (name, L"Serpent-AES") == 0)
{
switch (testCase)
{
@@ -703,7 +703,7 @@ BOOL TestSectorBufEncryption (PCRYPTO_INFO ci)
break;
}
}
- else if (strcmp (name, "Serpent-Twofish-AES") == 0)
+ else if (wcscmp (name, L"Serpent-Twofish-AES") == 0)
{
switch (testCase)
{
@@ -729,7 +729,7 @@ BOOL TestSectorBufEncryption (PCRYPTO_INFO ci)
break;
}
}
- else if (strcmp (name, "Twofish-Serpent") == 0)
+ else if (wcscmp (name, L"Twofish-Serpent") == 0)
{
switch (testCase)
{
@@ -801,49 +801,49 @@ BOOL TestSectorBufEncryption (PCRYPTO_INFO ci)
crc = GetCrc32 (buf, sizeof (buf));
- if (strcmp (name, "AES") == 0)
+ if (wcscmp (name, L"AES") == 0)
{
if (crc != 0x33b91fab)
return FALSE;
nTestsPerformed++;
}
- else if (strcmp (name, "Serpent") == 0)
+ else if (wcscmp (name, L"Serpent") == 0)
{
if (crc != 0x3494d480)
return FALSE;
nTestsPerformed++;
}
- else if (strcmp (name, "Twofish") == 0)
+ else if (wcscmp (name, L"Twofish") == 0)
{
if (crc != 0xc4d65b46)
return FALSE;
nTestsPerformed++;
}
- else if (strcmp (name, "AES-Twofish") == 0)
+ else if (wcscmp (name, L"AES-Twofish") == 0)
{
if (crc != 0x14ce7385)
return FALSE;
nTestsPerformed++;
}
- else if (strcmp (name, "AES-Twofish-Serpent") == 0)
+ else if (wcscmp (name, L"AES-Twofish-Serpent") == 0)
{
if (crc != 0x0ec81bf7)
return FALSE;
nTestsPerformed++;
}
- else if (strcmp (name, "Serpent-AES") == 0)
+ else if (wcscmp (name, L"Serpent-AES") == 0)
{
if (crc != 0x42f919ad)
return FALSE;
nTestsPerformed++;
}
- else if (strcmp (name, "Serpent-Twofish-AES") == 0)
+ else if (wcscmp (name, L"Serpent-Twofish-AES") == 0)
{
if (crc != 0x208d5c58)
return FALSE;
nTestsPerformed++;
}
- else if (strcmp (name, "Twofish-Serpent") == 0)
+ else if (wcscmp (name, L"Twofish-Serpent") == 0)
{
if (crc != 0xbe78cec1)
return FALSE;
diff --git a/src/Common/Xml.c b/src/Common/Xml.c
index bd01460b..71994510 100644
--- a/src/Common/Xml.c
+++ b/src/Common/Xml.c
@@ -210,26 +210,59 @@ char *XmlQuoteText (const char *textSrc, char *textDst, int textDstMaxSize)
return textDst;
}
-
-int XmlWriteHeader (FILE *file)
+wchar_t *XmlQuoteTextW (const wchar_t *textSrc, wchar_t *textDst, int textDstMaxSize)
{
- return fputs ("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<VeraCrypt>", file);
-}
+ wchar_t *textDstLast = textDst + textDstMaxSize - 1;
+ if (textDstMaxSize == 0)
+ return NULL;
-int XmlWriteHeaderW (FILE *file)
-{
- return fputws (L"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<VeraCrypt>", file);
+ while (*textSrc != 0 && textDst <= textDstLast)
+ {
+ wchar_t c = *textSrc++;
+ switch (c)
+ {
+ case L'&':
+ if (textDst + 6 > textDstLast)
+ return NULL;
+ wcscpy (textDst, L"&amp;");
+ textDst += 5;
+ continue;
+
+ case L'>':
+ if (textDst + 5 > textDstLast)
+ return NULL;
+ wcscpy (textDst, L"&gt;");
+ textDst += 4;
+ continue;
+
+ case L'<':
+ if (textDst + 5 > textDstLast)
+ return NULL;
+ wcscpy (textDst, L"&lt;");
+ textDst += 4;
+ continue;
+
+ default:
+ *textDst++ = c;
+ }
+ }
+
+ if (textDst > textDstLast)
+ return NULL;
+
+ *textDst = 0;
+ return textDst;
}
-int XmlWriteFooter (FILE *file)
+int XmlWriteHeader (FILE *file)
{
- return fputs ("\n</VeraCrypt>", file);
+ return fputws (L"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<VeraCrypt>", file);
}
-int XmlWriteFooterW (FILE *file)
+int XmlWriteFooter (FILE *file)
{
return fputws (L"\n</VeraCrypt>", file);
}
diff --git a/src/Common/Xml.h b/src/Common/Xml.h
index eef5015e..02eb69b0 100644
--- a/src/Common/Xml.h
+++ b/src/Common/Xml.h
@@ -19,11 +19,10 @@ char *XmlFindElement (char *xmlNode, char *nodeName);
char *XmlGetAttributeText (char *xmlNode, char *xmlAttrName, char *xmlAttrValue, int xmlAttrValueSize);
char *XmlGetNodeText (char *xmlNode, char *xmlText, int xmlTextSize);
int XmlWriteHeader (FILE *file);
-int XmlWriteHeaderW (FILE *file);
int XmlWriteFooter (FILE *file);
-int XmlWriteFooterW (FILE *file);
char *XmlFindElementByAttributeValue (char *xml, char *nodeName, char *attrName, char *attrValue);
char *XmlQuoteText (const char *textSrc, char *textDst, int textDstMaxSize);
+wchar_t *XmlQuoteTextW (const wchar_t *textSrc, wchar_t *textDst, int textDstMaxSize);
#ifdef __cplusplus
}