VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Common
diff options
context:
space:
mode:
Diffstat (limited to 'src/Common')
-rw-r--r--src/Common/BaseCom.cpp2
-rw-r--r--src/Common/BootEncryption.cpp100
-rw-r--r--src/Common/BootEncryption.h2
-rw-r--r--src/Common/Cmdline.c8
-rw-r--r--src/Common/Dlgcode.c116
-rw-r--r--src/Common/Dlgcode.h8
-rw-r--r--src/Common/Exception.h23
-rw-r--r--src/Common/Format.c10
-rw-r--r--src/Common/Keyfiles.c12
-rw-r--r--src/Common/Language.h2
-rw-r--r--src/Common/Password.c10
-rw-r--r--src/Common/Random.c12
12 files changed, 166 insertions, 139 deletions
diff --git a/src/Common/BaseCom.cpp b/src/Common/BaseCom.cpp
index 365fa293..d5a48c44 100644
--- a/src/Common/BaseCom.cpp
+++ b/src/Common/BaseCom.cpp
@@ -134,7 +134,7 @@ DWORD BaseCom::ReadWriteFile (BOOL write, BOOL device, BSTR filePath, BSTR *buff
try
{
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);
if (write)
diff --git a/src/Common/BootEncryption.cpp b/src/Common/BootEncryption.cpp
index 9f080f18..5670a1ac 100644
--- a/src/Common/BootEncryption.cpp
+++ b/src/Common/BootEncryption.cpp
@@ -68,7 +68,7 @@ namespace VeraCrypt
if (result != ERROR_SUCCESS)
{
SetLastError (result);
- throw SystemException();
+ throw SystemException(SRC_POS);
}
}
@@ -101,7 +101,7 @@ namespace VeraCrypt
if (result != ERROR_SUCCESS)
{
SetLastError (result);
- throw SystemException();
+ throw SystemException(SRC_POS);
}
}
@@ -124,7 +124,7 @@ namespace VeraCrypt
if (result != ERROR_SUCCESS)
{
SetLastError (result);
- throw SystemException();
+ throw SystemException(SRC_POS);
}
}
@@ -150,7 +150,7 @@ namespace VeraCrypt
if (result != ERROR_SUCCESS)
{
SetLastError (result);
- throw SystemException();
+ throw SystemException(SRC_POS);
}
if (!write)
@@ -194,7 +194,7 @@ namespace VeraCrypt
if (result != ERROR_SUCCESS)
{
SetLastError (result);
- throw SystemException();
+ throw SystemException(SRC_POS);
}
}
@@ -206,7 +206,7 @@ namespace VeraCrypt
if (result != ERROR_SUCCESS)
{
SetLastError (result);
- throw SystemException();
+ throw SystemException(SRC_POS);
}
}
@@ -218,7 +218,7 @@ namespace VeraCrypt
if (result != ERROR_SUCCESS)
{
SetLastError (result);
- throw SystemException();
+ throw SystemException(SRC_POS);
}
}
@@ -240,7 +240,7 @@ namespace VeraCrypt
if (result != ERROR_SUCCESS)
{
SetLastError (result);
- throw SystemException();
+ throw SystemException(SRC_POS);
}
}
@@ -250,7 +250,7 @@ namespace VeraCrypt
if (IsAdmin())
{
SetLastError (ERROR_ACCESS_DENIED);
- throw SystemException();
+ throw SystemException(SRC_POS);
}
if (!ElevatedComInstance || ElevatedComInstanceThreadId != GetCurrentThreadId())
@@ -338,7 +338,7 @@ namespace VeraCrypt
if (!FileOpen)
{
SetLastError (LastError);
- throw SystemException ();
+ throw SystemException (SRC_POS);
}
if (Elevated)
@@ -359,7 +359,7 @@ namespace VeraCrypt
if (!FileOpen)
{
SetLastError (LastError);
- throw SystemException ();
+ throw SystemException (SRC_POS);
}
FilePointerPosition = position;
@@ -379,7 +379,7 @@ namespace VeraCrypt
if (!FileOpen)
{
SetLastError (LastError);
- throw SystemException ();
+ throw SystemException (SRC_POS);
}
try
@@ -546,7 +546,7 @@ namespace VeraCrypt
}
throw ErrorException (wstring (GetString ("SYSTEM_PARTITION_NOT_ACTIVE"))
- + GetRemarksOnHiddenOS());
+ + GetRemarksOnHiddenOS(), SRC_POS);
}
activePartitionFound = true;
@@ -581,7 +581,7 @@ namespace VeraCrypt
if (!candidateForHiddenOSFound)
{
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)
@@ -589,19 +589,19 @@ namespace VeraCrypt
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"))
- + GetRemarksOnHiddenOS());
+ + GetRemarksOnHiddenOS(), SRC_POS);
}
}
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"))
- + GetRemarksOnHiddenOS());
+ + GetRemarksOnHiddenOS(), SRC_POS);
}
}
else
{
// No active partition on the system drive
- throw ErrorException ("SYSTEM_PARTITION_NOT_ACTIVE");
+ throw ErrorException ("SYSTEM_PARTITION_NOT_ACTIVE", SRC_POS);
}
HiddenOSCandidatePartition = candidatePartition;
@@ -884,7 +884,7 @@ namespace VeraCrypt
bool BootEncryption::SystemDriveContainsPartitionType (byte type)
{
Device device (GetSystemDriveConfiguration().DevicePath, true);
- device.CheckOpened ();
+ device.CheckOpened (SRC_POS);
byte mbrBuf[TC_SECTOR_SIZE_BIOS];
device.SeekAt (0);
@@ -1195,7 +1195,7 @@ namespace VeraCrypt
if (hiddenOSCreation)
{
Device device (GetSystemDriveConfiguration().DevicePath);
- device.CheckOpened ();
+ device.CheckOpened (SRC_POS);
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);
@@ -1284,7 +1284,7 @@ namespace VeraCrypt
void BootEncryption::WriteBootSectorConfig (const byte newConfig[])
{
Device device (GetSystemDriveConfiguration().DevicePath);
- device.CheckOpened ();
+ device.CheckOpened (SRC_POS);
byte mbr[TC_SECTOR_SIZE_BIOS];
device.SeekAt (0);
@@ -1300,14 +1300,14 @@ namespace VeraCrypt
device.Read (mbrVerificationBuf, sizeof (mbr));
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)
{
Device device (GetSystemDriveConfiguration().DevicePath);
- device.CheckOpened ();
+ device.CheckOpened (SRC_POS);
byte mbr[TC_SECTOR_SIZE_BIOS];
device.SeekAt (0);
@@ -1339,7 +1339,7 @@ namespace VeraCrypt
device.Read (mbrVerificationBuf, sizeof (mbr));
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.CheckOpened();
+ device.CheckOpened(SRC_POS);
byte mbr[TC_SECTOR_SIZE_BIOS];
device.SeekAt (0);
@@ -1497,7 +1497,7 @@ namespace VeraCrypt
// Write MBR
Device device (GetSystemDriveConfiguration().DevicePath);
- device.CheckOpened ();
+ device.CheckOpened (SRC_POS);
byte mbr[TC_SECTOR_SIZE_BIOS];
device.SeekAt (0);
@@ -1523,7 +1523,7 @@ namespace VeraCrypt
device.Read (mbrVerificationBuf, sizeof (mbr));
if (memcmp (mbr, mbrVerificationBuf, sizeof (mbr)) != 0)
- throw ErrorException ("ERROR_MBR_PROTECTED");
+ throw ErrorException ("ERROR_MBR_PROTECTED", SRC_POS);
// Write boot loader
device.SeekAt (TC_SECTOR_SIZE_BIOS);
@@ -1652,7 +1652,7 @@ namespace VeraCrypt
else
{
Device bootDevice (GetSystemDriveConfiguration().DevicePath, true);
- bootDevice.CheckOpened ();
+ bootDevice.CheckOpened (SRC_POS);
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);
}
@@ -1661,7 +1661,7 @@ namespace VeraCrypt
try
{
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);
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;
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;
Buffer buffer ((verifiedSectorCount + 1) * 2048);
@@ -1780,7 +1780,7 @@ namespace VeraCrypt
throw ParameterIncorrect (SRC_POS);
Device device (GetSystemDriveConfiguration().DevicePath);
- device.CheckOpened ();
+ device.CheckOpened (SRC_POS);
device.SeekAt (TC_BOOT_VOLUME_HEADER_SECTOR_OFFSET);
device.Write ((byte *) VolumeHeader, sizeof (VolumeHeader));
@@ -1812,7 +1812,7 @@ namespace VeraCrypt
void BootEncryption::BackupSystemLoader ()
{
Device device (GetSystemDriveConfiguration().DevicePath, true);
- device.CheckOpened ();
+ device.CheckOpened (SRC_POS);
byte bootLoaderBuf[TC_BOOT_LOADER_AREA_SECTOR_COUNT * TC_SECTOR_SIZE_BIOS];
device.SeekAt (0);
@@ -1839,12 +1839,12 @@ namespace VeraCrypt
byte bootLoaderBuf[TC_BOOT_LOADER_AREA_SECTOR_COUNT * TC_SECTOR_SIZE_BIOS];
File backupFile (GetSystemLoaderBackupPath(), true);
- backupFile.CheckOpened();
+ backupFile.CheckOpened(SRC_POS);
if (backupFile.Read (bootLoaderBuf, sizeof (bootLoaderBuf)) != sizeof (bootLoaderBuf))
throw ParameterIncorrect (SRC_POS);
Device device (GetSystemDriveConfiguration().DevicePath);
- device.CheckOpened ();
+ device.CheckOpened (SRC_POS);
// Preserve current partition table
byte mbr[TC_SECTOR_SIZE_BIOS];
@@ -2048,29 +2048,29 @@ namespace VeraCrypt
void BootEncryption::CheckRequirements ()
{
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)
- throw ErrorException ("SYS_ENCRYPTION_UNSUPPORTED_ON_VISTA_SP0");
+ throw ErrorException ("SYS_ENCRYPTION_UNSUPPORTED_ON_VISTA_SP0", SRC_POS);
if (IsNonInstallMode())
- throw ErrorException ("FEATURE_REQUIRES_INSTALLATION");
+ throw ErrorException ("FEATURE_REQUIRES_INSTALLATION", SRC_POS);
SystemDriveConfiguration config = GetSystemDriveConfiguration ();
if (config.SystemPartition.IsGPT)
- throw ErrorException ("GPT_BOOT_DRIVE_UNSUPPORTED");
+ throw ErrorException ("GPT_BOOT_DRIVE_UNSUPPORTED", SRC_POS);
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)
- throw ErrorException ("NO_SPACE_FOR_BOOT_LOADER");
+ throw ErrorException ("NO_SPACE_FOR_BOOT_LOADER", SRC_POS);
DISK_GEOMETRY geometry = GetDriveGeometry (config.DriveNumber);
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;
if (!config.SystemPartition.IsGPT)
@@ -2146,7 +2146,7 @@ namespace VeraCrypt
}
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
@@ -2154,14 +2154,14 @@ namespace VeraCrypt
if (configPath && toupper (configPath[0]) != windowsDrive)
{
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
if (toupper (GetTempPath()[0]) != windowsDrive)
{
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
Device device (config.DevicePath, true);
- device.CheckOpened ();
+ device.CheckOpened (SRC_POS);
byte header[TC_BOOT_ENCRYPTION_VOLUME_HEADER_SIZE];
device.SeekAt (TC_BOOT_VOLUME_HEADER_SECTOR_OFFSET);
@@ -2229,7 +2229,7 @@ namespace VeraCrypt
catch (Exception &e)
{
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];
Device device (config.DevicePath);
- device.CheckOpened ();
+ device.CheckOpened (SRC_POS);
// Only one algorithm is currently supported
if (pkcs5 != 0)
@@ -2282,7 +2282,7 @@ namespace VeraCrypt
if (status != 0)
{
- handleError (hwndDlg, status);
+ handleError (hwndDlg, status, SRC_POS);
return status;
}
@@ -2356,7 +2356,7 @@ namespace VeraCrypt
if (status != 0)
{
- handleError (hwndDlg, status);
+ handleError (hwndDlg, status, SRC_POS);
return status;
}
@@ -2461,7 +2461,7 @@ namespace VeraCrypt
Buffer sector (geometry.BytesPerSector);
Device device (config.DevicePath);
- device.CheckOpened ();
+ device.CheckOpened (SRC_POS);
try
{
@@ -2583,7 +2583,7 @@ namespace VeraCrypt
if (!IsUacSupported())
{
SetLastError (ERROR_ACCESS_DENIED);
- throw SystemException();
+ throw SystemException(SRC_POS);
}
else
Elevator::CopyFile (sourceFile, destinationFile);
diff --git a/src/Common/BootEncryption.h b/src/Common/BootEncryption.h
index a73ce6fc..e8b57211 100644
--- a/src/Common/BootEncryption.h
+++ b/src/Common/BootEncryption.h
@@ -26,7 +26,7 @@ namespace VeraCrypt
File (string path,bool readOnly = false, bool create = false);
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 ();
DWORD Read (byte *buffer, DWORD size);
void Write (byte *buffer, DWORD size);
diff --git a/src/Common/Cmdline.c b/src/Common/Cmdline.c
index 6e325fe3..929b777d 100644
--- a/src/Common/Cmdline.c
+++ b/src/Common/Cmdline.c
@@ -22,6 +22,10 @@
#include "Language.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
should return nonzero if it processes the message, and zero if it does
not. - see DialogProc */
@@ -92,7 +96,7 @@ int Win32CommandLine (char *lpszCommandLine, char ***lpszArgs)
LPWSTR *arguments = CommandLineToArgvW (GetCommandLineW(), &argumentCount);
if (!arguments)
{
- handleWin32Error (NULL);
+ handleWin32Error (NULL, SRC_POS);
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);
if (len == 0)
{
- handleWin32Error (NULL);
+ handleWin32Error (NULL, SRC_POS);
AbortProcessSilent();
}
}
diff --git a/src/Common/Dlgcode.c b/src/Common/Dlgcode.c
index 5e26ef0f..a317f607 100644
--- a/src/Common/Dlgcode.c
+++ b/src/Common/Dlgcode.c
@@ -548,10 +548,10 @@ BOOL IsDiskError (DWORD error)
}
-DWORD handleWin32Error (HWND hwndDlg)
+DWORD handleWin32Error (HWND hwndDlg, const char* srcPos)
{
PWSTR lpMsgBuf;
- DWORD dwError = GetLastError ();
+ DWORD dwError = GetLastError ();
if (Silent || dwError == 0 || dwError == ERROR_INVALID_WINDOW_HANDLE)
return dwError;
@@ -559,7 +559,7 @@ DWORD handleWin32Error (HWND hwndDlg)
// Access denied
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
return dwError;
}
@@ -574,7 +574,7 @@ DWORD handleWin32Error (HWND hwndDlg)
NULL
);
- MessageBoxW (hwndDlg, lpMsgBuf, lpszTitle, ICON_HAND);
+ MessageBoxW (hwndDlg, AppendSrcPos (lpMsgBuf, srcPos).c_str (), lpszTitle, ICON_HAND);
LocalFree (lpMsgBuf);
// User-friendly hardware error explanation
@@ -1265,7 +1265,7 @@ void InitDialog (HWND hwndDlg)
hFixedDigitFont = CreateFontIndirectW (&lf);
if (hFixedDigitFont == NULL)
{
- handleWin32Error (hwndDlg);
+ handleWin32Error (hwndDlg, SRC_POS);
AbortProcess ("NOFONT");
}
@@ -1279,7 +1279,7 @@ void InitDialog (HWND hwndDlg)
hBoldFont = CreateFontIndirectW (&lf);
if (hBoldFont == NULL)
{
- handleWin32Error (hwndDlg);
+ handleWin32Error (hwndDlg, SRC_POS);
AbortProcess ("NOFONT");
}
@@ -1293,7 +1293,7 @@ void InitDialog (HWND hwndDlg)
hTitleFont = CreateFontIndirectW (&lf);
if (hTitleFont == NULL)
{
- handleWin32Error (hwndDlg);
+ handleWin32Error (hwndDlg, SRC_POS);
AbortProcess ("NOFONT");
}
@@ -1318,7 +1318,7 @@ void InitDialog (HWND hwndDlg)
hFixedFont = CreateFontIndirectW (&lf);
if (hFixedFont == NULL)
{
- handleWin32Error (hwndDlg);
+ handleWin32Error (hwndDlg, SRC_POS);
AbortProcess ("NOFONT");
}
@@ -2525,7 +2525,7 @@ void InitApp (HINSTANCE hInstance, char *lpszCommandLine)
/* Get the attributes for the standard dialog class */
if ((GetClassInfo (hInst, WINDOWS_DIALOG_CLASS, &wc)) == 0)
{
- handleWin32Error (NULL);
+ handleWin32Error (NULL, SRC_POS);
AbortProcess ("INIT_REGISTER");
}
@@ -2543,7 +2543,7 @@ void InitApp (HINSTANCE hInstance, char *lpszCommandLine)
hDlgClass = RegisterClass (&wc);
if (hDlgClass == 0)
{
- handleWin32Error (NULL);
+ handleWin32Error (NULL, SRC_POS);
AbortProcess ("INIT_REGISTER");
}
@@ -2555,7 +2555,7 @@ void InitApp (HINSTANCE hInstance, char *lpszCommandLine)
hSplashClass = RegisterClass (&wc);
if (hSplashClass == 0)
{
- handleWin32Error (NULL);
+ handleWin32Error (NULL, SRC_POS);
AbortProcess ("INIT_REGISTER");
}
@@ -2567,7 +2567,7 @@ void InitApp (HINSTANCE hInstance, char *lpszCommandLine)
if ((hRichEditDll = LoadLibrary(dllPath)) == NULL)
{
// This error is fatal e.g. because legal notices could not be displayed
- handleWin32Error (NULL);
+ handleWin32Error (NULL, SRC_POS);
AbortProcess ("INIT_RICHEDIT");
}
@@ -2580,7 +2580,7 @@ void InitApp (HINSTANCE hInstance, char *lpszCommandLine)
#ifndef SETUP
if (!EncryptionThreadPoolStart (ReadEncryptionThreadPoolFreeCpuCountLimit()))
{
- handleWin32Error (NULL);
+ handleWin32Error (NULL, SRC_POS);
if (hRichEditDll)
{
FreeLibrary (hRichEditDll);
@@ -3470,7 +3470,7 @@ BOOL DoDriverInstall (HWND hwndDlg)
error:
if (bOK == FALSE && GetLastError () != ERROR_SERVICE_ALREADY_RUNNING)
{
- handleWin32Error (hwndDlg);
+ handleWin32Error (hwndDlg, SRC_POS);
MessageBoxW (hwndDlg, GetString ("DRIVER_INSTALL_FAILED"), lpszTitle, MB_ICONHAND);
}
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];
@@ -4100,57 +4100,57 @@ void handleError (HWND hwndDlg, int code)
switch (code & 0x0000FFFF)
{
case ERR_OS_ERROR:
- handleWin32Error (hwndDlg);
+ handleWin32Error (hwndDlg, srcPos);
break;
case ERR_OUTOFMEMORY:
- MessageBoxW (hwndDlg, GetString ("OUTOFMEMORY"), lpszTitle, ICON_HAND);
+ MessageBoxW (hwndDlg, AppendSrcPos (GetString ("OUTOFMEMORY"), srcPos).c_str(), lpszTitle, ICON_HAND);
break;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
case ERR_DRIVER_VERSION:
@@ -4158,7 +4158,7 @@ void handleError (HWND hwndDlg, int code)
break;
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;
case ERR_SELF_TESTS_FAILED:
@@ -4192,24 +4192,24 @@ void handleError (HWND hwndDlg, int code)
case ERR_UNSUPPORTED_TRUECRYPT_FORMAT:
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;
#ifndef SETUP
case ERR_RAND_INIT_FAILED:
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;
case ERR_CAPI_INIT_FAILED:
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;
#endif
default:
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
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);
}
#endif
@@ -5410,7 +5410,7 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
{
TCfree(keyfile);
NormalCursor();
- handleWin32Error (hwndDlg);
+ handleWin32Error (hwndDlg, SRC_POS);
return 1;
}
@@ -5452,7 +5452,7 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
{
TCfree(keyfile);
NormalCursor();
- handleWin32Error (hwndDlg);
+ handleWin32Error (hwndDlg, SRC_POS);
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)
{
- handleError (hwndDlg, tmpRetVal);
+ handleError (hwndDlg, tmpRetVal, SRC_POS);
crypto_close (ci);
return 1;
}
@@ -6271,7 +6271,7 @@ int DriverUnmountVolume (HWND hwndDlg, int nDosDriveNo, BOOL forced)
if (bResult == FALSE)
{
- handleWin32Error (hwndDlg);
+ handleWin32Error (hwndDlg, SRC_POS);
return 1;
}
@@ -6778,7 +6778,7 @@ retry:
}
if (!quiet && (!MultipleMountOperationInProgress || GetLastError() != ERROR_NOT_READY))
- handleWin32Error (hwndDlg);
+ handleWin32Error (hwndDlg, SRC_POS);
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)
WarningDirect ((GetWrongPasswordErrorMessage (hwndDlg) + L"\n\n" + GetString ("HIDDEN_VOL_PROT_PASSWORD_US_KEYB_LAYOUT")).c_str(), hwndDlg);
else
- handleError (hwndDlg, mount.nReturnCode);
+ handleError (hwndDlg, mount.nReturnCode, SRC_POS);
}
}
else
- handleError (hwndDlg, mount.nReturnCode);
+ handleError (hwndDlg, mount.nReturnCode, SRC_POS);
}
return 0;
}
if (!quiet)
- handleError (hwndDlg, mount.nReturnCode);
+ handleError (hwndDlg, mount.nReturnCode, SRC_POS);
return 0;
}
@@ -7234,7 +7234,7 @@ __int64 GetStatsFreeSpaceOnPartition (const char *devicePath, float *percentFree
{
if (!silent)
{
- handleWin32Error (MainDlg);
+ handleWin32Error (MainDlg, SRC_POS);
Error ("CANNOT_CALC_SPACE", MainDlg);
}
@@ -7252,7 +7252,7 @@ __int64 GetStatsFreeSpaceOnPartition (const char *devicePath, float *percentFree
{
if (!silent)
{
- handleWin32Error (MainDlg);
+ handleWin32Error (MainDlg, SRC_POS);
Error ("CANT_GET_VOLSIZE", MainDlg);
}
return -1;
@@ -7561,7 +7561,7 @@ BOOL SaveBufferToFile (const char *inputBuffer, const char *destinationFile, DWO
if (dst == INVALID_HANDLE_VALUE)
{
SetLastError (dwLastError);
- handleWin32Error (MainDlg);
+ handleWin32Error (MainDlg, SRC_POS);
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
// of an existing file (it's not an error)
if (! (GetLastError() == ERROR_ALREADY_EXISTS && !bAppend) )
- handleWin32Error (MainDlg);
+ handleWin32Error (MainDlg, SRC_POS);
}
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)
{
- handleWin32Error (hwndDlg);
+ handleWin32Error (hwndDlg, SRC_POS);
break;
}
@@ -10020,7 +10020,7 @@ BOOL CALLBACK SecurityTokenKeyfileDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam
byte *keyfileData = (byte *) LoadFile (keyfilePath, &keyfileSize);
if (!keyfileData)
{
- handleWin32Error (hwndDlg);
+ handleWin32Error (hwndDlg, SRC_POS);
return 1;
}
@@ -10059,7 +10059,7 @@ BOOL CALLBACK SecurityTokenKeyfileDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam
else
{
SetLastError (ERROR_HANDLE_EOF);
- handleWin32Error (hwndDlg);
+ handleWin32Error (hwndDlg, SRC_POS);
}
burn (keyfileData, keyfileSize);
@@ -10091,14 +10091,14 @@ BOOL CALLBACK SecurityTokenKeyfileDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam
if (keyfileData.empty())
{
SetLastError (ERROR_HANDLE_EOF);
- handleWin32Error (hwndDlg);
+ handleWin32Error (hwndDlg, SRC_POS);
return 1;
}
finally_do_arg (vector <byte> *, &keyfileData, { burn (&finally_arg->front(), finally_arg->size()); });
if (!SaveBufferToFile ((char *) &keyfileData.front(), keyfilePath, (DWORD) keyfileData.size(), FALSE, FALSE))
- throw SystemException ();
+ throw SystemException (SRC_POS);
}
Info ("KEYFILE_EXPORTED", hwndDlg);
@@ -10481,7 +10481,7 @@ BOOL RemoveDeviceWriteProtection (HWND hwndDlg, char *devicePath)
FILE *f = fopen (cmdBatch, "w");
if (!f)
{
- handleWin32Error (hwndDlg);
+ handleWin32Error (hwndDlg, SRC_POS);
return FALSE;
}
@@ -10493,7 +10493,7 @@ BOOL RemoveDeviceWriteProtection (HWND hwndDlg, char *devicePath)
f = fopen (diskpartScript, "w");
if (!f)
{
- handleWin32Error (hwndDlg);
+ handleWin32Error (hwndDlg, SRC_POS);
DeleteFile (cmdBatch);
return FALSE;
}
@@ -10631,7 +10631,7 @@ BOOL LaunchWindowsIsoBurner (HWND hwnd, const char *isoPath)
if (r <= 32)
{
SetLastError (r);
- handleWin32Error (hwnd);
+ handleWin32Error (hwnd, SRC_POS);
return FALSE;
}
diff --git a/src/Common/Dlgcode.h b/src/Common/Dlgcode.h
index f6b285c4..1d0db30c 100644
--- a/src/Common/Dlgcode.h
+++ b/src/Common/Dlgcode.h
@@ -237,7 +237,7 @@ void AbortProcess ( char *stringId );
void AbortProcessSilent ( void );
void *err_malloc ( size_t size );
char *err_strdup ( char *lpszText );
-DWORD handleWin32Error ( HWND hwndDlg );
+DWORD handleWin32Error ( HWND hwndDlg, const char* srcPos );
BOOL IsDiskReadError (DWORD error);
BOOL IsDiskWriteError (DWORD error);
BOOL IsDiskError (DWORD error);
@@ -317,7 +317,7 @@ 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);
-void handleError ( HWND hwndDlg , int code );
+void handleError ( HWND hwndDlg , int code, const char* srcPos );
BOOL CheckFileStreamWriteErrors (HWND hwndDlg, FILE *file, const char *fileName);
void LocalizeDialog ( HWND hwnd, char *stringId );
void OpenVolumeExplorerWindow (int driveNo);
@@ -552,6 +552,10 @@ std::string FindLatestFileOrDirectory (const std::string &directory, const char
std::string GetUserFriendlyVersionString (int version);
std::string IntToString (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
typedef void (CALLBACK* WaitThreadProc)(void* pArg, HWND hWaitDlg);
diff --git a/src/Common/Exception.h b/src/Common/Exception.h
index 0883df14..06545c65 100644
--- a/src/Common/Exception.h
+++ b/src/Common/Exception.h
@@ -11,6 +11,7 @@
#include "Platform/PlatformBase.h"
#include "Dlgcode.h"
+#include "Language.h"
#include <strsafe.h>
namespace VeraCrypt
@@ -22,30 +23,32 @@ namespace VeraCrypt
struct SystemException : public Exception
{
- SystemException () : ErrorCode (GetLastError()) { }
+ SystemException (const char *srcPos) : ErrorCode (GetLastError()), SrcPos (srcPos) { }
void Show (HWND parent) const
{
SetLastError (ErrorCode);
- handleWin32Error (parent);
+ handleWin32Error (parent, SrcPos);
}
DWORD ErrorCode;
+ const char *SrcPos;
};
struct ErrorException : public Exception
{
- ErrorException (char *langId) : ErrLangId (langId) { }
- ErrorException (const wstring &errMsg) : ErrLangId(NULL), ErrMsg (errMsg) { }
+ ErrorException (char *langId, const char *srcPos) : SrcPos (srcPos), ErrLangId (langId) { }
+ ErrorException (const wstring &errMsg, const char *srcPos) : SrcPos (srcPos), ErrLangId(NULL), ErrMsg (errMsg) { }
void Show (HWND parent) const
{
if (ErrMsg.empty())
- ::Error (ErrLangId? ErrLangId : "", parent);
+ ::ErrorDirect (AppendSrcPos (GetString (ErrLangId? ErrLangId : ""), SrcPos).c_str (), parent);
else
- ::ErrorDirect (ErrMsg.c_str(), parent);
+ ::ErrorDirect (AppendSrcPos (ErrMsg.c_str(), SrcPos).c_str (), parent);
}
+ const char *SrcPos;
char *ErrLangId;
wstring ErrMsg;
};
@@ -97,8 +100,10 @@ namespace VeraCrypt
struct TimeOut : public Exception
{
- TimeOut (const char *srcPos) { }
- void Show (HWND parent) const { ErrorDirect (L"Timeout", parent); }
+ TimeOut (const char *srcPos) : SrcPos (srcPos) { }
+ void Show (HWND parent) const { ErrorDirect (AppendSrcPos (L"Timeout", SrcPos).c_str (), parent); }
+
+ const char *SrcPos;
};
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
diff --git a/src/Common/Format.c b/src/Common/Format.c
index 3ebfef1e..14c91a33 100644
--- a/src/Common/Format.c
+++ b/src/Common/Format.c
@@ -31,6 +31,10 @@
#include <Strsafe.h>
+#ifndef SRC_POS
+#define SRC_POS (__FUNCTION__ ":" TC_TO_STRING(__LINE__))
+#endif
+
int FormatWriteBufferSize = 1024 * 1024;
static uint32 FormatSectorSize = 0;
@@ -286,7 +290,7 @@ begin_format:
}
else
{
- handleWin32Error (volParams->hwndDlg);
+ handleWin32Error (volParams->hwndDlg, SRC_POS);
Error ("CANT_ACCESS_VOL", hwndDlg);
nStatus = ERR_DONT_REPORT;
goto error;
@@ -893,7 +897,7 @@ static void __cdecl FormatWriteThreadProc (void *arg)
{
if (WaitForSingleObject (WriteBufferFullEvent, INFINITE) == WAIT_FAILED)
{
- handleWin32Error (NULL);
+ handleWin32Error (NULL, SRC_POS);
break;
}
@@ -907,7 +911,7 @@ static void __cdecl FormatWriteThreadProc (void *arg)
if (!SetEvent (WriteBufferEmptyEvent))
{
- handleWin32Error (NULL);
+ handleWin32Error (NULL, SRC_POS);
break;
}
}
diff --git a/src/Common/Keyfiles.c b/src/Common/Keyfiles.c
index cb36a146..dbda7d3c 100644
--- a/src/Common/Keyfiles.c
+++ b/src/Common/Keyfiles.c
@@ -252,7 +252,7 @@ BOOL KeyFilesApply (HWND hwndDlg, Password *password, KeyFile *firstKeyFile)
if (keyfileData.empty())
{
SetLastError (ERROR_HANDLE_EOF);
- handleWin32Error (hwndDlg);
+ handleWin32Error (hwndDlg, SRC_POS);
Error ("ERR_PROCESS_KEYFILE", hwndDlg);
status = FALSE;
continue;
@@ -291,7 +291,7 @@ BOOL KeyFilesApply (HWND hwndDlg, Password *password, KeyFile *firstKeyFile)
// Determine whether it's a path or a file
if (stat (kf->FileName, &statStruct) != 0)
{
- handleWin32Error (hwndDlg);
+ handleWin32Error (hwndDlg, SRC_POS);
Error ("ERR_PROCESS_KEYFILE", hwndDlg);
status = FALSE;
continue;
@@ -305,7 +305,7 @@ BOOL KeyFilesApply (HWND hwndDlg, Password *password, KeyFile *firstKeyFile)
StringCbPrintfA (searchPath, sizeof (searchPath), "%s\\*.*", kf->FileName);
if ((searchHandle = _findfirst (searchPath, &fBuf)) == -1)
{
- handleWin32Error (hwndDlg);
+ handleWin32Error (hwndDlg, SRC_POS);
Error ("ERR_PROCESS_KEYFILE_PATH", hwndDlg);
status = FALSE;
continue;
@@ -323,7 +323,7 @@ BOOL KeyFilesApply (HWND hwndDlg, Password *password, KeyFile *firstKeyFile)
// Determine whether it's a path or a file
if (stat (kfSub->FileName, &statStruct) != 0)
{
- handleWin32Error (hwndDlg);
+ handleWin32Error (hwndDlg, SRC_POS);
Error ("ERR_PROCESS_KEYFILE", hwndDlg);
status = FALSE;
continue;
@@ -347,7 +347,7 @@ BOOL KeyFilesApply (HWND hwndDlg, Password *password, KeyFile *firstKeyFile)
// Apply keyfile to the pool
if (!KeyFileProcess (keyPool, kfSub))
{
- handleWin32Error (hwndDlg);
+ handleWin32Error (hwndDlg, SRC_POS);
Error ("ERR_PROCESS_KEYFILE", hwndDlg);
status = FALSE;
}
@@ -366,7 +366,7 @@ BOOL KeyFilesApply (HWND hwndDlg, Password *password, KeyFile *firstKeyFile)
// Apply keyfile to the pool
else if (!KeyFileProcess (keyPool, kf))
{
- handleWin32Error (hwndDlg);
+ handleWin32Error (hwndDlg, SRC_POS);
Error ("ERR_PROCESS_KEYFILE", hwndDlg);
status = FALSE;
}
diff --git a/src/Common/Language.h b/src/Common/Language.h
index d2dde96c..750a3972 100644
--- a/src/Common/Language.h
+++ b/src/Common/Language.h
@@ -6,6 +6,8 @@
packages.
*/
+#pragma once
+
#include <windows.h>
#ifdef __cplusplus
diff --git a/src/Common/Password.c b/src/Common/Password.c
index 3ae264d2..b3dd54bb 100644
--- a/src/Common/Password.c
+++ b/src/Common/Password.c
@@ -22,6 +22,10 @@
#include <io.h>
+#ifndef SRC_POS
+#define SRC_POS (__FUNCTION__ ":" TC_TO_STRING(__LINE__))
+#endif
+
void VerifyPasswordAndUpdate (HWND hwndDlg, HWND hButton, HWND hPassword,
HWND hVerify, unsigned char *szPassword,
char *szVerify,
@@ -160,14 +164,14 @@ int ChangePwd (const char *lpszVolume, Password *oldPassword, int old_pkcs5, int
if ((wipePassCount <= 0) || (truecryptMode && (old_pkcs5 == SHA256)))
{
nStatus = ERR_PARAMETER_INCORRECT;
- handleError (hwndDlg, nStatus);
+ handleError (hwndDlg, nStatus, SRC_POS);
return nStatus;
}
if (!lpszVolume)
{
nStatus = ERR_OUTOFMEMORY;
- handleError (hwndDlg, nStatus);
+ handleError (hwndDlg, nStatus, SRC_POS);
return nStatus;
}
@@ -451,7 +455,7 @@ error:
return nStatus;
if (nStatus != 0)
- handleError (hwndDlg, nStatus);
+ handleError (hwndDlg, nStatus, SRC_POS);
return nStatus;
}
diff --git a/src/Common/Random.c b/src/Common/Random.c
index c1479340..1a0637ba 100644
--- a/src/Common/Random.c
+++ b/src/Common/Random.c
@@ -66,6 +66,10 @@ void RandAddInt64 (unsigned __int64 x)
#include <tlhelp32.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 hKeyboard = NULL; /* Keyboard hook for the random number generator */
@@ -112,12 +116,12 @@ int Randinit ()
}
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 ());
if (hMouse == 0)
{
- handleWin32Error (0);
+ handleWin32Error (0, SRC_POS);
goto error;
}
@@ -388,7 +392,7 @@ BOOL RandgetBytesFull ( void* hwndDlg, unsigned char *buf , int len, BOOL forceS
{
if (!SlowPoll ())
{
- handleError ((HWND) hwndDlg, ERR_CAPI_INIT_FAILED);
+ handleError ((HWND) hwndDlg, ERR_CAPI_INIT_FAILED, SRC_POS);
ret = FALSE;
}
else
@@ -397,7 +401,7 @@ BOOL RandgetBytesFull ( void* hwndDlg, unsigned char *buf , int len, BOOL forceS
if (!FastPoll ())
{
- handleError ((HWND) hwndDlg, ERR_CAPI_INIT_FAILED);
+ handleError ((HWND) hwndDlg, ERR_CAPI_INIT_FAILED, SRC_POS);
ret = FALSE;
}