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

Windows: Display source location of errors in order to help diagnose issues reported by users

This commit is contained in:
Mounir IDRASSI
2015-07-05 18:15:41 +02:00
parent c3b77fba25
commit 724043be0b
23 changed files with 270 additions and 227 deletions

View File

@@ -134,7 +134,7 @@ DWORD BaseCom::ReadWriteFile (BOOL write, BOOL device, BSTR filePath, BSTR *buff
try 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 (string (szFilePathA.m_psz), !write) : new File (string (szFilePathA.m_psz), !write));
file->CheckOpened (); file->CheckOpened (SRC_POS);
file->SeekAt (offset); file->SeekAt (offset);
if (write) if (write)

View File

@@ -68,7 +68,7 @@ namespace VeraCrypt
if (result != ERROR_SUCCESS) if (result != ERROR_SUCCESS)
{ {
SetLastError (result); SetLastError (result);
throw SystemException(); throw SystemException(SRC_POS);
} }
} }
@@ -101,7 +101,7 @@ namespace VeraCrypt
if (result != ERROR_SUCCESS) if (result != ERROR_SUCCESS)
{ {
SetLastError (result); SetLastError (result);
throw SystemException(); throw SystemException(SRC_POS);
} }
} }
@@ -124,7 +124,7 @@ namespace VeraCrypt
if (result != ERROR_SUCCESS) if (result != ERROR_SUCCESS)
{ {
SetLastError (result); SetLastError (result);
throw SystemException(); throw SystemException(SRC_POS);
} }
} }
@@ -150,7 +150,7 @@ namespace VeraCrypt
if (result != ERROR_SUCCESS) if (result != ERROR_SUCCESS)
{ {
SetLastError (result); SetLastError (result);
throw SystemException(); throw SystemException(SRC_POS);
} }
if (!write) if (!write)
@@ -194,7 +194,7 @@ namespace VeraCrypt
if (result != ERROR_SUCCESS) if (result != ERROR_SUCCESS)
{ {
SetLastError (result); SetLastError (result);
throw SystemException(); throw SystemException(SRC_POS);
} }
} }
@@ -206,7 +206,7 @@ namespace VeraCrypt
if (result != ERROR_SUCCESS) if (result != ERROR_SUCCESS)
{ {
SetLastError (result); SetLastError (result);
throw SystemException(); throw SystemException(SRC_POS);
} }
} }
@@ -218,7 +218,7 @@ namespace VeraCrypt
if (result != ERROR_SUCCESS) if (result != ERROR_SUCCESS)
{ {
SetLastError (result); SetLastError (result);
throw SystemException(); throw SystemException(SRC_POS);
} }
} }
@@ -240,7 +240,7 @@ namespace VeraCrypt
if (result != ERROR_SUCCESS) if (result != ERROR_SUCCESS)
{ {
SetLastError (result); SetLastError (result);
throw SystemException(); throw SystemException(SRC_POS);
} }
} }
@@ -250,7 +250,7 @@ namespace VeraCrypt
if (IsAdmin()) if (IsAdmin())
{ {
SetLastError (ERROR_ACCESS_DENIED); SetLastError (ERROR_ACCESS_DENIED);
throw SystemException(); throw SystemException(SRC_POS);
} }
if (!ElevatedComInstance || ElevatedComInstanceThreadId != GetCurrentThreadId()) if (!ElevatedComInstance || ElevatedComInstanceThreadId != GetCurrentThreadId())
@@ -338,7 +338,7 @@ namespace VeraCrypt
if (!FileOpen) if (!FileOpen)
{ {
SetLastError (LastError); SetLastError (LastError);
throw SystemException (); throw SystemException (SRC_POS);
} }
if (Elevated) if (Elevated)
@@ -359,7 +359,7 @@ namespace VeraCrypt
if (!FileOpen) if (!FileOpen)
{ {
SetLastError (LastError); SetLastError (LastError);
throw SystemException (); throw SystemException (SRC_POS);
} }
FilePointerPosition = position; FilePointerPosition = position;
@@ -379,7 +379,7 @@ namespace VeraCrypt
if (!FileOpen) if (!FileOpen)
{ {
SetLastError (LastError); SetLastError (LastError);
throw SystemException (); throw SystemException (SRC_POS);
} }
try try
@@ -546,7 +546,7 @@ namespace VeraCrypt
} }
throw ErrorException (wstring (GetString ("SYSTEM_PARTITION_NOT_ACTIVE")) throw ErrorException (wstring (GetString ("SYSTEM_PARTITION_NOT_ACTIVE"))
+ GetRemarksOnHiddenOS()); + GetRemarksOnHiddenOS(), SRC_POS);
} }
activePartitionFound = true; activePartitionFound = true;
@@ -581,7 +581,7 @@ namespace VeraCrypt
if (!candidateForHiddenOSFound) if (!candidateForHiddenOSFound)
{ {
throw ErrorException (wstring (GetString ("NO_PARTITION_FOLLOWS_BOOT_PARTITION")) throw ErrorException (wstring (GetString ("NO_PARTITION_FOLLOWS_BOOT_PARTITION"))
+ GetRemarksOnHiddenOS()); + GetRemarksOnHiddenOS(), SRC_POS);
} }
if (config.SystemPartition.Info.PartitionLength.QuadPart > TC_MAX_FAT_SECTOR_COUNT * TC_SECTOR_SIZE_BIOS) if (config.SystemPartition.Info.PartitionLength.QuadPart > TC_MAX_FAT_SECTOR_COUNT * TC_SECTOR_SIZE_BIOS)
@@ -589,19 +589,19 @@ namespace VeraCrypt
if ((double) candidatePartition.Info.PartitionLength.QuadPart / config.SystemPartition.Info.PartitionLength.QuadPart < MIN_HIDDENOS_DECOY_PARTITION_SIZE_RATIO_NTFS) if ((double) candidatePartition.Info.PartitionLength.QuadPart / config.SystemPartition.Info.PartitionLength.QuadPart < MIN_HIDDENOS_DECOY_PARTITION_SIZE_RATIO_NTFS)
{ {
throw ErrorException (wstring (GetString ("PARTITION_TOO_SMALL_FOR_HIDDEN_OS_NTFS")) throw ErrorException (wstring (GetString ("PARTITION_TOO_SMALL_FOR_HIDDEN_OS_NTFS"))
+ GetRemarksOnHiddenOS()); + GetRemarksOnHiddenOS(), SRC_POS);
} }
} }
else if ((double) candidatePartition.Info.PartitionLength.QuadPart / config.SystemPartition.Info.PartitionLength.QuadPart < MIN_HIDDENOS_DECOY_PARTITION_SIZE_RATIO_FAT) else if ((double) candidatePartition.Info.PartitionLength.QuadPart / config.SystemPartition.Info.PartitionLength.QuadPart < MIN_HIDDENOS_DECOY_PARTITION_SIZE_RATIO_FAT)
{ {
throw ErrorException (wstring (GetString ("PARTITION_TOO_SMALL_FOR_HIDDEN_OS")) throw ErrorException (wstring (GetString ("PARTITION_TOO_SMALL_FOR_HIDDEN_OS"))
+ GetRemarksOnHiddenOS()); + GetRemarksOnHiddenOS(), SRC_POS);
} }
} }
else else
{ {
// No active partition on the system drive // No active partition on the system drive
throw ErrorException ("SYSTEM_PARTITION_NOT_ACTIVE"); throw ErrorException ("SYSTEM_PARTITION_NOT_ACTIVE", SRC_POS);
} }
HiddenOSCandidatePartition = candidatePartition; HiddenOSCandidatePartition = candidatePartition;
@@ -884,7 +884,7 @@ namespace VeraCrypt
bool BootEncryption::SystemDriveContainsPartitionType (byte type) bool BootEncryption::SystemDriveContainsPartitionType (byte type)
{ {
Device device (GetSystemDriveConfiguration().DevicePath, true); Device device (GetSystemDriveConfiguration().DevicePath, true);
device.CheckOpened (); device.CheckOpened (SRC_POS);
byte mbrBuf[TC_SECTOR_SIZE_BIOS]; byte mbrBuf[TC_SECTOR_SIZE_BIOS];
device.SeekAt (0); device.SeekAt (0);
@@ -1195,7 +1195,7 @@ namespace VeraCrypt
if (hiddenOSCreation) if (hiddenOSCreation)
{ {
Device device (GetSystemDriveConfiguration().DevicePath); Device device (GetSystemDriveConfiguration().DevicePath);
device.CheckOpened (); device.CheckOpened (SRC_POS);
byte headerSector[TC_SECTOR_SIZE_BIOS]; byte headerSector[TC_SECTOR_SIZE_BIOS];
device.SeekAt (HiddenOSCandidatePartition.Info.StartingOffset.QuadPart + HiddenOSCandidatePartition.Info.PartitionLength.QuadPart - TC_VOLUME_HEADER_GROUP_SIZE + TC_VOLUME_HEADER_EFFECTIVE_SIZE); device.SeekAt (HiddenOSCandidatePartition.Info.StartingOffset.QuadPart + HiddenOSCandidatePartition.Info.PartitionLength.QuadPart - TC_VOLUME_HEADER_GROUP_SIZE + TC_VOLUME_HEADER_EFFECTIVE_SIZE);
@@ -1284,7 +1284,7 @@ namespace VeraCrypt
void BootEncryption::WriteBootSectorConfig (const byte newConfig[]) void BootEncryption::WriteBootSectorConfig (const byte newConfig[])
{ {
Device device (GetSystemDriveConfiguration().DevicePath); Device device (GetSystemDriveConfiguration().DevicePath);
device.CheckOpened (); device.CheckOpened (SRC_POS);
byte mbr[TC_SECTOR_SIZE_BIOS]; byte mbr[TC_SECTOR_SIZE_BIOS];
device.SeekAt (0); device.SeekAt (0);
@@ -1300,14 +1300,14 @@ namespace VeraCrypt
device.Read (mbrVerificationBuf, sizeof (mbr)); device.Read (mbrVerificationBuf, sizeof (mbr));
if (memcmp (mbr, mbrVerificationBuf, sizeof (mbr)) != 0) if (memcmp (mbr, mbrVerificationBuf, sizeof (mbr)) != 0)
throw ErrorException ("ERROR_MBR_PROTECTED"); throw ErrorException ("ERROR_MBR_PROTECTED", SRC_POS);
} }
void BootEncryption::WriteBootSectorUserConfig (byte userConfig, const string &customUserMessage) void BootEncryption::WriteBootSectorUserConfig (byte userConfig, const string &customUserMessage)
{ {
Device device (GetSystemDriveConfiguration().DevicePath); Device device (GetSystemDriveConfiguration().DevicePath);
device.CheckOpened (); device.CheckOpened (SRC_POS);
byte mbr[TC_SECTOR_SIZE_BIOS]; byte mbr[TC_SECTOR_SIZE_BIOS];
device.SeekAt (0); device.SeekAt (0);
@@ -1339,7 +1339,7 @@ namespace VeraCrypt
device.Read (mbrVerificationBuf, sizeof (mbr)); device.Read (mbrVerificationBuf, sizeof (mbr));
if (memcmp (mbr, mbrVerificationBuf, sizeof (mbr)) != 0) if (memcmp (mbr, mbrVerificationBuf, sizeof (mbr)) != 0)
throw ErrorException ("ERROR_MBR_PROTECTED"); throw ErrorException ("ERROR_MBR_PROTECTED", SRC_POS);
} }
@@ -1438,7 +1438,7 @@ namespace VeraCrypt
} }
Device device (GetSystemDriveConfiguration().DevicePath); Device device (GetSystemDriveConfiguration().DevicePath);
device.CheckOpened(); device.CheckOpened(SRC_POS);
byte mbr[TC_SECTOR_SIZE_BIOS]; byte mbr[TC_SECTOR_SIZE_BIOS];
device.SeekAt (0); device.SeekAt (0);
@@ -1497,7 +1497,7 @@ namespace VeraCrypt
// Write MBR // Write MBR
Device device (GetSystemDriveConfiguration().DevicePath); Device device (GetSystemDriveConfiguration().DevicePath);
device.CheckOpened (); device.CheckOpened (SRC_POS);
byte mbr[TC_SECTOR_SIZE_BIOS]; byte mbr[TC_SECTOR_SIZE_BIOS];
device.SeekAt (0); device.SeekAt (0);
@@ -1523,7 +1523,7 @@ namespace VeraCrypt
device.Read (mbrVerificationBuf, sizeof (mbr)); device.Read (mbrVerificationBuf, sizeof (mbr));
if (memcmp (mbr, mbrVerificationBuf, sizeof (mbr)) != 0) if (memcmp (mbr, mbrVerificationBuf, sizeof (mbr)) != 0)
throw ErrorException ("ERROR_MBR_PROTECTED"); throw ErrorException ("ERROR_MBR_PROTECTED", SRC_POS);
// Write boot loader // Write boot loader
device.SeekAt (TC_SECTOR_SIZE_BIOS); device.SeekAt (TC_SECTOR_SIZE_BIOS);
@@ -1652,7 +1652,7 @@ namespace VeraCrypt
else else
{ {
Device bootDevice (GetSystemDriveConfiguration().DevicePath, true); Device bootDevice (GetSystemDriveConfiguration().DevicePath, true);
bootDevice.CheckOpened (); bootDevice.CheckOpened (SRC_POS);
bootDevice.SeekAt (TC_BOOT_VOLUME_HEADER_SECTOR_OFFSET); bootDevice.SeekAt (TC_BOOT_VOLUME_HEADER_SECTOR_OFFSET);
bootDevice.Read (image + TC_CD_BOOTSECTOR_OFFSET + TC_BOOT_VOLUME_HEADER_SECTOR_OFFSET, TC_BOOT_ENCRYPTION_VOLUME_HEADER_SIZE); bootDevice.Read (image + TC_CD_BOOTSECTOR_OFFSET + TC_BOOT_VOLUME_HEADER_SECTOR_OFFSET, TC_BOOT_ENCRYPTION_VOLUME_HEADER_SIZE);
} }
@@ -1661,7 +1661,7 @@ namespace VeraCrypt
try try
{ {
File sysBakFile (GetSystemLoaderBackupPath(), true); File sysBakFile (GetSystemLoaderBackupPath(), true);
sysBakFile.CheckOpened (); sysBakFile.CheckOpened (SRC_POS);
sysBakFile.Read (image + TC_CD_BOOTSECTOR_OFFSET + TC_ORIG_BOOT_LOADER_BACKUP_SECTOR_OFFSET, TC_BOOT_LOADER_AREA_SIZE); sysBakFile.Read (image + TC_CD_BOOTSECTOR_OFFSET + TC_ORIG_BOOT_LOADER_BACKUP_SECTOR_OFFSET, TC_BOOT_LOADER_AREA_SIZE);
image[TC_CD_BOOTSECTOR_OFFSET + TC_BOOT_SECTOR_CONFIG_OFFSET] |= TC_BOOT_CFG_FLAG_RESCUE_DISK_ORIG_SYS_LOADER; image[TC_CD_BOOTSECTOR_OFFSET + TC_BOOT_SECTOR_CONFIG_OFFSET] |= TC_BOOT_CFG_FLAG_RESCUE_DISK_ORIG_SYS_LOADER;
@@ -1717,7 +1717,7 @@ namespace VeraCrypt
path[0] = drive; path[0] = drive;
Device driveDevice (path, true); Device driveDevice (path, true);
driveDevice.CheckOpened (); driveDevice.CheckOpened (SRC_POS);
size_t verifiedSectorCount = (TC_CD_BOOTSECTOR_OFFSET + TC_ORIG_BOOT_LOADER_BACKUP_SECTOR_OFFSET + TC_BOOT_LOADER_AREA_SIZE) / 2048; size_t verifiedSectorCount = (TC_CD_BOOTSECTOR_OFFSET + TC_ORIG_BOOT_LOADER_BACKUP_SECTOR_OFFSET + TC_BOOT_LOADER_AREA_SIZE) / 2048;
Buffer buffer ((verifiedSectorCount + 1) * 2048); Buffer buffer ((verifiedSectorCount + 1) * 2048);
@@ -1780,7 +1780,7 @@ namespace VeraCrypt
throw ParameterIncorrect (SRC_POS); throw ParameterIncorrect (SRC_POS);
Device device (GetSystemDriveConfiguration().DevicePath); Device device (GetSystemDriveConfiguration().DevicePath);
device.CheckOpened (); device.CheckOpened (SRC_POS);
device.SeekAt (TC_BOOT_VOLUME_HEADER_SECTOR_OFFSET); device.SeekAt (TC_BOOT_VOLUME_HEADER_SECTOR_OFFSET);
device.Write ((byte *) VolumeHeader, sizeof (VolumeHeader)); device.Write ((byte *) VolumeHeader, sizeof (VolumeHeader));
@@ -1812,7 +1812,7 @@ namespace VeraCrypt
void BootEncryption::BackupSystemLoader () void BootEncryption::BackupSystemLoader ()
{ {
Device device (GetSystemDriveConfiguration().DevicePath, true); Device device (GetSystemDriveConfiguration().DevicePath, true);
device.CheckOpened (); device.CheckOpened (SRC_POS);
byte bootLoaderBuf[TC_BOOT_LOADER_AREA_SECTOR_COUNT * TC_SECTOR_SIZE_BIOS]; byte bootLoaderBuf[TC_BOOT_LOADER_AREA_SECTOR_COUNT * TC_SECTOR_SIZE_BIOS];
device.SeekAt (0); device.SeekAt (0);
@@ -1839,12 +1839,12 @@ namespace VeraCrypt
byte bootLoaderBuf[TC_BOOT_LOADER_AREA_SECTOR_COUNT * TC_SECTOR_SIZE_BIOS]; byte bootLoaderBuf[TC_BOOT_LOADER_AREA_SECTOR_COUNT * TC_SECTOR_SIZE_BIOS];
File backupFile (GetSystemLoaderBackupPath(), true); File backupFile (GetSystemLoaderBackupPath(), true);
backupFile.CheckOpened(); backupFile.CheckOpened(SRC_POS);
if (backupFile.Read (bootLoaderBuf, sizeof (bootLoaderBuf)) != sizeof (bootLoaderBuf)) if (backupFile.Read (bootLoaderBuf, sizeof (bootLoaderBuf)) != sizeof (bootLoaderBuf))
throw ParameterIncorrect (SRC_POS); throw ParameterIncorrect (SRC_POS);
Device device (GetSystemDriveConfiguration().DevicePath); Device device (GetSystemDriveConfiguration().DevicePath);
device.CheckOpened (); device.CheckOpened (SRC_POS);
// Preserve current partition table // Preserve current partition table
byte mbr[TC_SECTOR_SIZE_BIOS]; byte mbr[TC_SECTOR_SIZE_BIOS];
@@ -2048,29 +2048,29 @@ namespace VeraCrypt
void BootEncryption::CheckRequirements () void BootEncryption::CheckRequirements ()
{ {
if (nCurrentOS == WIN_2000) if (nCurrentOS == WIN_2000)
throw ErrorException ("SYS_ENCRYPTION_UNSUPPORTED_ON_CURRENT_OS"); throw ErrorException ("SYS_ENCRYPTION_UNSUPPORTED_ON_CURRENT_OS", SRC_POS);
if (CurrentOSMajor == 6 && CurrentOSMinor == 0 && CurrentOSServicePack < 1) if (CurrentOSMajor == 6 && CurrentOSMinor == 0 && CurrentOSServicePack < 1)
throw ErrorException ("SYS_ENCRYPTION_UNSUPPORTED_ON_VISTA_SP0"); throw ErrorException ("SYS_ENCRYPTION_UNSUPPORTED_ON_VISTA_SP0", SRC_POS);
if (IsNonInstallMode()) if (IsNonInstallMode())
throw ErrorException ("FEATURE_REQUIRES_INSTALLATION"); throw ErrorException ("FEATURE_REQUIRES_INSTALLATION", SRC_POS);
SystemDriveConfiguration config = GetSystemDriveConfiguration (); SystemDriveConfiguration config = GetSystemDriveConfiguration ();
if (config.SystemPartition.IsGPT) if (config.SystemPartition.IsGPT)
throw ErrorException ("GPT_BOOT_DRIVE_UNSUPPORTED"); throw ErrorException ("GPT_BOOT_DRIVE_UNSUPPORTED", SRC_POS);
if (SystemDriveIsDynamic()) if (SystemDriveIsDynamic())
throw ErrorException ("SYSENC_UNSUPPORTED_FOR_DYNAMIC_DISK"); throw ErrorException ("SYSENC_UNSUPPORTED_FOR_DYNAMIC_DISK", SRC_POS);
if (config.InitialUnallocatedSpace < TC_BOOT_LOADER_AREA_SIZE) if (config.InitialUnallocatedSpace < TC_BOOT_LOADER_AREA_SIZE)
throw ErrorException ("NO_SPACE_FOR_BOOT_LOADER"); throw ErrorException ("NO_SPACE_FOR_BOOT_LOADER", SRC_POS);
DISK_GEOMETRY geometry = GetDriveGeometry (config.DriveNumber); DISK_GEOMETRY geometry = GetDriveGeometry (config.DriveNumber);
if (geometry.BytesPerSector != TC_SECTOR_SIZE_BIOS) if (geometry.BytesPerSector != TC_SECTOR_SIZE_BIOS)
throw ErrorException ("SYSENC_UNSUPPORTED_SECTOR_SIZE_BIOS"); throw ErrorException ("SYSENC_UNSUPPORTED_SECTOR_SIZE_BIOS", SRC_POS);
bool activePartitionFound = false; bool activePartitionFound = false;
if (!config.SystemPartition.IsGPT) if (!config.SystemPartition.IsGPT)
@@ -2146,7 +2146,7 @@ namespace VeraCrypt
} }
throw ErrorException (wstring (GetString ("PAGING_FILE_NOT_ON_SYS_PARTITION")) throw ErrorException (wstring (GetString ("PAGING_FILE_NOT_ON_SYS_PARTITION"))
+ GetString ("LEAKS_OUTSIDE_SYSPART_UNIVERSAL_EXPLANATION")); + GetString ("LEAKS_OUTSIDE_SYSPART_UNIVERSAL_EXPLANATION"), SRC_POS);
} }
// User profile // User profile
@@ -2154,14 +2154,14 @@ namespace VeraCrypt
if (configPath && toupper (configPath[0]) != windowsDrive) if (configPath && toupper (configPath[0]) != windowsDrive)
{ {
throw ErrorException (wstring (GetString ("USER_PROFILE_NOT_ON_SYS_PARTITION")) throw ErrorException (wstring (GetString ("USER_PROFILE_NOT_ON_SYS_PARTITION"))
+ GetString ("LEAKS_OUTSIDE_SYSPART_UNIVERSAL_EXPLANATION")); + GetString ("LEAKS_OUTSIDE_SYSPART_UNIVERSAL_EXPLANATION"), SRC_POS);
} }
// Temporary files // Temporary files
if (toupper (GetTempPath()[0]) != windowsDrive) if (toupper (GetTempPath()[0]) != windowsDrive)
{ {
throw ErrorException (wstring (GetString ("TEMP_NOT_ON_SYS_PARTITION")) throw ErrorException (wstring (GetString ("TEMP_NOT_ON_SYS_PARTITION"))
+ GetString ("LEAKS_OUTSIDE_SYSPART_UNIVERSAL_EXPLANATION")); + GetString ("LEAKS_OUTSIDE_SYSPART_UNIVERSAL_EXPLANATION"), SRC_POS);
} }
} }
@@ -2181,7 +2181,7 @@ namespace VeraCrypt
{ {
// Verify CRC of header salt // Verify CRC of header salt
Device device (config.DevicePath, true); Device device (config.DevicePath, true);
device.CheckOpened (); device.CheckOpened (SRC_POS);
byte header[TC_BOOT_ENCRYPTION_VOLUME_HEADER_SIZE]; byte header[TC_BOOT_ENCRYPTION_VOLUME_HEADER_SIZE];
device.SeekAt (TC_BOOT_VOLUME_HEADER_SECTOR_OFFSET); device.SeekAt (TC_BOOT_VOLUME_HEADER_SECTOR_OFFSET);
@@ -2229,7 +2229,7 @@ namespace VeraCrypt
catch (Exception &e) catch (Exception &e)
{ {
e.Show (ParentWindow); e.Show (ParentWindow);
throw ErrorException ("SYS_LOADER_RESTORE_FAILED"); throw ErrorException ("SYS_LOADER_RESTORE_FAILED", SRC_POS);
} }
} }
@@ -2245,7 +2245,7 @@ namespace VeraCrypt
char header[TC_BOOT_ENCRYPTION_VOLUME_HEADER_SIZE]; char header[TC_BOOT_ENCRYPTION_VOLUME_HEADER_SIZE];
Device device (config.DevicePath); Device device (config.DevicePath);
device.CheckOpened (); device.CheckOpened (SRC_POS);
// Only one algorithm is currently supported // Only one algorithm is currently supported
if (pkcs5 != 0) if (pkcs5 != 0)
@@ -2282,7 +2282,7 @@ namespace VeraCrypt
if (status != 0) if (status != 0)
{ {
handleError (hwndDlg, status); handleError (hwndDlg, status, SRC_POS);
return status; return status;
} }
@@ -2356,7 +2356,7 @@ namespace VeraCrypt
if (status != 0) if (status != 0)
{ {
handleError (hwndDlg, status); handleError (hwndDlg, status, SRC_POS);
return status; return status;
} }
@@ -2461,7 +2461,7 @@ namespace VeraCrypt
Buffer sector (geometry.BytesPerSector); Buffer sector (geometry.BytesPerSector);
Device device (config.DevicePath); Device device (config.DevicePath);
device.CheckOpened (); device.CheckOpened (SRC_POS);
try try
{ {
@@ -2583,7 +2583,7 @@ namespace VeraCrypt
if (!IsUacSupported()) if (!IsUacSupported())
{ {
SetLastError (ERROR_ACCESS_DENIED); SetLastError (ERROR_ACCESS_DENIED);
throw SystemException(); throw SystemException(SRC_POS);
} }
else else
Elevator::CopyFile (sourceFile, destinationFile); Elevator::CopyFile (sourceFile, destinationFile);

View File

@@ -26,7 +26,7 @@ namespace VeraCrypt
File (string path,bool readOnly = false, bool create = false); File (string path,bool readOnly = false, bool create = false);
virtual ~File () { Close(); } virtual ~File () { Close(); }
void CheckOpened () { if (!FileOpen) { SetLastError (LastError); throw SystemException ();} } void CheckOpened (const char* srcPos) { if (!FileOpen) { SetLastError (LastError); throw SystemException (srcPos);} }
void Close (); void Close ();
DWORD Read (byte *buffer, DWORD size); DWORD Read (byte *buffer, DWORD size);
void Write (byte *buffer, DWORD size); void Write (byte *buffer, DWORD size);

View File

@@ -22,6 +22,10 @@
#include "Language.h" #include "Language.h"
#include <Strsafe.h> #include <Strsafe.h>
#ifndef SRC_POS
#define SRC_POS (__FUNCTION__ ":" TC_TO_STRING(__LINE__))
#endif
/* Except in response to the WM_INITDIALOG message, the dialog box procedure /* Except in response to the WM_INITDIALOG message, the dialog box procedure
should return nonzero if it processes the message, and zero if it does should return nonzero if it processes the message, and zero if it does
not. - see DialogProc */ not. - see DialogProc */
@@ -92,7 +96,7 @@ int Win32CommandLine (char *lpszCommandLine, char ***lpszArgs)
LPWSTR *arguments = CommandLineToArgvW (GetCommandLineW(), &argumentCount); LPWSTR *arguments = CommandLineToArgvW (GetCommandLineW(), &argumentCount);
if (!arguments) if (!arguments)
{ {
handleWin32Error (NULL); handleWin32Error (NULL, SRC_POS);
return 0; return 0;
} }
@@ -120,7 +124,7 @@ int Win32CommandLine (char *lpszCommandLine, char ***lpszArgs)
int len = WideCharToMultiByte (CP_ACP, 0, arguments[i + 1], -1, arg, (int) argLen + 1, NULL, NULL); int len = WideCharToMultiByte (CP_ACP, 0, arguments[i + 1], -1, arg, (int) argLen + 1, NULL, NULL);
if (len == 0) if (len == 0)
{ {
handleWin32Error (NULL); handleWin32Error (NULL, SRC_POS);
AbortProcessSilent(); AbortProcessSilent();
} }
} }

View File

@@ -548,7 +548,7 @@ BOOL IsDiskError (DWORD error)
} }
DWORD handleWin32Error (HWND hwndDlg) DWORD handleWin32Error (HWND hwndDlg, const char* srcPos)
{ {
PWSTR lpMsgBuf; PWSTR lpMsgBuf;
DWORD dwError = GetLastError (); DWORD dwError = GetLastError ();
@@ -559,7 +559,7 @@ DWORD handleWin32Error (HWND hwndDlg)
// Access denied // Access denied
if (dwError == ERROR_ACCESS_DENIED && !IsAdmin ()) if (dwError == ERROR_ACCESS_DENIED && !IsAdmin ())
{ {
Error ("ERR_ACCESS_DENIED", hwndDlg); ErrorDirect ( AppendSrcPos (GetString ("ERR_ACCESS_DENIED"), srcPos).c_str (), hwndDlg);
SetLastError (dwError); // Preserve the original error code SetLastError (dwError); // Preserve the original error code
return dwError; return dwError;
} }
@@ -574,7 +574,7 @@ DWORD handleWin32Error (HWND hwndDlg)
NULL NULL
); );
MessageBoxW (hwndDlg, lpMsgBuf, lpszTitle, ICON_HAND); MessageBoxW (hwndDlg, AppendSrcPos (lpMsgBuf, srcPos).c_str (), lpszTitle, ICON_HAND);
LocalFree (lpMsgBuf); LocalFree (lpMsgBuf);
// User-friendly hardware error explanation // User-friendly hardware error explanation
@@ -1265,7 +1265,7 @@ void InitDialog (HWND hwndDlg)
hFixedDigitFont = CreateFontIndirectW (&lf); hFixedDigitFont = CreateFontIndirectW (&lf);
if (hFixedDigitFont == NULL) if (hFixedDigitFont == NULL)
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
AbortProcess ("NOFONT"); AbortProcess ("NOFONT");
} }
@@ -1279,7 +1279,7 @@ void InitDialog (HWND hwndDlg)
hBoldFont = CreateFontIndirectW (&lf); hBoldFont = CreateFontIndirectW (&lf);
if (hBoldFont == NULL) if (hBoldFont == NULL)
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
AbortProcess ("NOFONT"); AbortProcess ("NOFONT");
} }
@@ -1293,7 +1293,7 @@ void InitDialog (HWND hwndDlg)
hTitleFont = CreateFontIndirectW (&lf); hTitleFont = CreateFontIndirectW (&lf);
if (hTitleFont == NULL) if (hTitleFont == NULL)
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
AbortProcess ("NOFONT"); AbortProcess ("NOFONT");
} }
@@ -1318,7 +1318,7 @@ void InitDialog (HWND hwndDlg)
hFixedFont = CreateFontIndirectW (&lf); hFixedFont = CreateFontIndirectW (&lf);
if (hFixedFont == NULL) if (hFixedFont == NULL)
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
AbortProcess ("NOFONT"); AbortProcess ("NOFONT");
} }
@@ -2525,7 +2525,7 @@ void InitApp (HINSTANCE hInstance, char *lpszCommandLine)
/* Get the attributes for the standard dialog class */ /* Get the attributes for the standard dialog class */
if ((GetClassInfo (hInst, WINDOWS_DIALOG_CLASS, &wc)) == 0) if ((GetClassInfo (hInst, WINDOWS_DIALOG_CLASS, &wc)) == 0)
{ {
handleWin32Error (NULL); handleWin32Error (NULL, SRC_POS);
AbortProcess ("INIT_REGISTER"); AbortProcess ("INIT_REGISTER");
} }
@@ -2543,7 +2543,7 @@ void InitApp (HINSTANCE hInstance, char *lpszCommandLine)
hDlgClass = RegisterClass (&wc); hDlgClass = RegisterClass (&wc);
if (hDlgClass == 0) if (hDlgClass == 0)
{ {
handleWin32Error (NULL); handleWin32Error (NULL, SRC_POS);
AbortProcess ("INIT_REGISTER"); AbortProcess ("INIT_REGISTER");
} }
@@ -2555,7 +2555,7 @@ void InitApp (HINSTANCE hInstance, char *lpszCommandLine)
hSplashClass = RegisterClass (&wc); hSplashClass = RegisterClass (&wc);
if (hSplashClass == 0) if (hSplashClass == 0)
{ {
handleWin32Error (NULL); handleWin32Error (NULL, SRC_POS);
AbortProcess ("INIT_REGISTER"); AbortProcess ("INIT_REGISTER");
} }
@@ -2567,7 +2567,7 @@ void InitApp (HINSTANCE hInstance, char *lpszCommandLine)
if ((hRichEditDll = LoadLibrary(dllPath)) == NULL) if ((hRichEditDll = LoadLibrary(dllPath)) == NULL)
{ {
// This error is fatal e.g. because legal notices could not be displayed // This error is fatal e.g. because legal notices could not be displayed
handleWin32Error (NULL); handleWin32Error (NULL, SRC_POS);
AbortProcess ("INIT_RICHEDIT"); AbortProcess ("INIT_RICHEDIT");
} }
@@ -2580,7 +2580,7 @@ void InitApp (HINSTANCE hInstance, char *lpszCommandLine)
#ifndef SETUP #ifndef SETUP
if (!EncryptionThreadPoolStart (ReadEncryptionThreadPoolFreeCpuCountLimit())) if (!EncryptionThreadPoolStart (ReadEncryptionThreadPoolFreeCpuCountLimit()))
{ {
handleWin32Error (NULL); handleWin32Error (NULL, SRC_POS);
if (hRichEditDll) if (hRichEditDll)
{ {
FreeLibrary (hRichEditDll); FreeLibrary (hRichEditDll);
@@ -3470,7 +3470,7 @@ BOOL DoDriverInstall (HWND hwndDlg)
error: error:
if (bOK == FALSE && GetLastError () != ERROR_SERVICE_ALREADY_RUNNING) if (bOK == FALSE && GetLastError () != ERROR_SERVICE_ALREADY_RUNNING)
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
MessageBoxW (hwndDlg, GetString ("DRIVER_INSTALL_FAILED"), lpszTitle, MB_ICONHAND); MessageBoxW (hwndDlg, GetString ("DRIVER_INSTALL_FAILED"), lpszTitle, MB_ICONHAND);
} }
else else
@@ -4091,7 +4091,7 @@ std::wstring GetWrongPasswordErrorMessage (HWND hwndDlg)
} }
void handleError (HWND hwndDlg, int code) void handleError (HWND hwndDlg, int code, const char* srcPos)
{ {
WCHAR szTmp[4096]; WCHAR szTmp[4096];
@@ -4100,57 +4100,57 @@ void handleError (HWND hwndDlg, int code)
switch (code & 0x0000FFFF) switch (code & 0x0000FFFF)
{ {
case ERR_OS_ERROR: case ERR_OS_ERROR:
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, srcPos);
break; break;
case ERR_OUTOFMEMORY: case ERR_OUTOFMEMORY:
MessageBoxW (hwndDlg, GetString ("OUTOFMEMORY"), lpszTitle, ICON_HAND); MessageBoxW (hwndDlg, AppendSrcPos (GetString ("OUTOFMEMORY"), srcPos).c_str(), lpszTitle, ICON_HAND);
break; break;
case ERR_PASSWORD_WRONG: case ERR_PASSWORD_WRONG:
MessageBoxW (hwndDlg, GetWrongPasswordErrorMessage (hwndDlg).c_str(), lpszTitle, MB_ICONWARNING); MessageBoxW (hwndDlg, AppendSrcPos (GetWrongPasswordErrorMessage (hwndDlg).c_str(), srcPos).c_str(), lpszTitle, MB_ICONWARNING);
break; break;
case ERR_DRIVE_NOT_FOUND: case ERR_DRIVE_NOT_FOUND:
MessageBoxW (hwndDlg, GetString ("NOT_FOUND"), lpszTitle, ICON_HAND); MessageBoxW (hwndDlg, AppendSrcPos (GetString ("NOT_FOUND"), srcPos).c_str(), lpszTitle, ICON_HAND);
break; break;
case ERR_FILES_OPEN: case ERR_FILES_OPEN:
MessageBoxW (hwndDlg, GetString ("OPENFILES_DRIVER"), lpszTitle, ICON_HAND); MessageBoxW (hwndDlg, AppendSrcPos (GetString ("OPENFILES_DRIVER"), srcPos).c_str(), lpszTitle, ICON_HAND);
break; break;
case ERR_FILES_OPEN_LOCK: case ERR_FILES_OPEN_LOCK:
MessageBoxW (hwndDlg, GetString ("OPENFILES_LOCK"), lpszTitle, ICON_HAND); MessageBoxW (hwndDlg, AppendSrcPos (GetString ("OPENFILES_LOCK"), srcPos).c_str(), lpszTitle, ICON_HAND);
break; break;
case ERR_VOL_SIZE_WRONG: case ERR_VOL_SIZE_WRONG:
MessageBoxW (hwndDlg, GetString ("VOL_SIZE_WRONG"), lpszTitle, ICON_HAND); MessageBoxW (hwndDlg, AppendSrcPos (GetString ("VOL_SIZE_WRONG"), srcPos).c_str(), lpszTitle, ICON_HAND);
break; break;
case ERR_COMPRESSION_NOT_SUPPORTED: case ERR_COMPRESSION_NOT_SUPPORTED:
MessageBoxW (hwndDlg, GetString ("COMPRESSION_NOT_SUPPORTED"), lpszTitle, ICON_HAND); MessageBoxW (hwndDlg, AppendSrcPos (GetString ("COMPRESSION_NOT_SUPPORTED"), srcPos).c_str(), lpszTitle, ICON_HAND);
break; break;
case ERR_PASSWORD_CHANGE_VOL_TYPE: case ERR_PASSWORD_CHANGE_VOL_TYPE:
MessageBoxW (hwndDlg, GetString ("WRONG_VOL_TYPE"), lpszTitle, ICON_HAND); MessageBoxW (hwndDlg, AppendSrcPos (GetString ("WRONG_VOL_TYPE"), srcPos).c_str(), lpszTitle, ICON_HAND);
break; break;
case ERR_VOL_SEEKING: case ERR_VOL_SEEKING:
MessageBoxW (hwndDlg, GetString ("VOL_SEEKING"), lpszTitle, ICON_HAND); MessageBoxW (hwndDlg, AppendSrcPos (GetString ("VOL_SEEKING"), srcPos).c_str(), lpszTitle, ICON_HAND);
break; break;
case ERR_CIPHER_INIT_FAILURE: case ERR_CIPHER_INIT_FAILURE:
MessageBoxW (hwndDlg, GetString ("ERR_CIPHER_INIT_FAILURE"), lpszTitle, ICON_HAND); MessageBoxW (hwndDlg, AppendSrcPos (GetString ("ERR_CIPHER_INIT_FAILURE"), srcPos).c_str(), lpszTitle, ICON_HAND);
break; break;
case ERR_CIPHER_INIT_WEAK_KEY: case ERR_CIPHER_INIT_WEAK_KEY:
MessageBoxW (hwndDlg, GetString ("ERR_CIPHER_INIT_WEAK_KEY"), lpszTitle, ICON_HAND); MessageBoxW (hwndDlg, AppendSrcPos (GetString ("ERR_CIPHER_INIT_WEAK_KEY"), srcPos).c_str(), lpszTitle, ICON_HAND);
break; break;
case ERR_VOL_ALREADY_MOUNTED: case ERR_VOL_ALREADY_MOUNTED:
MessageBoxW (hwndDlg, GetString ("VOL_ALREADY_MOUNTED"), lpszTitle, ICON_HAND); MessageBoxW (hwndDlg, AppendSrcPos (GetString ("VOL_ALREADY_MOUNTED"), srcPos).c_str(), lpszTitle, ICON_HAND);
break; break;
case ERR_FILE_OPEN_FAILED: case ERR_FILE_OPEN_FAILED:
MessageBoxW (hwndDlg, GetString ("FILE_OPEN_FAILED"), lpszTitle, ICON_HAND); MessageBoxW (hwndDlg, AppendSrcPos (GetString ("FILE_OPEN_FAILED"), srcPos).c_str(), lpszTitle, ICON_HAND);
break; break;
case ERR_VOL_MOUNT_FAILED: case ERR_VOL_MOUNT_FAILED:
MessageBoxW (hwndDlg, GetString ("VOL_MOUNT_FAILED"), lpszTitle, ICON_HAND); MessageBoxW (hwndDlg, AppendSrcPos (GetString ("VOL_MOUNT_FAILED"), srcPos).c_str(), lpszTitle, ICON_HAND);
break; break;
case ERR_NO_FREE_DRIVES: case ERR_NO_FREE_DRIVES:
MessageBoxW (hwndDlg, GetString ("NO_FREE_DRIVES"), lpszTitle, ICON_HAND); MessageBoxW (hwndDlg, AppendSrcPos (GetString ("NO_FREE_DRIVES"), srcPos).c_str(), lpszTitle, ICON_HAND);
break; break;
case ERR_ACCESS_DENIED: case ERR_ACCESS_DENIED:
MessageBoxW (hwndDlg, GetString ("ACCESS_DENIED"), lpszTitle, ICON_HAND); MessageBoxW (hwndDlg, AppendSrcPos (GetString ("ACCESS_DENIED"), srcPos).c_str(), lpszTitle, ICON_HAND);
break; break;
case ERR_DRIVER_VERSION: case ERR_DRIVER_VERSION:
@@ -4158,7 +4158,7 @@ void handleError (HWND hwndDlg, int code)
break; break;
case ERR_NEW_VERSION_REQUIRED: case ERR_NEW_VERSION_REQUIRED:
MessageBoxW (hwndDlg, GetString ("NEW_VERSION_REQUIRED"), lpszTitle, ICON_HAND); MessageBoxW (hwndDlg, AppendSrcPos (GetString ("NEW_VERSION_REQUIRED"), srcPos).c_str(), lpszTitle, ICON_HAND);
break; break;
case ERR_SELF_TESTS_FAILED: case ERR_SELF_TESTS_FAILED:
@@ -4192,24 +4192,24 @@ void handleError (HWND hwndDlg, int code)
case ERR_UNSUPPORTED_TRUECRYPT_FORMAT: case ERR_UNSUPPORTED_TRUECRYPT_FORMAT:
StringCbPrintfW (szTmp, sizeof(szTmp), GetString ("UNSUPPORTED_TRUECRYPT_FORMAT"), (code >> 24), (code >> 16) & 0x000000FF); StringCbPrintfW (szTmp, sizeof(szTmp), GetString ("UNSUPPORTED_TRUECRYPT_FORMAT"), (code >> 24), (code >> 16) & 0x000000FF);
MessageBoxW (hwndDlg, szTmp, lpszTitle, ICON_HAND); MessageBoxW (hwndDlg, AppendSrcPos (szTmp, srcPos).c_str(), lpszTitle, ICON_HAND);
break; break;
#ifndef SETUP #ifndef SETUP
case ERR_RAND_INIT_FAILED: case ERR_RAND_INIT_FAILED:
StringCbPrintfW (szTmp, sizeof(szTmp), GetString ("INIT_RAND"), SRC_POS, GetLastError ()); StringCbPrintfW (szTmp, sizeof(szTmp), GetString ("INIT_RAND"), SRC_POS, GetLastError ());
MessageBoxW (hwndDlg, szTmp, lpszTitle, MB_ICONERROR); MessageBoxW (hwndDlg, AppendSrcPos (szTmp, srcPos).c_str(), lpszTitle, MB_ICONERROR);
break; break;
case ERR_CAPI_INIT_FAILED: case ERR_CAPI_INIT_FAILED:
StringCbPrintfW (szTmp, sizeof(szTmp), GetString ("CAPI_RAND"), SRC_POS, CryptoAPILastError); StringCbPrintfW (szTmp, sizeof(szTmp), GetString ("CAPI_RAND"), SRC_POS, CryptoAPILastError);
MessageBoxW (hwndDlg, szTmp, lpszTitle, MB_ICONERROR); MessageBoxW (hwndDlg, AppendSrcPos (szTmp, srcPos).c_str(), lpszTitle, MB_ICONERROR);
break; break;
#endif #endif
default: default:
StringCbPrintfW (szTmp, sizeof(szTmp), GetString ("ERR_UNKNOWN"), code); StringCbPrintfW (szTmp, sizeof(szTmp), GetString ("ERR_UNKNOWN"), code);
MessageBoxW (hwndDlg, szTmp, lpszTitle, ICON_HAND); MessageBoxW (hwndDlg, AppendSrcPos (szTmp, srcPos).c_str(), lpszTitle, ICON_HAND);
} }
} }
@@ -5210,7 +5210,7 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
#ifndef VOLFORMAT #ifndef VOLFORMAT
if (Randinit ()) if (Randinit ())
{ {
handleError (hwndDlg, (CryptoAPILastError == ERROR_SUCCESS)? ERR_RAND_INIT_FAILED : ERR_CAPI_INIT_FAILED); handleError (hwndDlg, (CryptoAPILastError == ERROR_SUCCESS)? ERR_RAND_INIT_FAILED : ERR_CAPI_INIT_FAILED, SRC_POS);
EndDialog (hwndDlg, IDCLOSE); EndDialog (hwndDlg, IDCLOSE);
} }
#endif #endif
@@ -5410,7 +5410,7 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
{ {
TCfree(keyfile); TCfree(keyfile);
NormalCursor(); NormalCursor();
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
return 1; return 1;
} }
@@ -5452,7 +5452,7 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
{ {
TCfree(keyfile); TCfree(keyfile);
NormalCursor(); NormalCursor();
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
return 1; return 1;
} }
} }
@@ -5776,7 +5776,7 @@ CipherTestDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
if ((tmpRetVal = EAInit (ci->ea, (unsigned char *) key, ci->ks)) != ERR_SUCCESS) if ((tmpRetVal = EAInit (ci->ea, (unsigned char *) key, ci->ks)) != ERR_SUCCESS)
{ {
handleError (hwndDlg, tmpRetVal); handleError (hwndDlg, tmpRetVal, SRC_POS);
crypto_close (ci); crypto_close (ci);
return 1; return 1;
} }
@@ -6271,7 +6271,7 @@ int DriverUnmountVolume (HWND hwndDlg, int nDosDriveNo, BOOL forced)
if (bResult == FALSE) if (bResult == FALSE)
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
return 1; return 1;
} }
@@ -6778,7 +6778,7 @@ retry:
} }
if (!quiet && (!MultipleMountOperationInProgress || GetLastError() != ERROR_NOT_READY)) if (!quiet && (!MultipleMountOperationInProgress || GetLastError() != ERROR_NOT_READY))
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
return -1; return -1;
} }
@@ -6816,18 +6816,18 @@ retry:
if (DeviceIoControl (hDriver, TC_IOCTL_OPEN_TEST, &openTestStruct, sizeof (OPEN_TEST_STRUCT), &openTestStruct, sizeof (OPEN_TEST_STRUCT), &dwResult, NULL) && openTestStruct.TCBootLoaderDetected) if (DeviceIoControl (hDriver, TC_IOCTL_OPEN_TEST, &openTestStruct, sizeof (OPEN_TEST_STRUCT), &openTestStruct, sizeof (OPEN_TEST_STRUCT), &dwResult, NULL) && openTestStruct.TCBootLoaderDetected)
WarningDirect ((GetWrongPasswordErrorMessage (hwndDlg) + L"\n\n" + GetString ("HIDDEN_VOL_PROT_PASSWORD_US_KEYB_LAYOUT")).c_str(), hwndDlg); WarningDirect ((GetWrongPasswordErrorMessage (hwndDlg) + L"\n\n" + GetString ("HIDDEN_VOL_PROT_PASSWORD_US_KEYB_LAYOUT")).c_str(), hwndDlg);
else else
handleError (hwndDlg, mount.nReturnCode); handleError (hwndDlg, mount.nReturnCode, SRC_POS);
} }
} }
else else
handleError (hwndDlg, mount.nReturnCode); handleError (hwndDlg, mount.nReturnCode, SRC_POS);
} }
return 0; return 0;
} }
if (!quiet) if (!quiet)
handleError (hwndDlg, mount.nReturnCode); handleError (hwndDlg, mount.nReturnCode, SRC_POS);
return 0; return 0;
} }
@@ -7234,7 +7234,7 @@ __int64 GetStatsFreeSpaceOnPartition (const char *devicePath, float *percentFree
{ {
if (!silent) if (!silent)
{ {
handleWin32Error (MainDlg); handleWin32Error (MainDlg, SRC_POS);
Error ("CANNOT_CALC_SPACE", MainDlg); Error ("CANNOT_CALC_SPACE", MainDlg);
} }
@@ -7252,7 +7252,7 @@ __int64 GetStatsFreeSpaceOnPartition (const char *devicePath, float *percentFree
{ {
if (!silent) if (!silent)
{ {
handleWin32Error (MainDlg); handleWin32Error (MainDlg, SRC_POS);
Error ("CANT_GET_VOLSIZE", MainDlg); Error ("CANT_GET_VOLSIZE", MainDlg);
} }
return -1; return -1;
@@ -7561,7 +7561,7 @@ BOOL SaveBufferToFile (const char *inputBuffer, const char *destinationFile, DWO
if (dst == INVALID_HANDLE_VALUE) if (dst == INVALID_HANDLE_VALUE)
{ {
SetLastError (dwLastError); SetLastError (dwLastError);
handleWin32Error (MainDlg); handleWin32Error (MainDlg, SRC_POS);
return FALSE; return FALSE;
} }
@@ -7579,7 +7579,7 @@ BOOL SaveBufferToFile (const char *inputBuffer, const char *destinationFile, DWO
// If CREATE_ALWAYS is used, ERROR_ALREADY_EXISTS is returned after successful overwrite // If CREATE_ALWAYS is used, ERROR_ALREADY_EXISTS is returned after successful overwrite
// of an existing file (it's not an error) // of an existing file (it's not an error)
if (! (GetLastError() == ERROR_ALREADY_EXISTS && !bAppend) ) if (! (GetLastError() == ERROR_ALREADY_EXISTS && !bAppend) )
handleWin32Error (MainDlg); handleWin32Error (MainDlg, SRC_POS);
} }
CloseHandle (dst); CloseHandle (dst);
@@ -9739,7 +9739,7 @@ BOOL CALLBACK SecurityTokenPasswordDlgProc (HWND hwndDlg, UINT msg, WPARAM wPara
if (GetWindowTextW (GetDlgItem (hwndDlg, IDC_TOKEN_PASSWORD), passwordWide, SecurityToken::MaxPasswordLength + 1) == 0) if (GetWindowTextW (GetDlgItem (hwndDlg, IDC_TOKEN_PASSWORD), passwordWide, SecurityToken::MaxPasswordLength + 1) == 0)
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
break; break;
} }
@@ -10020,7 +10020,7 @@ BOOL CALLBACK SecurityTokenKeyfileDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam
byte *keyfileData = (byte *) LoadFile (keyfilePath, &keyfileSize); byte *keyfileData = (byte *) LoadFile (keyfilePath, &keyfileSize);
if (!keyfileData) if (!keyfileData)
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
return 1; return 1;
} }
@@ -10059,7 +10059,7 @@ BOOL CALLBACK SecurityTokenKeyfileDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam
else else
{ {
SetLastError (ERROR_HANDLE_EOF); SetLastError (ERROR_HANDLE_EOF);
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
} }
burn (keyfileData, keyfileSize); burn (keyfileData, keyfileSize);
@@ -10091,14 +10091,14 @@ BOOL CALLBACK SecurityTokenKeyfileDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam
if (keyfileData.empty()) if (keyfileData.empty())
{ {
SetLastError (ERROR_HANDLE_EOF); SetLastError (ERROR_HANDLE_EOF);
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
return 1; return 1;
} }
finally_do_arg (vector <byte> *, &keyfileData, { burn (&finally_arg->front(), finally_arg->size()); }); finally_do_arg (vector <byte> *, &keyfileData, { burn (&finally_arg->front(), finally_arg->size()); });
if (!SaveBufferToFile ((char *) &keyfileData.front(), keyfilePath, (DWORD) keyfileData.size(), FALSE, FALSE)) if (!SaveBufferToFile ((char *) &keyfileData.front(), keyfilePath, (DWORD) keyfileData.size(), FALSE, FALSE))
throw SystemException (); throw SystemException (SRC_POS);
} }
Info ("KEYFILE_EXPORTED", hwndDlg); Info ("KEYFILE_EXPORTED", hwndDlg);
@@ -10481,7 +10481,7 @@ BOOL RemoveDeviceWriteProtection (HWND hwndDlg, char *devicePath)
FILE *f = fopen (cmdBatch, "w"); FILE *f = fopen (cmdBatch, "w");
if (!f) if (!f)
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
return FALSE; return FALSE;
} }
@@ -10493,7 +10493,7 @@ BOOL RemoveDeviceWriteProtection (HWND hwndDlg, char *devicePath)
f = fopen (diskpartScript, "w"); f = fopen (diskpartScript, "w");
if (!f) if (!f)
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
DeleteFile (cmdBatch); DeleteFile (cmdBatch);
return FALSE; return FALSE;
} }
@@ -10631,7 +10631,7 @@ BOOL LaunchWindowsIsoBurner (HWND hwnd, const char *isoPath)
if (r <= 32) if (r <= 32)
{ {
SetLastError (r); SetLastError (r);
handleWin32Error (hwnd); handleWin32Error (hwnd, SRC_POS);
return FALSE; return FALSE;
} }

