VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Common/Dlgcode.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/Common/Dlgcode.c')
-rw-r--r--src/Common/Dlgcode.c473
1 files changed, 269 insertions, 204 deletions
diff --git a/src/Common/Dlgcode.c b/src/Common/Dlgcode.c
index 31be6b90..30571260 100644
--- a/src/Common/Dlgcode.c
+++ b/src/Common/Dlgcode.c
@@ -1,11 +1,11 @@
/*
Legal Notice: Some portions of the source code contained in this file were
- derived from the source code of TrueCrypt 7.1a, which is
- Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
+ derived from the source code of TrueCrypt 7.1a, which is
+ Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
governed by the TrueCrypt License 3.0, also from the source code of
Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
- and which is governed by the 'License Agreement for Encryption for the Masses'
- Modifications and additions to the original source code (contained in this file)
+ and which is governed by the 'License Agreement for Encryption for the Masses'
+ Modifications and additions to the original source code (contained in this file)
and all other portions of this file are Copyright (c) 2013-2016 IDRIX
and are governed by the Apache License 2.0 the full text of which is
contained in the file License.txt included in VeraCrypt binary and source
@@ -114,9 +114,9 @@ BOOL bMountFavoritesOnLogon = FALSE;
BOOL bHistory = FALSE;
-// Status of detection of hidden sectors (whole-system-drive encryption).
+// Status of detection of hidden sectors (whole-system-drive encryption).
// 0 - Unknown/undetermined/completed, 1: Detection is or was in progress (but did not complete e.g. due to system crash).
-int HiddenSectorDetectionStatus = 0;
+int HiddenSectorDetectionStatus = 0;
OSVersionEnum nCurrentOS = WIN_UNKNOWN;
int CurrentOSMajor = 0;
@@ -129,7 +129,7 @@ BOOL bPortableModeConfirmed = FALSE; // TRUE if it is certain that the instance
BOOL bInPlaceEncNonSysPending = FALSE; // TRUE if the non-system in-place encryption config file indicates that one or more partitions are scheduled to be encrypted. This flag is set only when config files are loaded during app startup.
-/* Globals used by Mount and Format (separately per instance) */
+/* Globals used by Mount and Format (separately per instance) */
BOOL PimEnable = FALSE;
BOOL KeyFilesEnable = FALSE;
KeyFile *FirstKeyFile = NULL;
@@ -148,7 +148,7 @@ BOOL WaitDialogDisplaying = FALSE;
HANDLE hDriver = INVALID_HANDLE_VALUE;
/* This mutex is used to prevent multiple instances of the wizard or main app from dealing with system encryption */
-volatile HANDLE hSysEncMutex = NULL;
+volatile HANDLE hSysEncMutex = NULL;
/* This mutex is used for non-system in-place encryption but only for informative (non-blocking) purposes,
such as whether an app should prompt the user whether to resume scheduled process. */
@@ -172,7 +172,7 @@ ATOM hDlgClass, hSplashClass;
/* This value may changed only by calling ChangeSystemEncryptionStatus(). Only the wizard can change it
(others may still read it though). */
-int SystemEncryptionStatus = SYSENC_STATUS_NONE;
+int SystemEncryptionStatus = SYSENC_STATUS_NONE;
/* Only the wizard can change this value (others may only read it). */
WipeAlgorithmId nWipeMode = TC_WIPE_NONE;
@@ -329,7 +329,7 @@ enum
BENCHMARK_SORT_BY_SPEED
};
-typedef struct
+typedef struct
{
int id;
wchar_t name[100];
@@ -352,7 +352,7 @@ BOOL benchmarkGPT = FALSE;
#endif // #ifndef SETUP
-typedef struct
+typedef struct
{
void *strings;
BOOL bold;
@@ -745,7 +745,7 @@ BOOL IsDiskError (DWORD error)
DWORD handleWin32Error (HWND hwndDlg, const char* srcPos)
{
PWSTR lpMsgBuf;
- DWORD dwError = GetLastError ();
+ DWORD dwError = GetLastError ();
wchar_t szErrorValue[32];
wchar_t* pszDesc;
@@ -868,7 +868,7 @@ int GetTextGfxWidth (HWND hwndDlgItem, const wchar_t *text, HFONT hFont)
{
SIZE sizes;
TEXTMETRIC textMetrics;
- HDC hdc = GetDC (hwndDlgItem);
+ HDC hdc = GetDC (hwndDlgItem);
SelectObject(hdc, (HGDIOBJ) hFont);
@@ -876,7 +876,7 @@ int GetTextGfxWidth (HWND hwndDlgItem, const wchar_t *text, HFONT hFont)
GetTextMetrics(hdc, &textMetrics); // Necessary for non-TrueType raster fonts (tmOverhang)
- ReleaseDC (hwndDlgItem, hdc);
+ ReleaseDC (hwndDlgItem, hdc);
return ((int) sizes.cx - (int) textMetrics.tmOverhang);
}
@@ -885,13 +885,13 @@ int GetTextGfxWidth (HWND hwndDlgItem, const wchar_t *text, HFONT hFont)
int GetTextGfxHeight (HWND hwndDlgItem, const wchar_t *text, HFONT hFont)
{
SIZE sizes;
- HDC hdc = GetDC (hwndDlgItem);
+ HDC hdc = GetDC (hwndDlgItem);
SelectObject(hdc, (HGDIOBJ) hFont);
GetTextExtentPoint32W (hdc, text, (int) wcslen (text), &sizes);
- ReleaseDC (hwndDlgItem, hdc);
+ ReleaseDC (hwndDlgItem, hdc);
return ((int) sizes.cy);
}
@@ -907,7 +907,7 @@ std::wstring FitPathInGfxWidth (HWND hwnd, HFONT hFont, LONG width, const std::w
rect.right = width;
rect.bottom = LONG_MAX;
- HDC hdc = GetDC (hwnd);
+ HDC hdc = GetDC (hwnd);
SelectObject (hdc, (HGDIOBJ) hFont);
wchar_t pathBuf[TC_MAX_PATH];
@@ -916,7 +916,7 @@ std::wstring FitPathInGfxWidth (HWND hwnd, HFONT hFont, LONG width, const std::w
if (DrawText (hdc, pathBuf, (int) path.size(), &rect, DT_CALCRECT | DT_MODIFYSTRING | DT_PATH_ELLIPSIS | DT_SINGLELINE) != 0)
newPath = pathBuf;
- ReleaseDC (hwnd, hdc);
+ ReleaseDC (hwnd, hdc);
return newPath;
}
@@ -996,12 +996,12 @@ void AccommodateTextField (HWND hwndDlg, UINT ctrlId, BOOL bFirstUpdate, HFONT h
width = GetTextGfxWidth (hwndCtrl, text, hFont);
height = GetTextGfxHeight (hwndCtrl, text, hFont);
- GetClientRect (hwndCtrl, &rec);
+ GetClientRect (hwndCtrl, &rec);
origWidth = rec.right;
origHeight = rec.bottom;
if (width >= 0
- && (!bFirstUpdate || origWidth > width)) // The original width of the field is the maximum allowed size
+ && (!bFirstUpdate || origWidth > width)) // The original width of the field is the maximum allowed size
{
horizSubOffset = origWidth - width;
vertSubOffset = origHeight - height;
@@ -1024,7 +1024,7 @@ void AccommodateTextField (HWND hwndDlg, UINT ctrlId, BOOL bFirstUpdate, HFONT h
alignPosDiff = horizSubOffset / 2;
else if (windowInfo.dwStyle & SS_RIGHT)
alignPosDiff = horizSubOffset;
-
+
// Resize/move
if (alignPosDiff > 0)
{
@@ -1079,7 +1079,7 @@ static LRESULT CALLBACK BootPwdFieldProc (HWND hwnd, UINT message, WPARAM wParam
// Protects an input field from having its content updated by a Paste action. Used for pre-boot password
-// input fields (only the US keyboard layout is supported in pre-boot environment so we must prevent the
+// input fields (only the US keyboard layout is supported in pre-boot environment so we must prevent the
// user from pasting a password typed using a non-US keyboard layout).
void ToBootPwdField (HWND hwndDlg, UINT ctrlId)
{
@@ -1106,7 +1106,7 @@ BOOL CALLBACK AuxiliaryDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP
if (hDC)
{
ScreenDPI = GetDeviceCaps (hDC, LOGPIXELSY);
- ReleaseDC (hwndDlg, hDC);
+ ReleaseDC (hwndDlg, hDC);
}
DPIScaleFactorX = 1;
@@ -1115,7 +1115,7 @@ BOOL CALLBACK AuxiliaryDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP
if (ScreenDPI != USER_DEFAULT_SCREEN_DPI)
{
- // Windows skews the GUI aspect ratio if the user has a non-default DPI. Hence, working with
+ // Windows skews the GUI aspect ratio if the user has a non-default DPI. Hence, working with
// actual screen DPI is redundant and leads to incorrect results. What really matters here is
// how Windows actually renders our GUI. This is determined by comparing the expected and current
// sizes of a hidden calibration text field.
@@ -1174,7 +1174,7 @@ BOOL CALLBACK AboutDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam
GetClientRect (GetDlgItem (hwndDlg, IDC_ABOUT_LOGO_AREA), &rec);
SetWindowPos (GetDlgItem (hwndDlg, IDC_ABOUT_BKG), HWND_TOP, 0, 0, rec.right, rec.bottom, SWP_NOMOVE);
- // Resize the logo bitmap if the user has a non-default DPI
+ // Resize the logo bitmap if the user has a non-default DPI
if (ScreenDPI != USER_DEFAULT_SCREEN_DPI)
{
// Logo (must recreate and keep the original aspect ratio as Windows distorts it)
@@ -1490,7 +1490,7 @@ void InitDialog (HWND hwndDlg)
void ProcessPaintMessages (HWND hwnd, int maxMessagesToProcess)
{
MSG paintMsg;
- int msgCounter = maxMessagesToProcess;
+ int msgCounter = maxMessagesToProcess;
while (PeekMessageW (&paintMsg, hwnd, 0, 0, PM_REMOVE | PM_QS_PAINT) != 0 && msgCounter-- > 0)
{
@@ -1518,16 +1518,16 @@ HDC CreateMemBitmap (HINSTANCE hInstance, HWND hwnd, wchar_t *resource)
}
-/* Renders the specified bitmap at the specified location and stretches it to fit (anti-aliasing is applied).
+/* Renders the specified bitmap at the specified location and stretches it to fit (anti-aliasing is applied).
If bDirectRender is FALSE and both nWidth and nHeight are zero, the width and height of hwndDest are
retrieved and adjusted according to screen DPI (the width and height of the resultant image are adjusted the
same way); furthermore, if bKeepAspectRatio is TRUE, the smaller DPI factor of the two (i.e. horiz. or vert.)
is used both for horiz. and vert. scaling (note that the overall GUI aspect ratio changes irregularly in
-both directions depending on the DPI). If bDirectRender is TRUE, bKeepAspectRatio is ignored.
+both directions depending on the DPI). If bDirectRender is TRUE, bKeepAspectRatio is ignored.
This function returns a handle to the scaled bitmap. When the bitmap is no longer needed, it should be
-deleted by calling DeleteObject() with the handle passed as the parameter.
-Known Windows issues:
-- For some reason, anti-aliasing is not applied if the source bitmap contains less than 16K pixels.
+deleted by calling DeleteObject() with the handle passed as the parameter.
+Known Windows issues:
+- For some reason, anti-aliasing is not applied if the source bitmap contains less than 16K pixels.
- Windows 2000 may produce slightly inaccurate colors even when source, buffer, and target are 24-bit true color. */
HBITMAP RenderBitmap (wchar_t *resource, HWND hwndDest, int x, int y, int nWidth, int nHeight, BOOL bDirectRender, BOOL bKeepAspectRatio)
{
@@ -1576,11 +1576,11 @@ HBITMAP RenderBitmap (wchar_t *resource, HWND hwndDest, int x, int y, int nWidth
GetObject (picture, sizeof (BITMAP), &bitmap);
- hdcRescaled = CreateCompatibleDC (hdcSrc);
+ hdcRescaled = CreateCompatibleDC (hdcSrc);
if (hdcRescaled)
{
- hbmpRescaled = CreateCompatibleBitmap (hdcSrc, nWidth, nHeight);
+ hbmpRescaled = CreateCompatibleBitmap (hdcSrc, nWidth, nHeight);
SelectObject (hdcRescaled, hbmpRescaled);
@@ -1596,7 +1596,7 @@ HBITMAP RenderBitmap (wchar_t *resource, HWND hwndDest, int x, int y, int nWidth
hdcSrc,
0,
0,
- bitmap.bmWidth,
+ bitmap.bmWidth,
bitmap.bmHeight,
SRCCOPY);
@@ -1705,8 +1705,8 @@ RegisterRedTick (HINSTANCE hInstance)
wc.hCursor = NULL;
wc.hbrBackground = (HBRUSH) GetStockObject (LTGRAY_BRUSH);
wc.lpszClassName = L"VCREDTICK";
- wc.lpfnWndProc = &RedTick;
-
+ wc.lpfnWndProc = &RedTick;
+
rc = (ULONG) RegisterClassW (&wc);
return rc == 0 ? FALSE : TRUE;
@@ -1823,7 +1823,7 @@ void PopulateWipeModeCombo (HWND hComboBox, BOOL bNA, BOOL bInPlaceEncryption, B
{
if (!bHeaderWipe)
{
- AddComboPair (hComboBox, GetString ("WIPE_MODE_NONE"), TC_WIPE_NONE);
+ AddComboPair (hComboBox, GetString ("WIPE_MODE_NONE"), TC_WIPE_NONE);
}
AddComboPair (hComboBox, GetString ("WIPE_MODE_1_RAND"), TC_WIPE_1_RAND);
@@ -2090,7 +2090,7 @@ void ExceptionHandlerThread (void *threadArg)
else
lpack[0] = 0;
-
+
sprintf (url, TC_APPLINK_SECURE "&dest=err-report%s&os=%s&osver=%d.%d.%d&arch=%s&cpus=%d&app=%s&cksum=%x&dlg=%s&err=%x&addr=%x"
, lpack
, GetWindowsEdition().c_str()
@@ -2157,9 +2157,48 @@ static LRESULT CALLBACK NonInstallUacWndProc (HWND hWnd, UINT message, WPARAM wP
return DefWindowProcW (hWnd, message, wParam, lParam);
}
+BOOL LaunchElevatedProcess (HWND hwndDlg, const wchar_t* szModPath, const wchar_t* args)
+{
+ wchar_t newCmdLine[4096];
+ WNDCLASSEXW wcex;
+ HWND hWnd;
+
+ memset (&wcex, 0, sizeof (wcex));
+ wcex.cbSize = sizeof(WNDCLASSEX);
+ wcex.lpfnWndProc = (WNDPROC) NonInstallUacWndProc;
+ wcex.hInstance = hInst;
+ wcex.lpszClassName = L"VeraCrypt";
+ RegisterClassExW (&wcex);
+
+ // A small transparent window is necessary to bring the new instance to foreground
+ hWnd = CreateWindowExW (WS_EX_TOOLWINDOW | WS_EX_LAYERED,
+ L"VeraCrypt", L"VeraCrypt", 0,
+ GetSystemMetrics (SM_CXSCREEN)/2,
+ GetSystemMetrics (SM_CYSCREEN)/2,
+ 1, 1, NULL, NULL, hInst, NULL);
+
+ SetLayeredWindowAttributes (hWnd, 0, 0, LWA_ALPHA);
+ ShowWindow (hWnd, SW_SHOWNORMAL);
+
+ StringCbCopyW (newCmdLine, sizeof(newCmdLine), L"/q UAC ");
+ StringCbCatW (newCmdLine, sizeof (newCmdLine), args);
+
+ if ((int)ShellExecuteW (hWnd, L"runas", szModPath, newCmdLine, NULL, SW_SHOWNORMAL) <= 32)
+ {
+ if (hwndDlg)
+ handleWin32Error (hwndDlg, SRC_POS);
+ return FALSE;
+ }
+ else
+ {
+ Sleep (2000);
+ return TRUE;
+ }
+}
+
// Mutex handling to prevent multiple instances of the wizard or main app from dealing with system encryption.
-// Returns TRUE if the mutex is (or had been) successfully acquired (otherwise FALSE).
+// Returns TRUE if the mutex is (or had been) successfully acquired (otherwise FALSE).
BOOL CreateSysEncMutex (void)
{
return TCCreateMutex (&hSysEncMutex, TC_MUTEX_NAME_SYSENC);
@@ -2179,7 +2218,7 @@ void CloseSysEncMutex (void)
}
-// Returns TRUE if the mutex is (or had been) successfully acquired (otherwise FALSE).
+// Returns TRUE if the mutex is (or had been) successfully acquired (otherwise FALSE).
BOOL CreateNonSysInplaceEncMutex (void)
{
return TCCreateMutex (&hNonSysInplaceEncMutex, TC_MUTEX_NAME_NONSYS_INPLACE_ENC);
@@ -2201,14 +2240,14 @@ void CloseNonSysInplaceEncMutex (void)
// Returns TRUE if another instance of the wizard is preparing, resuming or performing non-system in-place encryption
BOOL NonSysInplaceEncInProgressElsewhere (void)
{
- return (!InstanceHasNonSysInplaceEncMutex ()
+ return (!InstanceHasNonSysInplaceEncMutex ()
&& MutexExistsOnSystem (TC_MUTEX_NAME_NONSYS_INPLACE_ENC));
}
// Mutex handling to prevent multiple instances of the wizard or main app from trying to install
// or register the driver or from trying to launch it in portable mode at the same time.
-// Returns TRUE if the mutex is (or had been) successfully acquired (otherwise FALSE).
+// Returns TRUE if the mutex is (or had been) successfully acquired (otherwise FALSE).
BOOL CreateDriverSetupMutex (void)
{
return TCCreateMutex (&hDriverSetupMutex, TC_MUTEX_NAME_DRIVER_SETUP);
@@ -2239,7 +2278,7 @@ BOOL IsTrueCryptInstallerRunning (void)
}
-// Returns TRUE if the mutex is (or had been) successfully acquired (otherwise FALSE).
+// Returns TRUE if the mutex is (or had been) successfully acquired (otherwise FALSE).
BOOL TCCreateMutex (volatile HANDLE *hMutex, wchar_t *name)
{
if (*hMutex != NULL)
@@ -2279,7 +2318,7 @@ void TCCloseMutex (volatile HANDLE *hMutex)
}
-// Returns TRUE if a process running on the system has the specified mutex (otherwise FALSE).
+// Returns TRUE if a process running on the system has the specified mutex (otherwise FALSE).
BOOL MutexExistsOnSystem (wchar_t *name)
{
if (name[0] == 0)
@@ -2293,7 +2332,7 @@ BOOL MutexExistsOnSystem (wchar_t *name)
return FALSE;
if (GetLastError () == ERROR_ACCESS_DENIED) // On Vista, this is returned if the owner of the mutex is elevated while we are not
- return TRUE;
+ return TRUE;
// The call failed and it is not certain whether the mutex exists or not
return FALSE;
@@ -2565,8 +2604,8 @@ static void LoadSystemDll (LPCTSTR szModuleName, HMODULE *pHandle, BOOL bIgnoreE
void InitApp (HINSTANCE hInstance, wchar_t *lpszCommandLine)
{
WNDCLASSW wc;
- char langId[6];
- InitCommonControlsPtr InitCommonControlsFn = NULL;
+ char langId[6];
+ InitCommonControlsPtr InitCommonControlsFn = NULL;
/* remove current directory from dll search path */
SetDllDirectoryFn = (SetDllDirectoryPtr) GetProcAddress (GetModuleHandle(L"kernel32.dll"), "SetDllDirectoryW");
@@ -2580,7 +2619,7 @@ void InitApp (HINSTANCE hInstance, wchar_t *lpszCommandLine)
if (SetDefaultDllDirectoriesFn)
SetDefaultDllDirectoriesFn (LOAD_LIBRARY_SEARCH_SYSTEM32);
- InitOSVersionInfo();
+ InitOSVersionInfo();
VirtualLock (&CmdTokenPin, sizeof (CmdTokenPin));
@@ -2604,9 +2643,9 @@ void InitApp (HINSTANCE hInstance, wchar_t *lpszCommandLine)
LoadSystemDll (L"dwmapi.dll", &hdwmapidll, TRUE, SRC_POS);
LoadSystemDll (L"UXTheme.dll", &hUXThemeDll, TRUE, SRC_POS);
- LoadSystemDll (L"msls31.dll", &hMsls31, TRUE, SRC_POS);
+ LoadSystemDll (L"msls31.dll", &hMsls31, TRUE, SRC_POS);
LoadSystemDll (L"SETUPAPI.DLL", &hSetupDll, FALSE, SRC_POS);
- LoadSystemDll (L"SHLWAPI.DLL", &hShlwapiDll, FALSE, SRC_POS);
+ LoadSystemDll (L"SHLWAPI.DLL", &hShlwapiDll, FALSE, SRC_POS);
LoadSystemDll (L"userenv.dll", &hUserenvDll, TRUE, SRC_POS);
LoadSystemDll (L"rsaenh.dll", &hRsaenhDll, TRUE, SRC_POS);
@@ -2623,7 +2662,7 @@ void InitApp (HINSTANCE hInstance, wchar_t *lpszCommandLine)
}
if (IsOSAtLeast (WIN_VISTA))
- {
+ {
LoadSystemDll (L"netapi32.dll", &hnetapi32dll, TRUE, SRC_POS);
LoadSystemDll (L"authz.dll", &hauthzdll, TRUE, SRC_POS);
LoadSystemDll (L"xmllite.dll", &hxmllitedll, TRUE, SRC_POS);
@@ -2631,7 +2670,7 @@ void InitApp (HINSTANCE hInstance, wchar_t *lpszCommandLine)
}
if (IsOSAtLeast (WIN_VISTA))
- {
+ {
LoadSystemDll (L"atl.dll", &hsppdll, TRUE, SRC_POS);
LoadSystemDll (L"vsstrace.dll", &hvsstracedll, TRUE, SRC_POS);
LoadSystemDll (L"vssapi.dll", &vssapidll, TRUE, SRC_POS);
@@ -2648,15 +2687,15 @@ void InitApp (HINSTANCE hInstance, wchar_t *lpszCommandLine)
LoadSystemDll (L"crypt32.dll", &hcrypt32dll, TRUE, SRC_POS);
LoadSystemDll (L"bcrypt.dll", &hbcryptdll, TRUE, SRC_POS);
- LoadSystemDll (L"bcryptprimitives.dll", &hbcryptprimitivesdll, TRUE, SRC_POS);
+ LoadSystemDll (L"bcryptprimitives.dll", &hbcryptprimitivesdll, TRUE, SRC_POS);
}
- }
+ }
#else
LoadSystemDll (L"WINSCARD.DLL", &hwinscarddll, TRUE, SRC_POS);
#endif
LoadSystemDll (L"COMCTL32.DLL", &hComctl32Dll, FALSE, SRC_POS);
-
+
// call InitCommonControls function
InitCommonControlsFn = (InitCommonControlsPtr) GetProcAddress (hComctl32Dll, "InitCommonControls");
ImageList_AddFn = (ImageList_AddPtr) GetProcAddress (hComctl32Dll, "ImageList_Add");
@@ -2717,7 +2756,7 @@ void InitApp (HINSTANCE hInstance, wchar_t *lpszCommandLine)
// Language
langId[0] = 0;
SetPreferredLangId (ConfigReadString ("Language", "", langId, sizeof (langId)));
-
+
if (langId[0] == 0)
{
if (IsNonInstallMode ())
@@ -2742,9 +2781,7 @@ void InitApp (HINSTANCE hInstance, wchar_t *lpszCommandLine)
// A new instance of the application must be created with elevated privileges.
if (IsNonInstallMode () && !IsAdmin () && IsUacSupported ())
{
- wchar_t modPath[MAX_PATH], newCmdLine[4096];
- WNDCLASSEXW wcex;
- HWND hWnd;
+ wchar_t modPath[MAX_PATH];
if (wcsstr (lpszCommandLine, L"/q UAC ") == lpszCommandLine)
{
@@ -2752,33 +2789,12 @@ void InitApp (HINSTANCE hInstance, wchar_t *lpszCommandLine)
exit (1);
}
- memset (&wcex, 0, sizeof (wcex));
- wcex.cbSize = sizeof(WNDCLASSEX);
- wcex.lpfnWndProc = (WNDPROC) NonInstallUacWndProc;
- wcex.hInstance = hInstance;
- wcex.lpszClassName = L"VeraCrypt";
- RegisterClassExW (&wcex);
-
- // A small transparent window is necessary to bring the new instance to foreground
- hWnd = CreateWindowExW (WS_EX_TOOLWINDOW | WS_EX_LAYERED,
- L"VeraCrypt", L"VeraCrypt", 0,
- GetSystemMetrics (SM_CXSCREEN)/2,
- GetSystemMetrics (SM_CYSCREEN)/2,
- 1, 1, NULL, NULL, hInstance, NULL);
-
- SetLayeredWindowAttributes (hWnd, 0, 0, LWA_ALPHA);
- ShowWindow (hWnd, SW_SHOWNORMAL);
-
GetModuleFileNameW (NULL, modPath, ARRAYSIZE (modPath));
- StringCbCopyW (newCmdLine, sizeof(newCmdLine), L"/q UAC ");
- StringCbCatW (newCmdLine, sizeof (newCmdLine), lpszCommandLine);
-
- if ((int)ShellExecuteW (hWnd, L"runas", modPath, newCmdLine, NULL, SW_SHOWNORMAL) <= 32)
+ if (LaunchElevatedProcess (NULL, modPath, lpszCommandLine))
+ exit (0);
+ else
exit (1);
-
- Sleep (2000);
- exit (0);
}
#endif
@@ -2831,7 +2847,7 @@ void InitApp (HINSTANCE hInstance, wchar_t *lpszCommandLine)
break;
}
}
-
+
/* Get the attributes for the standard dialog class */
if ((GetClassInfoW (hInst, WINDOWS_DIALOG_CLASS, &wc)) == 0)
{
@@ -3022,7 +3038,7 @@ BOOL OpenDevice (const wchar_t *lpszPath, OPEN_TEST_STRUCT *driver, BOOL detectF
&dwResult, NULL);
// check variable driver
- if ( bResult
+ if ( bResult
&& ( (driver->bDetectTCBootLoader != TRUE && driver->bDetectTCBootLoader != FALSE) ||
(driver->TCBootLoaderDetected != TRUE && driver->TCBootLoaderDetected != FALSE) ||
(driver->DetectFilesystem != TRUE && driver->DetectFilesystem != FALSE) ||
@@ -3048,7 +3064,7 @@ BOOL OpenDevice (const wchar_t *lpszPath, OPEN_TEST_STRUCT *driver, BOOL detectF
else
return FALSE;
}
-
+
return TRUE;
}
@@ -3076,10 +3092,10 @@ BOOL GetDriveLabel (int driveNo, wchar_t *label, int labelSize)
/* Stores the device path of the system partition in SysPartitionDevicePath and the device path of the system drive
in SysDriveDevicePath.
-IMPORTANT: As this may take a very long time if called for the first time, it should be called only before performing
- a dangerous operation (such as header backup restore or formatting a supposedly non-system device) never
- at WM_INITDIALOG or any other GUI events -- instead call IsSystemDevicePath (path, hwndDlg, FALSE) for
- very fast preliminary GUI checks; also note that right after the "Select Device" dialog exits with an OK
+IMPORTANT: As this may take a very long time if called for the first time, it should be called only before performing
+ a dangerous operation (such as header backup restore or formatting a supposedly non-system device) never
+ at WM_INITDIALOG or any other GUI events -- instead call IsSystemDevicePath (path, hwndDlg, FALSE) for
+ very fast preliminary GUI checks; also note that right after the "Select Device" dialog exits with an OK
return code, you can use the global flags bSysPartitionSelected and bSysDriveSelected to see if the user
selected the system partition/device.
After this function completes successfully, the results are cached for the rest of the session and repeated
@@ -3087,13 +3103,13 @@ executions complete very fast. Returns TRUE if successful (otherwise FALSE). */
BOOL GetSysDevicePaths (HWND hwndDlg)
{
if (!bCachedSysDevicePathsValid
- || wcslen (SysPartitionDevicePath) <= 1
+ || wcslen (SysPartitionDevicePath) <= 1
|| wcslen (SysDriveDevicePath) <= 1)
{
foreach (const HostDevice &device, GetAvailableHostDevices (false, true))
{
if (device.ContainsSystem)
- StringCchCopyW (device.IsPartition ? SysPartitionDevicePath : SysDriveDevicePath, TC_MAX_PATH, device.Path.c_str());
+ StringCchCopyW (device.IsPartition ? SysPartitionDevicePath : SysDriveDevicePath, TC_MAX_PATH, device.Path.c_str());
}
if (IsOSAtLeast (WIN_7))
@@ -3120,24 +3136,24 @@ BOOL GetSysDevicePaths (HWND hwndDlg)
bCachedSysDevicePathsValid = 1;
}
- return (bCachedSysDevicePathsValid
- && wcslen (SysPartitionDevicePath) > 1
+ return (bCachedSysDevicePathsValid
+ && wcslen (SysPartitionDevicePath) > 1
&& wcslen (SysDriveDevicePath) > 1);
}
-/* Determines whether the device path is the path of the system partition or of the system drive (or neither).
-If bReliableRequired is TRUE, very fast execution is guaranteed, but the results cannot be relied upon.
+/* Determines whether the device path is the path of the system partition or of the system drive (or neither).
+If bReliableRequired is TRUE, very fast execution is guaranteed, but the results cannot be relied upon.
If it's FALSE and the function is called for the first time, execution may take up to one minute but the
results are reliable.
IMPORTANT: As the execution may take a very long time if called for the first time with bReliableRequired set
to TRUE, it should be called with bReliableRequired set to TRUE only before performing a dangerous
- operation (such as header backup restore or formatting a supposedly non-system device) never at
- WM_INITDIALOG or any other GUI events (use IsSystemDevicePath(path, hwndDlg, FALSE) for fast
- preliminary GUI checks; also note that right after the "Select Device" dialog exits with an OK
+ operation (such as header backup restore or formatting a supposedly non-system device) never at
+ WM_INITDIALOG or any other GUI events (use IsSystemDevicePath(path, hwndDlg, FALSE) for fast
+ preliminary GUI checks; also note that right after the "Select Device" dialog exits with an OK
return code, you can use the global flags bSysPartitionSelected and bSysDriveSelected to see if the
user selected the system partition/device).
After this function completes successfully, the results are cached for the rest of the session, bReliableRequired
-is ignored (TRUE implied), repeated executions complete very fast, and the results are always reliable.
+is ignored (TRUE implied), repeated executions complete very fast, and the results are always reliable.
Return codes:
1 - it is the system partition path (e.g. \Device\Harddisk0\Partition1)
2 - it is the system drive path (e.g. \Device\Harddisk0\Partition0)
@@ -3172,10 +3188,10 @@ int IsSystemDevicePath (const wchar_t *path, HWND hwndDlg, BOOL bReliableRequire
/* Determines whether the path points to a non-system partition on the system drive.
IMPORTANT: As this may take a very long time if called for the first time, it should be called
- only before performing a dangerous operation, never at WM_INITDIALOG or any other GUI events.
+ only before performing a dangerous operation, never at WM_INITDIALOG or any other GUI events.
Return codes:
-0 - it isn't a non-system partition on the system drive
-1 - it's a non-system partition on the system drive
+0 - it isn't a non-system partition on the system drive
+1 - it's a non-system partition on the system drive
-1 - the result can't be determined, isn't reliable, or there was an error. */
int IsNonSysPartitionOnSysDrive (const wchar_t *path)
{
@@ -3215,12 +3231,12 @@ int IsNonSysPartitionOnSysDrive (const wchar_t *path)
if (wcsncmp (tmpPath, SysDriveDevicePath, max (wcslen(tmpPath), wcslen(SysDriveDevicePath))) == 0)
{
- // It is a non-system partition on the system drive
+ // It is a non-system partition on the system drive
return 1;
}
- else
+ else
{
- // The partition is not on the system drive
+ // The partition is not on the system drive
return 0;
}
}
@@ -3465,17 +3481,17 @@ BOOL CALLBACK RawDevicesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l
LocalizeDialog (hwndDlg, "IDD_RAWDEVICES_DLG");
SendMessage (hList,LVM_SETEXTENDEDLISTVIEWSTYLE,0,
- LVS_EX_FULLROWSELECT|LVS_EX_HEADERDRAGDROP|LVS_EX_TWOCLICKACTIVATE|LVS_EX_LABELTIP
- );
+ LVS_EX_FULLROWSELECT|LVS_EX_HEADERDRAGDROP|LVS_EX_TWOCLICKACTIVATE|LVS_EX_LABELTIP
+ );
- memset (&LvCol,0,sizeof(LvCol));
- LvCol.mask = LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM|LVCF_FMT;
+ memset (&LvCol,0,sizeof(LvCol));
+ LvCol.mask = LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM|LVCF_FMT;
LvCol.pszText = GetString ("DEVICE");
LvCol.cx = CompensateXDPI (186);
LvCol.fmt = LVCFMT_LEFT;
SendMessage (hList,LVM_INSERTCOLUMNW,0,(LPARAM)&LvCol);
- LvCol.pszText = GetString ("DRIVE");
+ LvCol.pszText = GetString ("DRIVE");
LvCol.cx = CompensateXDPI (38);
LvCol.fmt = LVCFMT_LEFT;
SendMessage (hList,LVM_INSERTCOLUMNW,1,(LPARAM)&LvCol);
@@ -3529,7 +3545,7 @@ BOOL CALLBACK RawDevicesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l
// Path
if (!device.IsPartition || device.DynamicVolume)
{
- if (!device.Floppy && (device.Size == 0)
+ if (!device.Floppy && (device.Size == 0)
&& (device.IsPartition || device.Partitions.empty() || device.Partitions[0].Size == 0)
)
continue;
@@ -3537,7 +3553,7 @@ BOOL CALLBACK RawDevicesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l
if (line > 1)
{
ListItemAdd (hList, item.iItem, L"");
- item.iItem = line++;
+ item.iItem = line++;
}
if (device.Floppy || device.DynamicVolume)
@@ -3590,7 +3606,7 @@ BOOL CALLBACK RawDevicesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l
}
#endif
- item.iItem = line++;
+ item.iItem = line++;
}
SendMessageW(hList, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(LVSCW_AUTOSIZE_USEHEADER, 0));
@@ -3613,8 +3629,8 @@ BOOL CALLBACK RawDevicesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l
{
BOOL bEnableOkButton = FALSE;
LVITEM LvItem;
- memset(&LvItem,0,sizeof(LvItem));
- LvItem.mask = LVIF_TEXT | LVIF_PARAM;
+ memset(&LvItem,0,sizeof(LvItem));
+ LvItem.mask = LVIF_TEXT | LVIF_PARAM;
LvItem.iItem = ((LPNMLISTVIEW) lParam)->iItem;
LvItem.pszText = lpszFileName;
LvItem.cchTextMax = TC_MAX_PATH;
@@ -3647,7 +3663,7 @@ BOOL CALLBACK RawDevicesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l
int selectedItem = ListView_GetSelectionMark (GetDlgItem (hwndDlg, IDC_DEVICELIST));
if (selectedItem == -1 || itemToDeviceMap.find (selectedItem) == itemToDeviceMap.end())
- return 1; // non-device line selected
+ return 1; // non-device line selected
const HostDevice selectedDevice = itemToDeviceMap[selectedItem];
StringCchCopyW (lpszFileName, TC_MAX_PATH, selectedDevice.Path.c_str());
@@ -3760,7 +3776,7 @@ BOOL CALLBACK RawDevicesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l
}
}
- // Disallow format if the device contains partitions, but not if the partition is virtual or system
+ // Disallow format if the device contains partitions, but not if the partition is virtual or system
if (!selectedDevice.IsVirtualPartition
&& !bHiddenVolDirect)
{
@@ -3781,7 +3797,7 @@ BOOL CALLBACK RawDevicesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l
#endif // #ifdef VOLFORMAT
}
- else
+ else
bSysDriveSelected = FALSE;
#ifdef VOLFORMAT
@@ -3958,7 +3974,7 @@ BOOL DriverUnload ()
if (hDriver == INVALID_HANDLE_VALUE)
return TRUE;
-
+
try
{
if (BootEncryption (NULL).GetStatus().DeviceFilterActive)
@@ -4075,7 +4091,7 @@ start:
}
// Try to open a handle to the driver again (keep the mutex in case the other instance failed)
- goto start;
+ goto start;
}
else
{
@@ -4084,7 +4100,7 @@ start:
if (SystemEncryptionStatus != SYSENC_STATUS_NONE)
{
// This is an inconsistent state. The config file indicates system encryption should be
- // active, but the driver is not running. This may happen e.g. when the pretest fails and
+ // active, but the driver is not running. This may happen e.g. when the pretest fails and
// the user selects "Last Known Good Configuration" from the Windows boot menu.
// To fix this, we're going to reinstall the driver, start it, and register it for boot.
@@ -4118,7 +4134,7 @@ load:
return res;
bPortableModeConfirmed = TRUE;
-
+
if (hDriver != INVALID_HANDLE_VALUE)
CloseHandle (hDriver);
hDriver = CreateFile (WIN32_ROOT_PREFIX, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
@@ -4292,7 +4308,7 @@ BOOL SelectMultipleFiles (HWND hwndDlg, const char *stringId, wchar_t *lpszFileN
| OFN_PATHMUSTEXIST
| OFN_ALLOWMULTISELECT
| (keepHistory ? 0 : OFN_DONTADDTORECENT);
-
+
if (!keepHistory)
CleanLastVisitedMRU ();
@@ -4322,7 +4338,7 @@ BOOL SelectMultipleFiles (HWND hwndDlg, const char *stringId, wchar_t *lpszFileN
CleanLastVisitedMRU ();
status = TRUE;
-
+
ret:
SystemFileSelectorCallPending = FALSE;
ResetCurrentDirectory();
@@ -4356,10 +4372,10 @@ BOOL SelectMultipleFilesNext (wchar_t *lpszFileName, size_t cbFileName)
}
-static int CALLBACK BrowseCallbackProc(HWND hwnd,UINT uMsg,LPARAM lp, LPARAM pData)
+static int CALLBACK BrowseCallbackProc(HWND hwnd,UINT uMsg,LPARAM lp, LPARAM pData)
{
switch(uMsg) {
- case BFFM_INITIALIZED:
+ case BFFM_INITIALIZED:
{
/* WParam is TRUE since we are passing a path.
It would be FALSE if we were passing a pidl. */
@@ -4367,12 +4383,12 @@ static int CALLBACK BrowseCallbackProc(HWND hwnd,UINT uMsg,LPARAM lp, LPARAM pDa
break;
}
- case BFFM_SELCHANGED:
+ case BFFM_SELCHANGED:
{
wchar_t szDir[TC_MAX_PATH];
/* Set the status window to the currently selected path. */
- if (SHGetPathFromIDList((LPITEMIDLIST) lp ,szDir))
+ if (SHGetPathFromIDList((LPITEMIDLIST) lp ,szDir))
{
SendMessage (hwnd,BFFM_SETSTATUSTEXT,0,(LPARAM)szDir);
}
@@ -4396,7 +4412,7 @@ BOOL BrowseDirectories (HWND hwndDlg, char *lpszTitle, wchar_t *dirName)
CoInitialize (NULL);
- if (SUCCEEDED (SHGetMalloc (&pMalloc)))
+ if (SUCCEEDED (SHGetMalloc (&pMalloc)))
{
ZeroMemory (&bi, sizeof(bi));
bi.hwndOwner = hwndDlg;
@@ -4408,9 +4424,9 @@ BOOL BrowseDirectories (HWND hwndDlg, char *lpszTitle, wchar_t *dirName)
bi.lParam = (LPARAM)dirName;
pidl = SHBrowseForFolderW (&bi);
- if (pidl != NULL)
+ if (pidl != NULL)
{
- if (SHGetPathFromIDList(pidl, dirName))
+ if (SHGetPathFromIDList(pidl, dirName))
{
bOK = TRUE;
}
@@ -4624,7 +4640,7 @@ static BOOL CALLBACK LocalizeDialogEnum( HWND hwnd, LPARAM font)
// Font
SendMessageW (hwnd, WM_SETFONT, (WPARAM) font, 0);
-
+
return TRUE;
}
@@ -4638,7 +4654,7 @@ void LocalizeDialog (HWND hwnd, char *stringId)
SetWindowTextW (hwnd, L"VeraCrypt");
else
SetWindowTextW (hwnd, GetString (stringId));
-
+
if (hUserFont != 0)
EnumChildWindows (hwnd, LocalizeDialogEnum, (LPARAM) hUserFont);
}
@@ -4719,10 +4735,10 @@ BOOL UpdateDriveCustomLabel (int driveNo, wchar_t* effectiveLabel, BOOL bSetValu
DWORD cbLabelLen = (DWORD) ((wcslen (effectiveLabel) + 1) * sizeof (wchar_t));
BOOL bToBeDeleted = FALSE;
- StringCbPrintfW (wszRegPath, sizeof (wszRegPath), L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\DriveIcons\\%s\\DefaultLabel", driveStr);
-
+ StringCbPrintfW (wszRegPath, sizeof (wszRegPath), L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\DriveIcons\\%s\\DefaultLabel", driveStr);
+
if (bSetValue)
- lStatus = RegCreateKeyExW (HKEY_CURRENT_USER, wszRegPath, NULL, NULL, 0,
+ lStatus = RegCreateKeyExW (HKEY_CURRENT_USER, wszRegPath, NULL, NULL, 0,
KEY_READ | KEY_WRITE | KEY_SET_VALUE, NULL, &hKey, NULL);
else
lStatus = RegOpenKeyExW (HKEY_CURRENT_USER, wszRegPath, 0, KEY_READ | KEY_WRITE | KEY_SET_VALUE, &hKey);
@@ -4746,7 +4762,7 @@ BOOL UpdateDriveCustomLabel (int driveNo, wchar_t* effectiveLabel, BOOL bSetValu
if (bToBeDeleted)
{
- StringCbPrintfW (wszRegPath, sizeof (wszRegPath), L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\DriveIcons\\%s", driveStr);
+ StringCbPrintfW (wszRegPath, sizeof (wszRegPath), L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\DriveIcons\\%s", driveStr);
lStatus = RegOpenKeyExW (HKEY_CURRENT_USER, wszRegPath, 0, KEY_READ | KEY_WRITE | KEY_SET_VALUE, &hKey);
if (ERROR_SUCCESS == lStatus)
{
@@ -4772,7 +4788,7 @@ wstring GetUserFriendlyVersionString (int version)
versionString.insert (version > 0xfff ? 2 : 1,L".");
if (versionString[versionString.length()-1] == L'0')
- versionString.erase (versionString.length()-1, 1);
+ versionString.erase (versionString.length()-1, 1);
return (versionString);
}
@@ -4824,7 +4840,7 @@ bool HexWideStringToArray (const wchar_t* hexStr, std::vector<byte>& arr)
arr.clear();
if (len %2)
return false;
-
+
for (i = 0; i < len/2; i++)
{
if (!HexToByte (*hexStr++, b1) || !HexToByte (*hexStr++, b2))
@@ -4887,7 +4903,7 @@ void GetSpeedString (unsigned __int64 speed, wchar_t *str, size_t cbStr)
{
static wchar_t *b, *kb, *mb, *gb, *tb, *pb;
static int serNo;
-
+
if (b == NULL || serNo != LocalizationSerialNo)
{
serNo = LocalizationSerialNo;
@@ -5029,7 +5045,7 @@ static void DisplayBenchmarkResults (HWND hwndDlg)
}
break;
}
-
+
for (i = 0; i < benchmarkTotalItems; i++)
{
ea = benchmarkTable[i].id;
@@ -5087,7 +5103,7 @@ static void DisplayBenchmarkResults (HWND hwndDlg)
typedef struct
{
HWND hBenchDlg;
- BOOL bStatus;
+ BOOL bStatus;
} BenchmarkThreadParam;
static BOOL PerformBenchmark(HWND hBenchDlg, HWND hwndDlg);
@@ -5284,7 +5300,7 @@ static BOOL PerformBenchmark(HWND hBenchDlg, HWND hwndDlg)
if (thid == SHA256)
{
#ifdef _WIN64
- benchmarkTable[benchmarkTotalItems].meanBytesPerSec = (benchmarkTable[benchmarkTotalItems].meanBytesPerSec * 26);
+ benchmarkTable[benchmarkTotalItems].meanBytesPerSec = (benchmarkTable[benchmarkTotalItems].meanBytesPerSec * 26);
#else
benchmarkTable[benchmarkTotalItems].meanBytesPerSec = (benchmarkTable[benchmarkTotalItems].meanBytesPerSec * 24);
#endif
@@ -5292,7 +5308,7 @@ static BOOL PerformBenchmark(HWND hBenchDlg, HWND hwndDlg)
else
{
#ifdef _WIN64
- benchmarkTable[benchmarkTotalItems].meanBytesPerSec = (benchmarkTable[benchmarkTotalItems].meanBytesPerSec * 21) / 5;
+ benchmarkTable[benchmarkTotalItems].meanBytesPerSec = (benchmarkTable[benchmarkTotalItems].meanBytesPerSec * 21) / 5;
#else
benchmarkTable[benchmarkTotalItems].meanBytesPerSec = (benchmarkTable[benchmarkTotalItems].meanBytesPerSec * 18) / 5;
#endif
@@ -5389,7 +5405,7 @@ static BOOL PerformBenchmark(HWND hBenchDlg, HWND hwndDlg)
return TRUE;
counter_error:
-
+
if (ci)
crypto_close (ci);
@@ -5441,11 +5457,11 @@ BOOL CALLBACK BenchmarkDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP
benchmarkGPT = FALSE;
SendMessage (hList,LVM_SETEXTENDEDLISTVIEWSTYLE,0,
- LVS_EX_FULLROWSELECT|LVS_EX_HEADERDRAGDROP|LVS_EX_LABELTIP
- );
+ LVS_EX_FULLROWSELECT|LVS_EX_HEADERDRAGDROP|LVS_EX_LABELTIP
+ );
- memset (&LvCol,0,sizeof(LvCol));
- LvCol.mask = LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM|LVCF_FMT;
+ memset (&LvCol,0,sizeof(LvCol));
+ LvCol.mask = LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM|LVCF_FMT;
LvCol.pszText = GetString ("ALGORITHM");
LvCol.cx = CompensateXDPI (114);
LvCol.fmt = LVCFMT_LEFT;
@@ -5733,7 +5749,7 @@ static BOOL CALLBACK RandomPoolEnrichementDlgProc (HWND hwndDlg, UINT msg, WPARA
SetTimer (hwndDlg, 0xfd, RANDPOOL_DISPLAY_REFRESH_INTERVAL, NULL);
SendMessage (GetDlgItem (hwndDlg, IDC_POOL_CONTENTS), WM_SETFONT, (WPARAM) hFixedDigitFont, (LPARAM) TRUE);
-
+
hEntropyBar = GetDlgItem (hwndDlg, IDC_ENTROPY_BAR);
SendMessage (hEntropyBar, PBM_SETRANGE32, 0, maxEntropyLevel);
SendMessage (hEntropyBar, PBM_SETSTEP, 1, 0);
@@ -5768,7 +5784,7 @@ static BOOL CALLBACK RandomPoolEnrichementDlgProc (HWND hwndDlg, UINT msg, WPARA
else if (bUseMask)
{
/* use mask to compute a randomized ascii representation */
- tmpByte = (randPool[row * RANDPOOL_DISPLAY_COLUMNS + col] -
+ tmpByte = (randPool[row * RANDPOOL_DISPLAY_COLUMNS + col] -
lastRandPool[row * RANDPOOL_DISPLAY_COLUMNS + col]) ^ maskRandPool [row * RANDPOOL_DISPLAY_COLUMNS + col];
tmp[0] = (wchar_t) (((tmpByte >> 4) % 6) + L'*');
tmp[1] = (wchar_t) (((tmpByte & 0x0F) % 6) + L'*');
@@ -5929,8 +5945,8 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
SendMessage (hEntropyBar, PBM_SETSTEP, 1, 0);
SendMessage (hEntropyBar, PBM_SETSTATE, PBST_ERROR, 0);
-#ifndef VOLFORMAT
- if (Randinit ())
+#ifndef VOLFORMAT
+ if (Randinit ())
{
handleError (hwndDlg, (CryptoAPILastError == ERROR_SUCCESS)? ERR_RAND_INIT_FAILED : ERR_CAPI_INIT_FAILED, SRC_POS);
EndDialog (hwndDlg, IDCLOSE);
@@ -5976,7 +5992,7 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
else if (bUseMask)
{
/* use mask to compute a randomized ASCII representation */
- tmpByte = (randPool[row * RANDPOOL_DISPLAY_COLUMNS + col] -
+ tmpByte = (randPool[row * RANDPOOL_DISPLAY_COLUMNS + col] -
lastRandPool[row * RANDPOOL_DISPLAY_COLUMNS + col]) ^ maskRandPool [row * RANDPOOL_DISPLAY_COLUMNS + col];
tmp[0] = (wchar_t) (((tmpByte >> 4) % 6) + L'*');
tmp[1] = (wchar_t) (((tmpByte & 0x0F) % 6) + L'*');
@@ -6104,7 +6120,7 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
for (i= 0; i < keyfilesCount; i++)
{
StringCbCopyW(szFileName, sizeof(szFileName), szDirName);
-
+
if (i > 0)
{
StringCbPrintfW(szSuffix, sizeof(szSuffix), L"_%d", i);
@@ -6161,7 +6177,7 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
NormalCursor();
return 1;
}
-
+
/* since keyfilesSize < 1024 * 1024, we mask with 0x000FFFFF */
keyfilesSize = (long) (((unsigned long) keyfilesSize) & 0x000FFFFF);
@@ -6169,7 +6185,7 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
keyfilesSize += 64;
}
- /* Generate the keyfile */
+ /* Generate the keyfile */
if (!RandgetBytesFull (hwndDlg, keyfile, keyfilesSize, TRUE, TRUE))
{
_close (fhKeyfile);
@@ -6177,7 +6193,7 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
TCfree(keyfile);
NormalCursor();
return 1;
- }
+ }
/* Write the keyfile */
status = _write (fhKeyfile, keyfile, keyfilesSize);
@@ -6190,7 +6206,7 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
NormalCursor();
handleWin32Error (hwndDlg, SRC_POS);
return 1;
- }
+ }
}
TCfree(keyfile);
@@ -6209,7 +6225,7 @@ exit:
WaitCursor();
KillTimer (hwndDlg, 0xfd);
-#ifndef VOLFORMAT
+#ifndef VOLFORMAT
RandStop (FALSE);
#endif
/* Cleanup */
@@ -6324,7 +6340,7 @@ CipherTestDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
ShowWindow(GetDlgItem(hwndDlg, IDC_TESTS_MESSAGE), SW_SHOWNORMAL);
SetWindowTextW(GetDlgItem(hwndDlg, IDC_TESTS_MESSAGE), GetString ("TESTS_FAILED"));
- }
+ }
else
{
ShowWindow(GetDlgItem(hwndDlg, IDC_TESTS_MESSAGE), SW_SHOWNORMAL);
@@ -6430,7 +6446,7 @@ CipherTestDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
inputtext[n] = (char) x;
}
-
+
// XTS
if (bXTSTestEnabled)
{
@@ -6487,10 +6503,10 @@ CipherTestDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
blockNo = (int) SendMessage (GetDlgItem (hwndDlg, IDC_TEST_BLOCK_NUMBER), CB_GETITEMDATA, SendMessage (GetDlgItem (hwndDlg, IDC_TEST_BLOCK_NUMBER), CB_GETCURSEL, 0, 0), 0);
} // if (bXTSTestEnabled)
-
+
/* Perform the actual tests */
- if (ks != CB_ERR && pt != CB_ERR)
+ if (ks != CB_ERR && pt != CB_ERR)
{
char tmp[128];
int tmpRetVal;
@@ -6587,7 +6603,7 @@ CipherTestDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
return 0;
}
-void
+void
ResetCipherTest(HWND hwndDlg, int idTestCipher)
{
int ndx;
@@ -6621,7 +6637,7 @@ ResetCipherTest(HWND hwndDlg, int idTestCipher)
SetWindowText(GetDlgItem(hwndDlg, IDC_SECONDARY_KEY), L"0000000000000000000000000000000000000000000000000000000000000000");
SetWindowText(GetDlgItem(hwndDlg, IDC_TEST_DATA_UNIT_NUMBER), L"0");
-
+
SetWindowText(GetDlgItem(hwndDlg, IDC_PLAINTEXT), L"0000000000000000");
SetWindowText(GetDlgItem(hwndDlg, IDC_CIPHERTEXT), L"0000000000000000");
@@ -6696,7 +6712,7 @@ BOOL CALLBACK MultiChoiceDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPA
pStr++;
pwStr++;
- do
+ do
{
if (*pStr != 0)
{
@@ -6710,7 +6726,7 @@ BOOL CALLBACK MultiChoiceDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPA
hUserFont),
nLongestButtonCaptionWidth);
- nLongestButtonCaptionCharLen = max (nLongestButtonCaptionCharLen,
+ nLongestButtonCaptionCharLen = max (nLongestButtonCaptionCharLen,
(int) wcslen ((const wchar_t *) (bResolve ? GetString(*pStr) : *pwStr)));
}
@@ -6729,14 +6745,14 @@ BOOL CALLBACK MultiChoiceDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPA
// Length of main message in characters (not bytes)
nMainTextLenInChars = (int) wcslen ((const wchar_t *) (bResolve ? GetString(*(pStrOrig+1)) : *(pwStrOrig+1)));
- if (nMainTextLenInChars > 200
+ if (nMainTextLenInChars > 200
&& nMainTextLenInChars / nLongestButtonCaptionCharLen >= 10)
{
- // As the main text is longer than 200 characters, we will "pad" the widest button caption with
- // spaces (if it is not wide enough) so as to increase the width of the whole dialog window.
+ // As the main text is longer than 200 characters, we will "pad" the widest button caption with
+ // spaces (if it is not wide enough) so as to increase the width of the whole dialog window.
// Otherwise, it would look too tall (dialog boxes look better when they are more wide than tall).
nLongestButtonCaptionWidth = CompensateXDPI (max (
- nLongestButtonCaptionWidth,
+ nLongestButtonCaptionWidth,
min (350, nMainTextLenInChars)));
}
@@ -6764,10 +6780,10 @@ BOOL CALLBACK MultiChoiceDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPA
do
{
- offset = FindString ((char *) (bResolve ? GetString(*(pStrOrig+1)) : *(pwStrOrig+1)),
+ offset = FindString ((char *) (bResolve ? GetString(*(pStrOrig+1)) : *(pwStrOrig+1)),
(char *) L"\n",
- nMainTextLenInChars * 2,
- (int) wcslen (L"\n") * 2,
+ nMainTextLenInChars * 2,
+ (int) wcslen (L"\n") * 2,
offset + 1);
newLineSeqCount++;
@@ -6788,8 +6804,8 @@ BOOL CALLBACK MultiChoiceDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPA
// Reduction in height according to the number of shown buttons
vertSubOffset = ((MAX_MULTI_CHOICES - nActiveChoices) * nBaseButtonHeight);
- if (horizSubOffset > 0
- || vertMsgHeightOffset > 0
+ if (horizSubOffset > 0
+ || vertMsgHeightOffset > 0
|| vertOffset > 0)
{
// Resize/move each button if necessary
@@ -6823,7 +6839,7 @@ BOOL CALLBACK MultiChoiceDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPA
trec.right + 2 + horizSubOffset,
trec.bottom + 2,
TRUE);
-
+
GetWindowRect(GetDlgItem(hwndDlg, IDC_MC_DLG_HR2), &rec);
GetClientRect(GetDlgItem(hwndDlg, IDC_MC_DLG_HR2), &trec);
MoveWindow (GetDlgItem(hwndDlg, IDC_MC_DLG_HR2),
@@ -6877,7 +6893,7 @@ BOOL CALLBACK MultiChoiceDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPA
BOOL CheckCapsLock (HWND hwnd, BOOL quiet)
{
- if ((GetKeyState(VK_CAPITAL) & 1) != 0)
+ if ((GetKeyState(VK_CAPITAL) & 1) != 0)
{
if (!quiet)
{
@@ -6906,7 +6922,7 @@ BOOL CheckFileExtension (wchar_t *fileName)
L".vb", L".vbe", L".vbs", L".vsmacros", L".vss", L".vst", L".vsw", L".ws", L".wsc", L".wsf", L".wsh", L".xsd", L".xsl",
// These additional file extensions are usually watched by antivirus programs
L".386", L".acm", L".ade", L".adp", L".ani", L".app", L".asd", L".asf", L".asx", L".awx", L".ax", L".boo", L".bz2", L".cdf",
- L".class", L".dhtm", L".dhtml",L".dlo", L".emf", L".eml", L".flt", L".fot", L".gz", L".hlp", L".htm", L".html", L".ini",
+ L".class", L".dhtm", L".dhtml",L".dlo", L".emf", L".eml", L".flt", L".fot", L".gz", L".hlp", L".htm", L".html", L".ini",
L".j2k", L".jar", L".jff", L".jif", L".jmh", L".jng", L".jp2", L".jpe", L".jpeg", L".jpg", L".lsp", L".mod", L".nws",
L".obj", L".olb", L".osd", L".ov1", L".ov2", L".ov3", L".ovl", L".ovl", L".ovr", L".pdr", L".pgm", L".php", L".pkg",
L".pl", L".png", L".pot", L".pps", L".ppt", L".ps1", L".ps1xml", L".psc1", L".rar", L".rpl", L".rtf", L".sbf", L".script", L".sh", L".sha", L".shtm",
@@ -7078,7 +7094,7 @@ int DriverUnmountVolume (HWND hwndDlg, int nDosDriveNo, BOOL forced)
memcpy (wszLabel, prop.wszLabel, sizeof (wszLabel));
bDriverSetLabel = prop.bDriverSetLabel;
}
-
+
unmount.nDosDriveNo = nDosDriveNo;
unmount.ignoreOpenFiles = forced;
@@ -7148,11 +7164,11 @@ void BroadcastDeviceChange (WPARAM message, int nDosDriveNo, DWORD driveMap)
}
}
- dbv.dbcv_size = sizeof (dbv);
- dbv.dbcv_devicetype = DBT_DEVTYP_VOLUME;
+ dbv.dbcv_size = sizeof (dbv);
+ dbv.dbcv_devicetype = DBT_DEVTYP_VOLUME;
dbv.dbcv_reserved = 0;
dbv.dbcv_unitmask = driveMap;
- dbv.dbcv_flags = 0;
+ dbv.dbcv_flags = 0;
UINT timeOut = 1000;
@@ -7252,8 +7268,8 @@ BOOL CALLBACK WaitDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
SetWindowLongPtrW (hProgress, GWL_STYLE, PBS_MARQUEE | GetWindowLongPtrW (hProgress, GWL_STYLE));
::SendMessageW(hProgress, PBM_SETMARQUEE, (WPARAM) TRUE, (LPARAM) 0);
}
-
- thParam->hwnd = hwndDlg;
+
+ thParam->hwnd = hwndDlg;
// For now, we don't have system menu is the resources but we leave this code
// if it is enabled in the future
@@ -7267,8 +7283,8 @@ BOOL CALLBACK WaitDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
HICON hIcon = (HICON)::LoadImage(hInst, MAKEINTRESOURCE(IDI_TRUECRYPT_ICON), IMAGE_ICON, ::GetSystemMetrics(SM_CXICON), ::GetSystemMetrics(SM_CYICON), LR_DEFAULTCOLOR);
::SendMessage(hwndDlg, WM_SETICON, TRUE, (LPARAM)hIcon);
HICON hIconSmall = (HICON)::LoadImage(hInst, MAKEINTRESOURCE(IDI_TRUECRYPT_ICON), IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR);
- ::SendMessage(hwndDlg, WM_SETICON, FALSE, (LPARAM)hIconSmall);
- }
+ ::SendMessage(hwndDlg, WM_SETICON, FALSE, (LPARAM)hIconSmall);
+ }
LocalizeDialog (hwndDlg, NULL);
_beginthread(WaitThread, 0, thParam);
@@ -7296,26 +7312,26 @@ BOOL CALLBACK WaitDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
void BringToForeground(HWND hWnd)
{
if(!::IsWindow(hWnd)) return;
-
+
DWORD lockTimeOut = 0;
HWND hCurrWnd = ::GetForegroundWindow();
DWORD dwThisTID = ::GetCurrentThreadId(),
dwCurrTID = ::GetWindowThreadProcessId(hCurrWnd,0);
-
+
if (hCurrWnd != hWnd)
{
if(dwThisTID != dwCurrTID)
{
::AttachThreadInput(dwThisTID, dwCurrTID, TRUE);
-
+
::SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT,0,&lockTimeOut,0);
::SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT,0,0,SPIF_SENDWININICHANGE | SPIF_UPDATEINIFILE);
-
+
::AllowSetForegroundWindow(ASFW_ANY);
}
-
+
::SetForegroundWindow(hWnd);
-
+
if(dwThisTID != dwCurrTID)
{
::SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT,0,(PVOID)lockTimeOut,SPIF_SENDWININICHANGE | SPIF_UPDATEINIFILE);
@@ -7388,12 +7404,12 @@ static BOOL PerformMountIoctl (MOUNT_STRUCT* pmount, LPDWORD pdwResult, BOOL use
CreateFullVolumePath (pmount->wszVolume, sizeof(pmount->wszVolume), devicePath.c_str(), &bDevice);
}
}
-
+
return DeviceIoControl (hDriver, TC_IOCTL_MOUNT_VOLUME, pmount,
sizeof (MOUNT_STRUCT), pmount, sizeof (MOUNT_STRUCT), pdwResult, NULL);
}
-// specific definitions and implementation for support of mount operation
+// specific definitions and implementation for support of mount operation
// in wait dialog mechanism
typedef struct
@@ -7526,7 +7542,7 @@ retry:
path = path.substr (4);
StringCchCopyW (volumePath, TC_MAX_PATH, path.c_str());
}
-
+
if (path.find (L"Volume{") == 0 && path.rfind (L"}\\") == path.size() - 2)
{
wstring resolvedPath = VolumeGuidPathToDevicePath (path);
@@ -7538,7 +7554,7 @@ retry:
if ((path.length () >= 3) && (_wcsnicmp (path.c_str(), L"ID:", 3) == 0))
{
std::vector<byte> arr;
- if ( (path.length() == (3 + 2*VOLUME_ID_SIZE))
+ if ( (path.length() == (3 + 2*VOLUME_ID_SIZE))
&& HexWideStringToArray (path.c_str() + 3, arr)
&& (arr.size() == VOLUME_ID_SIZE)
)
@@ -7575,7 +7591,7 @@ retry:
mount.BytesPerSector = bps;
mount.BytesPerPhysicalSector = bps;
}
-
+
if (IsOSAtLeast (WIN_VISTA))
{
if ( (wcslen(root) >= 2)
@@ -7683,7 +7699,7 @@ retry:
goto retry;
}
- // Ask user
+ // Ask user
if (IDYES == AskWarnNoYes ("FILE_IN_USE", hwndDlg))
{
mount.bExclusiveAccess = FALSE;
@@ -7704,12 +7720,12 @@ retry:
{
if (mount.nReturnCode == ERR_PASSWORD_WRONG)
{
- // Do not report wrong password, if not instructed to
+ // Do not report wrong password, if not instructed to
if (bReportWrongPassword)
{
IncreaseWrongPwdRetryCount (1); // We increase the count here only if bReportWrongPassword is TRUE, because "Auto-Mount All Devices" and other callers do it separately
- if (WrongPwdRetryCountOverLimit ()
+ if (WrongPwdRetryCountOverLimit ()
&& !mount.UseBackupHeader)
{
// Retry using embedded header backup (if any)
@@ -7757,7 +7773,7 @@ retry:
if (bReportWrongPassword && !Silent)
Warning ("HEADER_DAMAGED_AUTO_USED_HEADER_BAK", hwndDlg);
}
-
+
LastMountedVolumeDirty = mount.FilesystemDirty;
if (mount.FilesystemDirty)
@@ -12132,3 +12148,52 @@ BOOL CopyTextToClipboard (LPCWSTR txtValue)
return bRet;
}
+
+BOOL GetFreeDriveLetter(WCHAR* pCh) {
+ DWORD dwUsedDrives = GetLogicalDrives();
+ WCHAR l;
+ for (l = L'A'; l <= L'Z'; l++) {
+ if ((dwUsedDrives & 1) == 0) {
+ *pCh = l;
+ return TRUE;
+ }
+ dwUsedDrives = dwUsedDrives >> 1;
+ }
+ return FALSE;
+}
+
+BOOL RaisePrivileges(void)
+{
+ HANDLE hToken;
+ TOKEN_PRIVILEGES tkp;
+ BOOL bRet = FALSE;
+ DWORD dwLastError = 0;
+
+ if (OpenProcessToken(GetCurrentProcess(),
+ TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
+ &hToken))
+ {
+ if (LookupPrivilegeValue(NULL, SE_SYSTEM_ENVIRONMENT_NAME,
+ &tkp.Privileges[0].Luid))
+ {
+ DWORD len;
+
+ tkp.PrivilegeCount = 1;
+ tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
+
+ bRet = AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, NULL, &len);
+ if (!bRet)
+ dwLastError = GetLastError ();
+ }
+ else
+ dwLastError = GetLastError ();
+
+ CloseHandle(hToken);
+ }
+ else
+ dwLastError = GetLastError ();
+
+ SetLastError (dwLastError);
+
+ return bRet;
+} \ No newline at end of file