View File

@@ -237,7 +237,7 @@ void AbortProcess ( char *stringId );
void AbortProcessSilent ( void ); void AbortProcessSilent ( void );
void *err_malloc ( size_t size ); void *err_malloc ( size_t size );
char *err_strdup ( char *lpszText ); char *err_strdup ( char *lpszText );
DWORD handleWin32Error ( HWND hwndDlg ); DWORD handleWin32Error ( HWND hwndDlg, const char* srcPos );
BOOL IsDiskReadError (DWORD error); BOOL IsDiskReadError (DWORD error);
BOOL IsDiskWriteError (DWORD error); BOOL IsDiskWriteError (DWORD error);
BOOL IsDiskError (DWORD error); BOOL IsDiskError (DWORD error);
@@ -317,7 +317,7 @@ void ResetCipherTest ( HWND hwndDlg , int idTestCipher );
void ResetCurrentDirectory (); void ResetCurrentDirectory ();
BOOL BrowseFiles (HWND hwndDlg, char *stringId, char *lpszFileName, BOOL keepHistory, BOOL saveMode, wchar_t *browseFilter); BOOL BrowseFiles (HWND hwndDlg, char *stringId, char *lpszFileName, BOOL keepHistory, BOOL saveMode, wchar_t *browseFilter);
BOOL BrowseDirectories (HWND hWnd, char *lpszTitle, char *dirName); BOOL BrowseDirectories (HWND hWnd, char *lpszTitle, char *dirName);
void handleError ( HWND hwndDlg , int code ); 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 char *fileName);
void LocalizeDialog ( HWND hwnd, char *stringId ); void LocalizeDialog ( HWND hwnd, char *stringId );
void OpenVolumeExplorerWindow (int driveNo); void OpenVolumeExplorerWindow (int driveNo);
@@ -552,6 +552,10 @@ std::string FindLatestFileOrDirectory (const std::string &directory, const char
std::string GetUserFriendlyVersionString (int version); std::string GetUserFriendlyVersionString (int version);
std::string IntToString (int val); std::string IntToString (int val);
std::wstring IntToWideString (int val); std::wstring IntToWideString (int val);
inline std::wstring AppendSrcPos (const wchar_t* msg, const char* srcPos)
{
return std::wstring (msg) + L"\n\nSource: " + SingleStringToWide (srcPos);
}
// Display a wait dialog while calling the provided callback with the given parameter // Display a wait dialog while calling the provided callback with the given parameter
typedef void (CALLBACK* WaitThreadProc)(void* pArg, HWND hWaitDlg); typedef void (CALLBACK* WaitThreadProc)(void* pArg, HWND hWaitDlg);

View File

@@ -11,6 +11,7 @@
#include "Platform/PlatformBase.h" #include "Platform/PlatformBase.h"
#include "Dlgcode.h" #include "Dlgcode.h"
#include "Language.h"
#include <strsafe.h> #include <strsafe.h>
namespace VeraCrypt namespace VeraCrypt
@@ -22,30 +23,32 @@ namespace VeraCrypt
struct SystemException : public Exception struct SystemException : public Exception
{ {
SystemException () : ErrorCode (GetLastError()) { } SystemException (const char *srcPos) : ErrorCode (GetLastError()), SrcPos (srcPos) { }
void Show (HWND parent) const void Show (HWND parent) const
{ {
SetLastError (ErrorCode); SetLastError (ErrorCode);
handleWin32Error (parent); handleWin32Error (parent, SrcPos);
} }
DWORD ErrorCode; DWORD ErrorCode;
const char *SrcPos;
}; };
struct ErrorException : public Exception struct ErrorException : public Exception
{ {
ErrorException (char *langId) : ErrLangId (langId) { } ErrorException (char *langId, const char *srcPos) : SrcPos (srcPos), ErrLangId (langId) { }
ErrorException (const wstring &errMsg) : ErrLangId(NULL), ErrMsg (errMsg) { } ErrorException (const wstring &errMsg, const char *srcPos) : SrcPos (srcPos), ErrLangId(NULL), ErrMsg (errMsg) { }
void Show (HWND parent) const void Show (HWND parent) const
{ {
if (ErrMsg.empty()) if (ErrMsg.empty())
::Error (ErrLangId? ErrLangId : "", parent); ::ErrorDirect (AppendSrcPos (GetString (ErrLangId? ErrLangId : ""), SrcPos).c_str (), parent);
else else
::ErrorDirect (ErrMsg.c_str(), parent); ::ErrorDirect (AppendSrcPos (ErrMsg.c_str(), SrcPos).c_str (), parent);
} }
const char *SrcPos;
char *ErrLangId; char *ErrLangId;
wstring ErrMsg; wstring ErrMsg;
}; };
@@ -97,8 +100,10 @@ namespace VeraCrypt
struct TimeOut : public Exception struct TimeOut : public Exception
{ {
TimeOut (const char *srcPos) { } TimeOut (const char *srcPos) : SrcPos (srcPos) { }
void Show (HWND parent) const { ErrorDirect (L"Timeout", parent); } void Show (HWND parent) const { ErrorDirect (AppendSrcPos (L"Timeout", SrcPos).c_str (), parent); }
const char *SrcPos;
}; };
struct UserAbort : public Exception struct UserAbort : public Exception
@@ -108,7 +113,7 @@ namespace VeraCrypt
}; };
} }
#define throw_sys_if(condition) do { if (condition) throw SystemException(); } while (false) #define throw_sys_if(condition) do { if (condition) throw SystemException( SRC_POS ); } while (false)
#endif // TC_HEADER_Common_Exception #endif // TC_HEADER_Common_Exception

View File

@@ -31,6 +31,10 @@
#include <Strsafe.h> #include <Strsafe.h>
#ifndef SRC_POS
#define SRC_POS (__FUNCTION__ ":" TC_TO_STRING(__LINE__))
#endif
int FormatWriteBufferSize = 1024 * 1024; int FormatWriteBufferSize = 1024 * 1024;
static uint32 FormatSectorSize = 0; static uint32 FormatSectorSize = 0;
@@ -286,7 +290,7 @@ begin_format:
} }
else else
{ {
handleWin32Error (volParams->hwndDlg); handleWin32Error (volParams->hwndDlg, SRC_POS);
Error ("CANT_ACCESS_VOL", hwndDlg); Error ("CANT_ACCESS_VOL", hwndDlg);
nStatus = ERR_DONT_REPORT; nStatus = ERR_DONT_REPORT;
goto error; goto error;
@@ -893,7 +897,7 @@ static void __cdecl FormatWriteThreadProc (void *arg)
{ {
if (WaitForSingleObject (WriteBufferFullEvent, INFINITE) == WAIT_FAILED) if (WaitForSingleObject (WriteBufferFullEvent, INFINITE) == WAIT_FAILED)
{ {
handleWin32Error (NULL); handleWin32Error (NULL, SRC_POS);
break; break;
} }
@@ -907,7 +911,7 @@ static void __cdecl FormatWriteThreadProc (void *arg)
if (!SetEvent (WriteBufferEmptyEvent)) if (!SetEvent (WriteBufferEmptyEvent))
{ {
handleWin32Error (NULL); handleWin32Error (NULL, SRC_POS);
break; break;
} }
} }

View File

@@ -252,7 +252,7 @@ BOOL KeyFilesApply (HWND hwndDlg, Password *password, KeyFile *firstKeyFile)
if (keyfileData.empty()) if (keyfileData.empty())
{ {
SetLastError (ERROR_HANDLE_EOF); SetLastError (ERROR_HANDLE_EOF);
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
Error ("ERR_PROCESS_KEYFILE", hwndDlg); Error ("ERR_PROCESS_KEYFILE", hwndDlg);
status = FALSE; status = FALSE;
continue; continue;
@@ -291,7 +291,7 @@ BOOL KeyFilesApply (HWND hwndDlg, Password *password, KeyFile *firstKeyFile)
// Determine whether it's a path or a file // Determine whether it's a path or a file
if (stat (kf->FileName, &statStruct) != 0) if (stat (kf->FileName, &statStruct) != 0)
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
Error ("ERR_PROCESS_KEYFILE", hwndDlg); Error ("ERR_PROCESS_KEYFILE", hwndDlg);
status = FALSE; status = FALSE;
continue; continue;
@@ -305,7 +305,7 @@ BOOL KeyFilesApply (HWND hwndDlg, Password *password, KeyFile *firstKeyFile)
StringCbPrintfA (searchPath, sizeof (searchPath), "%s\\*.*", kf->FileName); StringCbPrintfA (searchPath, sizeof (searchPath), "%s\\*.*", kf->FileName);
if ((searchHandle = _findfirst (searchPath, &fBuf)) == -1) if ((searchHandle = _findfirst (searchPath, &fBuf)) == -1)
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
Error ("ERR_PROCESS_KEYFILE_PATH", hwndDlg); Error ("ERR_PROCESS_KEYFILE_PATH", hwndDlg);
status = FALSE; status = FALSE;
continue; continue;
@@ -323,7 +323,7 @@ BOOL KeyFilesApply (HWND hwndDlg, Password *password, KeyFile *firstKeyFile)
// Determine whether it's a path or a file // Determine whether it's a path or a file
if (stat (kfSub->FileName, &statStruct) != 0) if (stat (kfSub->FileName, &statStruct) != 0)
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
Error ("ERR_PROCESS_KEYFILE", hwndDlg); Error ("ERR_PROCESS_KEYFILE", hwndDlg);
status = FALSE; status = FALSE;
continue; continue;
@@ -347,7 +347,7 @@ BOOL KeyFilesApply (HWND hwndDlg, Password *password, KeyFile *firstKeyFile)
// Apply keyfile to the pool // Apply keyfile to the pool
if (!KeyFileProcess (keyPool, kfSub)) if (!KeyFileProcess (keyPool, kfSub))
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
Error ("ERR_PROCESS_KEYFILE", hwndDlg); Error ("ERR_PROCESS_KEYFILE", hwndDlg);
status = FALSE; status = FALSE;
} }
@@ -366,7 +366,7 @@ BOOL KeyFilesApply (HWND hwndDlg, Password *password, KeyFile *firstKeyFile)
// Apply keyfile to the pool // Apply keyfile to the pool
else if (!KeyFileProcess (keyPool, kf)) else if (!KeyFileProcess (keyPool, kf))
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
Error ("ERR_PROCESS_KEYFILE", hwndDlg); Error ("ERR_PROCESS_KEYFILE", hwndDlg);
status = FALSE; status = FALSE;
} }

View File

@@ -6,6 +6,8 @@
packages. packages.
*/ */
#pragma once
#include <windows.h> #include <windows.h>
#ifdef __cplusplus #ifdef __cplusplus

View File

@@ -22,6 +22,10 @@
#include <io.h> #include <io.h>
#ifndef SRC_POS
#define SRC_POS (__FUNCTION__ ":" TC_TO_STRING(__LINE__))
#endif
void VerifyPasswordAndUpdate (HWND hwndDlg, HWND hButton, HWND hPassword, void VerifyPasswordAndUpdate (HWND hwndDlg, HWND hButton, HWND hPassword,
HWND hVerify, unsigned char *szPassword, HWND hVerify, unsigned char *szPassword,
char *szVerify, char *szVerify,
@@ -160,14 +164,14 @@ int ChangePwd (const char *lpszVolume, Password *oldPassword, int old_pkcs5, int
if ((wipePassCount <= 0) || (truecryptMode && (old_pkcs5 == SHA256))) if ((wipePassCount <= 0) || (truecryptMode && (old_pkcs5 == SHA256)))
{ {
nStatus = ERR_PARAMETER_INCORRECT; nStatus = ERR_PARAMETER_INCORRECT;
handleError (hwndDlg, nStatus); handleError (hwndDlg, nStatus, SRC_POS);
return nStatus; return nStatus;
} }
if (!lpszVolume) if (!lpszVolume)
{ {
nStatus = ERR_OUTOFMEMORY; nStatus = ERR_OUTOFMEMORY;
handleError (hwndDlg, nStatus); handleError (hwndDlg, nStatus, SRC_POS);
return nStatus; return nStatus;
} }
@@ -451,7 +455,7 @@ error:
return nStatus; return nStatus;
if (nStatus != 0) if (nStatus != 0)
handleError (hwndDlg, nStatus); handleError (hwndDlg, nStatus, SRC_POS);
return nStatus; return nStatus;
} }

View File

@@ -66,6 +66,10 @@ void RandAddInt64 (unsigned __int64 x)
#include <tlhelp32.h> #include <tlhelp32.h>
#include "Dlgcode.h" #include "Dlgcode.h"
#ifndef SRC_POS
#define SRC_POS (__FUNCTION__ ":" TC_TO_STRING(__LINE__))
#endif
HHOOK hMouse = NULL; /* Mouse hook for the random number generator */ HHOOK hMouse = NULL; /* Mouse hook for the random number generator */
HHOOK hKeyboard = NULL; /* Keyboard hook for the random number generator */ HHOOK hKeyboard = NULL; /* Keyboard hook for the random number generator */
@@ -112,12 +116,12 @@ int Randinit ()
} }
hKeyboard = SetWindowsHookEx (WH_KEYBOARD, (HOOKPROC)&KeyboardProc, NULL, GetCurrentThreadId ()); hKeyboard = SetWindowsHookEx (WH_KEYBOARD, (HOOKPROC)&KeyboardProc, NULL, GetCurrentThreadId ());
if (hKeyboard == 0) handleWin32Error (0); if (hKeyboard == 0) handleWin32Error (0, SRC_POS);
hMouse = SetWindowsHookEx (WH_MOUSE, (HOOKPROC)&MouseProc, NULL, GetCurrentThreadId ()); hMouse = SetWindowsHookEx (WH_MOUSE, (HOOKPROC)&MouseProc, NULL, GetCurrentThreadId ());
if (hMouse == 0) if (hMouse == 0)
{ {
handleWin32Error (0); handleWin32Error (0, SRC_POS);
goto error; goto error;
} }
@@ -388,7 +392,7 @@ BOOL RandgetBytesFull ( void* hwndDlg, unsigned char *buf , int len, BOOL forceS
{ {
if (!SlowPoll ()) if (!SlowPoll ())
{ {
handleError ((HWND) hwndDlg, ERR_CAPI_INIT_FAILED); handleError ((HWND) hwndDlg, ERR_CAPI_INIT_FAILED, SRC_POS);
ret = FALSE; ret = FALSE;
} }
else else
@@ -397,7 +401,7 @@ BOOL RandgetBytesFull ( void* hwndDlg, unsigned char *buf , int len, BOOL forceS
if (!FastPoll ()) if (!FastPoll ())
{ {
handleError ((HWND) hwndDlg, ERR_CAPI_INIT_FAILED); handleError ((HWND) hwndDlg, ERR_CAPI_INIT_FAILED, SRC_POS);
ret = FALSE; ret = FALSE;
} }

View File

@@ -385,7 +385,7 @@ BOOL CALLBACK ExpandVolProgressDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, L
pProgressDlgParam->hwndDlg = hwndDlg; pProgressDlgParam->hwndDlg = hwndDlg;
if ( _beginthread (volTransformThreadFunction, 0, pProgressDlgParam) == -1L ) if ( _beginthread (volTransformThreadFunction, 0, pProgressDlgParam) == -1L )
{ {
handleError (hwndDlg, ERR_OS_ERROR); handleError (hwndDlg, ERR_OS_ERROR, SRC_POS);
EndDialog (hwndDlg, lw); EndDialog (hwndDlg, lw);
} }
WaitCursor(); WaitCursor();
@@ -572,7 +572,7 @@ void ExpandVolumeWizard (HWND hwndDlg, char *lpszVolume)
NormalCursor(); NormalCursor();
handleError (hwndDlg, nStatus); handleError (hwndDlg, nStatus, SRC_POS);
} }
WaitCursor(); WaitCursor();
@@ -722,7 +722,7 @@ ret:
error: error:
if (nStatus != 0) if (nStatus != 0)
handleError (hwndDlg, nStatus); handleError (hwndDlg, nStatus, SRC_POS);
burn (&VolumePassword, sizeof (VolumePassword)); burn (&VolumePassword, sizeof (VolumePassword));

View File

@@ -56,6 +56,10 @@ Original legal notice of the TrueCrypt source files:
#include "ExpandVolume.h" #include "ExpandVolume.h"
#include "Resource.h" #include "Resource.h"
#ifndef SRC_POS
#define SRC_POS (__FUNCTION__ ":" TC_TO_STRING(__LINE__))
#endif
#define DEBUG_EXPAND_VOLUME #define DEBUG_EXPAND_VOLUME
#ifdef DEBUG_EXPAND_VOLUME #ifdef DEBUG_EXPAND_VOLUME
@@ -987,7 +991,7 @@ void __cdecl volTransformThreadFunction (void *pExpandDlgParam)
pParam->VolumePkcs5, pParam->VolumePin, pParam->newSize, pParam->bInitFreeSpace ); pParam->VolumePkcs5, pParam->VolumePin, pParam->newSize, pParam->bInitFreeSpace );
if (nStatus!=ERR_SUCCESS && nStatus!=ERR_USER_ABORT) if (nStatus!=ERR_SUCCESS && nStatus!=ERR_USER_ABORT)
handleError (hwndDlg, nStatus); handleError (hwndDlg, nStatus, SRC_POS);
bVolTransformThreadCancel = FALSE; bVolTransformThreadCancel = FALSE;

View File

@@ -59,6 +59,10 @@ Original legal notice of the TrueCrypt source:
#include "InitDataArea.h" #include "InitDataArea.h"
#ifndef SRC_POS
#define SRC_POS (__FUNCTION__ ":" TC_TO_STRING(__LINE__))
#endif
int FormatWriteBufferSize = 1024 * 1024; int FormatWriteBufferSize = 1024 * 1024;
static uint32 FormatSectorSize = 0; static uint32 FormatSectorSize = 0;
@@ -226,7 +230,7 @@ static void __cdecl FormatWriteThreadProc (void *arg)
{ {
if (WaitForSingleObject (WriteBufferFullEvent, INFINITE) == WAIT_FAILED) if (WaitForSingleObject (WriteBufferFullEvent, INFINITE) == WAIT_FAILED)
{ {
handleWin32Error (NULL); handleWin32Error (NULL, SRC_POS);
break; break;
} }
@@ -240,7 +244,7 @@ static void __cdecl FormatWriteThreadProc (void *arg)
if (!SetEvent (WriteBufferEmptyEvent)) if (!SetEvent (WriteBufferEmptyEvent))
{ {
handleWin32Error (NULL); handleWin32Error (NULL, SRC_POS);
break; break;
} }
} }

View File

@@ -983,9 +983,9 @@ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, char *lpszComm
if (status != 0) if (status != 0)
{ {
if (status == ERR_OS_ERROR) if (status == ERR_OS_ERROR)
handleWin32Error (NULL); handleWin32Error (NULL, SRC_POS);
else else
handleError (NULL, status); handleError (NULL, status, SRC_POS);
AbortProcess ("NODRIVER"); AbortProcess ("NODRIVER");
} }

View File

@@ -79,7 +79,7 @@ static __int64 NewFileSysSizeAfterShrink (HANDLE dev, const char *devicePath, in
NULL)) NULL))
{ {
if (!silent) if (!silent)
handleWin32Error (MainDlg); handleWin32Error (MainDlg, SRC_POS);
return -1; return -1;
} }
@@ -90,7 +90,7 @@ static __int64 NewFileSysSizeAfterShrink (HANDLE dev, const char *devicePath, in
{ {
SetLastError (ERROR_INTERNAL_ERROR); SetLastError (ERROR_INTERNAL_ERROR);
if (!silent) if (!silent)
handleWin32Error (MainDlg); handleWin32Error (MainDlg, SRC_POS);
return -1; return -1;
} }
@@ -189,7 +189,7 @@ BOOL CheckRequirementsForNonSysInPlaceEnc (HWND hwndDlg, const char *devicePath,
{ {
if (!silent) if (!silent)
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
Error ("INPLACE_ENC_CANT_ACCESS_OR_GET_INFO_ON_VOL", hwndDlg); Error ("INPLACE_ENC_CANT_ACCESS_OR_GET_INFO_ON_VOL", hwndDlg);
} }
return FALSE; return FALSE;
@@ -458,7 +458,7 @@ int EncryptPartitionInPlaceBegin (volatile FORMAT_VOL_PARAMETERS *volParams, vol
&dwResult, &dwResult,
NULL)) NULL))
{ {
handleWin32Error (MainDlg); handleWin32Error (MainDlg, SRC_POS);
ShowInPlaceEncErrMsgWAltSteps (hwndDlg, "INPLACE_ENC_CANT_ACCESS_OR_GET_INFO_ON_VOL_ALT", TRUE); ShowInPlaceEncErrMsgWAltSteps (hwndDlg, "INPLACE_ENC_CANT_ACCESS_OR_GET_INFO_ON_VOL_ALT", TRUE);
nStatus = ERR_DONT_REPORT; nStatus = ERR_DONT_REPORT;
goto closing_seq; goto closing_seq;
@@ -496,7 +496,7 @@ int EncryptPartitionInPlaceBegin (volatile FORMAT_VOL_PARAMETERS *volParams, vol
&dwResult, &dwResult,
NULL)) NULL))
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
ShowInPlaceEncErrMsgWAltSteps (hwndDlg, "CANNOT_RESIZE_FILESYS", TRUE); ShowInPlaceEncErrMsgWAltSteps (hwndDlg, "CANNOT_RESIZE_FILESYS", TRUE);
nStatus = ERR_DONT_REPORT; nStatus = ERR_DONT_REPORT;
goto closing_seq; goto closing_seq;
@@ -523,11 +523,11 @@ int EncryptPartitionInPlaceBegin (volatile FORMAT_VOL_PARAMETERS *volParams, vol
continue; continue;
} }
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
} }
} }
else else
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
ShowInPlaceEncErrMsgWAltSteps (hwndDlg, "CANNOT_RESIZE_FILESYS", TRUE); ShowInPlaceEncErrMsgWAltSteps (hwndDlg, "CANNOT_RESIZE_FILESYS", TRUE);
nStatus = ERR_DONT_REPORT; nStatus = ERR_DONT_REPORT;
@@ -1237,7 +1237,7 @@ int DecryptPartitionInPlace (volatile FORMAT_VOL_PARAMETERS *volParams, volatile
if (driveLetter == -1 if (driveLetter == -1
|| !UnmountVolume (hwndDlg, driveLetter, TRUE)) || !UnmountVolume (hwndDlg, driveLetter, TRUE))
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
AbortProcess ("CANT_DISMOUNT_VOLUME"); AbortProcess ("CANT_DISMOUNT_VOLUME");
} }
} }
@@ -1797,7 +1797,7 @@ static HANDLE OpenPartitionVolume (HWND hwndDlg, const char *devName,
{ {
if (!bSilent) if (!bSilent)
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
if (bShowAlternativeSteps) if (bShowAlternativeSteps)
ShowInPlaceEncErrMsgWAltSteps (hwndDlg, "INPLACE_ENC_CANT_ACCESS_OR_GET_INFO_ON_VOL_ALT", TRUE); ShowInPlaceEncErrMsgWAltSteps (hwndDlg, "INPLACE_ENC_CANT_ACCESS_OR_GET_INFO_ON_VOL_ALT", TRUE);
@@ -1823,7 +1823,7 @@ static HANDLE OpenPartitionVolume (HWND hwndDlg, const char *devName,
{ {
if (!bSilent) if (!bSilent)
{ {
handleWin32Error (MainDlg); handleWin32Error (MainDlg, SRC_POS);
if (bShowAlternativeSteps) if (bShowAlternativeSteps)
ShowInPlaceEncErrMsgWAltSteps (hwndDlg, "INPLACE_ENC_CANT_ACCESS_OR_GET_INFO_ON_VOL_ALT", TRUE); ShowInPlaceEncErrMsgWAltSteps (hwndDlg, "INPLACE_ENC_CANT_ACCESS_OR_GET_INFO_ON_VOL_ALT", TRUE);

View File

@@ -308,7 +308,7 @@ void CALLBACK ResumeInPlaceEncWaitThreadProc(void* pArg, HWND hwndDlg)
} }
else else
{ {
handleError(hwndDlg, status); handleError(hwndDlg, status, SRC_POS);
} }
break; break;
@@ -524,7 +524,7 @@ static BOOL SaveSysEncSettings (HWND hwndDlg)
if (f == NULL) if (f == NULL)
{ {
Error ("CANNOT_SAVE_SYS_ENCRYPTION_SETTINGS", hwndDlg); Error ("CANNOT_SAVE_SYS_ENCRYPTION_SETTINGS", hwndDlg);
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
return FALSE; return FALSE;
} }
@@ -540,7 +540,7 @@ static BOOL SaveSysEncSettings (HWND hwndDlg)
|| XmlWriteFooter (f) < 0) || XmlWriteFooter (f) < 0)
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
fclose (f); fclose (f);
Error ("CANNOT_SAVE_SYS_ENCRYPTION_SETTINGS", hwndDlg); Error ("CANNOT_SAVE_SYS_ENCRYPTION_SETTINGS", hwndDlg);
return FALSE; return FALSE;
@@ -2662,7 +2662,7 @@ static void __cdecl volTransformThreadFunction (void *hwndDlgArg)
wchar_t szMsg[8192]; wchar_t szMsg[8192];
handleError (hwndDlg, nStatus); handleError (hwndDlg, nStatus, SRC_POS);
if (bInPlaceEncNonSys) if (bInPlaceEncNonSys)
{ {
@@ -3292,7 +3292,7 @@ BOOL QueryFreeSpace (HWND hwndDlg, HWND hwndTextBox, BOOL display)
if (!GetVolumePathName (szFileName, root, sizeof (root))) if (!GetVolumePathName (szFileName, root, sizeof (root)))
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
return FALSE; return FALSE;
} }
@@ -5226,7 +5226,7 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
nVolumeSize = GetDeviceSize (szDiskFile); nVolumeSize = GetDeviceSize (szDiskFile);
if (nVolumeSize == -1) if (nVolumeSize == -1)
{ {
handleWin32Error (MainDlg); handleWin32Error (MainDlg, SRC_POS);
return 1; return 1;
} }
@@ -5846,7 +5846,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
if (!ComServerFormat ()) if (!ComServerFormat ())
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
exit (1); exit (1);
} }
exit (0); exit (0);
@@ -6993,7 +6993,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
if (nVolumeSize == -1) if (nVolumeSize == -1)
{ {
handleWin32Error (MainDlg); handleWin32Error (MainDlg, SRC_POS);
return 1; return 1;
} }
@@ -7353,7 +7353,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
nVolumeSize = GetDeviceSize (szDiskFile); nVolumeSize = GetDeviceSize (szDiskFile);
if (nVolumeSize == -1) if (nVolumeSize == -1)
{ {
handleWin32Error (MainDlg); handleWin32Error (MainDlg, SRC_POS);
NormalCursor(); NormalCursor();
return 1; return 1;
} }
@@ -7380,7 +7380,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
if (driveNo == -1 if (driveNo == -1
|| !UnmountVolume (hwndDlg, driveNo, TRUE)) || !UnmountVolume (hwndDlg, driveNo, TRUE))
{ {
handleWin32Error (MainDlg); handleWin32Error (MainDlg, SRC_POS);
AbortProcess ("CANT_DISMOUNT_VOLUME"); AbortProcess ("CANT_DISMOUNT_VOLUME");
} }
} }
@@ -7413,7 +7413,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
volProp.driveNo = driveNo; volProp.driveNo = driveNo;
if (!DeviceIoControl (hDriver, TC_IOCTL_GET_VOLUME_PROPERTIES, &volProp, sizeof (volProp), &volProp, sizeof (volProp), &dwResult, NULL) || dwResult == 0) if (!DeviceIoControl (hDriver, TC_IOCTL_GET_VOLUME_PROPERTIES, &volProp, sizeof (volProp), &volProp, sizeof (volProp), &dwResult, NULL) || dwResult == 0)
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
UnmountVolume (hwndDlg, driveNo, TRUE); UnmountVolume (hwndDlg, driveNo, TRUE);
AbortProcess ("CANT_GET_VOL_INFO"); AbortProcess ("CANT_GET_VOL_INFO");
} }
@@ -7435,7 +7435,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
if (!UnmountVolume (hwndDlg, driveNo, TRUE)) if (!UnmountVolume (hwndDlg, driveNo, TRUE))
{ {
handleWin32Error (MainDlg); handleWin32Error (MainDlg, SRC_POS);
AbortProcess ("CANT_DISMOUNT_VOLUME"); AbortProcess ("CANT_DISMOUNT_VOLUME");
} }
@@ -7449,7 +7449,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
if (!UnmountVolume (hwndDlg, driveNo, TRUE)) if (!UnmountVolume (hwndDlg, driveNo, TRUE))
{ {
handleWin32Error (MainDlg); handleWin32Error (MainDlg, SRC_POS);
AbortProcess ("CANT_DISMOUNT_VOLUME"); AbortProcess ("CANT_DISMOUNT_VOLUME");
} }
@@ -7460,7 +7460,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
nVolumeSize = GetDeviceSize (szDiskFile); nVolumeSize = GetDeviceSize (szDiskFile);
if (nVolumeSize == -1) if (nVolumeSize == -1)
{ {
handleWin32Error (MainDlg); handleWin32Error (MainDlg, SRC_POS);
AbortProcessSilent (); AbortProcessSilent ();
} }
@@ -8745,7 +8745,7 @@ int AnalyzeHiddenVolumeHost (HWND hwndDlg, int *driveNo, __int64 hiddenVolHostSi
volProp.driveNo = *driveNo; volProp.driveNo = *driveNo;
if (!DeviceIoControl (hDriver, TC_IOCTL_GET_VOLUME_PROPERTIES, &volProp, sizeof (volProp), &volProp, sizeof (volProp), &dwResult, NULL) || dwResult == 0) if (!DeviceIoControl (hDriver, TC_IOCTL_GET_VOLUME_PROPERTIES, &volProp, sizeof (volProp), &volProp, sizeof (volProp), &dwResult, NULL) || dwResult == 0)
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
Error ("CANT_ACCESS_OUTER_VOL", hwndDlg); Error ("CANT_ACCESS_OUTER_VOL", hwndDlg);
goto efsf_error; goto efsf_error;
} }
@@ -8783,7 +8783,7 @@ int AnalyzeHiddenVolumeHost (HWND hwndDlg, int *driveNo, __int64 hiddenVolHostSi
if (SetFilePointerEx (hDevice, offset, &offsetNew, FILE_BEGIN) == 0) if (SetFilePointerEx (hDevice, offset, &offsetNew, FILE_BEGIN) == 0)
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
goto efs_error; goto efs_error;
} }
@@ -8791,7 +8791,7 @@ int AnalyzeHiddenVolumeHost (HWND hwndDlg, int *driveNo, __int64 hiddenVolHostSi
if (result == 0) if (result == 0)
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
MessageBoxW (hwndDlg, GetString ("CANT_ACCESS_OUTER_VOL"), lpszTitle, ICON_HAND); MessageBoxW (hwndDlg, GetString ("CANT_ACCESS_OUTER_VOL"), lpszTitle, ICON_HAND);
goto efs_error; goto efs_error;
} }
@@ -8842,7 +8842,7 @@ int AnalyzeHiddenVolumeHost (HWND hwndDlg, int *driveNo, __int64 hiddenVolHostSi
&dwNumberOfFreeClusters, &dwNumberOfFreeClusters,
&dwTotalNumberOfClusters)) &dwTotalNumberOfClusters))
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
Error ("CANT_GET_OUTER_VOL_INFO", hwndDlg); Error ("CANT_GET_OUTER_VOL_INFO", hwndDlg);
return -1; return -1;
}; };
@@ -8955,7 +8955,7 @@ int ScanVolClusterBitmap (HWND hwndDlg, int *driveNo, __int64 nbrClusters, __int
&lBytesReturned, &lBytesReturned,
NULL)) NULL))
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
MessageBoxW (hwndDlg, GetString ("CANT_GET_CLUSTER_BITMAP"), lpszTitle, ICON_HAND); MessageBoxW (hwndDlg, GetString ("CANT_GET_CLUSTER_BITMAP"), lpszTitle, ICON_HAND);
goto vcm_error; goto vcm_error;
@@ -9649,9 +9649,9 @@ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, char *lpszComm
if (status != 0) if (status != 0)
{ {
if (status == ERR_OS_ERROR) if (status == ERR_OS_ERROR)
handleWin32Error (NULL); handleWin32Error (NULL, SRC_POS);
else else
handleError (NULL, status); handleError (NULL, status, SRC_POS);
AbortProcess ("NODRIVER"); AbortProcess ("NODRIVER");
} }
@@ -9677,7 +9677,7 @@ static int GetFormatSectorSize ()
if (!GetDriveGeometry (szDiskFile, &geometry)) if (!GetDriveGeometry (szDiskFile, &geometry))
{ {
handleWin32Error (MainDlg); handleWin32Error (MainDlg, SRC_POS);
AbortProcessSilent(); AbortProcessSilent();
} }

View File

@@ -39,7 +39,7 @@ namespace VeraCrypt
if (!DeviceIoControl (hDriver, TC_IOCTL_GET_VOLUME_PROPERTIES, &prop, sizeof (prop), &prop, sizeof (prop), &bytesReturned, NULL)) if (!DeviceIoControl (hDriver, TC_IOCTL_GET_VOLUME_PROPERTIES, &prop, sizeof (prop), &prop, sizeof (prop), &bytesReturned, NULL))
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
return FALSE; return FALSE;
} }
@@ -137,7 +137,7 @@ namespace VeraCrypt
BootEncryptionStatus bootEncStatus = BootEncryption (hwndDlg).GetStatus(); BootEncryptionStatus bootEncStatus = BootEncryption (hwndDlg).GetStatus();
if (!bootEncStatus.DriveMounted) if (!bootEncStatus.DriveMounted)
throw ErrorException ("SYS_FAVORITES_REQUIRE_PBA"); throw ErrorException ("SYS_FAVORITES_REQUIRE_PBA", SRC_POS);
ShowWindow (GetDlgItem(hwndDlg, IDC_FAVORITE_MOUNT_ON_LOGON), SW_HIDE); ShowWindow (GetDlgItem(hwndDlg, IDC_FAVORITE_MOUNT_ON_LOGON), SW_HIDE);
ShowWindow (GetDlgItem(hwndDlg, IDC_FAVORITE_MOUNT_ON_ARRIVAL), SW_HIDE); ShowWindow (GetDlgItem(hwndDlg, IDC_FAVORITE_MOUNT_ON_ARRIVAL), SW_HIDE);
@@ -667,7 +667,7 @@ namespace VeraCrypt
f = fopen (GetConfigPath (systemFavorites ? TC_APPD_FILENAME_SYSTEM_FAVORITE_VOLUMES : TC_APPD_FILENAME_FAVORITE_VOLUMES), "w,ccs=UTF-8"); f = fopen (GetConfigPath (systemFavorites ? TC_APPD_FILENAME_SYSTEM_FAVORITE_VOLUMES : TC_APPD_FILENAME_FAVORITE_VOLUMES), "w,ccs=UTF-8");
if (f == NULL) if (f == NULL)
{ {
handleWin32Error (MainDlg); handleWin32Error (MainDlg, SRC_POS);
return false; return false;
} }

View File

@@ -15,6 +15,10 @@
#include <Strsafe.h> #include <Strsafe.h>
#ifndef SRC_POS
#define SRC_POS (__FUNCTION__ ":" TC_TO_STRING(__LINE__))
#endif
#define MAX_KEY_COMB_NAME_LEN 260 #define MAX_KEY_COMB_NAME_LEN 260
TCHOTKEY Hotkeys [NBR_HOTKEYS]; TCHOTKEY Hotkeys [NBR_HOTKEYS];
@@ -422,13 +426,13 @@ BOOL CALLBACK HotkeysDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPar
if (!bOwnActiveShortcut if (!bOwnActiveShortcut
&& !RegisterHotKey (hwndDlg, nSelectedHotkeyId, modifiers, currentVKeyCode)) && !RegisterHotKey (hwndDlg, nSelectedHotkeyId, modifiers, currentVKeyCode))
{ {
handleWin32Error(hwndDlg); handleWin32Error(hwndDlg, SRC_POS);
return 1; return 1;
} }
else else
{ {
if (!bOwnActiveShortcut && !UnregisterHotKey (hwndDlg, nSelectedHotkeyId)) if (!bOwnActiveShortcut && !UnregisterHotKey (hwndDlg, nSelectedHotkeyId))
handleWin32Error(hwndDlg); handleWin32Error(hwndDlg, SRC_POS);
tmpHotkeys[nSelectedHotkeyId].vKeyCode = currentVKeyCode; tmpHotkeys[nSelectedHotkeyId].vKeyCode = currentVKeyCode;
tmpHotkeys[nSelectedHotkeyId].vKeyModifiers = modifiers; tmpHotkeys[nSelectedHotkeyId].vKeyModifiers = modifiers;

View File

@@ -1325,7 +1325,7 @@ static void LaunchVolCreationWizard (HWND hwndDlg, const char *arg)
if (!CreateProcess (NULL, (LPSTR) t, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi)) if (!CreateProcess (NULL, (LPSTR) t, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi))
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
} }
else else
{ {
@@ -1352,7 +1352,7 @@ static void LaunchVolExpander (HWND hwndDlg)
Error ("VOL_EXPANDER_NOT_FOUND", hwndDlg); // Display a user-friendly error message and advise what to do Error ("VOL_EXPANDER_NOT_FOUND", hwndDlg); // Display a user-friendly error message and advise what to do
else if (((int)ShellExecuteA (NULL, (!IsAdmin() && IsUacSupported()) ? "runas" : "open", t, NULL, NULL, SW_SHOW)) <= 32) else if (((int)ShellExecuteA (NULL, (!IsAdmin() && IsUacSupported()) ? "runas" : "open", t, NULL, NULL, SW_SHOW)) <= 32)
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
} }
} }
} }
@@ -1408,7 +1408,7 @@ void LoadDriveLetters (HWND hwndDlg, HWND hTree, int drive)
if (bResult == FALSE) if (bResult == FALSE)
{ {
KillTimer (MainDlg, TIMER_ID_MAIN); KillTimer (MainDlg, TIMER_ID_MAIN);
handleWin32Error (hTree); handleWin32Error (hTree, SRC_POS);
AbortProcessSilent(); AbortProcessSilent();
} }
@@ -3882,7 +3882,7 @@ BOOL CALLBACK TravelerDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
StringCbPrintfA (dstPath, sizeof(dstPath), "%s\\VeraCrypt\\VeraCrypt.exe", dstDir); StringCbPrintfA (dstPath, sizeof(dstPath), "%s\\VeraCrypt\\VeraCrypt.exe", dstDir);
if (!TCCopyFile (srcPath, dstPath)) if (!TCCopyFile (srcPath, dstPath))
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
goto stop; goto stop;
} }
@@ -3893,7 +3893,7 @@ BOOL CALLBACK TravelerDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
StringCbPrintfA (dstPath, sizeof(dstPath), "%s\\VeraCrypt\\VeraCrypt Format.exe", dstDir); StringCbPrintfA (dstPath, sizeof(dstPath), "%s\\VeraCrypt\\VeraCrypt Format.exe", dstDir);
if (!TCCopyFile (srcPath, dstPath)) if (!TCCopyFile (srcPath, dstPath))
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
goto stop; goto stop;
} }
} }
@@ -3903,7 +3903,7 @@ BOOL CALLBACK TravelerDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
StringCbPrintfA (dstPath, sizeof(dstPath), "%s\\VeraCrypt\\veracrypt.sys", dstDir); StringCbPrintfA (dstPath, sizeof(dstPath), "%s\\VeraCrypt\\veracrypt.sys", dstDir);
if (!TCCopyFile (srcPath, dstPath)) if (!TCCopyFile (srcPath, dstPath))
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
goto stop; goto stop;
} }
@@ -3912,7 +3912,7 @@ BOOL CALLBACK TravelerDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
StringCbPrintfA (dstPath, sizeof(dstPath), "%s\\VeraCrypt\\veracrypt-x64.sys", dstDir); StringCbPrintfA (dstPath, sizeof(dstPath), "%s\\VeraCrypt\\veracrypt-x64.sys", dstDir);
if (!TCCopyFile (srcPath, dstPath)) if (!TCCopyFile (srcPath, dstPath))
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
goto stop; goto stop;
} }
@@ -4179,7 +4179,7 @@ static BOOL Mount (HWND hwndDlg, int nDosDriveNo, char *szFileName, int pin)
if (!VolumePathExists (szFileName)) if (!VolumePathExists (szFileName))
{ {
if (!MultipleMountOperationInProgress) if (!MultipleMountOperationInProgress)
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
status = FALSE; status = FALSE;
goto ret; goto ret;
@@ -4431,7 +4431,7 @@ retry:
if (bResult == FALSE) if (bResult == FALSE)
{ {
NormalCursor(); NormalCursor();
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
return FALSE; return FALSE;
} }
@@ -4798,7 +4798,7 @@ static void ChangePassword (HWND hwndDlg)
if (!VolumePathExists (szFileName)) if (!VolumePathExists (szFileName))
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
return; return;
} }
@@ -5119,7 +5119,7 @@ static void DecryptNonSysDevice (HWND hwndDlg, BOOL bResolveAmbiguousSelection,
if (!DeviceIoControl (hDriver, TC_IOCTL_GET_VOLUME_PROPERTIES, &prop, sizeof (prop), &prop, sizeof (prop), &bytesReturned, NULL)) if (!DeviceIoControl (hDriver, TC_IOCTL_GET_VOLUME_PROPERTIES, &prop, sizeof (prop), &prop, sizeof (prop), &bytesReturned, NULL))
{ {
handleWin32Error (MainDlg); handleWin32Error (MainDlg, SRC_POS);
return; return;
} }
@@ -5446,7 +5446,7 @@ static void WipeCache (HWND hwndDlg, BOOL silent)
return; return;
if (bResult == FALSE) if (bResult == FALSE)
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
else else
{ {
EnableDisableButtons (hwndDlg); EnableDisableButtons (hwndDlg);
@@ -5716,7 +5716,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
if (!ComServerMain ()) if (!ComServerMain ())
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
exit (1); exit (1);
} }
exit (0); exit (0);
@@ -5785,7 +5785,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
if (!VolumePathExists (szFileName)) if (!VolumePathExists (szFileName))
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
} }
else else
{ {
@@ -8190,9 +8190,9 @@ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, char *lpszComm
if (status != 0) if (status != 0)
{ {
if (status == ERR_OS_ERROR) if (status == ERR_OS_ERROR)
handleWin32Error (NULL); handleWin32Error (NULL, SRC_POS);
else else
handleError (NULL, status); handleError (NULL, status, SRC_POS);
AbortProcess ("NODRIVER"); AbortProcess ("NODRIVER");
} }
@@ -8560,7 +8560,7 @@ static void SaveDefaultKeyFilesParam (HWND hwnd)
f = fopen (GetConfigPath (TC_APPD_FILENAME_DEFAULT_KEYFILES), "w"); f = fopen (GetConfigPath (TC_APPD_FILENAME_DEFAULT_KEYFILES), "w");
if (f == NULL) if (f == NULL)
{ {
handleWin32Error (MainDlg); handleWin32Error (MainDlg, SRC_POS);
return; return;
} }
@@ -8729,7 +8729,7 @@ int BackupVolumeHeader (HWND hwndDlg, BOOL bRequireConfirmation, const char *lps
if (!lpszVolume) if (!lpszVolume)
{ {
nStatus = ERR_OUTOFMEMORY; nStatus = ERR_OUTOFMEMORY;
handleError (hwndDlg, nStatus); handleError (hwndDlg, nStatus, SRC_POS);
return nStatus; return nStatus;
} }
@@ -8754,7 +8754,7 @@ int BackupVolumeHeader (HWND hwndDlg, BOOL bRequireConfirmation, const char *lps
if (!VolumePathExists (lpszVolume)) if (!VolumePathExists (lpszVolume))
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
goto ret; goto ret;
} }
@@ -8794,7 +8794,7 @@ int BackupVolumeHeader (HWND hwndDlg, BOOL bRequireConfirmation, const char *lps
|| (type == TC_VOLUME_TYPE_HIDDEN && !askVol->CryptoInfo->hiddenVolume)) || (type == TC_VOLUME_TYPE_HIDDEN && !askVol->CryptoInfo->hiddenVolume))
{ {
CloseVolume (askVol); CloseVolume (askVol);
handleError (hwndDlg, ERR_PASSWORD_WRONG); handleError (hwndDlg, ERR_PASSWORD_WRONG, SRC_POS);
continue; continue;
} }
@@ -8823,7 +8823,7 @@ int BackupVolumeHeader (HWND hwndDlg, BOOL bRequireConfirmation, const char *lps
if (nStatus != ERR_PASSWORD_WRONG) if (nStatus != ERR_PASSWORD_WRONG)
goto error; goto error;
handleError (hwndDlg, nStatus); handleError (hwndDlg, nStatus, SRC_POS);
} }
} }
noHidden: noHidden:
@@ -8937,7 +8937,7 @@ error:
SetLastError (dwError); SetLastError (dwError);
if (nStatus != 0) if (nStatus != 0)
handleError (hwndDlg, nStatus); handleError (hwndDlg, nStatus, SRC_POS);
burn (&VolumePassword, sizeof (VolumePassword)); burn (&VolumePassword, sizeof (VolumePassword));
burn (&VolumePkcs5, sizeof (VolumePkcs5)); burn (&VolumePkcs5, sizeof (VolumePkcs5));
@@ -8977,7 +8977,7 @@ int RestoreVolumeHeader (HWND hwndDlg, const char *lpszVolume)
if (!lpszVolume) if (!lpszVolume)
{ {
nStatus = ERR_OUTOFMEMORY; nStatus = ERR_OUTOFMEMORY;
handleError (hwndDlg, nStatus); handleError (hwndDlg, nStatus, SRC_POS);
return nStatus; return nStatus;
} }
@@ -9008,7 +9008,7 @@ int RestoreVolumeHeader (HWND hwndDlg, const char *lpszVolume)
if (!VolumePathExists (lpszVolume)) if (!VolumePathExists (lpszVolume))
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
return 0; return 0;
} }
@@ -9065,7 +9065,7 @@ int RestoreVolumeHeader (HWND hwndDlg, const char *lpszVolume)
if (nStatus != ERR_PASSWORD_WRONG) if (nStatus != ERR_PASSWORD_WRONG)
goto error; goto error;
handleError (hwndDlg, nStatus); handleError (hwndDlg, nStatus, SRC_POS);
} }
if (volume.CryptoInfo->LegacyVolume) if (volume.CryptoInfo->LegacyVolume)
@@ -9273,7 +9273,7 @@ int RestoreVolumeHeader (HWND hwndDlg, const char *lpszVolume)
if (nStatus != ERR_PASSWORD_WRONG) if (nStatus != ERR_PASSWORD_WRONG)
goto error; goto error;
handleError (hwndDlg, nStatus); handleError (hwndDlg, nStatus, SRC_POS);
} }
BOOL hiddenVol = restoredCryptoInfo->hiddenVolume; BOOL hiddenVol = restoredCryptoInfo->hiddenVolume;
@@ -9363,7 +9363,7 @@ error:
SetLastError (dwError); SetLastError (dwError);
if (nStatus != 0) if (nStatus != 0)
handleError (hwndDlg, nStatus); handleError (hwndDlg, nStatus, SRC_POS);
burn (&VolumePassword, sizeof (VolumePassword)); burn (&VolumePassword, sizeof (VolumePassword));
burn (&VolumePkcs5, sizeof (VolumePkcs5)); burn (&VolumePkcs5, sizeof (VolumePkcs5));
@@ -9486,7 +9486,7 @@ static BOOL CALLBACK PerformanceSettingsDlgProc (HWND hwndDlg, UINT msg, WPARAM
DWORD bytesReturned; DWORD bytesReturned;
if (!DeviceIoControl (hDriver, TC_IOCTL_REREAD_DRIVER_CONFIG, NULL, 0, NULL, 0, &bytesReturned, NULL)) if (!DeviceIoControl (hDriver, TC_IOCTL_REREAD_DRIVER_CONFIG, NULL, 0, NULL, 0, &bytesReturned, NULL))
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
EnableHwEncryption (!disableHW); EnableHwEncryption (!disableHW);

View File

@@ -20,6 +20,10 @@
#include "Resource.h" #include "Resource.h"
#include <Strsafe.h> #include <Strsafe.h>
#ifndef SRC_POS
#define SRC_POS (__FUNCTION__ ":" TC_TO_STRING(__LINE__))
#endif
#define OutputPackageFile "VeraCrypt Setup " VERSION_STRING ".exe" #define OutputPackageFile "VeraCrypt Setup " VERSION_STRING ".exe"
#define MAG_START_MARKER "TCINSTRT" #define MAG_START_MARKER "TCINSTRT"
@@ -252,7 +256,7 @@ BOOL MakeSelfExtractingPackage (HWND hwndDlg, char *szDestDir)
if (!TCCopyFile (inputFile, outputFile)) if (!TCCopyFile (inputFile, outputFile))
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
PkgError ("Cannot copy 'VeraCrypt Setup.exe' to the package"); PkgError ("Cannot copy 'VeraCrypt Setup.exe' to the package");
goto err; goto err;
} }
@@ -435,7 +439,7 @@ BOOL MakeSelfExtractingPackage (HWND hwndDlg, char *szDestDir)
if (tmpBuffer == NULL) if (tmpBuffer == NULL)
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
if (remove (outputFile)) if (remove (outputFile))
PkgError ("Cannot load the package to compute CRC.\nFailed also to delete package file"); PkgError ("Cannot load the package to compute CRC.\nFailed also to delete package file");
else else
@@ -720,7 +724,7 @@ void __cdecl ExtractAllFilesThread (void *hwndDlg)
{ {
wchar_t szTmp[TC_MAX_PATH]; wchar_t szTmp[TC_MAX_PATH];
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
StringCbPrintfW (szTmp, sizeof(szTmp), GetString ("CANT_CREATE_FOLDER"), DestExtractPath); StringCbPrintfW (szTmp, sizeof(szTmp), GetString ("CANT_CREATE_FOLDER"), DestExtractPath);
MessageBoxW (hwndDlg, szTmp, lpszTitle, MB_ICONHAND); MessageBoxW (hwndDlg, szTmp, lpszTitle, MB_ICONHAND);
bSuccess = FALSE; bSuccess = FALSE;

View File

@@ -726,7 +726,7 @@ BOOL DoFilesInstall (HWND hwndDlg, char *szDestDir)
// Dump filter driver cannot be installed to SysWOW64 directory // Dump filter driver cannot be installed to SysWOW64 directory
if (driver64 && !EnableWow64FsRedirection (FALSE)) if (driver64 && !EnableWow64FsRedirection (FALSE))
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
bResult = FALSE; bResult = FALSE;
goto err; goto err;
} }
@@ -742,7 +742,7 @@ BOOL DoFilesInstall (HWND hwndDlg, char *szDestDir)
{ {
if (!EnableWow64FsRedirection (TRUE)) if (!EnableWow64FsRedirection (TRUE))
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
bResult = FALSE; bResult = FALSE;
goto err; goto err;
} }
@@ -1002,7 +1002,7 @@ error:
if (bOK == FALSE) if (bOK == FALSE)
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
Error ("REG_INSTALL_FAILED", hwndDlg); Error ("REG_INSTALL_FAILED", hwndDlg);
} }
@@ -1060,7 +1060,7 @@ BOOL DoApplicationDataUninstall (HWND hwndDlg)
RemoveMessage (hwndDlg, path); RemoveMessage (hwndDlg, path);
if (!StatRemoveDirectory (path)) if (!StatRemoveDirectory (path))
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
bOK = FALSE; bOK = FALSE;
} }
@@ -1274,7 +1274,7 @@ error:
if (bOK == FALSE && GetLastError ()!= ERROR_SERVICE_DOES_NOT_EXIST) if (bOK == FALSE && GetLastError ()!= ERROR_SERVICE_DOES_NOT_EXIST)
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
MessageBoxW (hwndDlg, GetString ("DRIVER_UINSTALL_FAILED"), lpszTitle, MB_ICONHAND); MessageBoxW (hwndDlg, GetString ("DRIVER_UINSTALL_FAILED"), lpszTitle, MB_ICONHAND);
} }
else else
@@ -1300,13 +1300,13 @@ BOOL DoDriverUnload (HWND hwndDlg)
{ {
if (status == ERR_OS_ERROR && GetLastError () != ERROR_FILE_NOT_FOUND) if (status == ERR_OS_ERROR && GetLastError () != ERROR_FILE_NOT_FOUND)
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
AbortProcess ("NODRIVER"); AbortProcess ("NODRIVER");
} }
if (status != ERR_OS_ERROR) if (status != ERR_OS_ERROR)
{ {
handleError (NULL, status); handleError (NULL, status, SRC_POS);
AbortProcess ("NODRIVER"); AbortProcess ("NODRIVER");
} }
} }
@@ -1401,7 +1401,7 @@ BOOL DoDriverUnload (HWND hwndDlg)
else else
{ {
bOK = FALSE; bOK = FALSE;
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
} }
} }
@@ -1544,7 +1544,7 @@ BOOL DoShortcutsUninstall (HWND hwndDlg, char *szDestDir)
// Start menu group // Start menu group
RemoveMessage ((HWND) hwndDlg, szLinkDir); RemoveMessage ((HWND) hwndDlg, szLinkDir);
if (StatRemoveDirectory (szLinkDir) == FALSE) if (StatRemoveDirectory (szLinkDir) == FALSE)
handleWin32Error ((HWND) hwndDlg); handleWin32Error ((HWND) hwndDlg, SRC_POS);
// Desktop icon // Desktop icon
@@ -1613,7 +1613,7 @@ BOOL DoShortcutsInstall (HWND hwndDlg, char *szDestDir, BOOL bProgGroup, BOOL bD
{ {
wchar_t szTmpW[TC_MAX_PATH]; wchar_t szTmpW[TC_MAX_PATH];
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
StringCbPrintfW (szTmpW, sizeof(szTmpW), GetString ("CANT_CREATE_FOLDER"), szLinkDir); StringCbPrintfW (szTmpW, sizeof(szTmpW), GetString ("CANT_CREATE_FOLDER"), szLinkDir);
MessageBoxW (hwndDlg, szTmpW, lpszTitle, MB_ICONHAND); MessageBoxW (hwndDlg, szTmpW, lpszTitle, MB_ICONHAND);
goto error; goto error;
@@ -1895,7 +1895,7 @@ void DoInstall (void *arg)
{ {
wchar_t szTmp[TC_MAX_PATH]; wchar_t szTmp[TC_MAX_PATH];
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
StringCbPrintfW (szTmp, sizeof(szTmp), GetString ("CANT_CREATE_FOLDER"), InstallationPath); StringCbPrintfW (szTmp, sizeof(szTmp), GetString ("CANT_CREATE_FOLDER"), InstallationPath);
MessageBoxW (hwndDlg, szTmp, lpszTitle, MB_ICONHAND); MessageBoxW (hwndDlg, szTmp, lpszTitle, MB_ICONHAND);
Error ("INSTALL_FAILED", hwndDlg); Error ("INSTALL_FAILED", hwndDlg);
@@ -1938,7 +1938,7 @@ void DoInstall (void *arg)
{ {
if (!DisablePagingFile()) if (!DisablePagingFile())
{ {
handleWin32Error (hwndDlg); handleWin32Error (hwndDlg, SRC_POS);
Error ("FAILED_TO_DISABLE_PAGING_FILES", hwndDlg); Error ("FAILED_TO_DISABLE_PAGING_FILES", hwndDlg);
} }
else else