diff options
Diffstat (limited to 'src/Format')
-rw-r--r-- | src/Format/Format.manifest | 21 | ||||
-rw-r--r-- | src/Format/Format.rc | 698 | ||||
-rw-r--r-- | src/Format/Format.vcproj | 682 | ||||
-rw-r--r-- | src/Format/FormatCom.cpp | 222 | ||||
-rw-r--r-- | src/Format/FormatCom.h | 32 | ||||
-rw-r--r-- | src/Format/FormatCom.idl | 48 | ||||
-rw-r--r-- | src/Format/InPlace.c | 1692 | ||||
-rw-r--r-- | src/Format/InPlace.h | 45 | ||||
-rw-r--r-- | src/Format/Resource.h | 151 | ||||
-rw-r--r-- | src/Format/Tcformat.c | 9004 | ||||
-rw-r--r-- | src/Format/Tcformat.h | 104 | ||||
-rw-r--r-- | src/Format/TrueCrypt_Wizard.bmp | bin | 0 -> 166518 bytes |
12 files changed, 12699 insertions, 0 deletions
diff --git a/src/Format/Format.manifest b/src/Format/Format.manifest new file mode 100644 index 00000000..48616cfc --- /dev/null +++ b/src/Format/Format.manifest @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8" standalone="yes"?>
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
+ <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
+ <security>
+ <requestedPrivileges>
+ <requestedExecutionLevel level="asInvoker" uiAccess="false"/>
+ </requestedPrivileges>
+ </security>
+ </trustInfo>
+ <asmv3:application>
+ <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
+ <dpiAware>true</dpiAware>
+ </asmv3:windowsSettings>
+ </asmv3:application>
+ <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
+ <application>
+ <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
+ <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
+ </application>
+ </compatibility>
+</assembly>
\ No newline at end of file diff --git a/src/Format/Format.rc b/src/Format/Format.rc new file mode 100644 index 00000000..83d4d675 --- /dev/null +++ b/src/Format/Format.rc @@ -0,0 +1,698 @@ +// Microsoft Visual C++ generated resource script.
+//
+#include "resource.h"
+
+#define APSTUDIO_READONLY_SYMBOLS
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 2 resource.
+//
+#include "afxres.h"
+#include "..\\common\\resource.h"
+
+/////////////////////////////////////////////////////////////////////////////
+#undef APSTUDIO_READONLY_SYMBOLS
+
+/////////////////////////////////////////////////////////////////////////////
+// English (U.S.) resources
+
+#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
+#ifdef _WIN32
+LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
+#pragma code_page(1252)
+#endif //_WIN32
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Version
+//
+
+VS_VERSION_INFO VERSIONINFO
+ FILEVERSION 7,1,1,0
+ PRODUCTVERSION 7,1,1,0
+ FILEFLAGSMASK 0x17L
+#ifdef _DEBUG
+ FILEFLAGS 0x1L
+#else
+ FILEFLAGS 0x0L
+#endif
+ FILEOS 0x4L
+ FILETYPE 0x1L
+ FILESUBTYPE 0x0L
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "040904b0"
+ BEGIN
+ VALUE "CompanyName", "TrueCrypt Foundation"
+ VALUE "FileDescription", "TrueCrypt Format"
+ VALUE "FileVersion", "7.1a"
+ VALUE "LegalTrademarks", "TrueCrypt"
+ VALUE "OriginalFilename", "TrueCrypt Format.exe"
+ VALUE "ProductName", "TrueCrypt"
+ VALUE "ProductVersion", "7.1a"
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x409, 1200
+ END
+END
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// HEADER
+//
+
+IDR_FORMAT_RSRC_HEADER HEADER "resource.h"
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// TYPELIB
+//
+
+IDR_FORMAT_TLB TYPELIB "Format.tlb"
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Dialog
+//
+
+IDD_VOL_CREATION_WIZARD_DLG DIALOGEX 0, 0, 400, 209
+STYLE DS_SETFONT | DS_SETFOREGROUND | DS_FIXEDSYS | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "TrueCrypt Volume Creation Wizard"
+CLASS "CustomDlg"
+FONT 8, "MS Shell Dlg", 0, 0, 0x0
+BEGIN
+ PUSHBUTTON "&Help",IDHELP,176,189,50,14
+ PUSHBUTTON "",IDC_PREV,235,189,50,14
+ DEFPUSHBUTTON "",IDC_NEXT,285,189,50,14
+ PUSHBUTTON "Cancel",IDCANCEL,343,189,50,14
+ LTEXT "",IDC_BOX_TITLE,160,8,233,17
+ GROUPBOX "",IDC_STATIC,4,0,392,183
+ CONTROL 116,IDC_BITMAP_WIZARD,"Static",SS_BITMAP | SS_SUNKEN,10,9,137,169
+ LTEXT "",IDC_POS_BOX,160,24,231,152
+END
+
+IDD_CIPHER_PAGE_DLG DIALOGEX 0, 0, 226, 152
+STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
+FONT 8, "MS Shell Dlg", 0, 0, 0x0
+BEGIN
+ COMBOBOX IDC_COMBO_BOX,7,23,137,126,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
+ PUSHBUTTON "&Test",IDC_CIPHER_TEST,149,22,59,14
+ PUSHBUTTON "&Benchmark",IDC_BENCHMARK,149,82,59,14
+ COMBOBOX IDC_COMBO_BOX_HASH_ALGO,7,122,83,126,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
+ LTEXT "",IDC_BOX_HELP,7,40,205,40
+ GROUPBOX "Encryption Algorithm",IDT_ENCRYPTION_ALGO,0,10,217,95
+ GROUPBOX "Hash Algorithm",IDT_HASH_ALGO,0,109,217,35
+ LTEXT "More information",IDC_LINK_MORE_INFO_ABOUT_CIPHER,7,82,135,10,SS_NOTIFY
+ LTEXT "Information on hash algorithms",IDC_LINK_HASH_INFO,97,124,115,8,SS_NOTIFY
+END
+
+IDD_PASSWORD_PAGE_DLG DIALOGEX 0, 0, 226, 152
+STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
+FONT 8, "MS Shell Dlg", 0, 0, 0x0
+BEGIN
+ EDITTEXT IDC_PASSWORD,53,3,163,14,ES_PASSWORD | ES_AUTOHSCROLL
+ EDITTEXT IDC_VERIFY,53,19,163,14,ES_PASSWORD | ES_AUTOHSCROLL
+ CONTROL "&Display password",IDC_SHOW_PASSWORD,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,53,45,95,11,WS_EX_TRANSPARENT
+ CONTROL "U&se keyfiles",IDC_KEYFILES_ENABLE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,53,35,95,10
+ PUSHBUTTON "&Keyfiles...",IDC_KEY_FILES,152,36,64,14,WS_DISABLED
+ RTEXT "Password:",IDT_PASSWORD,1,6,50,8
+ RTEXT "&Confirm:",IDT_CONFIRM,1,23,50,8
+ LTEXT "",IDC_BOX_HELP,0,59,225,89
+END
+
+IDD_SIZE_PAGE_DLG DIALOGEX 0, 0, 226, 152
+STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
+FONT 8, "MS Shell Dlg", 0, 0, 0x0
+BEGIN
+ EDITTEXT IDC_SIZEBOX,0,22,71,14,ES_AUTOHSCROLL | ES_NUMBER
+ CONTROL "&KB",IDC_KB,"Button",BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP,80,25,38,10
+ CONTROL "&MB",IDC_MB,"Button",BS_AUTORADIOBUTTON,119,25,38,10
+ CONTROL "&GB",IDC_GB,"Button",BS_AUTORADIOBUTTON,158,25,38,10
+ LTEXT "",IDC_BOX_HELP,0,75,214,64
+ LTEXT "",IDC_SPACE_LEFT,0,44,214,21
+END
+
+IDD_VOLUME_LOCATION_PAGE_DLG DIALOGEX 0, 0, 226, 152
+STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
+FONT 8, "MS Shell Dlg", 0, 0, 0x0
+BEGIN
+ COMBOBOX IDC_COMBO_BOX,0,9,148,80,CBS_DROPDOWN | CBS_AUTOHSCROLL | WS_VSCROLL | WS_TABSTOP
+ CONTROL "&Never save history",IDC_NO_HISTORY,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3,28,137,10
+ PUSHBUTTON "",IDC_SELECT_VOLUME_LOCATION,155,9,62,14
+ LTEXT "",IDC_BOX_HELP,0,45,219,104
+END
+
+IDD_FORMAT_PAGE_DLG DIALOGEX 0, 0, 226, 152
+STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
+FONT 8, "MS Shell Dlg", 0, 0, 0x0
+BEGIN
+ COMBOBOX IDC_FILESYS,43,13,36,90,CBS_DROPDOWNLIST | WS_TABSTOP
+ COMBOBOX IDC_CLUSTERSIZE,112,13,42,90,CBS_DROPDOWNLIST | WS_TABSTOP
+ CONTROL "Quick Format",IDC_QUICKFORMAT,"Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,163,11,60,18
+ CONTROL "",IDC_SHOW_KEYS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,214,38,9,8
+ PUSHBUTTON "Abort",IDC_ABORT_BUTTON,169,75,50,14
+ RTEXT "Header Key: ",IDT_HEADER_KEY,2,47,54,8
+ CONTROL "",IDC_HEADER_KEY,"Static",SS_LEFTNOWORDWRAP | WS_GROUP,57,46,163,8,WS_EX_TRANSPARENT
+ RTEXT "Master Key: ",IDT_MASTER_KEY,2,55,54,8
+ LTEXT "",IDC_DISK_KEY,57,54,163,8,0,WS_EX_TRANSPARENT
+ RTEXT "Cluster ",IDT_CLUSTER,80,15,32,8
+ LTEXT "",IDC_BOX_HELP,1,112,224,40
+ GROUPBOX "Options",IDT_FORMAT_OPTIONS,0,3,225,29
+ CONTROL "",IDC_PROGRESS_BAR,"msctls_progress32",PBS_SMOOTH | WS_BORDER,6,76,158,12
+ RTEXT "",IDC_TIMEREMAIN,177,93,42,11,SS_CENTERIMAGE,WS_EX_TRANSPARENT | WS_EX_RIGHT | WS_EX_STATICEDGE
+ RTEXT "",IDC_WRITESPEED,106,93,42,11,SS_CENTERIMAGE,WS_EX_TRANSPARENT | WS_EX_RIGHT | WS_EX_STATICEDGE
+ LTEXT "",IDC_BYTESWRITTEN,29,93,39,11,SS_CENTERIMAGE,WS_EX_TRANSPARENT | WS_EX_RIGHT | WS_EX_STATICEDGE
+ RTEXT "Done",IDT_DONE,5,94,22,8
+ RTEXT "Speed",IDT_SPEED,70,94,34,8
+ RTEXT "Left",IDT_LEFT,150,94,25,8
+ GROUPBOX "",IDC_STATIC,0,67,225,41
+ RTEXT "Filesystem ",IDT_FILESYSTEM,1,15,41,8,0,WS_EX_RIGHT
+ RTEXT "Random Pool: ",IDT_RANDOM_POOL,2,39,54,8
+ GROUPBOX "",IDC_STATIC,0,32,225,35
+ CONTROL "",IDC_RANDOM_BYTES,"Static",SS_SIMPLE | WS_GROUP,57,38,155,8,WS_EX_TRANSPARENT
+END
+
+IDD_INTRO_PAGE_DLG DIALOGEX 0, 0, 226, 152
+STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
+FONT 8, "MS Shell Dlg", 400, 0, 0x1
+BEGIN
+ CONTROL "Create an encrypted file container",IDC_FILE_CONTAINER,
+ "Button",BS_AUTORADIOBUTTON,0,7,217,10
+ LTEXT "More information",IDC_MORE_INFO_ON_CONTAINERS,16,39,165,10,SS_NOTIFY
+ CONTROL "Encrypt a non-system partition/drive",IDC_NONSYS_DEVICE,
+ "Button",BS_AUTORADIOBUTTON,0,53,217,10
+ CONTROL "Encrypt the system partition or entire system drive",IDC_SYS_DEVICE,
+ "Button",BS_AUTORADIOBUTTON,0,87,217,10
+ LTEXT "More information about system encryption",IDC_MORE_INFO_ON_SYS_ENCRYPTION,16,136,190,10,SS_NOTIFY
+ LTEXT "Creates a virtual encrypted disk within a file. Recommended for inexperienced users.",IDT_FILE_CONTAINER,16,20,205,16
+ LTEXT "Encrypts a non-system partition on any internal or external drive (e.g. a flash drive). Optionally, creates a hidden volume.",IDT_NON_SYS_DEVICE,16,66,205,16
+ LTEXT "Encrypts the partition/drive where Windows is installed. Anyone who wants to gain access and use the system, read and write files, etc., will need to enter the correct password each time before Windows boots. Optionally, creates a hidden system.",IDT_SYS_DEVICE,16,100,205,33
+END
+
+IDD_INFO_PAGE_DLG DIALOGEX 0, 0, 226, 152
+STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
+FONT 8, "MS Shell Dlg", 400, 0, 0x1
+BEGIN
+ LTEXT "",IDC_BOX_HELP,0,10,225,137
+END
+
+IDD_HIDVOL_HOST_FILL_PAGE_DLG DIALOGEX 0, 0, 226, 152
+STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
+FONT 8, "MS Shell Dlg", 400, 0, 0x1
+BEGIN
+ LTEXT "",IDC_BOX_HELP,0,6,226,130
+ PUSHBUTTON "Open Outer Volume",IDC_OPEN_OUTER_VOLUME,0,136,85,14
+END
+
+IDD_HIDDEN_VOL_WIZARD_MODE_PAGE_DLG DIALOGEX 0, 0, 226, 152
+STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
+FONT 8, "MS Shell Dlg", 400, 0, 0x1
+BEGIN
+ CONTROL "Normal mode",IDC_HIDVOL_WIZ_MODE_FULL,"Button",BS_AUTORADIOBUTTON,0,7,217,10
+ CONTROL "Direct mode",IDC_HIDVOL_WIZ_MODE_DIRECT,"Button",BS_AUTORADIOBUTTON,0,76,217,10
+ LTEXT "",IDC_BOX_HELP,16,20,205,48
+ LTEXT "",IDC_BOX_HELP2,16,89,205,50
+END
+
+IDD_PASSWORD_ENTRY_PAGE_DLG DIALOGEX 0, 0, 226, 152
+STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
+FONT 8, "MS Shell Dlg", 0, 0, 0x0
+BEGIN
+ EDITTEXT IDC_PASSWORD_DIRECT,50,11,149,14,ES_PASSWORD | ES_AUTOHSCROLL
+ CONTROL "&Display password",IDC_SHOW_PASSWORD_SINGLE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,50,27,84,11,WS_EX_TRANSPARENT
+ CONTROL "U&se keyfiles",IDC_KEYFILES_ENABLE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,50,38,82,11
+ PUSHBUTTON "&Keyfiles...",IDC_KEY_FILES,135,29,64,14
+ LTEXT "",IDC_BOX_HELP,0,57,225,94
+ RTEXT "Password:",IDT_PASSWORD,0,15,48,8
+END
+
+IDD_VOLUME_TYPE_PAGE_DLG DIALOGEX 0, 0, 226, 152
+STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
+FONT 8, "MS Shell Dlg", 400, 0, 0x1
+BEGIN
+ CONTROL "Standard TrueCrypt volume",IDC_STD_VOL,"Button",BS_AUTORADIOBUTTON,0,7,212,10
+ CONTROL "Hi&dden TrueCrypt volume ",IDC_HIDDEN_VOL,"Button",BS_AUTORADIOBUTTON,0,53,212,10
+ LTEXT "More information about hidden volumes",IDC_HIDDEN_VOL_HELP,16,125,205,10,SS_NOTIFY
+ LTEXT "",IDC_BOX_HELP_NORMAL_VOL,16,20,205,25
+ LTEXT "",IDC_BOX_HELP,16,66,205,57
+END
+
+IDD_SYSENC_SPAN_PAGE_DLG DIALOGEX 0, 0, 226, 152
+STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
+FONT 8, "MS Shell Dlg", 400, 0, 0x1
+BEGIN
+ CONTROL "Encrypt the Windows system partition",IDC_SYS_PARTITION,
+ "Button",BS_AUTORADIOBUTTON,0,7,212,10
+ CONTROL "Encrypt the whole drive",IDC_WHOLE_SYS_DRIVE,"Button",BS_AUTORADIOBUTTON,0,53,212,10
+ LTEXT "Select this option to encrypt the partition where the currently running Windows operating system is installed.",IDT_SYS_PARTITION,16,20,205,32
+ LTEXT "",IDT_WHOLE_SYS_DRIVE,16,66,205,79
+END
+
+IDD_SYSENC_RESCUE_DISK_CREATION_DLG DIALOGEX 0, 0, 226, 152
+STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
+FONT 8, "MS Shell Dlg", 0, 0, 0x0
+BEGIN
+ EDITTEXT IDC_RESCUE_DISK_ISO_PATH,0,135,163,13,ES_AUTOHSCROLL
+ PUSHBUTTON "Bro&wse...",IDC_BROWSE,166,134,59,14
+ LTEXT "",IDT_RESCUE_DISK_INFO,0,1,225,129
+END
+
+IDD_SYSENC_COLLECTING_RANDOM_DATA_DLG DIALOGEX 0, 0, 226, 152
+STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
+FONT 8, "MS Shell Dlg", 0, 0, 0x0
+BEGIN
+ CONTROL "Display pool content",IDC_DISPLAY_POOL_CONTENTS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,1,98,122,10
+ CONTROL "",IDC_SYS_POOL_CONTENTS,"Static",SS_LEFTNOWORDWRAP | WS_GROUP,8,14,205,72,WS_EX_TRANSPARENT
+ LTEXT "IMPORTANT: Move your mouse as randomly as possible within this window. The longer you move it, the better. This significantly increases the cryptographic strength of the encryption keys. Then click Next to continue.",IDT_COLLECTING_RANDOM_DATA_NOTE,1,112,224,40
+ GROUPBOX "Current pool content (partial)",IDT_PARTIAL_POOL_CONTENTS,0,5,222,88
+END
+
+IDD_SYSENC_MULTI_BOOT_MODE_PAGE_DLG DIALOGEX 0, 0, 226, 152
+STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
+FONT 8, "MS Shell Dlg", 400, 0, 0x1
+BEGIN
+ CONTROL "Single-boot",IDC_SINGLE_BOOT,"Button",BS_AUTORADIOBUTTON,0,7,212,10
+ CONTROL "Multi-boot",IDC_MULTI_BOOT,"Button",BS_AUTORADIOBUTTON,0,53,217,10
+ LTEXT "Select this option if there is only one operating system installed on this computer (even if it has multiple users).",IDT_SINGLE_BOOT,16,20,205,32
+ LTEXT "Select this option if there are two or more operating systems installed on this computer.\n\nFor example:\n- Windows XP and Windows XP\n- Windows XP and Windows Vista\n- Windows and Mac OS X\n- Windows and Linux\n- Windows, Linux and Mac OS X",IDT_MULTI_BOOT,16,66,205,72
+END
+
+IDD_SYSENC_RESCUE_DISK_BURN_PAGE_DLG DIALOGEX 0, 0, 226, 152
+STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
+FONT 8, "MS Shell Dlg", 0, 0, 0x0
+BEGIN
+ LTEXT "Download CD/DVD recording software",IDC_DOWNLOAD_CD_BURN_SOFTWARE,0,136,217,10,SS_NOTIFY
+ LTEXT "",IDT_RESCUE_DISK_BURN_INFO,0,4,225,128
+END
+
+IDD_SYSENC_WIPE_MODE_PAGE_DLG DIALOGEX 0, 0, 226, 152
+STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
+FONT 8, "MS Shell Dlg", 400, 0, 0x1
+BEGIN
+ COMBOBOX IDC_WIPE_MODE,61,0,127,90,CBS_DROPDOWNLIST | WS_TABSTOP
+ RTEXT "Wipe mode:",IDT_WIPE_MODE,0,2,59,8,0,WS_EX_RIGHT
+ LTEXT "",IDT_WIPE_MODE_INFO,0,19,225,128
+END
+
+IDD_INPLACE_ENCRYPTION_PAGE_DLG DIALOGEX 0, 0, 226, 152
+STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
+FONT 8, "MS Shell Dlg", 0, 0, 0x0
+BEGIN
+ COMBOBOX IDC_WIPE_MODE,67,13,125,90,CBS_DROPDOWNLIST | WS_TABSTOP
+ PUSHBUTTON "&Pause",IDC_PAUSE,169,40,50,14
+ LTEXT "More information",IDC_MORE_INFO_SYS_ENCRYPTION,1,141,202,10,SS_NOTIFY
+ LTEXT "",IDC_BYTESWRITTEN,29,58,39,11,SS_CENTERIMAGE,WS_EX_TRANSPARENT | WS_EX_RIGHT | WS_EX_STATICEDGE
+ RTEXT "",IDC_WRITESPEED,103,58,46,11,SS_CENTERIMAGE,WS_EX_TRANSPARENT | WS_EX_RIGHT | WS_EX_STATICEDGE
+ RTEXT "",IDC_TIMEREMAIN,177,58,42,11,SS_CENTERIMAGE,WS_EX_TRANSPARENT | WS_EX_RIGHT | WS_EX_STATICEDGE
+ RTEXT "Wipe mode:",IDT_WIPE_MODE,6,15,59,8,0,WS_EX_RIGHT
+ CONTROL "",IDC_PROGRESS_BAR,"msctls_progress32",PBS_SMOOTH | WS_BORDER,6,41,158,12
+ RTEXT "Done",IDT_DONE,5,59,22,8
+ RTEXT "Status",IDT_STATUS,72,59,29,8
+ RTEXT "Left",IDT_LEFT,151,59,24,8
+ LTEXT "",IDC_BOX_HELP,1,77,224,64
+ GROUPBOX "Options",IDT_FORMAT_OPTIONS,0,3,225,29
+ GROUPBOX "",IDC_STATIC,0,32,225,41
+END
+
+IDD_SYSENC_KEYS_GEN_PAGE_DLG DIALOGEX 0, 0, 226, 152
+STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
+FONT 8, "MS Shell Dlg", 0, 0, 0x0
+BEGIN
+ CONTROL "Display generated keys (their portions)",IDC_DISPLAY_KEYS,
+ "Button",BS_AUTOCHECKBOX | WS_TABSTOP,1,94,216,10
+ CONTROL "",IDC_HEADER_KEY,"Static",SS_LEFTNOWORDWRAP | WS_GROUP,57,71,163,8,WS_EX_TRANSPARENT
+ LTEXT "",IDC_DISK_KEY,57,79,163,8,0,WS_EX_TRANSPARENT
+ LTEXT "The keys, salt, and other data have been successfully generated. If you want to generate new keys, click Back and then Next. Otherwise, click Next to continue.",IDT_SYSENC_KEYS_GEN_INFO,1,23,224,41
+ RTEXT "Header Key: ",IDT_HEADER_KEY,2,72,54,8
+ RTEXT "Master Key: ",IDT_MASTER_KEY,2,80,54,8
+ GROUPBOX "",-1,0,65,225,26
+END
+
+IDD_UNIVERSAL_DUAL_CHOICE_PAGE_DLG DIALOGEX 0, 0, 226, 152
+STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
+FONT 8, "MS Shell Dlg", 400, 0, 0x1
+BEGIN
+ CONTROL "",IDC_CHOICE1,"Button",BS_AUTORADIOBUTTON,0,7,212,10
+ CONTROL "",IDC_CHOICE2,"Button",BS_AUTORADIOBUTTON,0,17,217,10
+ LTEXT "",IDC_BOX_HELP,1,34,220,112
+END
+
+IDD_SYSENC_DRIVE_ANALYSIS_PAGE_DLG DIALOGEX 0, 0, 226, 152
+STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
+FONT 8, "MS Shell Dlg", 0, 0, 0x0
+BEGIN
+ LTEXT "",IDT_SYSENC_DRIVE_ANALYSIS_INFO,2,10,215,88
+ CONTROL "",IDC_PROGRESS_BAR,"msctls_progress32",PBS_SMOOTH | WS_BORDER,1,115,216,12
+ LTEXT "Progress:",IDT_PROGRESS,2,104,57,8
+END
+
+IDD_SYSENC_TYPE_PAGE_DLG DIALOGEX 0, 0, 226, 152
+STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
+FONT 8, "MS Shell Dlg", 400, 0, 0x1
+BEGIN
+ CONTROL "Normal",IDC_SYSENC_NORMAL,"Button",BS_AUTORADIOBUTTON,0,7,212,10
+ CONTROL "Hi&dden",IDC_SYSENC_HIDDEN,"Button",BS_AUTORADIOBUTTON,0,53,212,10
+ LTEXT "More information",IDC_HIDDEN_SYSENC_INFO_LINK,16,138,205,10,SS_NOTIFY
+ LTEXT "",IDC_BOX_HELP_SYSENC_NORMAL,16,20,205,25
+ LTEXT "",IDC_BOX_HELP,16,66,205,72
+END
+
+IDD_SYSENC_HIDDEN_OS_REQ_CHECK_PAGE_DLG DIALOGEX 0, 0, 226, 152
+STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
+FONT 8, "MS Shell Dlg", 0, 0, 0x0
+BEGIN
+ LTEXT "More information",IDC_HIDDEN_SYSENC_INFO_LINK,0,141,217,10,SS_NOTIFY
+ LTEXT "",IDC_BOX_HELP,0,2,225,136
+END
+
+IDD_DEVICE_WIPE_PAGE_DLG DIALOGEX 0, 0, 226, 152
+STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
+FONT 8, "MS Shell Dlg", 0, 0, 0x0
+BEGIN
+ PUSHBUTTON "Abort",IDC_ABORT_BUTTON,169,48,50,14
+ LTEXT "",IDC_BYTESWRITTEN,29,66,39,11,SS_CENTERIMAGE,WS_EX_TRANSPARENT | WS_EX_RIGHT | WS_EX_STATICEDGE
+ RTEXT "",IDC_WRITESPEED,103,66,46,11,SS_CENTERIMAGE | NOT WS_VISIBLE,WS_EX_TRANSPARENT | WS_EX_RIGHT | WS_EX_STATICEDGE
+ RTEXT "",IDC_TIMEREMAIN,177,66,42,11,SS_CENTERIMAGE,WS_EX_TRANSPARENT | WS_EX_RIGHT | WS_EX_STATICEDGE
+ RTEXT "Wipe mode:",IDT_WIPE_MODE,6,22,59,8,0,WS_EX_RIGHT
+ CONTROL "",IDC_PROGRESS_BAR,"msctls_progress32",PBS_SMOOTH | WS_BORDER,6,49,158,12
+ RTEXT "Done",IDT_DONE,5,67,22,8
+ RTEXT "Pass",IDT_PASS,72,67,29,8,NOT WS_VISIBLE
+ RTEXT "Left",IDT_LEFT,151,67,24,8
+ LTEXT "",IDC_BOX_HELP,1,86,224,64
+ GROUPBOX "",IDT_FORMAT_OPTIONS,0,10,225,29
+ GROUPBOX "",IDC_STATIC,0,40,225,42
+ LTEXT "",IDC_WIPE_MODE,67,21,125,11,SS_CENTERIMAGE,WS_EX_TRANSPARENT | WS_EX_STATICEDGE
+END
+
+IDD_DEVICE_WIPE_MODE_PAGE_DLG DIALOGEX 0, 0, 226, 152
+STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
+FONT 8, "MS Shell Dlg", 400, 0, 0x1
+BEGIN
+ COMBOBOX IDC_WIPE_MODE,61,9,127,90,CBS_DROPDOWNLIST | WS_TABSTOP
+ RTEXT "Wipe mode:",IDT_WIPE_MODE,0,11,59,8,0,WS_EX_RIGHT
+ LTEXT "",IDT_WIPE_MODE_INFO,0,29,225,122
+END
+
+IDD_DEVICE_TRANSFORM_MODE_DLG DIALOGEX 0, 0, 226, 152
+STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
+FONT 8, "MS Shell Dlg", 400, 0, 0x1
+BEGIN
+ CONTROL "Create encrypted volume and format it",IDC_DEVICE_TRANSFORM_MODE_FORMAT,
+ "Button",BS_AUTORADIOBUTTON,0,8,217,10
+ CONTROL "Encrypt partition in place",IDC_DEVICE_TRANSFORM_MODE_INPLACE,
+ "Button",BS_AUTORADIOBUTTON,0,98,217,10
+ LTEXT "",IDC_BOX_HELP,16,21,205,74
+ LTEXT "",IDC_BOX_HELP2,16,111,205,34
+END
+
+IDD_EXPANDED_LIST_SELECT_PAGE_DLG DIALOGEX 0, 0, 226, 152
+STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
+FONT 8, "MS Shell Dlg", 400, 0, 0x1
+BEGIN
+ LTEXT "",IDC_BOX_HELP,0,107,225,41
+ LISTBOX IDC_LIST_BOX,0,3,222,100,LBS_NOINTEGRALHEIGHT | LBS_DISABLENOSCROLL | WS_VSCROLL
+END
+
+
+#ifdef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// TEXTINCLUDE
+//
+
+1 TEXTINCLUDE
+BEGIN
+ "resource.h\0"
+END
+
+2 TEXTINCLUDE
+BEGIN
+ "#include ""afxres.h""\r\n"
+ "#include ""..\\\\common\\\\resource.h""\r\n"
+ "\0"
+END
+
+3 TEXTINCLUDE
+BEGIN
+ "#include ""..\\\\common\\\\common.rc""\r\n"
+ "\0"
+END
+
+#endif // APSTUDIO_INVOKED
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// DESIGNINFO
+//
+
+#ifdef APSTUDIO_INVOKED
+GUIDELINES DESIGNINFO
+BEGIN
+ IDD_VOL_CREATION_WIZARD_DLG, DIALOG
+ BEGIN
+ RIGHTMARGIN, 393
+ TOPMARGIN, 1
+ BOTTOMMARGIN, 207
+ HORZGUIDE, 196
+ END
+
+ IDD_CIPHER_PAGE_DLG, DIALOG
+ BEGIN
+ RIGHTMARGIN, 223
+ BOTTOMMARGIN, 141
+ END
+
+ IDD_PASSWORD_PAGE_DLG, DIALOG
+ BEGIN
+ RIGHTMARGIN, 223
+ BOTTOMMARGIN, 123
+ END
+
+ IDD_SIZE_PAGE_DLG, DIALOG
+ BEGIN
+ RIGHTMARGIN, 223
+ BOTTOMMARGIN, 145
+ END
+
+ IDD_VOLUME_LOCATION_PAGE_DLG, DIALOG
+ BEGIN
+ RIGHTMARGIN, 223
+ BOTTOMMARGIN, 147
+ END
+
+ IDD_FORMAT_PAGE_DLG, DIALOG
+ BEGIN
+ RIGHTMARGIN, 217
+ BOTTOMMARGIN, 133
+ HORZGUIDE, 80
+ HORZGUIDE, 96
+ END
+
+ IDD_INTRO_PAGE_DLG, DIALOG
+ BEGIN
+ LEFTMARGIN, 7
+ RIGHTMARGIN, 219
+ TOPMARGIN, 7
+ BOTTOMMARGIN, 145
+ END
+
+ IDD_INFO_PAGE_DLG, DIALOG
+ BEGIN
+ LEFTMARGIN, 7
+ RIGHTMARGIN, 219
+ TOPMARGIN, 7
+ BOTTOMMARGIN, 145
+ END
+
+ IDD_HIDVOL_HOST_FILL_PAGE_DLG, DIALOG
+ BEGIN
+ LEFTMARGIN, 7
+ RIGHTMARGIN, 219
+ TOPMARGIN, 7
+ BOTTOMMARGIN, 145
+ END
+
+ IDD_HIDDEN_VOL_WIZARD_MODE_PAGE_DLG, DIALOG
+ BEGIN
+ LEFTMARGIN, 7
+ RIGHTMARGIN, 219
+ TOPMARGIN, 7
+ BOTTOMMARGIN, 145
+ END
+
+ IDD_PASSWORD_ENTRY_PAGE_DLG, DIALOG
+ BEGIN
+ RIGHTMARGIN, 223
+ BOTTOMMARGIN, 123
+ END
+
+ IDD_VOLUME_TYPE_PAGE_DLG, DIALOG
+ BEGIN
+ LEFTMARGIN, 7
+ RIGHTMARGIN, 219
+ TOPMARGIN, 7
+ BOTTOMMARGIN, 145
+ END
+
+ IDD_SYSENC_SPAN_PAGE_DLG, DIALOG
+ BEGIN
+ LEFTMARGIN, 7
+ RIGHTMARGIN, 219
+ TOPMARGIN, 7
+ BOTTOMMARGIN, 145
+ END
+
+ IDD_SYSENC_RESCUE_DISK_CREATION_DLG, DIALOG
+ BEGIN
+ RIGHTMARGIN, 223
+ BOTTOMMARGIN, 147
+ END
+
+ IDD_SYSENC_COLLECTING_RANDOM_DATA_DLG, DIALOG
+ BEGIN
+ RIGHTMARGIN, 217
+ BOTTOMMARGIN, 133
+ HORZGUIDE, 80
+ HORZGUIDE, 96
+ END
+
+ IDD_SYSENC_MULTI_BOOT_MODE_PAGE_DLG, DIALOG
+ BEGIN
+ LEFTMARGIN, 7
+ RIGHTMARGIN, 219
+ TOPMARGIN, 7
+ BOTTOMMARGIN, 145
+ END
+
+ IDD_SYSENC_RESCUE_DISK_BURN_PAGE_DLG, DIALOG
+ BEGIN
+ RIGHTMARGIN, 223
+ BOTTOMMARGIN, 147
+ END
+
+ IDD_SYSENC_WIPE_MODE_PAGE_DLG, DIALOG
+ BEGIN
+ LEFTMARGIN, 7
+ RIGHTMARGIN, 219
+ TOPMARGIN, 7
+ BOTTOMMARGIN, 145
+ END
+
+ IDD_INPLACE_ENCRYPTION_PAGE_DLG, DIALOG
+ BEGIN
+ RIGHTMARGIN, 217
+ BOTTOMMARGIN, 133
+ HORZGUIDE, 80
+ HORZGUIDE, 96
+ END
+
+ IDD_SYSENC_KEYS_GEN_PAGE_DLG, DIALOG
+ BEGIN
+ RIGHTMARGIN, 217
+ BOTTOMMARGIN, 133
+ HORZGUIDE, 80
+ HORZGUIDE, 96
+ END
+
+ IDD_UNIVERSAL_DUAL_CHOICE_PAGE_DLG, DIALOG
+ BEGIN
+ LEFTMARGIN, 7
+ RIGHTMARGIN, 219
+ TOPMARGIN, 7
+ BOTTOMMARGIN, 145
+ END
+
+ IDD_SYSENC_DRIVE_ANALYSIS_PAGE_DLG, DIALOG
+ BEGIN
+ RIGHTMARGIN, 217
+ BOTTOMMARGIN, 133
+ HORZGUIDE, 80
+ HORZGUIDE, 96
+ END
+
+ IDD_SYSENC_TYPE_PAGE_DLG, DIALOG
+ BEGIN
+ LEFTMARGIN, 7
+ RIGHTMARGIN, 219
+ TOPMARGIN, 7
+ BOTTOMMARGIN, 145
+ END
+
+ IDD_SYSENC_HIDDEN_OS_REQ_CHECK_PAGE_DLG, DIALOG
+ BEGIN
+ RIGHTMARGIN, 223
+ BOTTOMMARGIN, 147
+ END
+
+ IDD_DEVICE_WIPE_PAGE_DLG, DIALOG
+ BEGIN
+ RIGHTMARGIN, 217
+ BOTTOMMARGIN, 133
+ HORZGUIDE, 80
+ HORZGUIDE, 96
+ END
+
+ IDD_DEVICE_WIPE_MODE_PAGE_DLG, DIALOG
+ BEGIN
+ LEFTMARGIN, 7
+ RIGHTMARGIN, 219
+ TOPMARGIN, 7
+ BOTTOMMARGIN, 145
+ END
+
+ IDD_DEVICE_TRANSFORM_MODE_DLG, DIALOG
+ BEGIN
+ LEFTMARGIN, 7
+ RIGHTMARGIN, 219
+ TOPMARGIN, 7
+ BOTTOMMARGIN, 145
+ END
+
+ IDD_EXPANDED_LIST_SELECT_PAGE_DLG, DIALOG
+ BEGIN
+ LEFTMARGIN, 7
+ RIGHTMARGIN, 219
+ TOPMARGIN, 7
+ BOTTOMMARGIN, 145
+ END
+END
+#endif // APSTUDIO_INVOKED
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Bitmap
+//
+
+IDB_WIZARD BITMAP "TrueCrypt_wizard.bmp"
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// String Table
+//
+
+STRINGTABLE
+BEGIN
+ IDS_UACSTRING_FMT "TrueCrypt"
+END
+
+#endif // English (U.S.) resources
+/////////////////////////////////////////////////////////////////////////////
+
+
+
+#ifndef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 3 resource.
+//
+#include "..\\common\\common.rc"
+
+/////////////////////////////////////////////////////////////////////////////
+#endif // not APSTUDIO_INVOKED
+
diff --git a/src/Format/Format.vcproj b/src/Format/Format.vcproj new file mode 100644 index 00000000..878199ad --- /dev/null +++ b/src/Format/Format.vcproj @@ -0,0 +1,682 @@ +<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="9.00"
+ Name="Format"
+ ProjectGUID="{9DC1ABE2-D18B-48FB-81D2-8C50ADC57BCF}"
+ RootNamespace="Format"
+ Keyword="Win32Proj"
+ TargetFrameworkVersion="131072"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="Debug"
+ IntermediateDirectory="Debug"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ TypeLibraryName="$(SolutionDir)/$(ProjectName)/$(ProjectName).tlb"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\Common;..\Crypto;..\;$(PKCS11_INC)"
+ PreprocessorDefinitions="VOLFORMAT;WIN32;DEBUG;_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_CRT_NON_CONFORMING_SWPRINTFS"
+ MinimalRebuild="true"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ BufferSecurityCheck="true"
+ UsePrecompiledHeader="0"
+ WarningLevel="4"
+ DebugInformationFormat="4"
+ DisableSpecificWarnings="4057;4100;4127;4201;4204;4701;4706"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="comctl32.lib setupapi.lib ..\Crypto\Debug\crypto.lib"
+ OutputFile="$(OutDir)/TrueCryptFormat.exe"
+ LinkIncremental="2"
+ GenerateManifest="false"
+ IgnoreAllDefaultLibraries="false"
+ GenerateDebugInformation="true"
+ ProgramDatabaseFile="$(OutDir)/Format.pdb"
+ SubSystem="2"
+ RandomizedBaseAddress="1"
+ DataExecutionPrevention="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ AdditionalManifestFiles="Format.manifest"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ CommandLine="md "..\Debug\Setup Files" 2>NUL:
copy Debug\TrueCryptFormat.exe "..\Debug\Setup Files\TrueCrypt Format.exe" >NUL:
"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="Release"
+ IntermediateDirectory="Release"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ TypeLibraryName="$(SolutionDir)/$(ProjectName)/$(ProjectName).tlb"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/w34189"
+ Optimization="2"
+ AdditionalIncludeDirectories="..\Common;..\Crypto;..\;$(PKCS11_INC)"
+ PreprocessorDefinitions="VOLFORMAT;WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_CRT_NON_CONFORMING_SWPRINTFS"
+ RuntimeLibrary="0"
+ BufferSecurityCheck="true"
+ UsePrecompiledHeader="0"
+ AssemblerOutput="2"
+ AssemblerListingLocation="$(IntDir)/"
+ WarningLevel="4"
+ DebugInformationFormat="0"
+ DisableSpecificWarnings="4057;4100;4127;4201;4204;4701;4706"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="comctl32.lib setupapi.lib ..\Crypto\Release\crypto.lib"
+ OutputFile="$(OutDir)/TrueCryptFormat.exe"
+ LinkIncremental="1"
+ GenerateManifest="false"
+ IgnoreAllDefaultLibraries="false"
+ GenerateDebugInformation="false"
+ GenerateMapFile="true"
+ SubSystem="2"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ RandomizedBaseAddress="1"
+ DataExecutionPrevention="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ AdditionalManifestFiles="Format.manifest"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ CommandLine="copy Release\TrueCryptFormat.exe "..\Release\Setup Files\TrueCrypt Format.exe""
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
+ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+ >
+ <File
+ RelativePath=".\FormatCom.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\FormatCom.idl"
+ >
+ </File>
+ <File
+ RelativePath=".\InPlace.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ CompileAs="2"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ CompileAs="2"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\Tcformat.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ CompileAs="2"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ CompileAs="2"
+ />
+ </FileConfiguration>
+ </File>
+ <Filter
+ Name="Common"
+ >
+ <File
+ RelativePath="..\Common\BaseCom.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\BootEncryption.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Cmdline.c"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Combo.c"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Crc.c"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Crypto.c"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Dictionary.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ CompileAs="2"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ CompileAs="2"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\Common\Dlgcode.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ CompileAs="2"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ CompileAs="2"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\Common\EncryptionThreadPool.c"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Endian.c"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Fat.c"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Format.c"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\GfMul.c"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Keyfiles.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ CompileAs="2"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ CompileAs="2"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\Common\Language.c"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Password.c"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Pkcs5.c"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Progress.c"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Random.c"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Registry.c"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\SecurityToken.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Tests.c"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Volumes.c"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Wipe.c"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Xml.c"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Xts.c"
+ >
+ </File>
+ </Filter>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc;xsd"
+ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+ >
+ <File
+ RelativePath="..\Common\BaseCom.h"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Common.h"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Crc.h"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Crypto.h"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Dictionary.h"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Dlgcode.h"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\EncryptionThreadPool.h"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Endian.h"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Exception.h"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Fat.h"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Format.h"
+ >
+ </File>
+ <File
+ RelativePath=".\FormatCom.h"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\GfMul.h"
+ >
+ </File>
+ <File
+ RelativePath=".\InPlace.h"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Keyfiles.h"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Language.h"
+ >
+ </File>
+ <File
+ RelativePath="..\Mount\Mount.h"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Pkcs5.h"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Progress.h"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Random.h"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Registry.h"
+ >
+ </File>
+ <File
+ RelativePath=".\resource.h"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Resource.h"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\SecurityToken.h"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Tcdefs.h"
+ >
+ </File>
+ <File
+ RelativePath=".\Tcformat.h"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Tests.h"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Volumes.h"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Wipe.h"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Xml.h"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Xts.h"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
+ UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
+ >
+ <File
+ RelativePath=".\Format.manifest"
+ >
+ </File>
+ <File
+ RelativePath=".\Format.rc"
+ >
+ </File>
+ <File
+ RelativePath=".\Format.tlb"
+ SubType="Designer"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\TrueCrypt_Volume.ico"
+ >
+ </File>
+ <File
+ RelativePath=".\TrueCrypt_wizard.bmp"
+ >
+ </File>
+ <Filter
+ Name="Common"
+ >
+ <File
+ RelativePath="..\Boot\Windows\Rescue_AES\BootLoader.com.gz"
+ >
+ </File>
+ <File
+ RelativePath="..\Boot\Windows\Rescue\BootLoader.com.gz"
+ >
+ </File>
+ <File
+ RelativePath="..\Boot\Windows\Rescue_Twofish\BootLoader.com.gz"
+ >
+ </File>
+ <File
+ RelativePath="..\Boot\Windows\Release_Serpent\BootLoader.com.gz"
+ >
+ </File>
+ <File
+ RelativePath="..\Boot\Windows\Release_AES\BootLoader.com.gz"
+ >
+ </File>
+ <File
+ RelativePath="..\Boot\Windows\Release\BootLoader.com.gz"
+ >
+ </File>
+ <File
+ RelativePath="..\Boot\Windows\Release_Twofish\BootLoader.com.gz"
+ >
+ </File>
+ <File
+ RelativePath="..\Boot\Windows\Rescue_Serpent\BootLoader.com.gz"
+ >
+ </File>
+ <File
+ RelativePath="..\Boot\Windows\Rescue_AES\BootSector.bin"
+ >
+ </File>
+ <File
+ RelativePath="..\Boot\Windows\Rescue\BootSector.bin"
+ >
+ </File>
+ <File
+ RelativePath="..\Boot\Windows\Release\BootSector.bin"
+ >
+ </File>
+ <File
+ RelativePath="..\Boot\Windows\Release_Serpent\BootSector.bin"
+ >
+ </File>
+ <File
+ RelativePath="..\Boot\Windows\Rescue_Serpent\BootSector.bin"
+ >
+ </File>
+ <File
+ RelativePath="..\Boot\Windows\Rescue_Twofish\BootSector.bin"
+ >
+ </File>
+ <File
+ RelativePath="..\Boot\Windows\Release_Twofish\BootSector.bin"
+ >
+ </File>
+ <File
+ RelativePath="..\Boot\Windows\Release_AES\BootSector.bin"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Common.rc"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\Boot\Windows\Release\Decompressor.com"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Language.xml"
+ >
+ </File>
+ <File
+ RelativePath="..\Resources\Texts\License.rtf"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Textual_logo_288dpi.bmp"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Textual_logo_96dpi.bmp"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Textual_logo_background.bmp"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\TrueCrypt.ico"
+ >
+ </File>
+ </Filter>
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/src/Format/FormatCom.cpp b/src/Format/FormatCom.cpp new file mode 100644 index 00000000..9ab57c86 --- /dev/null +++ b/src/Format/FormatCom.cpp @@ -0,0 +1,222 @@ +/*
+ Copyright (c) 2007-2008 TrueCrypt Developers Association. All rights reserved.
+
+ Governed by the TrueCrypt License 3.0 the full text of which is contained in
+ the file License.txt included in TrueCrypt binary and source code distribution
+ packages.
+*/
+
+#include <atlcomcli.h>
+#include <atlconv.h>
+#include <comutil.h>
+#include <windows.h>
+#include "BaseCom.h"
+#include "BootEncryption.h"
+#include "Dlgcode.h"
+#include "Format.h"
+#include "Progress.h"
+#include "TcFormat.h"
+#include "FormatCom.h"
+#include "FormatCom_h.h"
+#include "FormatCom_i.c"
+
+using namespace TrueCrypt;
+
+static volatile LONG ObjectCount = 0;
+
+class TrueCryptFormatCom : public ITrueCryptFormatCom
+{
+
+public:
+ TrueCryptFormatCom (DWORD messageThreadId) : RefCount (0),
+ MessageThreadId (messageThreadId),
+ CallBack (NULL)
+ {
+ InterlockedIncrement (&ObjectCount);
+ }
+
+ ~TrueCryptFormatCom ()
+ {
+ if (InterlockedDecrement (&ObjectCount) == 0)
+ PostThreadMessage (MessageThreadId, WM_APP, 0, 0);
+ }
+
+ virtual ULONG STDMETHODCALLTYPE AddRef ()
+ {
+ return InterlockedIncrement (&RefCount);
+ }
+
+ virtual ULONG STDMETHODCALLTYPE Release ()
+ {
+ if (!InterlockedDecrement (&RefCount))
+ {
+ delete this;
+ return 0;
+ }
+
+ return RefCount;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE QueryInterface (REFIID riid, void **ppvObject)
+ {
+ if (riid == IID_IUnknown || riid == IID_ITrueCryptFormatCom)
+ *ppvObject = this;
+ else
+ {
+ *ppvObject = NULL;
+ return E_NOINTERFACE;
+ }
+
+ AddRef ();
+ return S_OK;
+ }
+
+ virtual DWORD STDMETHODCALLTYPE CallDriver (DWORD ioctl, BSTR input, BSTR *output)
+ {
+ return BaseCom::CallDriver (ioctl, input, output);
+ }
+
+ virtual DWORD STDMETHODCALLTYPE CopyFile (BSTR sourceFile, BSTR destinationFile)
+ {
+ return BaseCom::CopyFile (sourceFile, destinationFile);
+ }
+
+ virtual DWORD STDMETHODCALLTYPE DeleteFile (BSTR file)
+ {
+ return BaseCom::DeleteFile (file);
+ }
+
+ virtual BOOL STDMETHODCALLTYPE FormatNtfs (int driveNo, int clusterSize)
+ {
+ return ::FormatNtfs (driveNo, clusterSize);
+ }
+
+ virtual int STDMETHODCALLTYPE AnalyzeHiddenVolumeHost (
+ LONG_PTR hwndDlg, int *driveNo, __int64 hiddenVolHostSize, int *realClusterSize, __int64 *nbrFreeClusters)
+ {
+ return ::AnalyzeHiddenVolumeHost (
+ (HWND) hwndDlg, driveNo, hiddenVolHostSize, realClusterSize, nbrFreeClusters);
+ }
+
+ virtual DWORD STDMETHODCALLTYPE ReadWriteFile (BOOL write, BOOL device, BSTR filePath, BSTR *bufferBstr, unsigned __int64 offset, unsigned __int32 size, DWORD *sizeDone)
+ {
+ return BaseCom::ReadWriteFile (write, device, filePath, bufferBstr, offset, size, sizeDone);
+ }
+
+ virtual DWORD STDMETHODCALLTYPE RegisterFilterDriver (BOOL registerDriver, int filterType)
+ {
+ return BaseCom::RegisterFilterDriver (registerDriver, filterType);
+ }
+
+ virtual DWORD STDMETHODCALLTYPE RegisterSystemFavoritesService (BOOL registerService)
+ {
+ return BaseCom::RegisterSystemFavoritesService (registerService);
+ }
+
+ virtual DWORD STDMETHODCALLTYPE SetDriverServiceStartType (DWORD startType)
+ {
+ return BaseCom::SetDriverServiceStartType (startType);
+ }
+
+ virtual BOOL STDMETHODCALLTYPE IsPagingFileActive (BOOL checkNonWindowsPartitionsOnly)
+ {
+ return BaseCom::IsPagingFileActive (checkNonWindowsPartitionsOnly);
+ }
+
+ virtual DWORD STDMETHODCALLTYPE WriteLocalMachineRegistryDwordValue (BSTR keyPath, BSTR valueName, DWORD value)
+ {
+ return BaseCom::WriteLocalMachineRegistryDwordValue (keyPath, valueName, value);
+ }
+
+protected:
+ DWORD MessageThreadId;
+ LONG RefCount;
+ ITrueCryptFormatCom *CallBack;
+};
+
+
+extern "C" BOOL ComServerFormat ()
+{
+ SetProcessShutdownParameters (0x100, 0);
+
+ TrueCryptFactory<TrueCryptFormatCom> factory (GetCurrentThreadId ());
+ DWORD cookie;
+
+ if (IsUacSupported ())
+ UacElevated = TRUE;
+
+ if (CoRegisterClassObject (CLSID_TrueCryptFormatCom, (LPUNKNOWN) &factory,
+ CLSCTX_LOCAL_SERVER, REGCLS_SINGLEUSE, &cookie) != S_OK)
+ return FALSE;
+
+ MSG msg;
+ while (int r = GetMessage (&msg, NULL, 0, 0))
+ {
+ if (r == -1)
+ return FALSE;
+
+ TranslateMessage (&msg);
+ DispatchMessage (&msg);
+
+ if (msg.message == WM_APP
+ && ObjectCount < 1
+ && !factory.IsServerLocked ())
+ break;
+ }
+ CoRevokeClassObject (cookie);
+
+ return TRUE;
+}
+
+
+static BOOL ComGetInstance (HWND hWnd, ITrueCryptFormatCom **tcServer)
+{
+ return ComGetInstanceBase (hWnd, CLSID_TrueCryptFormatCom, IID_ITrueCryptFormatCom, (void **) tcServer);
+}
+
+
+ITrueCryptFormatCom *GetElevatedInstance (HWND parent)
+{
+ ITrueCryptFormatCom *instance;
+
+ if (!ComGetInstance (parent, &instance))
+ throw UserAbort (SRC_POS);
+
+ return instance;
+}
+
+
+extern "C" int UacFormatNtfs (HWND hWnd, int driveNo, int clusterSize)
+{
+ CComPtr<ITrueCryptFormatCom> tc;
+ int r;
+
+ CoInitialize (NULL);
+
+ if (ComGetInstance (hWnd, &tc))
+ r = tc->FormatNtfs (driveNo, clusterSize);
+ else
+ r = 0;
+
+ CoUninitialize ();
+
+ return r;
+}
+
+
+extern "C" int UacAnalyzeHiddenVolumeHost (HWND hwndDlg, int *driveNo, __int64 hiddenVolHostSize, int *realClusterSize, __int64 *nbrFreeClusters)
+{
+ CComPtr<ITrueCryptFormatCom> tc;
+ int r;
+
+ CoInitialize (NULL);
+
+ if (ComGetInstance (hwndDlg, &tc))
+ r = tc->AnalyzeHiddenVolumeHost ((LONG_PTR) hwndDlg, driveNo, hiddenVolHostSize, realClusterSize, nbrFreeClusters);
+ else
+ r = 0;
+
+ CoUninitialize ();
+
+ return r;
+}
diff --git a/src/Format/FormatCom.h b/src/Format/FormatCom.h new file mode 100644 index 00000000..97685e9b --- /dev/null +++ b/src/Format/FormatCom.h @@ -0,0 +1,32 @@ +/*
+ Copyright (c) 2007-2008 TrueCrypt Developers Association. All rights reserved.
+
+ Governed by the TrueCrypt License 3.0 the full text of which is contained in
+ the file License.txt included in TrueCrypt binary and source code distribution
+ packages.
+*/
+
+#ifndef TC_HEADER_FORMAT_COM
+#define TC_HEADER_FORMAT_COM
+
+#include <windows.h>
+
+#ifdef __cplusplus
+
+#include "FormatCom_h.h"
+ITrueCryptFormatCom *GetElevatedInstance (HWND parent);
+
+extern "C" {
+#endif
+
+BOOL ComServerFormat ();
+int UacFormatNtfs (HWND hWnd, int driveNo, int clusterSize);
+int UacAnalyzeHiddenVolumeHost (HWND hwndDlg, int *driveNo, __int64 hiddenVolHostSize, int *realClusterSize, __int64 *nbrFreeClusters);
+int UacFormatVolume (char *cvolumePath , BOOL bDevice , unsigned __int64 size , unsigned __int64 hiddenVolHostSize , Password *password , int cipher , int pkcs5 , BOOL quickFormat, BOOL sparseFileSwitch, int fileSystem , int clusterSize, HWND hwndDlg , BOOL hiddenVol , int *realClusterSize);
+BOOL UacUpdateProgressBar (__int64 nSecNo, BOOL *bVolTransformThreadCancel);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // TC_HEADER_FORMAT_COM
\ No newline at end of file diff --git a/src/Format/FormatCom.idl b/src/Format/FormatCom.idl new file mode 100644 index 00000000..0f5dc111 --- /dev/null +++ b/src/Format/FormatCom.idl @@ -0,0 +1,48 @@ +/*
+ Copyright (c) 2007-2010 TrueCrypt Developers Association. All rights reserved.
+
+ Governed by the TrueCrypt License 3.0 the full text of which is contained in
+ the file License.txt included in TrueCrypt binary and source code distribution
+ packages.
+*/
+
+import "wtypes.idl";
+import "..\Common\Password.h";
+
+[
+ uuid(A7DF958C-0716-49E9-8C3E-53A775797576),
+ helpstring("TrueCrypt Format UAC Support Library"),
+ version(2.4) // Update ComSetup.cpp when changing version number
+]
+library TrueCryptFormatCom
+{
+ [
+ uuid(9EE02955-174A-48F1-820C-022F327BE109),
+ object,
+ oleautomation,
+ helpstring("TrueCrypt Format UAC Support Interface")
+ ]
+ interface ITrueCryptFormatCom : IUnknown
+ {
+ int AnalyzeHiddenVolumeHost (LONG_PTR hwndDlg, int *driveNo, __int64 hiddenVolHostSize, int *realClusterSize, __int64 *nbrFreeClusters);
+ DWORD CallDriver (DWORD ioctl, BSTR input, BSTR *output);
+ DWORD CopyFile (BSTR sourceFile, BSTR destinationFile);
+ DWORD DeleteFile (BSTR file);
+ BOOL FormatNtfs (int driveNo, int clusterSize);
+ BOOL IsPagingFileActive (BOOL checkNonWindowsPartitionsOnly);
+ DWORD ReadWriteFile (BOOL write, BOOL device, BSTR filePath, BSTR *bufferBstr, unsigned __int64 offset, unsigned __int32 size, DWORD *sizeDone);
+ DWORD RegisterFilterDriver (BOOL registerDriver, int filterType);
+ DWORD RegisterSystemFavoritesService (BOOL registerService);
+ DWORD SetDriverServiceStartType (DWORD startType);
+ DWORD WriteLocalMachineRegistryDwordValue (BSTR keyPath, BSTR valueName, DWORD value);
+ };
+
+ [
+ uuid(777DCDFD-C330-480B-B582-B02B57580CC9),
+ helpstring("TrueCrypt Format UAC Support Coclass")
+ ]
+ coclass TrueCryptFormatCom
+ {
+ [default] interface ITrueCryptFormatCom;
+ }
+}
diff --git a/src/Format/InPlace.c b/src/Format/InPlace.c new file mode 100644 index 00000000..ee864769 --- /dev/null +++ b/src/Format/InPlace.c @@ -0,0 +1,1692 @@ +/*
+ Copyright (c) 2008-2010 TrueCrypt Developers Association. All rights reserved.
+
+ Governed by the TrueCrypt License 3.0 the full text of which is contained in
+ the file License.txt included in TrueCrypt binary and source code distribution
+ packages.
+*/
+
+
+/* In this file, _WIN32_WINNT is defined as 0x0600 to make filesystem shrink available (Vista
+or later). _WIN32_WINNT cannot be defined as 0x0600 for the entire user-space projects
+because it breaks the main font app when the app is running on XP (likely an MS bug).
+IMPORTANT: Due to this issue, functions in this file must not directly interact with GUI. */
+#define TC_LOCAL_WIN32_WINNT_OVERRIDE 1
+#if (_WIN32_WINNT < 0x0600)
+# undef _WIN32_WINNT
+# define _WIN32_WINNT 0x0600
+#endif
+
+
+#include <stdlib.h>
+#include <string.h>
+#include <string>
+
+#include "Tcdefs.h"
+#include "Platform/Finally.h"
+
+#include "Common.h"
+#include "Crc.h"
+#include "Dlgcode.h"
+#include "Language.h"
+#include "Tcformat.h"
+#include "Volumes.h"
+
+#include "InPlace.h"
+
+using namespace std;
+using namespace TrueCrypt;
+
+#define TC_MAX_NONSYS_INPLACE_ENC_WORK_CHUNK_SIZE (2048 * BYTES_PER_KB)
+#define TC_INITIAL_NTFS_CONCEAL_PORTION_SIZE (2 * TC_MAX_VOLUME_SECTOR_SIZE)
+#define TC_NTFS_CONCEAL_CONSTANT 0xFF
+#define TC_NONSYS_INPLACE_ENC_HEADER_UPDATE_INTERVAL (64 * BYTES_PER_MB)
+#define TC_NONSYS_INPLACE_ENC_MIN_VOL_SIZE (TC_TOTAL_VOLUME_HEADERS_SIZE + TC_MIN_NTFS_FS_SIZE * 2)
+
+
+// If the returned value is greater than 0, it is the desired volume size in NTFS sectors (not in bytes)
+// after shrinking has been performed. If there's any error, returns -1.
+static __int64 NewFileSysSizeAfterShrink (HANDLE dev, const char *devicePath, int64 *totalClusterCount, DWORD *bytesPerCluster, BOOL silent)
+{
+ NTFS_VOLUME_DATA_BUFFER ntfsVolData;
+ DWORD nBytesReturned;
+ __int64 fileSysSize, desiredNbrSectors;
+
+ // Filesystem size and sector size
+
+ if (!DeviceIoControl (dev,
+ FSCTL_GET_NTFS_VOLUME_DATA,
+ NULL,
+ 0,
+ (LPVOID) &ntfsVolData,
+ sizeof (ntfsVolData),
+ &nBytesReturned,
+ NULL))
+ {
+ if (!silent)
+ handleWin32Error (MainDlg);
+
+ return -1;
+ }
+
+ fileSysSize = ntfsVolData.NumberSectors.QuadPart * ntfsVolData.BytesPerSector;
+
+ desiredNbrSectors = (fileSysSize - TC_TOTAL_VOLUME_HEADERS_SIZE) / ntfsVolData.BytesPerSector;
+
+ if (desiredNbrSectors <= 0)
+ return -1;
+
+ if (totalClusterCount)
+ *totalClusterCount = ntfsVolData.TotalClusters.QuadPart;
+ if (bytesPerCluster)
+ *bytesPerCluster = ntfsVolData.BytesPerCluster;
+
+ return desiredNbrSectors;
+}
+
+
+BOOL CheckRequirementsForNonSysInPlaceEnc (const char *devicePath, BOOL silent)
+{
+ NTFS_VOLUME_DATA_BUFFER ntfsVolData;
+ DWORD nBytesReturned;
+ HANDLE dev;
+ char szFileSysName [256];
+ WCHAR devPath [MAX_PATH];
+ char dosDev [TC_MAX_PATH] = {0};
+ char devName [MAX_PATH] = {0};
+ int driveLetterNo = -1;
+ char szRootPath[4] = {0, ':', '\\', 0};
+ __int64 deviceSize;
+ int partitionNumber = -1, driveNumber = -1;
+
+
+ /* ---------- Checks that do not require admin rights ----------- */
+
+
+ /* Operating system */
+
+ if (CurrentOSMajor < 6)
+ {
+ if (!silent)
+ ShowInPlaceEncErrMsgWAltSteps ("OS_NOT_SUPPORTED_FOR_NONSYS_INPLACE_ENC", FALSE);
+
+ return FALSE;
+ }
+
+
+ /* Volume type (must be a partition or a dynamic volume) */
+
+ if (sscanf (devicePath, "\\Device\\HarddiskVolume%d", &partitionNumber) != 1
+ && sscanf (devicePath, "\\Device\\Harddisk%d\\Partition%d", &driveNumber, &partitionNumber) != 2)
+ {
+ if (!silent)
+ Error ("INPLACE_ENC_INVALID_PATH");
+
+ return FALSE;
+ }
+
+ if (partitionNumber == 0)
+ {
+ if (!silent)
+ Warning ("RAW_DEV_NOT_SUPPORTED_FOR_INPLACE_ENC");
+
+ return FALSE;
+ }
+
+
+ /* Admin rights */
+
+ if (!IsAdmin())
+ {
+ // We rely on the wizard process to call us only when the whole wizard process has been elevated (so UAC
+ // status can be ignored). In case the IsAdmin() detection somehow fails, we allow the user to continue.
+
+ if (!silent)
+ Warning ("ADMIN_PRIVILEGES_WARN_DEVICES");
+ }
+
+
+ /* ---------- Checks that may require admin rights ----------- */
+
+
+ /* Access to the partition */
+
+ strcpy ((char *) devPath, devicePath);
+ ToUNICODE ((char *) devPath);
+
+ driveLetterNo = GetDiskDeviceDriveLetter (devPath);
+
+ if (driveLetterNo >= 0)
+ szRootPath[0] = (char) driveLetterNo + 'A';
+
+ if (FakeDosNameForDevice (devicePath, dosDev, devName, FALSE) != 0)
+ {
+ if (!silent)
+ {
+ handleWin32Error (MainDlg);
+ Error ("INPLACE_ENC_CANT_ACCESS_OR_GET_INFO_ON_VOL");
+ }
+ return FALSE;
+ }
+
+ dev = OpenPartitionVolume (devName,
+ FALSE, // Do not require exclusive access
+ TRUE, // Require shared access (must be TRUE; otherwise, volume properties will not be possible to obtain)
+ FALSE, // Do not ask the user to confirm shared access (if exclusive fails)
+ FALSE, // Do not append alternative instructions how to encrypt the data (to applicable error messages)
+ silent); // Silent mode
+
+ if (dev == INVALID_HANDLE_VALUE)
+ return FALSE;
+
+
+ /* File system type */
+
+ GetVolumeInformation (szRootPath, NULL, 0, NULL, NULL, NULL, szFileSysName, sizeof(szFileSysName));
+
+ if (strncmp (szFileSysName, "NTFS", 4))
+ {
+ // The previous filesystem type detection method failed (or it's not NTFS) -- try an alternative method
+
+ if (!DeviceIoControl (dev,
+ FSCTL_GET_NTFS_VOLUME_DATA,
+ NULL,
+ 0,
+ (LPVOID) &ntfsVolData,
+ sizeof (ntfsVolData),
+ &nBytesReturned,
+ NULL))
+ {
+ if (!silent)
+ {
+ // The filesystem is not NTFS or the filesystem type could not be determined (or the NTFS filesystem
+ // is dismounted).
+
+ if (IsDeviceMounted (devName))
+ ShowInPlaceEncErrMsgWAltSteps ("ONLY_NTFS_SUPPORTED_FOR_NONSYS_INPLACE_ENC", FALSE);
+ else
+ Warning ("ONLY_MOUNTED_VOL_SUPPORTED_FOR_NONSYS_INPLACE_ENC");
+ }
+
+ CloseHandle (dev);
+ return FALSE;
+ }
+ }
+
+
+ /* Attempt to determine whether the filesystem can be safely shrunk */
+
+ if (NewFileSysSizeAfterShrink (dev, devicePath, NULL, NULL, silent) == -1)
+ {
+ // Cannot determine whether shrinking is required
+ if (!silent)
+ ShowInPlaceEncErrMsgWAltSteps ("INPLACE_ENC_CANT_ACCESS_OR_GET_INFO_ON_VOL_ALT", TRUE);
+
+ CloseHandle (dev);
+ return FALSE;
+ }
+
+
+ /* Partition size */
+
+ deviceSize = GetDeviceSize (devicePath);
+ if (deviceSize < 0)
+ {
+ // Cannot determine the size of the partition
+ if (!silent)
+ Error ("INPLACE_ENC_CANT_ACCESS_OR_GET_INFO_ON_VOL");
+
+ CloseHandle (dev);
+ return FALSE;
+ }
+
+ if (deviceSize < TC_NONSYS_INPLACE_ENC_MIN_VOL_SIZE)
+ {
+ // The partition is too small
+ if (!silent)
+ {
+ ShowInPlaceEncErrMsgWAltSteps ("PARTITION_TOO_SMALL_FOR_NONSYS_INPLACE_ENC", FALSE);
+ }
+
+ CloseHandle (dev);
+ return FALSE;
+ }
+
+
+ /* Free space on the filesystem */
+
+ if (!DeviceIoControl (dev,
+ FSCTL_GET_NTFS_VOLUME_DATA,
+ NULL,
+ 0,
+ (LPVOID) &ntfsVolData,
+ sizeof (ntfsVolData),
+ &nBytesReturned,
+ NULL))
+ {
+ if (!silent)
+ ShowInPlaceEncErrMsgWAltSteps ("INPLACE_ENC_CANT_ACCESS_OR_GET_INFO_ON_VOL", TRUE);
+
+ CloseHandle (dev);
+ return FALSE;
+ }
+
+ if (ntfsVolData.FreeClusters.QuadPart * ntfsVolData.BytesPerCluster < TC_TOTAL_VOLUME_HEADERS_SIZE)
+ {
+ if (!silent)
+ ShowInPlaceEncErrMsgWAltSteps ("NOT_ENOUGH_FREE_FILESYS_SPACE_FOR_SHRINK", TRUE);
+
+ CloseHandle (dev);
+ return FALSE;
+ }
+
+
+ /* Filesystem sector size */
+
+ if (ntfsVolData.BytesPerSector > TC_MAX_VOLUME_SECTOR_SIZE
+ || ntfsVolData.BytesPerSector % ENCRYPTION_DATA_UNIT_SIZE != 0)
+ {
+ if (!silent)
+ ShowInPlaceEncErrMsgWAltSteps ("SECTOR_SIZE_UNSUPPORTED", TRUE);
+
+ CloseHandle (dev);
+ return FALSE;
+ }
+
+
+ CloseHandle (dev);
+ return TRUE;
+}
+
+
+int EncryptPartitionInPlaceBegin (volatile FORMAT_VOL_PARAMETERS *volParams, volatile HANDLE *outHandle, WipeAlgorithmId wipeAlgorithm)
+{
+ SHRINK_VOLUME_INFORMATION shrinkVolInfo;
+ signed __int64 sizeToShrinkTo;
+ int nStatus = ERR_SUCCESS;
+ PCRYPTO_INFO cryptoInfo = NULL;
+ PCRYPTO_INFO cryptoInfo2 = NULL;
+ HANDLE dev = INVALID_HANDLE_VALUE;
+ DWORD dwError;
+ char *header;
+ char dosDev[TC_MAX_PATH] = {0};
+ char devName[MAX_PATH] = {0};
+ int driveLetter = -1;
+ WCHAR deviceName[MAX_PATH];
+ uint64 dataAreaSize;
+ __int64 deviceSize;
+ LARGE_INTEGER offset;
+ DWORD dwResult;
+
+ SetNonSysInplaceEncUIStatus (NONSYS_INPLACE_ENC_STATUS_PREPARING);
+
+
+ if (!CheckRequirementsForNonSysInPlaceEnc (volParams->volumePath, FALSE))
+ return ERR_DONT_REPORT;
+
+
+ header = (char *) TCalloc (TC_VOLUME_HEADER_EFFECTIVE_SIZE);
+ if (!header)
+ return ERR_OUTOFMEMORY;
+
+ VirtualLock (header, TC_VOLUME_HEADER_EFFECTIVE_SIZE);
+
+ deviceSize = GetDeviceSize (volParams->volumePath);
+ if (deviceSize < 0)
+ {
+ // Cannot determine the size of the partition
+ nStatus = ERR_PARAMETER_INCORRECT;
+ goto closing_seq;
+ }
+
+ if (deviceSize < TC_NONSYS_INPLACE_ENC_MIN_VOL_SIZE)
+ {
+ ShowInPlaceEncErrMsgWAltSteps ("PARTITION_TOO_SMALL_FOR_NONSYS_INPLACE_ENC", TRUE);
+ nStatus = ERR_DONT_REPORT;
+ goto closing_seq;
+ }
+
+ dataAreaSize = GetVolumeDataAreaSize (volParams->hiddenVol, deviceSize);
+
+ strcpy ((char *)deviceName, volParams->volumePath);
+ ToUNICODE ((char *)deviceName);
+
+ driveLetter = GetDiskDeviceDriveLetter (deviceName);
+
+
+ if (FakeDosNameForDevice (volParams->volumePath, dosDev, devName, FALSE) != 0)
+ {
+ nStatus = ERR_OS_ERROR;
+ goto closing_seq;
+ }
+
+ if (IsDeviceMounted (devName))
+ {
+ dev = OpenPartitionVolume (devName,
+ FALSE, // Do not require exclusive access (must be FALSE; otherwise, it will not be possible to dismount the volume or obtain its properties and FSCTL_ALLOW_EXTENDED_DASD_IO will fail too)
+ TRUE, // Require shared access (must be TRUE; otherwise, it will not be possible to dismount the volume or obtain its properties and FSCTL_ALLOW_EXTENDED_DASD_IO will fail too)
+ FALSE, // Do not ask the user to confirm shared access (if exclusive fails)
+ FALSE, // Do not append alternative instructions how to encrypt the data (to applicable error messages)
+ FALSE); // Non-silent mode
+
+ if (dev == INVALID_HANDLE_VALUE)
+ {
+ nStatus = ERR_DONT_REPORT;
+ goto closing_seq;
+ }
+ }
+ else
+ {
+ // The volume is not mounted so we can't work with the filesystem.
+ Error ("ONLY_MOUNTED_VOL_SUPPORTED_FOR_NONSYS_INPLACE_ENC");
+ nStatus = ERR_DONT_REPORT;
+ goto closing_seq;
+ }
+
+
+ /* Gain "raw" access to the partition (the NTFS driver guards hidden sectors). */
+
+ if (!DeviceIoControl (dev,
+ FSCTL_ALLOW_EXTENDED_DASD_IO,
+ NULL,
+ 0,
+ NULL,
+ 0,
+ &dwResult,
+ NULL))
+ {
+ handleWin32Error (MainDlg);
+ ShowInPlaceEncErrMsgWAltSteps ("INPLACE_ENC_CANT_ACCESS_OR_GET_INFO_ON_VOL_ALT", TRUE);
+ nStatus = ERR_DONT_REPORT;
+ goto closing_seq;
+ }
+
+
+
+ /* Shrink the filesystem */
+
+ int64 totalClusterCount;
+ DWORD bytesPerCluster;
+
+ sizeToShrinkTo = NewFileSysSizeAfterShrink (dev, volParams->volumePath, &totalClusterCount, &bytesPerCluster, FALSE);
+
+ if (sizeToShrinkTo == -1)
+ {
+ ShowInPlaceEncErrMsgWAltSteps ("INPLACE_ENC_CANT_ACCESS_OR_GET_INFO_ON_VOL_ALT", TRUE);
+ nStatus = ERR_DONT_REPORT;
+ goto closing_seq;
+ }
+
+ SetNonSysInplaceEncUIStatus (NONSYS_INPLACE_ENC_STATUS_RESIZING);
+
+ memset (&shrinkVolInfo, 0, sizeof (shrinkVolInfo));
+
+ shrinkVolInfo.ShrinkRequestType = ShrinkPrepare;
+ shrinkVolInfo.NewNumberOfSectors = sizeToShrinkTo;
+
+ if (!DeviceIoControl (dev,
+ FSCTL_SHRINK_VOLUME,
+ (LPVOID) &shrinkVolInfo,
+ sizeof (shrinkVolInfo),
+ NULL,
+ 0,
+ &dwResult,
+ NULL))
+ {
+ handleWin32Error (MainDlg);
+ ShowInPlaceEncErrMsgWAltSteps ("CANNOT_RESIZE_FILESYS", TRUE);
+ nStatus = ERR_DONT_REPORT;
+ goto closing_seq;
+ }
+
+ BOOL clustersMovedBeforeVolumeEnd = FALSE;
+
+ while (true)
+ {
+ shrinkVolInfo.ShrinkRequestType = ShrinkCommit;
+ shrinkVolInfo.NewNumberOfSectors = 0;
+
+ if (!DeviceIoControl (dev, FSCTL_SHRINK_VOLUME, &shrinkVolInfo, sizeof (shrinkVolInfo), NULL, 0, &dwResult, NULL))
+ {
+ // If there are any occupied clusters beyond the new desired end of the volume, the call fails with
+ // ERROR_ACCESS_DENIED (STATUS_ALREADY_COMMITTED).
+ if (GetLastError () == ERROR_ACCESS_DENIED)
+ {
+ if (!clustersMovedBeforeVolumeEnd)
+ {
+ if (MoveClustersBeforeThreshold (dev, deviceName, totalClusterCount - (bytesPerCluster > TC_TOTAL_VOLUME_HEADERS_SIZE ? 1 : TC_TOTAL_VOLUME_HEADERS_SIZE / bytesPerCluster)))
+ {
+ clustersMovedBeforeVolumeEnd = TRUE;
+ continue;
+ }
+
+ handleWin32Error (MainDlg);
+ }
+ }
+ else
+ handleWin32Error (MainDlg);
+
+ ShowInPlaceEncErrMsgWAltSteps ("CANNOT_RESIZE_FILESYS", TRUE);
+ nStatus = ERR_DONT_REPORT;
+ goto closing_seq;
+ }
+
+ break;
+ }
+
+ SetNonSysInplaceEncUIStatus (NONSYS_INPLACE_ENC_STATUS_PREPARING);
+
+
+ /* Gain exclusive access to the volume */
+
+ nStatus = DismountFileSystem (dev,
+ driveLetter,
+ TRUE,
+ TRUE,
+ FALSE);
+
+ if (nStatus != ERR_SUCCESS)
+ {
+ nStatus = ERR_DONT_REPORT;
+ goto closing_seq;
+ }
+
+
+
+ /* Create header backup on the partition. Until the volume is fully encrypted, the backup header will provide
+ us with the master key, encrypted range, and other data for pause/resume operations. We cannot create the
+ primary header until the entire partition is encrypted (because we encrypt backwards and the primary header
+ area is occuppied by data until the very end of the process). */
+
+ // Prepare the backup header
+ for (int wipePass = 0; wipePass < (wipeAlgorithm == TC_WIPE_NONE ? 1 : PRAND_DISK_WIPE_PASSES); wipePass++)
+ {
+ nStatus = CreateVolumeHeaderInMemory (FALSE,
+ header,
+ volParams->ea,
+ FIRST_MODE_OF_OPERATION_ID,
+ volParams->password,
+ volParams->pkcs5,
+ wipePass == 0 ? NULL : (char *) cryptoInfo->master_keydata,
+ &cryptoInfo,
+ dataAreaSize,
+ 0,
+ TC_VOLUME_DATA_OFFSET + dataAreaSize, // Start of the encrypted area = the first byte of the backup heeader (encrypting from the end)
+ 0, // No data is encrypted yet
+ 0,
+ volParams->headerFlags | TC_HEADER_FLAG_NONSYS_INPLACE_ENC,
+ volParams->sectorSize,
+ wipeAlgorithm == TC_WIPE_NONE ? FALSE : (wipePass < PRAND_DISK_WIPE_PASSES - 1));
+
+ if (nStatus != 0)
+ goto closing_seq;
+
+ offset.QuadPart = TC_VOLUME_DATA_OFFSET + dataAreaSize;
+
+ if (!SetFilePointerEx (dev, offset, NULL, FILE_BEGIN))
+ {
+ nStatus = ERR_OS_ERROR;
+ goto closing_seq;
+ }
+
+ // Write the backup header to the partition
+ if (!WriteEffectiveVolumeHeader (TRUE, dev, (byte *) header))
+ {
+ nStatus = ERR_OS_ERROR;
+ goto closing_seq;
+ }
+
+ // Fill the reserved sectors of the backup header area with random data
+ nStatus = WriteRandomDataToReservedHeaderAreas (dev, cryptoInfo, dataAreaSize, FALSE, TRUE);
+
+ if (nStatus != ERR_SUCCESS)
+ goto closing_seq;
+ }
+
+
+ /* Now we will try to decrypt the backup header to verify it has been correctly written. */
+
+ nStatus = OpenBackupHeader (dev, volParams->volumePath, volParams->password, &cryptoInfo2, NULL, deviceSize);
+
+ if (nStatus != ERR_SUCCESS
+ || cryptoInfo->EncryptedAreaStart.Value != cryptoInfo2->EncryptedAreaStart.Value
+ || cryptoInfo2->EncryptedAreaStart.Value == 0)
+ {
+ if (nStatus == ERR_SUCCESS)
+ nStatus = ERR_PARAMETER_INCORRECT;
+
+ goto closing_seq;
+ }
+
+ // The backup header is valid so we know we should be able to safely resume in-place encryption
+ // of this partition even if the system/app crashes.
+
+
+
+ /* Conceal the NTFS filesystem (by performing an easy-to-undo modification). This will prevent Windows
+ and apps from interfering with the volume until it has been fully encrypted. */
+
+ nStatus = ConcealNTFS (dev);
+
+ if (nStatus != ERR_SUCCESS)
+ goto closing_seq;
+
+
+
+ // /* If a drive letter is assigned to the device, remove it (so that users do not try to open it, which
+ //would cause Windows to ask them if they want to format the volume and other dangerous things). */
+
+ //if (driveLetter >= 0)
+ //{
+ // char rootPath[] = { driveLetter + 'A', ':', '\\', 0 };
+
+ // // Try to remove the assigned drive letter
+ // if (DeleteVolumeMountPoint (rootPath))
+ // driveLetter = -1;
+ //}
+
+
+
+ /* Update config files and app data */
+
+ // In the config file, increase the number of partitions where in-place encryption is in progress
+
+ SaveNonSysInPlaceEncSettings (1, wipeAlgorithm);
+
+
+ // Add the wizard to the system startup sequence if appropriate
+
+ if (!IsNonInstallMode ())
+ ManageStartupSeqWiz (FALSE, "/prinplace");
+
+
+ nStatus = ERR_SUCCESS;
+
+
+closing_seq:
+
+ dwError = GetLastError();
+
+ if (cryptoInfo != NULL)
+ {
+ crypto_close (cryptoInfo);
+ cryptoInfo = NULL;
+ }
+
+ if (cryptoInfo2 != NULL)
+ {
+ crypto_close (cryptoInfo2);
+ cryptoInfo2 = NULL;
+ }
+
+ burn (header, TC_VOLUME_HEADER_EFFECTIVE_SIZE);
+ VirtualUnlock (header, TC_VOLUME_HEADER_EFFECTIVE_SIZE);
+ TCfree (header);
+
+ if (dosDev[0])
+ RemoveFakeDosName (volParams->volumePath, dosDev);
+
+ *outHandle = dev;
+
+ if (nStatus != ERR_SUCCESS)
+ SetLastError (dwError);
+
+ return nStatus;
+}
+
+
+int EncryptPartitionInPlaceResume (HANDLE dev,
+ volatile FORMAT_VOL_PARAMETERS *volParams,
+ WipeAlgorithmId wipeAlgorithm,
+ volatile BOOL *bTryToCorrectReadErrors)
+{
+ PCRYPTO_INFO masterCryptoInfo = NULL, headerCryptoInfo = NULL, tmpCryptoInfo = NULL;
+ UINT64_STRUCT unitNo;
+ char *buf = NULL, *header = NULL;
+ byte *wipeBuffer = NULL;
+ byte wipeRandChars [TC_WIPE_RAND_CHAR_COUNT];
+ byte wipeRandCharsUpdate [TC_WIPE_RAND_CHAR_COUNT];
+ char dosDev[TC_MAX_PATH] = {0};
+ char devName[MAX_PATH] = {0};
+ WCHAR deviceName[MAX_PATH];
+ int nStatus = ERR_SUCCESS;
+ __int64 deviceSize;
+ uint64 remainingBytes, lastHeaderUpdateDistance = 0, zeroedSectorCount = 0;
+ uint32 workChunkSize;
+ DWORD dwError, dwResult;
+ BOOL bPause = FALSE, bEncryptedAreaSizeChanged = FALSE;
+ LARGE_INTEGER offset;
+ int sectorSize;
+ int i;
+ DWORD n;
+ char *devicePath = volParams->volumePath;
+ Password *password = volParams->password;
+ DISK_GEOMETRY driveGeometry;
+
+
+ bInPlaceEncNonSysResumed = TRUE;
+
+ buf = (char *) TCalloc (TC_MAX_NONSYS_INPLACE_ENC_WORK_CHUNK_SIZE);
+ if (!buf)
+ {
+ nStatus = ERR_OUTOFMEMORY;
+ goto closing_seq;
+ }
+
+ header = (char *) TCalloc (TC_VOLUME_HEADER_EFFECTIVE_SIZE);
+ if (!header)
+ {
+ nStatus = ERR_OUTOFMEMORY;
+ goto closing_seq;
+ }
+
+ VirtualLock (header, TC_VOLUME_HEADER_EFFECTIVE_SIZE);
+
+ if (wipeAlgorithm != TC_WIPE_NONE)
+ {
+ wipeBuffer = (byte *) TCalloc (TC_MAX_NONSYS_INPLACE_ENC_WORK_CHUNK_SIZE);
+ if (!wipeBuffer)
+ {
+ nStatus = ERR_OUTOFMEMORY;
+ goto closing_seq;
+ }
+ }
+
+ headerCryptoInfo = crypto_open();
+
+ if (headerCryptoInfo == NULL)
+ {
+ nStatus = ERR_OUTOFMEMORY;
+ goto closing_seq;
+ }
+
+ deviceSize = GetDeviceSize (devicePath);
+ if (deviceSize < 0)
+ {
+ // Cannot determine the size of the partition
+ nStatus = ERR_OS_ERROR;
+ goto closing_seq;
+ }
+
+ if (dev == INVALID_HANDLE_VALUE)
+ {
+ strcpy ((char *)deviceName, devicePath);
+ ToUNICODE ((char *)deviceName);
+
+ if (FakeDosNameForDevice (devicePath, dosDev, devName, FALSE) != 0)
+ {
+ nStatus = ERR_OS_ERROR;
+ goto closing_seq;
+ }
+
+ dev = OpenPartitionVolume (devName,
+ FALSE, // Do not require exclusive access
+ FALSE, // Do not require shared access
+ TRUE, // Ask the user to confirm shared access (if exclusive fails)
+ FALSE, // Do not append alternative instructions how to encrypt the data (to applicable error messages)
+ FALSE); // Non-silent mode
+
+ if (dev == INVALID_HANDLE_VALUE)
+ {
+ nStatus = ERR_DONT_REPORT;
+ goto closing_seq;
+ }
+ }
+
+ // This should never be needed, but is still performed for extra safety (without checking the result)
+ DeviceIoControl (dev,
+ FSCTL_ALLOW_EXTENDED_DASD_IO,
+ NULL,
+ 0,
+ NULL,
+ 0,
+ &dwResult,
+ NULL);
+
+
+ if (!DeviceIoControl (dev, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, &driveGeometry, sizeof (driveGeometry), &dwResult, NULL))
+ {
+ nStatus = ERR_OS_ERROR;
+ goto closing_seq;
+ }
+
+ sectorSize = driveGeometry.BytesPerSector;
+
+
+ nStatus = OpenBackupHeader (dev, devicePath, password, &masterCryptoInfo, headerCryptoInfo, deviceSize);
+
+ if (nStatus != ERR_SUCCESS)
+ goto closing_seq;
+
+
+
+ remainingBytes = masterCryptoInfo->VolumeSize.Value - masterCryptoInfo->EncryptedAreaLength.Value;
+
+ lastHeaderUpdateDistance = 0;
+
+
+ ExportProgressStats (masterCryptoInfo->EncryptedAreaLength.Value, masterCryptoInfo->VolumeSize.Value);
+
+ SetNonSysInplaceEncUIStatus (NONSYS_INPLACE_ENC_STATUS_ENCRYPTING);
+
+ bFirstNonSysInPlaceEncResumeDone = TRUE;
+
+
+ /* The in-place encryption core */
+
+ while (remainingBytes > 0)
+ {
+ workChunkSize = (uint32) min (remainingBytes, TC_MAX_NONSYS_INPLACE_ENC_WORK_CHUNK_SIZE);
+
+ if (workChunkSize % ENCRYPTION_DATA_UNIT_SIZE != 0)
+ {
+ nStatus = ERR_PARAMETER_INCORRECT;
+ goto closing_seq;
+ }
+
+ unitNo.Value = (remainingBytes - workChunkSize + TC_VOLUME_DATA_OFFSET) / ENCRYPTION_DATA_UNIT_SIZE;
+
+
+ // Read the plaintext into RAM
+
+inplace_enc_read:
+
+ offset.QuadPart = masterCryptoInfo->EncryptedAreaStart.Value - workChunkSize - TC_VOLUME_DATA_OFFSET;
+
+ if (SetFilePointerEx (dev, offset, NULL, FILE_BEGIN) == 0)
+ {
+ nStatus = ERR_OS_ERROR;
+ goto closing_seq;
+ }
+
+ if (ReadFile (dev, buf, workChunkSize, &n, NULL) == 0)
+ {
+ // Read error
+
+ DWORD dwTmpErr = GetLastError ();
+
+ if (IsDiskReadError (dwTmpErr) && !bVolTransformThreadCancel)
+ {
+ // Physical defect or data corruption
+
+ if (!*bTryToCorrectReadErrors)
+ {
+ *bTryToCorrectReadErrors = (AskWarnYesNo ("ENABLE_BAD_SECTOR_ZEROING") == IDYES);
+ }
+
+ if (*bTryToCorrectReadErrors)
+ {
+ // Try to correct the read errors physically
+
+ offset.QuadPart = masterCryptoInfo->EncryptedAreaStart.Value - workChunkSize - TC_VOLUME_DATA_OFFSET;
+
+ nStatus = ZeroUnreadableSectors (dev, offset, workChunkSize, sectorSize, &zeroedSectorCount);
+
+ if (nStatus != ERR_SUCCESS)
+ {
+ // Due to write errors, we can't correct the read errors
+ nStatus = ERR_OS_ERROR;
+ goto closing_seq;
+ }
+
+ goto inplace_enc_read;
+ }
+ }
+
+ SetLastError (dwTmpErr); // Preserve the original error code
+
+ nStatus = ERR_OS_ERROR;
+ goto closing_seq;
+ }
+
+ if (remainingBytes - workChunkSize < TC_INITIAL_NTFS_CONCEAL_PORTION_SIZE)
+ {
+ // We reached the inital portion of the filesystem, which we had concealed (in order to prevent
+ // Windows from interfering with the volume). Now we need to undo that modification.
+
+ for (i = 0; i < TC_INITIAL_NTFS_CONCEAL_PORTION_SIZE - (remainingBytes - workChunkSize); i++)
+ buf[i] ^= TC_NTFS_CONCEAL_CONSTANT;
+ }
+
+
+ // Encrypt the plaintext in RAM
+
+ EncryptDataUnits ((byte *) buf, &unitNo, workChunkSize / ENCRYPTION_DATA_UNIT_SIZE, masterCryptoInfo);
+
+
+ // If enabled, wipe the area to which we will write the ciphertext
+
+ if (wipeAlgorithm != TC_WIPE_NONE)
+ {
+ byte wipePass;
+
+ offset.QuadPart = masterCryptoInfo->EncryptedAreaStart.Value - workChunkSize;
+
+ for (wipePass = 1; wipePass <= GetWipePassCount (wipeAlgorithm); ++wipePass)
+ {
+ if (!WipeBuffer (wipeAlgorithm, wipeRandChars, wipePass, wipeBuffer, workChunkSize))
+ {
+ ULONG i;
+ for (i = 0; i < workChunkSize; ++i)
+ {
+ wipeBuffer[i] = buf[i] + wipePass;
+ }
+
+ EncryptDataUnits (wipeBuffer, &unitNo, workChunkSize / ENCRYPTION_DATA_UNIT_SIZE, masterCryptoInfo);
+ memcpy (wipeRandCharsUpdate, wipeBuffer, sizeof (wipeRandCharsUpdate));
+ }
+
+ if (SetFilePointerEx (dev, offset, NULL, FILE_BEGIN) == 0
+ || WriteFile (dev, wipeBuffer, workChunkSize, &n, NULL) == 0)
+ {
+ // Write error
+ dwError = GetLastError();
+
+ // Undo failed write operation
+ if (workChunkSize > TC_VOLUME_DATA_OFFSET && SetFilePointerEx (dev, offset, NULL, FILE_BEGIN))
+ {
+ DecryptDataUnits ((byte *) buf, &unitNo, workChunkSize / ENCRYPTION_DATA_UNIT_SIZE, masterCryptoInfo);
+ WriteFile (dev, buf + TC_VOLUME_DATA_OFFSET, workChunkSize - TC_VOLUME_DATA_OFFSET, &n, NULL);
+ }
+
+ SetLastError (dwError);
+ nStatus = ERR_OS_ERROR;
+ goto closing_seq;
+ }
+ }
+
+ memcpy (wipeRandChars, wipeRandCharsUpdate, sizeof (wipeRandCharsUpdate));
+ }
+
+
+ // Write the ciphertext
+
+ offset.QuadPart = masterCryptoInfo->EncryptedAreaStart.Value - workChunkSize;
+
+ if (SetFilePointerEx (dev, offset, NULL, FILE_BEGIN) == 0)
+ {
+ nStatus = ERR_OS_ERROR;
+ goto closing_seq;
+ }
+
+ if (WriteFile (dev, buf, workChunkSize, &n, NULL) == 0)
+ {
+ // Write error
+ dwError = GetLastError();
+
+ // Undo failed write operation
+ if (workChunkSize > TC_VOLUME_DATA_OFFSET && SetFilePointerEx (dev, offset, NULL, FILE_BEGIN))
+ {
+ DecryptDataUnits ((byte *) buf, &unitNo, workChunkSize / ENCRYPTION_DATA_UNIT_SIZE, masterCryptoInfo);
+ WriteFile (dev, buf + TC_VOLUME_DATA_OFFSET, workChunkSize - TC_VOLUME_DATA_OFFSET, &n, NULL);
+ }
+
+ SetLastError (dwError);
+ nStatus = ERR_OS_ERROR;
+ goto closing_seq;
+ }
+
+
+ masterCryptoInfo->EncryptedAreaStart.Value -= workChunkSize;
+ masterCryptoInfo->EncryptedAreaLength.Value += workChunkSize;
+
+ remainingBytes -= workChunkSize;
+ lastHeaderUpdateDistance += workChunkSize;
+
+ bEncryptedAreaSizeChanged = TRUE;
+
+ if (lastHeaderUpdateDistance >= TC_NONSYS_INPLACE_ENC_HEADER_UPDATE_INTERVAL)
+ {
+ nStatus = FastVolumeHeaderUpdate (dev, headerCryptoInfo, masterCryptoInfo, deviceSize);
+
+ if (nStatus != ERR_SUCCESS)
+ goto closing_seq;
+
+ lastHeaderUpdateDistance = 0;
+ }
+
+ ExportProgressStats (masterCryptoInfo->EncryptedAreaLength.Value, masterCryptoInfo->VolumeSize.Value);
+
+ if (bVolTransformThreadCancel)
+ {
+ bPause = TRUE;
+ break;
+ }
+ }
+
+ nStatus = FastVolumeHeaderUpdate (dev, headerCryptoInfo, masterCryptoInfo, deviceSize);
+
+
+ if (nStatus != ERR_SUCCESS)
+ goto closing_seq;
+
+
+ if (!bPause)
+ {
+ /* The data area has been fully encrypted; create and write the primary volume header */
+
+ SetNonSysInplaceEncUIStatus (NONSYS_INPLACE_ENC_STATUS_FINALIZING);
+
+ for (int wipePass = 0; wipePass < (wipeAlgorithm == TC_WIPE_NONE ? 1 : PRAND_DISK_WIPE_PASSES); wipePass++)
+ {
+ nStatus = CreateVolumeHeaderInMemory (FALSE,
+ header,
+ headerCryptoInfo->ea,
+ headerCryptoInfo->mode,
+ password,
+ masterCryptoInfo->pkcs5,
+ (char *) masterCryptoInfo->master_keydata,
+ &tmpCryptoInfo,
+ masterCryptoInfo->VolumeSize.Value,
+ 0,
+ masterCryptoInfo->EncryptedAreaStart.Value,
+ masterCryptoInfo->EncryptedAreaLength.Value,
+ masterCryptoInfo->RequiredProgramVersion,
+ masterCryptoInfo->HeaderFlags | TC_HEADER_FLAG_NONSYS_INPLACE_ENC,
+ masterCryptoInfo->SectorSize,
+ wipeAlgorithm == TC_WIPE_NONE ? FALSE : (wipePass < PRAND_DISK_WIPE_PASSES - 1));
+
+ if (nStatus != ERR_SUCCESS)
+ goto closing_seq;
+
+
+ offset.QuadPart = TC_VOLUME_HEADER_OFFSET;
+
+ if (SetFilePointerEx (dev, offset, NULL, FILE_BEGIN) == 0
+ || !WriteEffectiveVolumeHeader (TRUE, dev, (byte *) header))
+ {
+ nStatus = ERR_OS_ERROR;
+ goto closing_seq;
+ }
+
+ // Fill the reserved sectors of the header area with random data
+ nStatus = WriteRandomDataToReservedHeaderAreas (dev, headerCryptoInfo, masterCryptoInfo->VolumeSize.Value, TRUE, FALSE);
+
+ if (nStatus != ERR_SUCCESS)
+ goto closing_seq;
+ }
+
+ // Update the configuration files
+
+ SaveNonSysInPlaceEncSettings (-1, wipeAlgorithm);
+
+
+
+ SetNonSysInplaceEncUIStatus (NONSYS_INPLACE_ENC_STATUS_FINISHED);
+
+ nStatus = ERR_SUCCESS;
+ }
+ else
+ {
+ // The process has been paused by the user or aborted by the wizard (e.g. on app exit)
+
+ nStatus = ERR_USER_ABORT;
+
+ SetNonSysInplaceEncUIStatus (NONSYS_INPLACE_ENC_STATUS_PAUSED);
+ }
+
+
+closing_seq:
+
+ dwError = GetLastError();
+
+ if (bEncryptedAreaSizeChanged
+ && dev != INVALID_HANDLE_VALUE
+ && masterCryptoInfo != NULL
+ && headerCryptoInfo != NULL
+ && deviceSize > 0)
+ {
+ // Execution of the core loop may have been interrupted due to an error or user action without updating the header
+ FastVolumeHeaderUpdate (dev, headerCryptoInfo, masterCryptoInfo, deviceSize);
+ }
+
+ if (masterCryptoInfo != NULL)
+ {
+ crypto_close (masterCryptoInfo);
+ masterCryptoInfo = NULL;
+ }
+
+ if (headerCryptoInfo != NULL)
+ {
+ crypto_close (headerCryptoInfo);
+ headerCryptoInfo = NULL;
+ }
+
+ if (tmpCryptoInfo != NULL)
+ {
+ crypto_close (tmpCryptoInfo);
+ tmpCryptoInfo = NULL;
+ }
+
+ if (dosDev[0])
+ RemoveFakeDosName (devicePath, dosDev);
+
+ if (dev != INVALID_HANDLE_VALUE)
+ {
+ CloseHandle (dev);
+ dev = INVALID_HANDLE_VALUE;
+ }
+
+ if (buf != NULL)
+ TCfree (buf);
+
+ if (header != NULL)
+ {
+ burn (header, TC_VOLUME_HEADER_EFFECTIVE_SIZE);
+ VirtualUnlock (header, TC_VOLUME_HEADER_EFFECTIVE_SIZE);
+ TCfree (header);
+ }
+
+ if (wipeBuffer != NULL)
+ TCfree (wipeBuffer);
+
+ if (zeroedSectorCount > 0)
+ {
+ wchar_t msg[30000] = {0};
+ wchar_t sizeStr[500] = {0};
+
+ GetSizeString (zeroedSectorCount * sectorSize, sizeStr);
+
+ wsprintfW (msg,
+ GetString ("ZEROED_BAD_SECTOR_COUNT"),
+ zeroedSectorCount,
+ sizeStr);
+
+ WarningDirect (msg);
+ }
+
+ if (nStatus != ERR_SUCCESS && nStatus != ERR_USER_ABORT)
+ SetLastError (dwError);
+
+ return nStatus;
+}
+
+
+int FastVolumeHeaderUpdate (HANDLE dev, CRYPTO_INFO *headerCryptoInfo, CRYPTO_INFO *masterCryptoInfo, __int64 deviceSize)
+{
+ LARGE_INTEGER offset;
+ DWORD n;
+ int nStatus = ERR_SUCCESS;
+ byte *header;
+ DWORD dwError;
+ uint32 headerCrc32;
+ byte *fieldPos;
+
+ header = (byte *) TCalloc (TC_VOLUME_HEADER_EFFECTIVE_SIZE);
+
+ if (!header)
+ return ERR_OUTOFMEMORY;
+
+ VirtualLock (header, TC_VOLUME_HEADER_EFFECTIVE_SIZE);
+
+
+ fieldPos = (byte *) header + TC_HEADER_OFFSET_ENCRYPTED_AREA_START;
+
+ offset.QuadPart = deviceSize - TC_VOLUME_HEADER_GROUP_SIZE;
+
+ if (SetFilePointerEx (dev, offset, NULL, FILE_BEGIN) == 0
+ || !ReadEffectiveVolumeHeader (TRUE, dev, header, &n) || n < TC_VOLUME_HEADER_EFFECTIVE_SIZE)
+ {
+ nStatus = ERR_OS_ERROR;
+ goto closing_seq;
+ }
+
+
+ DecryptBuffer (header + HEADER_ENCRYPTED_DATA_OFFSET, HEADER_ENCRYPTED_DATA_SIZE, headerCryptoInfo);
+
+ if (GetHeaderField32 (header, TC_HEADER_OFFSET_MAGIC) != 0x54525545)
+ {
+ nStatus = ERR_PARAMETER_INCORRECT;
+ goto closing_seq;
+ }
+
+ mputInt64 (fieldPos, (masterCryptoInfo->EncryptedAreaStart.Value));
+ mputInt64 (fieldPos, (masterCryptoInfo->EncryptedAreaLength.Value));
+
+
+ headerCrc32 = GetCrc32 (header + TC_HEADER_OFFSET_MAGIC, TC_HEADER_OFFSET_HEADER_CRC - TC_HEADER_OFFSET_MAGIC);
+ fieldPos = (byte *) header + TC_HEADER_OFFSET_HEADER_CRC;
+ mputLong (fieldPos, headerCrc32);
+
+ EncryptBuffer (header + HEADER_ENCRYPTED_DATA_OFFSET, HEADER_ENCRYPTED_DATA_SIZE, headerCryptoInfo);
+
+
+ if (SetFilePointerEx (dev, offset, NULL, FILE_BEGIN) == 0
+ || !WriteEffectiveVolumeHeader (TRUE, dev, header))
+ {
+ nStatus = ERR_OS_ERROR;
+ goto closing_seq;
+ }
+
+
+closing_seq:
+
+ dwError = GetLastError();
+
+ burn (header, TC_VOLUME_HEADER_EFFECTIVE_SIZE);
+ VirtualUnlock (header, TC_VOLUME_HEADER_EFFECTIVE_SIZE);
+ TCfree (header);
+
+ if (nStatus != ERR_SUCCESS)
+ SetLastError (dwError);
+
+ return nStatus;
+}
+
+
+static HANDLE OpenPartitionVolume (const char *devName,
+ BOOL bExclusiveRequired,
+ BOOL bSharedRequired,
+ BOOL bSharedRequiresConfirmation,
+ BOOL bShowAlternativeSteps,
+ BOOL bSilent)
+{
+ HANDLE dev = INVALID_HANDLE_VALUE;
+ int retryCount = 0;
+
+ if (bExclusiveRequired)
+ bSharedRequired = FALSE;
+
+ if (bExclusiveRequired || !bSharedRequired)
+ {
+ // Exclusive access
+ // Note that when exclusive access is denied, it is worth retrying (usually succeeds after a few tries).
+ while (dev == INVALID_HANDLE_VALUE && retryCount++ < EXCL_ACCESS_MAX_AUTO_RETRIES)
+ {
+ dev = CreateFile (devName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_WRITE_THROUGH, NULL);
+
+ if (retryCount > 1)
+ Sleep (EXCL_ACCESS_AUTO_RETRY_DELAY);
+ }
+ }
+
+ if (dev == INVALID_HANDLE_VALUE)
+ {
+ if (bExclusiveRequired)
+ {
+ if (!bSilent)
+ {
+ handleWin32Error (MainDlg);
+
+ if (bShowAlternativeSteps)
+ ShowInPlaceEncErrMsgWAltSteps ("INPLACE_ENC_CANT_ACCESS_OR_GET_INFO_ON_VOL_ALT", TRUE);
+ else
+ Error ("INPLACE_ENC_CANT_ACCESS_OR_GET_INFO_ON_VOL");
+ }
+ return INVALID_HANDLE_VALUE;
+ }
+
+ // Shared mode
+ dev = CreateFile (devName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_WRITE_THROUGH, NULL);
+ if (dev != INVALID_HANDLE_VALUE)
+ {
+ if (bSharedRequiresConfirmation
+ && !bSilent
+ && AskWarnNoYes ("DEVICE_IN_USE_INPLACE_ENC") == IDNO)
+ {
+ CloseHandle (dev);
+ return INVALID_HANDLE_VALUE;
+ }
+ }
+ else
+ {
+ if (!bSilent)
+ {
+ handleWin32Error (MainDlg);
+
+ if (bShowAlternativeSteps)
+ ShowInPlaceEncErrMsgWAltSteps ("INPLACE_ENC_CANT_ACCESS_OR_GET_INFO_ON_VOL_ALT", TRUE);
+ else
+ Error ("INPLACE_ENC_CANT_ACCESS_OR_GET_INFO_ON_VOL");
+ }
+ return INVALID_HANDLE_VALUE;
+ }
+ }
+
+ return dev;
+}
+
+
+static int DismountFileSystem (HANDLE dev,
+ int driveLetter,
+ BOOL bForcedAllowed,
+ BOOL bForcedRequiresConfirmation,
+ BOOL bSilent)
+{
+ int attempt;
+ BOOL bResult;
+ DWORD dwResult;
+
+ CloseVolumeExplorerWindows (MainDlg, driveLetter);
+
+ attempt = UNMOUNT_MAX_AUTO_RETRIES * 10;
+
+ while (!(bResult = DeviceIoControl (dev, FSCTL_LOCK_VOLUME, NULL, 0, NULL, 0, &dwResult, NULL))
+ && attempt > 0)
+ {
+ Sleep (UNMOUNT_AUTO_RETRY_DELAY);
+ attempt--;
+ }
+
+ if (!bResult)
+ {
+ if (!bForcedAllowed)
+ {
+ if (!bSilent)
+ ShowInPlaceEncErrMsgWAltSteps ("INPLACE_ENC_CANT_LOCK_OR_DISMOUNT_FILESYS", TRUE);
+
+ return ERR_DONT_REPORT;
+ }
+
+ if (bForcedRequiresConfirmation
+ && !bSilent
+ && AskWarnYesNo ("VOL_LOCK_FAILED_OFFER_FORCED_DISMOUNT") == IDNO)
+ {
+ return ERR_DONT_REPORT;
+ }
+ }
+
+ // Dismount the volume
+
+ attempt = UNMOUNT_MAX_AUTO_RETRIES * 10;
+
+ while (!(bResult = DeviceIoControl (dev, FSCTL_DISMOUNT_VOLUME, NULL, 0, NULL, 0, &dwResult, NULL))
+ && attempt > 0)
+ {
+ Sleep (UNMOUNT_AUTO_RETRY_DELAY);
+ attempt--;
+ }
+
+ if (!bResult)
+ {
+ if (!bSilent)
+ ShowInPlaceEncErrMsgWAltSteps ("INPLACE_ENC_CANT_LOCK_OR_DISMOUNT_FILESYS", TRUE);
+
+ return ERR_DONT_REPORT;
+ }
+
+ return ERR_SUCCESS;
+}
+
+
+// Easy-to-undo modification applied to conceal the NTFS filesystem (to prevent Windows and apps from
+// interfering with it until the volume has been fully encrypted). Note that this function will precisely
+// undo any modifications it made to the filesystem automatically if an error occurs when writing (including
+// physical drive defects).
+static int ConcealNTFS (HANDLE dev)
+{
+ char buf [TC_INITIAL_NTFS_CONCEAL_PORTION_SIZE];
+ DWORD nbrBytesProcessed, nbrBytesProcessed2;
+ int i;
+ LARGE_INTEGER offset;
+ DWORD dwError;
+
+ offset.QuadPart = 0;
+
+ if (SetFilePointerEx (dev, offset, NULL, FILE_BEGIN) == 0)
+ return ERR_OS_ERROR;
+
+ if (ReadFile (dev, buf, TC_INITIAL_NTFS_CONCEAL_PORTION_SIZE, &nbrBytesProcessed, NULL) == 0)
+ return ERR_OS_ERROR;
+
+ for (i = 0; i < TC_INITIAL_NTFS_CONCEAL_PORTION_SIZE; i++)
+ buf[i] ^= TC_NTFS_CONCEAL_CONSTANT;
+
+ offset.QuadPart = 0;
+
+ if (SetFilePointerEx (dev, offset, NULL, FILE_BEGIN) == 0)
+ return ERR_OS_ERROR;
+
+ if (WriteFile (dev, buf, TC_INITIAL_NTFS_CONCEAL_PORTION_SIZE, &nbrBytesProcessed, NULL) == 0)
+ {
+ // One or more of the sectors is/are probably damaged and cause write errors.
+ // We must undo the modifications we made.
+
+ dwError = GetLastError();
+
+ for (i = 0; i < TC_INITIAL_NTFS_CONCEAL_PORTION_SIZE; i++)
+ buf[i] ^= TC_NTFS_CONCEAL_CONSTANT;
+
+ offset.QuadPart = 0;
+
+ do
+ {
+ Sleep (1);
+ }
+ while (SetFilePointerEx (dev, offset, NULL, FILE_BEGIN) == 0
+ || WriteFile (dev, buf, TC_INITIAL_NTFS_CONCEAL_PORTION_SIZE, &nbrBytesProcessed2, NULL) == 0);
+
+ SetLastError (dwError);
+
+ return ERR_OS_ERROR;
+ }
+
+ return ERR_SUCCESS;
+}
+
+
+void ShowInPlaceEncErrMsgWAltSteps (char *iniStrId, BOOL bErr)
+{
+ wchar_t msg[30000];
+
+ wcscpy (msg, GetString (iniStrId));
+
+ wcscat (msg, L"\n\n\n");
+ wcscat (msg, GetString ("INPLACE_ENC_ALTERNATIVE_STEPS"));
+
+ if (bErr)
+ ErrorDirect (msg);
+ else
+ WarningDirect (msg);
+}
+
+
+static void ExportProgressStats (__int64 bytesDone, __int64 totalSize)
+{
+ NonSysInplaceEncBytesDone = bytesDone;
+ NonSysInplaceEncTotalSize = totalSize;
+}
+
+
+void SetNonSysInplaceEncUIStatus (int nonSysInplaceEncStatus)
+{
+ NonSysInplaceEncStatus = nonSysInplaceEncStatus;
+}
+
+
+BOOL SaveNonSysInPlaceEncSettings (int delta, WipeAlgorithmId newWipeAlgorithm)
+{
+ int count;
+ char str[32];
+ WipeAlgorithmId savedWipeAlgorithm = TC_WIPE_NONE;
+
+ if (delta == 0)
+ return TRUE;
+
+ count = LoadNonSysInPlaceEncSettings (&savedWipeAlgorithm) + delta;
+
+ if (count < 1)
+ {
+ RemoveNonSysInPlaceEncNotifications();
+ return TRUE;
+ }
+ else
+ {
+ if (newWipeAlgorithm != TC_WIPE_NONE)
+ {
+ sprintf (str, "%d", (int) newWipeAlgorithm);
+
+ SaveBufferToFile (str, GetConfigPath (TC_APPD_FILENAME_NONSYS_INPLACE_ENC_WIPE), strlen(str), FALSE);
+ }
+ else if (FileExists (GetConfigPath (TC_APPD_FILENAME_NONSYS_INPLACE_ENC_WIPE)))
+ {
+ remove (GetConfigPath (TC_APPD_FILENAME_NONSYS_INPLACE_ENC_WIPE));
+ }
+
+ sprintf (str, "%d", count);
+
+ return SaveBufferToFile (str, GetConfigPath (TC_APPD_FILENAME_NONSYS_INPLACE_ENC), strlen(str), FALSE);
+ }
+}
+
+
+// Repairs damaged sectors (i.e. those with read errors) by zeroing them.
+// Note that this operating fails if there are any write errors.
+int ZeroUnreadableSectors (HANDLE dev, LARGE_INTEGER startOffset, int64 size, int sectorSize, uint64 *zeroedSectorCount)
+{
+ int nStatus;
+ DWORD n;
+ int64 sectorCount;
+ LARGE_INTEGER workOffset;
+ byte *sectorBuffer = NULL;
+ DWORD dwError;
+
+ workOffset.QuadPart = startOffset.QuadPart;
+
+ sectorBuffer = (byte *) TCalloc (sectorSize);
+
+ if (!sectorBuffer)
+ return ERR_OUTOFMEMORY;
+
+ if (SetFilePointerEx (dev, startOffset, NULL, FILE_BEGIN) == 0)
+ {
+ nStatus = ERR_OS_ERROR;
+ goto closing_seq;
+ }
+
+
+ for (sectorCount = size / sectorSize; sectorCount > 0; --sectorCount)
+ {
+ if (ReadFile (dev, sectorBuffer, sectorSize, &n, NULL) == 0)
+ {
+ memset (sectorBuffer, 0, sectorSize);
+
+ if (SetFilePointerEx (dev, workOffset, NULL, FILE_BEGIN) == 0)
+ {
+ nStatus = ERR_OS_ERROR;
+ goto closing_seq;
+ }
+
+ if (WriteFile (dev, sectorBuffer, sectorSize, &n, NULL) == 0)
+ {
+ nStatus = ERR_OS_ERROR;
+ goto closing_seq;
+ }
+ ++(*zeroedSectorCount);
+ }
+
+ workOffset.QuadPart += n;
+ }
+
+ nStatus = ERR_SUCCESS;
+
+closing_seq:
+
+ dwError = GetLastError();
+
+ if (sectorBuffer != NULL)
+ TCfree (sectorBuffer);
+
+ if (nStatus != ERR_SUCCESS)
+ SetLastError (dwError);
+
+ return nStatus;
+}
+
+
+static int OpenBackupHeader (HANDLE dev, const char *devicePath, Password *password, PCRYPTO_INFO *retMasterCryptoInfo, CRYPTO_INFO *headerCryptoInfo, __int64 deviceSize)
+{
+ LARGE_INTEGER offset;
+ DWORD n;
+ int nStatus = ERR_SUCCESS;
+ char *header;
+ DWORD dwError;
+
+ header = (char *) TCalloc (TC_VOLUME_HEADER_EFFECTIVE_SIZE);
+ if (!header)
+ return ERR_OUTOFMEMORY;
+
+ VirtualLock (header, TC_VOLUME_HEADER_EFFECTIVE_SIZE);
+
+
+
+ offset.QuadPart = deviceSize - TC_VOLUME_HEADER_GROUP_SIZE;
+
+ if (SetFilePointerEx (dev, offset, NULL, FILE_BEGIN) == 0
+ || !ReadEffectiveVolumeHeader (TRUE, dev, (byte *) header, &n) || n < TC_VOLUME_HEADER_EFFECTIVE_SIZE)
+ {
+ nStatus = ERR_OS_ERROR;
+ goto closing_seq;
+ }
+
+
+ nStatus = ReadVolumeHeader (FALSE, header, password, retMasterCryptoInfo, headerCryptoInfo);
+ if (nStatus != ERR_SUCCESS)
+ goto closing_seq;
+
+
+closing_seq:
+
+ dwError = GetLastError();
+
+ burn (header, TC_VOLUME_HEADER_EFFECTIVE_SIZE);
+ VirtualUnlock (header, TC_VOLUME_HEADER_EFFECTIVE_SIZE);
+ TCfree (header);
+
+ dwError = GetLastError();
+
+ if (nStatus != ERR_SUCCESS)
+ SetLastError (dwError);
+
+ return nStatus;
+}
+
+
+static BOOL GetFreeClusterBeforeThreshold (HANDLE volumeHandle, int64 *freeCluster, int64 clusterThreshold)
+{
+ const int bitmapSize = 65536;
+ byte bitmapBuffer[bitmapSize + sizeof (VOLUME_BITMAP_BUFFER)];
+ VOLUME_BITMAP_BUFFER *bitmap = (VOLUME_BITMAP_BUFFER *) bitmapBuffer;
+ STARTING_LCN_INPUT_BUFFER startLcn;
+ startLcn.StartingLcn.QuadPart = 0;
+
+ DWORD bytesReturned;
+ while (DeviceIoControl (volumeHandle, FSCTL_GET_VOLUME_BITMAP, &startLcn, sizeof (startLcn), &bitmapBuffer, sizeof (bitmapBuffer), &bytesReturned, NULL)
+ || GetLastError() == ERROR_MORE_DATA)
+ {
+ for (int64 bitmapIndex = 0; bitmapIndex < min (bitmapSize, (bitmap->BitmapSize.QuadPart / 8)); ++bitmapIndex)
+ {
+ if (bitmap->StartingLcn.QuadPart + bitmapIndex * 8 >= clusterThreshold)
+ goto err;
+
+ if (bitmap->Buffer[bitmapIndex] != 0xff)
+ {
+ for (int bit = 0; bit < 8; ++bit)
+ {
+ if ((bitmap->Buffer[bitmapIndex] & (1 << bit)) == 0)
+ {
+ *freeCluster = bitmap->StartingLcn.QuadPart + bitmapIndex * 8 + bit;
+
+ if (*freeCluster >= clusterThreshold)
+ goto err;
+
+ return TRUE;
+ }
+ }
+ }
+ }
+
+ startLcn.StartingLcn.QuadPart += min (bitmapSize * 8, bitmap->BitmapSize.QuadPart);
+ }
+
+err:
+ SetLastError (ERROR_DISK_FULL);
+ return FALSE;
+}
+
+
+static BOOL MoveClustersBeforeThresholdInDir (HANDLE volumeHandle, const wstring &directory, int64 clusterThreshold)
+{
+ WIN32_FIND_DATAW findData;
+
+ HANDLE findHandle = FindFirstFileW (((directory.size() <= 3 ? L"" : L"\\\\?\\") + directory + L"\\*").c_str(), &findData);
+ if (findHandle == INVALID_HANDLE_VALUE)
+ return TRUE; // Error ignored
+
+ finally_do_arg (HANDLE, findHandle, { FindClose (finally_arg); });
+
+ // Find all files and directories
+ do
+ {
+ if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+ {
+ wstring subDir = findData.cFileName;
+
+ if (subDir == L"." || subDir == L"..")
+ continue;
+
+ if (!MoveClustersBeforeThresholdInDir (volumeHandle, directory + L"\\" + subDir, clusterThreshold))
+ return FALSE;
+ }
+
+ DWORD access = FILE_READ_ATTRIBUTES;
+
+ if (findData.dwFileAttributes & FILE_ATTRIBUTE_ENCRYPTED)
+ access = FILE_READ_DATA;
+
+ HANDLE fsObject = CreateFileW ((directory + L"\\" + findData.cFileName).c_str(), access, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
+ if (fsObject == INVALID_HANDLE_VALUE)
+ continue;
+
+ finally_do_arg (HANDLE, fsObject, { CloseHandle (finally_arg); });
+
+ STARTING_VCN_INPUT_BUFFER startVcn;
+ startVcn.StartingVcn.QuadPart = 0;
+ RETRIEVAL_POINTERS_BUFFER retPointers;
+ DWORD bytesReturned;
+
+ // Find clusters allocated beyond the threshold
+ while (DeviceIoControl (fsObject, FSCTL_GET_RETRIEVAL_POINTERS, &startVcn, sizeof (startVcn), &retPointers, sizeof (retPointers), &bytesReturned, NULL)
+ || GetLastError() == ERROR_MORE_DATA)
+ {
+ if (retPointers.ExtentCount == 0)
+ break;
+
+ if (retPointers.Extents[0].Lcn.QuadPart != -1)
+ {
+ int64 extentStartCluster = retPointers.Extents[0].Lcn.QuadPart;
+ int64 extentLen = retPointers.Extents[0].NextVcn.QuadPart - retPointers.StartingVcn.QuadPart;
+ int64 extentEndCluster = extentStartCluster + extentLen - 1;
+
+ if (extentEndCluster >= clusterThreshold)
+ {
+ // Move clusters before the threshold
+ for (int64 movedCluster = max (extentStartCluster, clusterThreshold); movedCluster <= extentEndCluster; ++movedCluster)
+ {
+ for (int retry = 0; ; ++retry)
+ {
+ MOVE_FILE_DATA moveData;
+
+ if (GetFreeClusterBeforeThreshold (volumeHandle, &moveData.StartingLcn.QuadPart, clusterThreshold))
+ {
+ moveData.FileHandle = fsObject;
+ moveData.StartingVcn.QuadPart = movedCluster - extentStartCluster + retPointers.StartingVcn.QuadPart;
+ moveData.ClusterCount = 1;
+
+ if (DeviceIoControl (volumeHandle, FSCTL_MOVE_FILE, &moveData, sizeof (moveData), NULL, 0, &bytesReturned, NULL))
+ break;
+ }
+
+ if (retry > 600)
+ return FALSE;
+
+ // There are possible race conditions as we work on a live filesystem
+ Sleep (100);
+ }
+ }
+ }
+ }
+
+ startVcn.StartingVcn = retPointers.Extents[0].NextVcn;
+ }
+
+ } while (FindNextFileW (findHandle, &findData));
+
+ return TRUE;
+}
+
+
+BOOL MoveClustersBeforeThreshold (HANDLE volumeHandle, PWSTR volumeDevicePath, int64 clusterThreshold)
+{
+ int drive = GetDiskDeviceDriveLetter (volumeDevicePath);
+ if (drive == -1)
+ {
+ SetLastError (ERROR_INVALID_PARAMETER);
+ return FALSE;
+ }
+
+ wstring volumeRoot = L"X:";
+ volumeRoot[0] = L'A' + (wchar_t) drive;
+
+ return MoveClustersBeforeThresholdInDir (volumeHandle, volumeRoot, clusterThreshold);
+}
diff --git a/src/Format/InPlace.h b/src/Format/InPlace.h new file mode 100644 index 00000000..82bae5b4 --- /dev/null +++ b/src/Format/InPlace.h @@ -0,0 +1,45 @@ +/*
+ Copyright (c) 2008-2010 TrueCrypt Developers Association. All rights reserved.
+
+ Governed by the TrueCrypt License 3.0 the full text of which is contained in
+ the file License.txt included in TrueCrypt binary and source code distribution
+ packages.
+*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "Format.h"
+
+enum nonsys_inplace_enc_status
+{
+ NONSYS_INPLACE_ENC_STATUS_NONE = 0,
+ NONSYS_INPLACE_ENC_STATUS_PREPARING,
+ NONSYS_INPLACE_ENC_STATUS_RESIZING,
+ NONSYS_INPLACE_ENC_STATUS_ENCRYPTING,
+ NONSYS_INPLACE_ENC_STATUS_FINALIZING,
+ NONSYS_INPLACE_ENC_STATUS_PAUSED,
+ NONSYS_INPLACE_ENC_STATUS_FINISHED,
+ NONSYS_INPLACE_ENC_STATUS_ERROR
+};
+
+BOOL CheckRequirementsForNonSysInPlaceEnc (const char *devicePath, BOOL silent);
+int EncryptPartitionInPlaceBegin (volatile FORMAT_VOL_PARAMETERS *volParams, volatile HANDLE *outHandle, WipeAlgorithmId wipeAlgorithm);
+int EncryptPartitionInPlaceResume (HANDLE dev, volatile FORMAT_VOL_PARAMETERS *volParams, WipeAlgorithmId wipeAlgorithm, volatile BOOL *bTryToCorrectReadErrors);
+void ShowInPlaceEncErrMsgWAltSteps (char *iniStrId, BOOL bErr);
+void SetNonSysInplaceEncUIStatus (int nonSysInplaceEncStatus);
+int FastVolumeHeaderUpdate (HANDLE dev, CRYPTO_INFO *headerCryptoInfo, CRYPTO_INFO *masterCryptoInfo, __int64 deviceSize);
+
+static HANDLE OpenPartitionVolume (const char *devName, BOOL bExclusiveRequired, BOOL bSharedRequired, BOOL bSharedRequiresConfirmation, BOOL bShowAlternativeSteps, BOOL bSilent);
+static int DismountFileSystem (HANDLE dev, int driveLetter, BOOL bForcedAllowed, BOOL bForcedRequiresConfirmation, BOOL bSilent);
+static int ConcealNTFS (HANDLE dev);
+BOOL SaveNonSysInPlaceEncSettings (int delta, WipeAlgorithmId wipeAlgorithm);
+static void ExportProgressStats (__int64 bytesDone, __int64 totalSize);
+int ZeroUnreadableSectors (HANDLE dev, LARGE_INTEGER startOffset, int64 size, int sectorSize, uint64 *zeroedSectorCount);
+static int OpenBackupHeader (HANDLE dev, const char *devicePath, Password *password, PCRYPTO_INFO *retCryptoInfo, CRYPTO_INFO *headerCryptoInfo, __int64 deviceSize);
+BOOL MoveClustersBeforeThreshold (HANDLE volumeHandle, PWSTR volumeDevicePath, int64 clusterThreshold);
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/src/Format/Resource.h b/src/Format/Resource.h new file mode 100644 index 00000000..61a38332 --- /dev/null +++ b/src/Format/Resource.h @@ -0,0 +1,151 @@ +//{{NO_DEPENDENCIES}}
+// Microsoft Visual C++ generated include file.
+// Used by Format.rc
+//
+#define IDR_FORMAT_TLB 1
+#define IDD_VOL_CREATION_WIZARD_DLG 101
+#define IDD_CIPHER_PAGE_DLG 102
+#define IDD_SIZE_PAGE_DLG 103
+#define IDD_PASSWORD_PAGE_DLG 104
+#define IDD_VOLUME_LOCATION_PAGE_DLG 105
+#define IDD_FORMAT_PAGE_DLG 106
+#define IDD_INTRO_PAGE_DLG 107
+#define IDD_INFO_PAGE_DLG 108
+#define IDD_HIDVOL_HOST_FILL_PAGE_DLG 109
+#define IDD_HIDDEN_VOL_WIZARD_MODE_PAGE_DLG 110
+#define IDD_PASSWORD_ENTRY_PAGE_DLG 111
+#define IDS_UACSTRING_FMT 112
+#define IDD_VOLUME_TYPE_PAGE_DLG 113
+#define IDR_FORMAT_RSRC_HEADER 114
+#define IDD_SYSENC_SPAN_PAGE_DLG 115
+#define IDB_WIZARD 116
+#define IDD_SYSENC_RESCUE_DISK_CREATION_DLG 117
+#define IDD_SYSENC_COLLECTING_RANDOM_DATA_DLG 118
+#define IDD_SYSENC_MULTI_BOOT_MODE_PAGE_DLG 119
+#define IDD_SYSENC_RESCUE_DISK_BURN_PAGE_DLG 120
+#define IDD_SYSENC_WIPE_MODE_PAGE_DLG 121
+#define IDD_INPLACE_ENCRYPTION_PAGE_DLG 122
+#define IDD_SYSENC_KEYS_GEN_PAGE_DLG 123
+#define IDD_UNIVERSAL_DUAL_CHOICE_PAGE_DLG 124
+#define IDD_SYSENC_DRIVE_ANALYSIS_PAGE_DLG 125
+#define IDD_SYSENC_TYPE_PAGE_DLG 126
+#define IDD_SYSENC_HIDDEN_OS_REQ_CHECK_PAGE_DLG 127
+#define IDD_DEVICE_WIPE_PAGE_DLG 128
+#define IDD_DEVICE_WIPE_MODE_PAGE_DLG 129
+#define IDD_DEVICE_TRANSFORM_MODE_DLG 130
+#define IDD_EXPANDED_LIST_SELECT_PAGE_DLG 131
+#define IDC_BOX_TITLE 1000
+#define IDC_RESCUE_DISK_ISO_PATH 1001
+#define IDC_COMBO_BOX 1002
+#define IDC_BOX_HELP 1003
+#define IDC_PASSWORD 1004
+#define IDC_BROWSE 1005
+#define IDC_BOX_HELP2 1006
+#define IDC_COMBO_BOX_HASH 1007
+#define IDC_COMBO_BOX_HASH_ALGO 1008
+#define IDC_SPACE_LEFT 1009
+#define IDC_VERIFY 1010
+#define IDC_KB 1011
+#define IDC_NO_HISTORY 1012
+#define IDC_MB 1013
+#define IDC_PROGRESS_BAR 1014
+#define IDC_GB 1015
+#define IDC_ABORT_BUTTON 1016
+#define IDC_HEADER_KEY 1017
+#define IDC_LIST_BOX 1018
+#define IDC_DISK_KEY 1019
+#define IDC_RANDOM_BYTES 1020
+#define IDC_CIPHER_TEST 1021
+#define IDC_BENCHMARK 1022
+#define IDC_QUICKFORMAT 1023
+#define IDC_BYTESWRITTEN 1024
+#define IDC_WRITESPEED 1025
+#define IDC_KEY_FILES 1026
+#define IDC_TIMEREMAIN 1027
+#define IDC_CLUSTERSIZE 1028
+#define IDC_FILESYS 1029
+#define IDC_SHOW_KEYS 1030
+#define IDC_STD_VOL 1031
+#define IDC_HIDDEN_VOL 1032
+#define IDC_HIDDEN_VOL_HELP 1033
+#define IDC_OPEN_OUTER_VOLUME 1034
+#define IDC_HIDVOL_WIZ_MODE_FULL 1035
+#define IDC_HIDVOL_WIZ_MODE_DIRECT 1036
+#define IDC_PASSWORD_DIRECT 1037
+#define IDC_SIZEBOX 1038
+#define IDC_SELECT_VOLUME_LOCATION 1039
+#define IDC_NEXT 1040
+#define IDC_PREV 1041
+#define IDT_ENCRYPTION_ALGO 1042
+#define IDT_HASH_ALGO 1043
+#define IDT_FORMAT_OPTIONS 1044
+#define IDT_FILESYSTEM 1045
+#define IDT_CLUSTER 1046
+#define IDT_RANDOM_POOL 1047
+#define IDT_HEADER_KEY 1048
+#define IDT_MASTER_KEY 1049
+#define IDT_DONE 1050
+#define IDT_SPEED 1051
+#define IDT_LEFT 1052
+#define IDT_CONFIRM 1053
+#define IDT_PASSWORD 1054
+#define IDC_SHOW_PASSWORD_SINGLE 1055
+#define IDC_SHOW_PASSWORD 1056
+#define IDC_LINK_MORE_INFO_ABOUT_CIPHER 1057
+#define IDC_LINK_HASH_INFO 1058
+#define IDC_POS_BOX 1059
+#define IDC_BITMAP_WIZARD 1060
+#define IDC_FILE_CONTAINER 1061
+#define IDC_NONSYS_DEVICE 1062
+#define IDC_SYS_DEVICE 1063
+#define IDT_FILE_CONTAINER 1064
+#define IDT_NON_SYS_DEVICE 1065
+#define IDT_SYS_DEVICE 1066
+#define IDC_WHOLE_SYS_DRIVE 1067
+#define IDC_SYS_PARTITION 1068
+#define IDT_WHOLE_SYS_DRIVE 1069
+#define IDT_SYS_PARTITION 1070
+#define IDT_RESCUE_DISK_INFO 1071
+#define IDC_MORE_INFO 1072
+#define IDC_MORE_INFO_ON_SYS_ENCRYPTION 1073
+#define IDT_COLLECTING_RANDOM_DATA_NOTE 1074
+#define IDC_MORE_INFO_ON_CONTAINERS 1075
+#define IDC_SINGLE_BOOT 1076
+#define IDC_MULTI_BOOT 1077
+#define IDT_MULTI_BOOT 1078
+#define IDT_SINGLE_BOOT 1079
+#define IDC_SYS_POOL_CONTENTS 1080
+#define IDT_PARTIAL_POOL_CONTENTS 1081
+#define IDC_DOWNLOAD_CD_BURN_SOFTWARE 1082
+#define IDT_RESCUE_DISK_BURN_INFO 1083
+#define IDT_WIPE_MODE_INFO 1084
+#define IDC_WIPE_MODE 1085
+#define IDC_SELECT 1086
+#define IDT_SYSENC_KEYS_GEN_INFO 1087
+#define IDC_DISPLAY_KEYS 1088
+#define IDC_PAUSE 1089
+#define IDT_WIPE_MODE 1090
+#define IDC_MORE_INFO_SYS_ENCRYPTION 1091
+#define IDC_BOX_HELP_NORMAL_VOL 1092
+#define IDT_STATUS 1093
+#define IDT_PROGRESS 1094
+#define IDT_SYSENC_DRIVE_ANALYSIS_INFO 1095
+#define IDC_SYSENC_NORMAL 1096
+#define IDC_SYSENC_HIDDEN 1097
+#define IDC_BOX_HELP_SYSENC_NORMAL 1098
+#define IDC_HIDDEN_SYSENC_INFO_LINK 1099
+#define IDT_PASS 1100
+#define IDC_DEVICE_TRANSFORM_MODE_FORMAT 1101
+#define IDC_DEVICE_TRANSFORM_MODE_INPLACE 1102
+
+// Next default values for new objects
+//
+#ifdef APSTUDIO_INVOKED
+#ifndef APSTUDIO_READONLY_SYMBOLS
+#define _APS_NO_MFC 1
+#define _APS_NEXT_RESOURCE_VALUE 132
+#define _APS_NEXT_COMMAND_VALUE 40001
+#define _APS_NEXT_CONTROL_VALUE 1103
+#define _APS_NEXT_SYMED_VALUE 101
+#endif
+#endif
diff --git a/src/Format/Tcformat.c b/src/Format/Tcformat.c new file mode 100644 index 00000000..89e5bbe9 --- /dev/null +++ b/src/Format/Tcformat.c @@ -0,0 +1,9004 @@ +/*
+ Legal Notice: Some portions of the source code contained in this file were
+ derived 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 all other portions
+ of this file are Copyright (c) 2003-2010 TrueCrypt Developers Association
+ and are governed by the TrueCrypt License 3.0 the full text of which is
+ contained in the file License.txt included in TrueCrypt binary and source
+ code distribution packages. */
+
+#include "Tcdefs.h"
+
+#include <stdlib.h>
+#include <limits.h>
+#include <time.h>
+#include <errno.h>
+#include <io.h>
+#include <sys/stat.h>
+#include <shlobj.h>
+
+#include "Crypto.h"
+#include "Apidrvr.h"
+#include "Dlgcode.h"
+#include "Language.h"
+#include "Combo.h"
+#include "Registry.h"
+#include "Boot/Windows/BootDefs.h"
+#include "Common/Common.h"
+#include "Common/BootEncryption.h"
+#include "Common/Dictionary.h"
+#include "Common/Endian.h"
+#include "Common/resource.h"
+#include "Platform/Finally.h"
+#include "Platform/ForEach.h"
+#include "Random.h"
+#include "Fat.h"
+#include "InPlace.h"
+#include "Resource.h"
+#include "TcFormat.h"
+#include "Format.h"
+#include "FormatCom.h"
+#include "Password.h"
+#include "Progress.h"
+#include "Tests.h"
+#include "Cmdline.h"
+#include "Volumes.h"
+#include "Wipe.h"
+#include "Xml.h"
+
+using namespace TrueCrypt;
+
+enum wizard_pages
+{
+ /* IMPORTANT: IF YOU ADD/REMOVE/MOVE ANY PAGES THAT ARE RELATED TO SYSTEM ENCRYPTION,
+ REVISE THE 'DECOY_OS_INSTRUCTIONS_PORTION_??' STRINGS! */
+
+ INTRO_PAGE,
+ SYSENC_TYPE_PAGE,
+ SYSENC_HIDDEN_OS_REQ_CHECK_PAGE,
+ SYSENC_SPAN_PAGE,
+ SYSENC_PRE_DRIVE_ANALYSIS_PAGE,
+ SYSENC_DRIVE_ANALYSIS_PAGE,
+ SYSENC_MULTI_BOOT_MODE_PAGE,
+ SYSENC_MULTI_BOOT_SYS_EQ_BOOT_PAGE,
+ SYSENC_MULTI_BOOT_NBR_SYS_DRIVES_PAGE,
+ SYSENC_MULTI_BOOT_ADJACENT_SYS_PAGE,
+ SYSENC_MULTI_BOOT_NONWIN_BOOT_LOADER_PAGE,
+ SYSENC_MULTI_BOOT_OUTCOME_PAGE,
+ VOLUME_TYPE_PAGE,
+ HIDDEN_VOL_WIZARD_MODE_PAGE,
+ VOLUME_LOCATION_PAGE,
+ DEVICE_TRANSFORM_MODE_PAGE,
+ HIDDEN_VOL_HOST_PRE_CIPHER_PAGE,
+ HIDDEN_VOL_PRE_CIPHER_PAGE,
+ CIPHER_PAGE,
+ SIZE_PAGE,
+ HIDDEN_VOL_HOST_PASSWORD_PAGE,
+ PASSWORD_PAGE,
+ FILESYS_PAGE,
+ SYSENC_COLLECTING_RANDOM_DATA_PAGE,
+ SYSENC_KEYS_GEN_PAGE,
+ SYSENC_RESCUE_DISK_CREATION_PAGE,
+ SYSENC_RESCUE_DISK_BURN_PAGE,
+ SYSENC_RESCUE_DISK_VERIFIED_PAGE,
+ SYSENC_WIPE_MODE_PAGE,
+ SYSENC_PRETEST_INFO_PAGE,
+ SYSENC_PRETEST_RESULT_PAGE,
+ SYSENC_ENCRYPTION_PAGE,
+ NONSYS_INPLACE_ENC_RESUME_PASSWORD_PAGE,
+ NONSYS_INPLACE_ENC_RESUME_PARTITION_SEL_PAGE,
+ NONSYS_INPLACE_ENC_RAND_DATA_PAGE,
+ NONSYS_INPLACE_ENC_WIPE_MODE_PAGE,
+ NONSYS_INPLACE_ENC_ENCRYPTION_PAGE,
+ NONSYS_INPLACE_ENC_ENCRYPTION_FINISHED_PAGE,
+ FORMAT_PAGE,
+ FORMAT_FINISHED_PAGE,
+ SYSENC_HIDDEN_OS_INITIAL_INFO_PAGE,
+ SYSENC_HIDDEN_OS_WIPE_INFO_PAGE,
+ DEVICE_WIPE_MODE_PAGE,
+ DEVICE_WIPE_PAGE
+};
+
+#define TIMER_INTERVAL_RANDVIEW 30
+#define TIMER_INTERVAL_SYSENC_PROGRESS 30
+#define TIMER_INTERVAL_NONSYS_INPLACE_ENC_PROGRESS 30
+#define TIMER_INTERVAL_SYSENC_DRIVE_ANALYSIS_PROGRESS 100
+#define TIMER_INTERVAL_WIPE_PROGRESS 30
+#define TIMER_INTERVAL_KEYB_LAYOUT_GUARD 10
+
+enum sys_encryption_cmd_line_switches
+{
+ SYSENC_COMMAND_NONE = 0,
+ SYSENC_COMMAND_RESUME,
+ SYSENC_COMMAND_STARTUP_SEQ_RESUME,
+ SYSENC_COMMAND_ENCRYPT,
+ SYSENC_COMMAND_DECRYPT,
+ SYSENC_COMMAND_CREATE_HIDDEN_OS,
+ SYSENC_COMMAND_CREATE_HIDDEN_OS_ELEV
+};
+
+typedef struct
+{
+ int NumberOfSysDrives; // Number of drives that contain an operating system. -1: unknown, 1: one, 2: two or more
+ int MultipleSystemsOnDrive; // Multiple systems are installed on the drive where the currently running system resides. -1: unknown, 0: no, 1: yes
+ int BootLoaderLocation; // Boot loader (boot manager) installed in: 1: MBR/1st cylinder, 0: partition/bootsector: -1: unknown
+ int BootLoaderBrand; // -1: unknown, 0: Microsoft Windows, 1: any non-Windows boot manager/loader
+ int SystemOnBootDrive; // If the currently running operating system is installed on the boot drive. -1: unknown, 0: no, 1: yes
+} SYSENC_MULTIBOOT_CFG;
+
+#define SYSENC_PAUSE_RETRY_INTERVAL 100
+#define SYSENC_PAUSE_RETRIES 200
+
+// Expected duration of system drive analysis, in ms
+#define SYSENC_DRIVE_ANALYSIS_ETA (4*60000)
+
+BootEncryption *BootEncObj = NULL;
+BootEncryptionStatus BootEncStatus;
+
+HWND hCurPage = NULL; /* Handle to current wizard page */
+int nCurPageNo = -1; /* The current wizard page */
+int nLastPageNo = -1;
+volatile int WizardMode = DEFAULT_VOL_CREATION_WIZARD_MODE; /* IMPORTANT: Never change this value directly -- always use ChangeWizardMode() instead. */
+volatile BOOL bHiddenOS = FALSE; /* If TRUE, we are performing or (or supposed to perform) actions relating to an operating system installed in a hidden volume (i.e., encrypting a decoy OS partition or creating the outer/hidden volume for the hidden OS). To determine or set the phase of the process, call ChangeHiddenOSCreationPhase() and DetermineHiddenOSCreationPhase()) */
+BOOL bDirectSysEncMode = FALSE;
+BOOL bDirectSysEncModeCommand = SYSENC_COMMAND_NONE;
+BOOL DirectDeviceEncMode = FALSE;
+BOOL DirectNonSysInplaceEncResumeMode = FALSE;
+BOOL DirectPromptNonSysInplaceEncResumeMode = FALSE;
+volatile BOOL bInPlaceEncNonSys = FALSE; /* If TRUE, existing data on a non-system partition/volume are to be encrypted (for system encryption, this flag is ignored) */
+volatile BOOL bInPlaceEncNonSysResumed = FALSE; /* If TRUE, the wizard is supposed to resume (or has resumed) process of non-system in-place encryption. */
+volatile BOOL bFirstNonSysInPlaceEncResumeDone = FALSE;
+__int64 NonSysInplaceEncBytesDone = 0;
+__int64 NonSysInplaceEncTotalSize = 0;
+BOOL bDeviceTransformModeChoiceMade = FALSE; /* TRUE if the user has at least once manually selected the 'in-place' or 'format' option (on the 'device transform mode' page). */
+int nNeedToStoreFilesOver4GB = 0; /* Whether the user wants to be able to store files larger than 4GB on the volume: -1 = Undecided or error, 0 = No, 1 = Yes */
+int nVolumeEA = 1; /* Default encryption algorithm */
+BOOL bSystemEncryptionInProgress = FALSE; /* TRUE when encrypting/decrypting the system partition/drive (FALSE when paused). */
+BOOL bWholeSysDrive = FALSE; /* Whether to encrypt the entire system drive or just the system partition. */
+static BOOL bSystemEncryptionStatusChanged = FALSE; /* TRUE if this instance changed the value of SystemEncryptionStatus (it's set to FALSE each time the system encryption settings are saved to the config file). This value is to be treated as protected -- only the wizard can change this value (others may only read it). */
+volatile BOOL bSysEncDriveAnalysisInProgress = FALSE;
+volatile BOOL bSysEncDriveAnalysisTimeOutOccurred = FALSE;
+int SysEncDetectHiddenSectors = -1; /* Whether the user wants us to detect and encrypt the Host Protect Area (if any): -1 = Undecided or error, 0 = No, 1 = Yes */
+int SysEncDriveAnalysisStart;
+BOOL bDontVerifyRescueDisk = FALSE;
+BOOL bFirstSysEncResumeDone = FALSE;
+int nMultiBoot = 0; /* The number of operating systems installed on the computer, according to the user. 0: undetermined, 1: one, 2: two or more */
+volatile BOOL bHiddenVol = FALSE; /* If true, we are (or will be) creating a hidden volume. */
+volatile BOOL bHiddenVolHost = FALSE; /* If true, we are (or will be) creating the host volume (called "outer") for a hidden volume. */
+volatile BOOL bHiddenVolDirect = FALSE; /* If true, the wizard omits creating a host volume in the course of the process of hidden volume creation. */
+volatile BOOL bHiddenVolFinished = FALSE;
+int hiddenVolHostDriveNo = -1; /* Drive letter for the volume intended to host a hidden volume. */
+BOOL bRemovableHostDevice = FALSE; /* TRUE when creating a device/partition-hosted volume on a removable device. State undefined when creating file-hosted volumes. */
+int realClusterSize; /* Parameter used when determining the maximum possible size of a hidden volume. */
+int hash_algo = DEFAULT_HASH_ALGORITHM; /* Which PRF to use in header key derivation (PKCS #5) and in the RNG. */
+unsigned __int64 nUIVolumeSize = 0; /* The volume size. Important: This value is not in bytes. It has to be multiplied by nMultiplier. Do not use this value when actually creating the volume (it may chop off sector size, if it is not a multiple of 1024 bytes). */
+unsigned __int64 nVolumeSize = 0; /* The volume size, in bytes. */
+unsigned __int64 nHiddenVolHostSize = 0; /* Size of the hidden volume host, in bytes */
+__int64 nMaximumHiddenVolSize = 0; /* Maximum possible size of the hidden volume, in bytes */
+__int64 nbrFreeClusters = 0;
+int nMultiplier = BYTES_PER_MB; /* Size selection multiplier. */
+char szFileName[TC_MAX_PATH+1]; /* The file selected by the user */
+char szDiskFile[TC_MAX_PATH+1]; /* Fully qualified name derived from szFileName */
+char szRescueDiskISO[TC_MAX_PATH+1]; /* The filename and path to the Rescue Disk ISO file to be burned (for boot encryption) */
+BOOL bDeviceWipeInProgress = FALSE;
+volatile BOOL bTryToCorrectReadErrors = FALSE;
+volatile BOOL DiscardUnreadableEncryptedSectors = FALSE;
+
+volatile BOOL bVolTransformThreadCancel = FALSE; /* TRUE if the user cancels/pauses volume encryption/format */
+volatile BOOL bVolTransformThreadRunning = FALSE; /* Is the volume encryption/format thread running */
+volatile BOOL bVolTransformThreadToRun = FALSE; /* TRUE if the Format/Encrypt button has been clicked and we are proceeding towards launching the thread. */
+
+volatile BOOL bConfirmQuit = FALSE; /* If TRUE, the user is asked to confirm exit when he clicks the X icon, Exit, etc. */
+volatile BOOL bConfirmQuitSysEncPretest = FALSE;
+
+BOOL bDevice = FALSE; /* Is this a partition volume ? */
+
+BOOL showKeys = TRUE;
+volatile HWND hMasterKey = NULL; /* Text box showing hex dump of the master key */
+volatile HWND hHeaderKey = NULL; /* Text box showing hex dump of the header key */
+volatile HWND hRandPool = NULL; /* Text box showing hex dump of the random pool */
+volatile HWND hRandPoolSys = NULL; /* Text box showing hex dump of the random pool for system encryption */
+volatile HWND hPasswordInputField = NULL; /* Password input field */
+volatile HWND hVerifyPasswordInputField = NULL; /* Verify-password input field */
+
+HBITMAP hbmWizardBitmapRescaled = NULL;
+
+char OrigKeyboardLayout [8+1] = "00000409";
+BOOL bKeyboardLayoutChanged = FALSE; /* TRUE if the keyboard layout was changed to the standard US keyboard layout (from any other layout). */
+BOOL bKeybLayoutAltKeyWarningShown = FALSE; /* TRUE if the user has been informed that it is not possible to type characters by pressing keys while the right Alt key is held down. */
+
+#ifndef _DEBUG
+ BOOL bWarnDeviceFormatAdvanced = TRUE;
+#else
+ BOOL bWarnDeviceFormatAdvanced = FALSE;
+#endif
+
+BOOL bWarnOuterVolSuitableFileSys = TRUE;
+
+Password volumePassword; /* User password */
+char szVerify[MAX_PASSWORD + 1]; /* Tmp password buffer */
+char szRawPassword[MAX_PASSWORD + 1]; /* Password before keyfile was applied to it */
+
+BOOL bHistoryCmdLine = FALSE; /* History control is always disabled */
+BOOL ComServerMode = FALSE;
+
+int nPbar = 0; /* Control ID of progress bar:- for format code */
+
+char HeaderKeyGUIView [KEY_GUI_VIEW_SIZE];
+char MasterKeyGUIView [KEY_GUI_VIEW_SIZE];
+
+#define RANDPOOL_DISPLAY_COLUMNS 15
+#define RANDPOOL_DISPLAY_ROWS 8
+#define RANDPOOL_DISPLAY_BYTE_PORTION (RANDPOOL_DISPLAY_COLUMNS * RANDPOOL_DISPLAY_ROWS)
+#define RANDPOOL_DISPLAY_SIZE (RANDPOOL_DISPLAY_BYTE_PORTION * 3 + RANDPOOL_DISPLAY_ROWS + 2)
+unsigned char randPool [RANDPOOL_DISPLAY_BYTE_PORTION];
+unsigned char lastRandPool [RANDPOOL_DISPLAY_BYTE_PORTION];
+unsigned char outRandPoolDispBuffer [RANDPOOL_DISPLAY_SIZE];
+BOOL bDisplayPoolContents = TRUE;
+
+volatile BOOL bSparseFileSwitch = FALSE;
+volatile BOOL quickFormat = FALSE; /* WARNING: Meaning of this variable depends on bSparseFileSwitch. If bSparseFileSwitch is TRUE, this variable represents the sparse file flag. */
+volatile int fileSystem = FILESYS_NONE;
+volatile int clusterSize = 0;
+
+SYSENC_MULTIBOOT_CFG SysEncMultiBootCfg;
+wchar_t SysEncMultiBootCfgOutcome [4096] = {'N','/','A',0};
+volatile int NonSysInplaceEncStatus = NONSYS_INPLACE_ENC_STATUS_NONE;
+
+vector <HostDevice> DeferredNonSysInPlaceEncDevices;
+
+
+static BOOL ElevateWholeWizardProcess (string arguments)
+{
+ char modPath[MAX_PATH];
+
+ if (IsAdmin())
+ return TRUE;
+
+ if (!IsUacSupported())
+ return IsAdmin();
+
+ GetModuleFileName (NULL, modPath, sizeof (modPath));
+
+ if ((int)ShellExecute (MainDlg, "runas", modPath, (string("/q UAC ") + arguments).c_str(), NULL, SW_SHOWNORMAL) > 32)
+ {
+ exit (0);
+ }
+ else
+ {
+ Error ("UAC_INIT_ERROR");
+ return FALSE;
+ }
+}
+
+static void WipePasswordsAndKeyfiles (void)
+{
+ char tmp[MAX_PASSWORD+1];
+
+ // Attempt to wipe passwords stored in the input field buffers
+ memset (tmp, 'X', MAX_PASSWORD);
+ tmp [MAX_PASSWORD] = 0;
+ SetWindowText (hPasswordInputField, tmp);
+ SetWindowText (hVerifyPasswordInputField, tmp);
+
+ burn (&szVerify[0], sizeof (szVerify));
+ burn (&volumePassword, sizeof (volumePassword));
+ burn (&szRawPassword[0], sizeof (szRawPassword));
+
+ SetWindowText (hPasswordInputField, "");
+ SetWindowText (hVerifyPasswordInputField, "");
+
+ KeyFileRemoveAll (&FirstKeyFile);
+ KeyFileRemoveAll (&defaultKeyFilesParam.FirstKeyFile);
+}
+
+static void localcleanup (void)
+{
+ char tmp[RANDPOOL_DISPLAY_SIZE+1];
+
+ // System encryption
+
+ if (WizardMode == WIZARD_MODE_SYS_DEVICE
+ && InstanceHasSysEncMutex ())
+ {
+ try
+ {
+ BootEncStatus = BootEncObj->GetStatus();
+
+ if (BootEncStatus.SetupInProgress)
+ {
+ BootEncObj->AbortSetup ();
+ }
+ }
+ catch (...)
+ {
+ // NOP
+ }
+ }
+
+ // Mon-system in-place encryption
+
+ if (bInPlaceEncNonSys && (bVolTransformThreadRunning || bVolTransformThreadToRun))
+ {
+ NonSysInplaceEncPause ();
+ }
+
+ CloseNonSysInplaceEncMutex ();
+
+
+ // Device wipe
+
+ if (bDeviceWipeInProgress)
+ WipeAbort();
+
+
+ WipePasswordsAndKeyfiles ();
+
+ RandStop (TRUE);
+
+ burn (HeaderKeyGUIView, sizeof(HeaderKeyGUIView));
+ burn (MasterKeyGUIView, sizeof(MasterKeyGUIView));
+ burn (randPool, sizeof(randPool));
+ burn (lastRandPool, sizeof(lastRandPool));
+ burn (outRandPoolDispBuffer, sizeof(outRandPoolDispBuffer));
+ burn (szFileName, sizeof(szFileName));
+ burn (szDiskFile, sizeof(szDiskFile));
+
+ // Attempt to wipe the GUI fields showing portions of randpool, of the master and header keys
+ memset (tmp, 'X', sizeof(tmp));
+ tmp [sizeof(tmp)-1] = 0;
+ SetWindowText (hRandPool, tmp);
+ SetWindowText (hRandPoolSys, tmp);
+ SetWindowText (hMasterKey, tmp);
+ SetWindowText (hHeaderKey, tmp);
+
+ UnregisterRedTick (hInst);
+
+ // Delete buffered bitmaps (if any)
+ if (hbmWizardBitmapRescaled != NULL)
+ {
+ DeleteObject ((HGDIOBJ) hbmWizardBitmapRescaled);
+ hbmWizardBitmapRescaled = NULL;
+ }
+
+ // Cleanup common code resources
+ cleanup ();
+
+ if (BootEncObj != NULL)
+ {
+ delete BootEncObj;
+ BootEncObj = NULL;
+ }
+}
+
+static BOOL CALLBACK BroadcastSysEncCfgUpdateCallb (HWND hwnd, LPARAM lParam)
+{
+ if (GetWindowLongPtr (hwnd, GWLP_USERDATA) == (LONG_PTR) 'TRUE')
+ {
+ char name[1024] = { 0 };
+ GetWindowText (hwnd, name, sizeof (name) - 1);
+ if (hwnd != MainDlg && strstr (name, "TrueCrypt"))
+ {
+ PostMessage (hwnd, TC_APPMSG_SYSENC_CONFIG_UPDATE, 0, 0);
+ }
+ }
+ return TRUE;
+}
+
+static BOOL BroadcastSysEncCfgUpdate (void)
+{
+ BOOL bSuccess = FALSE;
+ EnumWindows (BroadcastSysEncCfgUpdateCallb, (LPARAM) &bSuccess);
+ return bSuccess;
+}
+
+// IMPORTANT: This function may be called only by Format (other modules can only _read_ the system encryption config).
+// Returns TRUE if successful (otherwise FALSE)
+static BOOL SaveSysEncSettings (HWND hwndDlg)
+{
+ FILE *f;
+
+ if (!bSystemEncryptionStatusChanged)
+ return TRUE;
+
+ if (hwndDlg == NULL && MainDlg != NULL)
+ hwndDlg = MainDlg;
+
+ if (!CreateSysEncMutex ())
+ return FALSE; // Only one instance that has the mutex can modify the system encryption settings
+
+ if (SystemEncryptionStatus == SYSENC_STATUS_NONE)
+ {
+ if (remove (GetConfigPath (TC_APPD_FILENAME_SYSTEM_ENCRYPTION)) != 0)
+ {
+ Error ("CANNOT_SAVE_SYS_ENCRYPTION_SETTINGS");
+ return FALSE;
+ }
+
+ bSystemEncryptionStatusChanged = FALSE;
+ BroadcastSysEncCfgUpdate ();
+ return TRUE;
+ }
+
+ f = fopen (GetConfigPath (TC_APPD_FILENAME_SYSTEM_ENCRYPTION), "w");
+ if (f == NULL)
+ {
+ Error ("CANNOT_SAVE_SYS_ENCRYPTION_SETTINGS");
+ handleWin32Error (hwndDlg);
+ return FALSE;
+ }
+
+ if (XmlWriteHeader (f) < 0
+
+ || fputs ("\n\t<sysencryption>", f) < 0
+
+ || fprintf (f, "\n\t\t<config key=\"SystemEncryptionStatus\">%d</config>", SystemEncryptionStatus) < 0
+
+ || fprintf (f, "\n\t\t<config key=\"WipeMode\">%d</config>", (int) nWipeMode) < 0
+
+ || fputs ("\n\t</sysencryption>", f) < 0
+
+ || XmlWriteFooter (f) < 0)
+ {
+ handleWin32Error (hwndDlg);
+ fclose (f);
+ Error ("CANNOT_SAVE_SYS_ENCRYPTION_SETTINGS");
+ return FALSE;
+ }
+
+ TCFlushFile (f);
+
+ fclose (f);
+
+ bSystemEncryptionStatusChanged = FALSE;
+ BroadcastSysEncCfgUpdate ();
+
+ return TRUE;
+}
+
+// WARNING: This function may take a long time to finish
+static unsigned int DetermineHiddenOSCreationPhase (void)
+{
+ unsigned int phase = TC_HIDDEN_OS_CREATION_PHASE_NONE;
+
+ try
+ {
+ phase = BootEncObj->GetHiddenOSCreationPhase();
+ }
+ catch (Exception &e)
+ {
+ e.Show (MainDlg);
+ AbortProcess("ERR_GETTING_SYSTEM_ENCRYPTION_STATUS");
+ }
+
+ return phase;
+}
+
+// IMPORTANT: This function may be called only by Format (other modules can only _read_ the status).
+// Returns TRUE if successful (otherwise FALSE)
+static BOOL ChangeHiddenOSCreationPhase (int newPhase)
+{
+ if (!CreateSysEncMutex ())
+ {
+ Error ("SYSTEM_ENCRYPTION_IN_PROGRESS_ELSEWHERE");
+ return FALSE;
+ }
+
+ try
+ {
+ BootEncObj->SetHiddenOSCreationPhase (newPhase);
+ }
+ catch (Exception &e)
+ {
+ e.Show (MainDlg);
+ return FALSE;
+ }
+
+ //// The contents of the following items might be inappropriate after a change of the phase
+ //szFileName[0] = 0;
+ //szDiskFile[0] = 0;
+ //nUIVolumeSize = 0;
+ //nVolumeSize = 0;
+
+ return TRUE;
+}
+
+// IMPORTANT: This function may be called only by Format (other modules can only _read_ the system encryption status).
+// Returns TRUE if successful (otherwise FALSE)
+static BOOL ChangeSystemEncryptionStatus (int newStatus)
+{
+ if (!CreateSysEncMutex ())
+ {
+ Error ("SYSTEM_ENCRYPTION_IN_PROGRESS_ELSEWHERE");
+ return FALSE; // Only one instance that has the mutex can modify the system encryption settings
+ }
+
+ SystemEncryptionStatus = newStatus;
+ bSystemEncryptionStatusChanged = TRUE;
+
+ if (newStatus == SYSENC_STATUS_ENCRYPTING)
+ {
+ // If the user has created a hidden OS and now is creating a decoy OS, we must wipe the hidden OS
+ // config area in the MBR.
+ WipeHiddenOSCreationConfig();
+ }
+
+ if (newStatus == SYSENC_STATUS_NONE && !IsHiddenOSRunning())
+ {
+ if (DetermineHiddenOSCreationPhase() != TC_HIDDEN_OS_CREATION_PHASE_NONE
+ && !ChangeHiddenOSCreationPhase (TC_HIDDEN_OS_CREATION_PHASE_NONE))
+ return FALSE;
+
+ WipeHiddenOSCreationConfig();
+ }
+
+ if (!SaveSysEncSettings (MainDlg))
+ {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+// If the return code of this function is ignored and newWizardMode == WIZARD_MODE_SYS_DEVICE, then this function
+// may be called only after CreateSysEncMutex() returns TRUE. It returns TRUE if successful (otherwise FALSE).
+static BOOL ChangeWizardMode (int newWizardMode)
+{
+ if (WizardMode != newWizardMode)
+ {
+ if (WizardMode == WIZARD_MODE_SYS_DEVICE || newWizardMode == WIZARD_MODE_SYS_DEVICE)
+ {
+ if (newWizardMode == WIZARD_MODE_SYS_DEVICE)
+ {
+ if (!CreateSysEncMutex ())
+ {
+ Error ("SYSTEM_ENCRYPTION_IN_PROGRESS_ELSEWHERE");
+ return FALSE;
+ }
+ }
+
+ // If the previous mode was different, the password may have been typed using a different
+ // keyboard layout (which might confuse the user and cause other problems if system encryption
+ // was or will be involved).
+ WipePasswordsAndKeyfiles();
+ }
+
+ if (newWizardMode != WIZARD_MODE_NONSYS_DEVICE)
+ bInPlaceEncNonSys = FALSE;
+
+ if (newWizardMode == WIZARD_MODE_NONSYS_DEVICE && !IsAdmin() && IsUacSupported())
+ {
+ if (!ElevateWholeWizardProcess ("/e"))
+ return FALSE;
+ }
+
+ // The contents of the following items may be inappropriate after a change of mode
+ szFileName[0] = 0;
+ szDiskFile[0] = 0;
+ nUIVolumeSize = 0;
+ nVolumeSize = 0;
+
+ WizardMode = newWizardMode;
+ }
+
+ bDevice = (WizardMode != WIZARD_MODE_FILE_CONTAINER);
+
+ if (newWizardMode != WIZARD_MODE_SYS_DEVICE
+ && !bHiddenOS)
+ {
+ CloseSysEncMutex ();
+ }
+
+ return TRUE;
+}
+
+// Determines whether the wizard directly affects system encryption in any way.
+// Note, for example, that when the user enters a password for a hidden volume that is to host a hidden OS,
+// WizardMode is NOT set to WIZARD_MODE_SYS_DEVICE. The keyboard layout, however, has to be US. That's why
+// this function has to be called instead of checking the value of WizardMode.
+static BOOL SysEncInEffect (void)
+{
+ return (WizardMode == WIZARD_MODE_SYS_DEVICE
+ || CreatingHiddenSysVol());
+}
+
+static BOOL CreatingHiddenSysVol (void)
+{
+ return (bHiddenOS
+ && bHiddenVol && !bHiddenVolHost);
+}
+
+static void LoadSettings (HWND hwndDlg)
+{
+ EnableHwEncryption ((ReadDriverConfigurationFlags() & TC_DRIVER_CONFIG_DISABLE_HARDWARE_ENCRYPTION) ? FALSE : TRUE);
+
+ WipeAlgorithmId savedWipeAlgorithm = TC_WIPE_NONE;
+
+ LoadSysEncSettings (hwndDlg);
+
+ if (LoadNonSysInPlaceEncSettings (&savedWipeAlgorithm) != 0)
+ bInPlaceEncNonSysPending = TRUE;
+
+ defaultKeyFilesParam.EnableKeyFiles = FALSE;
+
+ bStartOnLogon = ConfigReadInt ("StartOnLogon", FALSE);
+
+ HiddenSectorDetectionStatus = ConfigReadInt ("HiddenSectorDetectionStatus", 0);
+
+ bHistory = ConfigReadInt ("SaveVolumeHistory", FALSE);
+
+ ConfigReadString ("SecurityTokenLibrary", "", SecurityTokenLibraryPath, sizeof (SecurityTokenLibraryPath) - 1);
+ if (SecurityTokenLibraryPath[0])
+ InitSecurityTokenLibrary();
+
+ if (hwndDlg != NULL)
+ {
+ LoadCombo (GetDlgItem (hwndDlg, IDC_COMBO_BOX));
+ return;
+ }
+
+ if (bHistoryCmdLine)
+ return;
+}
+
+static void SaveSettings (HWND hwndDlg)
+{
+ WaitCursor ();
+
+ if (hwndDlg != NULL)
+ DumpCombo (GetDlgItem (hwndDlg, IDC_COMBO_BOX), !bHistory);
+
+ ConfigWriteBegin ();
+
+ ConfigWriteInt ("StartOnLogon", bStartOnLogon);
+ ConfigWriteInt ("HiddenSectorDetectionStatus", HiddenSectorDetectionStatus);
+ ConfigWriteInt ("SaveVolumeHistory", bHistory);
+ ConfigWriteString ("SecurityTokenLibrary", SecurityTokenLibraryPath[0] ? SecurityTokenLibraryPath : "");
+
+ if (GetPreferredLangId () != NULL)
+ ConfigWriteString ("Language", GetPreferredLangId ());
+
+ ConfigWriteEnd ();
+
+ NormalCursor ();
+}
+
+// WARNING: This function does NOT cause immediate application exit (use e.g. return 1 after calling it
+// from a DialogProc function).
+static void EndMainDlg (HWND hwndDlg)
+{
+ if (nCurPageNo == VOLUME_LOCATION_PAGE)
+ {
+ if (IsWindow(GetDlgItem(hCurPage, IDC_NO_HISTORY)))
+ bHistory = !IsButtonChecked (GetDlgItem (hCurPage, IDC_NO_HISTORY));
+
+ MoveEditToCombo (GetDlgItem (hCurPage, IDC_COMBO_BOX), bHistory);
+ SaveSettings (hCurPage);
+ }
+ else
+ {
+ SaveSettings (NULL);
+ }
+
+ SaveSysEncSettings (hwndDlg);
+
+ if (!bHistory)
+ CleanLastVisitedMRU ();
+
+ EndDialog (hwndDlg, 0);
+}
+
+// Returns TRUE if system encryption or decryption had been or is in progress and has not been completed
+static BOOL SysEncryptionOrDecryptionRequired (void)
+{
+ /* If you update this function, revise SysEncryptionOrDecryptionRequired() in Mount.c as well. */
+
+ static BootEncryptionStatus locBootEncStatus;
+
+ try
+ {
+ locBootEncStatus = BootEncObj->GetStatus();
+ }
+ catch (Exception &e)
+ {
+ e.Show (MainDlg);
+ }
+
+ return (SystemEncryptionStatus == SYSENC_STATUS_ENCRYPTING
+ || SystemEncryptionStatus == SYSENC_STATUS_DECRYPTING
+ ||
+ (
+ locBootEncStatus.DriveMounted
+ &&
+ (
+ locBootEncStatus.ConfiguredEncryptedAreaStart != locBootEncStatus.EncryptedAreaStart
+ || locBootEncStatus.ConfiguredEncryptedAreaEnd != locBootEncStatus.EncryptedAreaEnd
+ )
+ )
+ );
+}
+
+// Returns TRUE if the system partition/drive is completely encrypted
+static BOOL SysDriveOrPartitionFullyEncrypted (BOOL bSilent)
+{
+ /* If you update this function, revise SysDriveOrPartitionFullyEncrypted() in Mount.c as well. */
+
+ static BootEncryptionStatus locBootEncStatus;
+
+ try
+ {
+ locBootEncStatus = BootEncObj->GetStatus();
+ }
+ catch (Exception &e)
+ {
+ if (!bSilent)
+ e.Show (MainDlg);
+ }
+
+ return (!locBootEncStatus.SetupInProgress
+ && locBootEncStatus.ConfiguredEncryptedAreaEnd != 0
+ && locBootEncStatus.ConfiguredEncryptedAreaEnd != -1
+ && locBootEncStatus.ConfiguredEncryptedAreaStart == locBootEncStatus.EncryptedAreaStart
+ && locBootEncStatus.ConfiguredEncryptedAreaEnd == locBootEncStatus.EncryptedAreaEnd);
+}
+
+// This functions is to be used when the wizard mode needs to be changed to WIZARD_MODE_SYS_DEVICE.
+// If the function fails to switch the mode, it returns FALSE (otherwise TRUE).
+BOOL SwitchWizardToSysEncMode (void)
+{
+ WaitCursor ();
+
+ try
+ {
+ BootEncStatus = BootEncObj->GetStatus();
+ bWholeSysDrive = BootEncObj->SystemPartitionCoversWholeDrive();
+ }
+ catch (Exception &e)
+ {
+ e.Show (MainDlg);
+ Error ("ERR_GETTING_SYSTEM_ENCRYPTION_STATUS");
+ NormalCursor ();
+ return FALSE;
+ }
+
+ // From now on, we should be the only instance of the TC wizard allowed to deal with system encryption
+ if (!CreateSysEncMutex ())
+ {
+ Warning ("SYSTEM_ENCRYPTION_IN_PROGRESS_ELSEWHERE");
+ NormalCursor ();
+ return FALSE;
+ }
+
+ // User-mode app may have crashed and its mutex may have gotten lost, so we need to check the driver status too
+ if (BootEncStatus.SetupInProgress)
+ {
+ if (AskWarnYesNo ("SYSTEM_ENCRYPTION_RESUME_PROMPT") == IDYES)
+ {
+ if (SystemEncryptionStatus != SYSENC_STATUS_ENCRYPTING
+ && SystemEncryptionStatus != SYSENC_STATUS_DECRYPTING)
+ {
+ // The config file with status was lost or not written correctly
+ if (!ResolveUnknownSysEncDirection ())
+ {
+ CloseSysEncMutex ();
+ NormalCursor ();
+ return FALSE;
+ }
+ }
+
+ bDirectSysEncMode = TRUE;
+ ChangeWizardMode (WIZARD_MODE_SYS_DEVICE);
+ LoadPage (MainDlg, SYSENC_ENCRYPTION_PAGE);
+ NormalCursor ();
+ return TRUE;
+ }
+ else
+ {
+ CloseSysEncMutex ();
+ Error ("SYS_ENCRYPTION_OR_DECRYPTION_IN_PROGRESS");
+ NormalCursor ();
+ return FALSE;
+ }
+ }
+
+ if (BootEncStatus.DriveMounted
+ || BootEncStatus.DriveEncrypted
+ || SysEncryptionOrDecryptionRequired ())
+ {
+
+ if (!SysDriveOrPartitionFullyEncrypted (FALSE)
+ && AskWarnYesNo ("SYSTEM_ENCRYPTION_RESUME_PROMPT") == IDYES)
+ {
+ if (SystemEncryptionStatus == SYSENC_STATUS_NONE)
+ {
+ // If the config file with status was lost or not written correctly, we
+ // don't know whether to encrypt or decrypt (but we know that encryption or
+ // decryption is required). Ask the user to select encryption, decryption,
+ // or cancel
+ if (!ResolveUnknownSysEncDirection ())
+ {
+ CloseSysEncMutex ();
+ NormalCursor ();
+ return FALSE;
+ }
+ }
+
+ bDirectSysEncMode = TRUE;
+ ChangeWizardMode (WIZARD_MODE_SYS_DEVICE);
+ LoadPage (MainDlg, SYSENC_ENCRYPTION_PAGE);
+ NormalCursor ();
+ return TRUE;
+ }
+ else
+ {
+ CloseSysEncMutex ();
+ Error ("SETUP_FAILED_BOOT_DRIVE_ENCRYPTED");
+ NormalCursor ();
+ return FALSE;
+ }
+ }
+ else
+ {
+ // Check compliance with requirements for boot encryption
+
+ if (!IsAdmin())
+ {
+ if (!IsUacSupported())
+ {
+ Warning ("ADMIN_PRIVILEGES_WARN_DEVICES");
+ }
+ }
+
+ try
+ {
+ BootEncObj->CheckRequirements ();
+ }
+ catch (Exception &e)
+ {
+ CloseSysEncMutex ();
+ e.Show (MainDlg);
+ NormalCursor ();
+ return FALSE;
+ }
+
+ if (!ChangeWizardMode (WIZARD_MODE_SYS_DEVICE))
+ {
+ NormalCursor ();
+ return FALSE;
+ }
+
+ if (bSysDriveSelected || bSysPartitionSelected)
+ {
+ // The user selected the non-sys-device wizard mode but then selected a system device
+
+ bWholeSysDrive = (bSysDriveSelected && !bSysPartitionSelected);
+
+ bSysDriveSelected = FALSE;
+ bSysPartitionSelected = FALSE;
+
+ try
+ {
+ if (!bHiddenVol)
+ {
+ if (bWholeSysDrive && !BootEncObj->SystemPartitionCoversWholeDrive())
+ {
+ if (BootEncObj->SystemDriveContainsNonStandardPartitions())
+ {
+ if (AskWarnYesNoString ((wstring (GetString ("SYSDRIVE_NON_STANDARD_PARTITIONS")) + L"\n\n" + GetString ("ASK_ENCRYPT_PARTITION_INSTEAD_OF_DRIVE")).c_str()) == IDYES)
+ bWholeSysDrive = FALSE;
+ }
+
+ if (!IsOSAtLeast (WIN_VISTA) && bWholeSysDrive)
+ {
+ if (BootEncObj->SystemDriveContainsExtendedPartition())
+ {
+ bWholeSysDrive = FALSE;
+
+ Error ("WDE_UNSUPPORTED_FOR_EXTENDED_PARTITIONS");
+
+ if (AskYesNo ("ASK_ENCRYPT_PARTITION_INSTEAD_OF_DRIVE") == IDNO)
+ {
+ ChangeWizardMode (WIZARD_MODE_NONSYS_DEVICE);
+ return FALSE;
+ }
+ }
+ else
+ Warning ("WDE_EXTENDED_PARTITIONS_WARNING");
+ }
+ }
+ else if (BootEncObj->SystemPartitionCoversWholeDrive()
+ && !bWholeSysDrive)
+ bWholeSysDrive = (AskYesNo ("WHOLE_SYC_DEVICE_RECOM") == IDYES);
+ }
+
+ }
+ catch (Exception &e)
+ {
+ e.Show (MainDlg);
+ return FALSE;
+ }
+
+ if (!bHiddenVol)
+ {
+ // Skip SYSENC_SPAN_PAGE and SYSENC_TYPE_PAGE as the user already made the choice
+ LoadPage (MainDlg, bWholeSysDrive ? SYSENC_PRE_DRIVE_ANALYSIS_PAGE : SYSENC_MULTI_BOOT_MODE_PAGE);
+ }
+ else
+ {
+ // The user selected the non-sys-device wizard mode but then selected a system device.
+ // In addition, he selected the hidden volume mode.
+
+ if (bWholeSysDrive)
+ Warning ("HIDDEN_OS_PRECLUDES_SINGLE_KEY_WDE");
+
+ bWholeSysDrive = FALSE;
+
+ LoadPage (MainDlg, SYSENC_TYPE_PAGE);
+ }
+ }
+ else
+ LoadPage (MainDlg, SYSENC_TYPE_PAGE);
+
+ NormalCursor ();
+ return TRUE;
+ }
+}
+
+void SwitchWizardToFileContainerMode (void)
+{
+ ChangeWizardMode (WIZARD_MODE_FILE_CONTAINER);
+
+ LoadPage (MainDlg, VOLUME_LOCATION_PAGE);
+
+ NormalCursor ();
+}
+
+void SwitchWizardToNonSysDeviceMode (void)
+{
+ ChangeWizardMode (WIZARD_MODE_NONSYS_DEVICE);
+
+ LoadPage (MainDlg, VOLUME_TYPE_PAGE);
+
+ NormalCursor ();
+}
+
+BOOL SwitchWizardToHiddenOSMode (void)
+{
+ if (SwitchWizardToSysEncMode())
+ {
+ if (nCurPageNo != SYSENC_ENCRYPTION_PAGE) // If the user did not manually choose to resume encryption or decryption of the system partition/drive
+ {
+ bHiddenOS = TRUE;
+ bHiddenVol = TRUE;
+ bHiddenVolHost = TRUE;
+ bHiddenVolDirect = FALSE;
+ bWholeSysDrive = FALSE;
+ bInPlaceEncNonSys = FALSE;
+
+ if (bDirectSysEncModeCommand == SYSENC_COMMAND_CREATE_HIDDEN_OS_ELEV)
+ {
+ // Some of the requirements for hidden OS should have already been checked by the wizard process
+ // that launched us (in order to elevate), but we must recheck them. Otherwise, an advanced user
+ // could bypass the checks by using the undocumented CLI switch. Moreover, some requirements
+ // can be checked only at this point (when we are elevated).
+ try
+ {
+ BootEncObj->CheckRequirementsHiddenOS ();
+
+ BootEncObj->InitialSecurityChecksForHiddenOS ();
+ }
+ catch (Exception &e)
+ {
+ e.Show (MainDlg);
+ return FALSE;
+ }
+
+ LoadPage (MainDlg, SYSENC_MULTI_BOOT_MODE_PAGE);
+ }
+ else
+ LoadPage (MainDlg, SYSENC_HIDDEN_OS_REQ_CHECK_PAGE);
+
+ NormalCursor ();
+ }
+ else
+ return TRUE;
+ }
+ else
+ return FALSE;
+
+ return TRUE;
+}
+
+void SwitchWizardToNonSysInplaceEncResumeMode (void)
+{
+ if (!IsAdmin() && IsUacSupported())
+ {
+ if (!ElevateWholeWizardProcess ("/zinplace"))
+ AbortProcessSilent ();
+ }
+
+ if (!IsAdmin())
+ AbortProcess("ADMIN_PRIVILEGES_WARN_DEVICES");
+
+ CreateNonSysInplaceEncMutex ();
+
+ bInPlaceEncNonSys = TRUE;
+ bInPlaceEncNonSysResumed = TRUE;
+
+ ChangeWizardMode (WIZARD_MODE_NONSYS_DEVICE);
+
+ LoadPage (MainDlg, NONSYS_INPLACE_ENC_RESUME_PASSWORD_PAGE);
+}
+
+// Use this function e.g. if the config file with the system encryption settings was lost or not written
+// correctly, and we don't know whether to encrypt or decrypt (but we know that encryption or decryption
+// is required). Returns FALSE if failed or cancelled.
+static BOOL ResolveUnknownSysEncDirection (void)
+{
+ if (CreateSysEncMutex ())
+ {
+ if (SystemEncryptionStatus != SYSENC_STATUS_ENCRYPTING
+ && SystemEncryptionStatus != SYSENC_STATUS_DECRYPTING)
+ {
+ try
+ {
+ BootEncStatus = BootEncObj->GetStatus();
+ }
+ catch (Exception &e)
+ {
+ e.Show (MainDlg);
+ Error ("ERR_GETTING_SYSTEM_ENCRYPTION_STATUS");
+ return FALSE;
+ }
+
+ if (BootEncStatus.SetupInProgress)
+ {
+ return ChangeSystemEncryptionStatus (
+ (BootEncStatus.SetupMode != SetupDecryption) ? SYSENC_STATUS_ENCRYPTING : SYSENC_STATUS_DECRYPTING);
+ }
+ else
+ {
+ // Ask the user to select encryption, decryption, or cancel
+
+ char *tmpStr[] = {0,
+ !BootEncStatus.DriveEncrypted ? "CHOOSE_ENCRYPT_OR_DECRYPT_FINALIZE_DECRYPT_NOTE" : "CHOOSE_ENCRYPT_OR_DECRYPT",
+ "ENCRYPT",
+ "DECRYPT",
+ "IDCANCEL",
+ 0};
+
+ switch (AskMultiChoice ((void **) tmpStr, FALSE))
+ {
+ case 1:
+ return ChangeSystemEncryptionStatus (SYSENC_STATUS_ENCRYPTING);
+ case 2:
+ return ChangeSystemEncryptionStatus (SYSENC_STATUS_DECRYPTING);
+ default:
+ return FALSE;
+ }
+ }
+ }
+ else
+ return TRUE;
+ }
+ else
+ {
+ Error ("SYSTEM_ENCRYPTION_IN_PROGRESS_ELSEWHERE");
+ return FALSE;
+ }
+}
+
+// This function should be used to resolve inconsistencies that might lead to a deadlock (inability to encrypt or
+// decrypt the system partition/drive and to uninstall TrueCrypt). The function removes the system encryption key
+// data ("volume header"), the TrueCrypt boot loader, restores the original system loader (if available),
+// unregisters the boot driver, etc. Note that if the system partition/drive is encrypted, it will start decrypting
+// it in the background (therefore, it should be used when the system partition/drive is not encrypted, ideally).
+// Exceptions are handled and errors are reported within the function. Returns TRUE if successful.
+static BOOL ForceRemoveSysEnc (void)
+{
+ if (CreateSysEncMutex ()) // If no other instance is currently taking care of system encryption
+ {
+ BootEncryptionStatus locBootEncStatus;
+
+ try
+ {
+ locBootEncStatus = BootEncObj->GetStatus();
+
+ if (locBootEncStatus.SetupInProgress)
+ BootEncObj->AbortSetupWait ();
+
+ locBootEncStatus = BootEncObj->GetStatus();
+
+ if (locBootEncStatus.DriveMounted)
+ {
+ // Remove the header
+ BootEncObj->StartDecryption (DiscardUnreadableEncryptedSectors);
+ locBootEncStatus = BootEncObj->GetStatus();
+
+ while (locBootEncStatus.SetupInProgress)
+ {
+ Sleep (100);
+ locBootEncStatus = BootEncObj->GetStatus();
+ }
+
+ BootEncObj->CheckEncryptionSetupResult ();
+ }
+
+ Sleep (50);
+ }
+ catch (Exception &e)
+ {
+ e.Show (MainDlg);
+ return FALSE;
+ }
+
+ try
+ {
+ locBootEncStatus = BootEncObj->GetStatus();
+
+ if (!locBootEncStatus.DriveMounted)
+ BootEncObj->Deinstall (true);
+ }
+ catch (Exception &e)
+ {
+ e.Show (MainDlg);
+ return FALSE;
+ }
+
+ return TRUE;
+ }
+ else
+ return FALSE;
+}
+
+// Returns 0 if there's an error.
+__int64 GetSystemPartitionSize (void)
+{
+ try
+ {
+ return BootEncObj->GetSystemDriveConfiguration().SystemPartition.Info.PartitionLength.QuadPart;
+ }
+ catch (Exception &e)
+ {
+ e.Show (MainDlg);
+ return 0;
+ }
+}
+
+void ComboSelChangeEA (HWND hwndDlg)
+{
+ LPARAM nIndex = SendMessage (GetDlgItem (hwndDlg, IDC_COMBO_BOX), CB_GETCURSEL, 0, 0);
+
+ if (nIndex == CB_ERR)
+ {
+ SetWindowText (GetDlgItem (hwndDlg, IDC_BOX_HELP), "");
+ }
+ else
+ {
+ char name[100];
+ wchar_t auxLine[4096];
+ wchar_t hyperLink[256] = { 0 };
+ int cipherIDs[5];
+ int i, cnt = 0;
+
+ nIndex = SendMessage (GetDlgItem (hwndDlg, IDC_COMBO_BOX), CB_GETITEMDATA, nIndex, 0);
+ EAGetName (name, nIndex);
+
+ if (strcmp (name, "AES") == 0)
+ {
+ swprintf_s (hyperLink, sizeof(hyperLink) / 2, GetString ("MORE_INFO_ABOUT"), name);
+
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString ("AES_HELP"));
+ }
+ else if (strcmp (name, "Serpent") == 0)
+ {
+ swprintf_s (hyperLink, sizeof(hyperLink) / 2, GetString ("MORE_INFO_ABOUT"), name);
+
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString ("SERPENT_HELP"));
+ }
+ else if (strcmp (name, "Twofish") == 0)
+ {
+ swprintf_s (hyperLink, sizeof(hyperLink) / 2, GetString ("MORE_INFO_ABOUT"), name);
+
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString ("TWOFISH_HELP"));
+ }
+ else if (EAGetCipherCount (nIndex) > 1)
+ {
+ // Cascade
+ cipherIDs[cnt++] = i = EAGetLastCipher(nIndex);
+ while (i = EAGetPreviousCipher(nIndex, i))
+ {
+ cipherIDs[cnt] = i;
+ cnt++;
+ }
+
+ switch (cnt) // Number of ciphers in the cascade
+ {
+ case 2:
+ swprintf (auxLine, GetString ("TWO_LAYER_CASCADE_HELP"),
+ CipherGetName (cipherIDs[1]),
+ CipherGetKeySize (cipherIDs[1])*8,
+ CipherGetName (cipherIDs[0]),
+ CipherGetKeySize (cipherIDs[0])*8);
+ break;
+
+ case 3:
+ swprintf (auxLine, GetString ("THREE_LAYER_CASCADE_HELP"),
+ CipherGetName (cipherIDs[2]),
+ CipherGetKeySize (cipherIDs[2])*8,
+ CipherGetName (cipherIDs[1]),
+ CipherGetKeySize (cipherIDs[1])*8,
+ CipherGetName (cipherIDs[0]),
+ CipherGetKeySize (cipherIDs[0])*8);
+ break;
+ }
+
+ wcscpy_s (hyperLink, sizeof(hyperLink) / 2, GetString ("IDC_LINK_MORE_INFO_ABOUT_CIPHER"));
+
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), auxLine);
+ }
+ else
+ {
+ // No info available for this encryption algorithm
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), L"");
+ }
+
+
+ // Update hyperlink
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_LINK_MORE_INFO_ABOUT_CIPHER), hyperLink);
+ AccommodateTextField (hwndDlg, IDC_LINK_MORE_INFO_ABOUT_CIPHER, FALSE, hUserUnderlineFont);
+ }
+}
+
+static void VerifySizeAndUpdate (HWND hwndDlg, BOOL bUpdate)
+{
+ BOOL bEnable = TRUE;
+ char szTmp[50];
+ __int64 lTmp;
+ size_t i;
+ static unsigned __int64 nLastVolumeSize = 0;
+
+ GetWindowText (GetDlgItem (hwndDlg, IDC_SIZEBOX), szTmp, sizeof (szTmp));
+
+ for (i = 0; i < strlen (szTmp); i++)
+ {
+ if (szTmp[i] >= '0' && szTmp[i] <= '9')
+ continue;
+ else
+ {
+ bEnable = FALSE;
+ break;
+ }
+ }
+
+ if (IsButtonChecked (GetDlgItem (hwndDlg, IDC_KB)))
+ nMultiplier = BYTES_PER_KB;
+ else if (IsButtonChecked (GetDlgItem (hwndDlg, IDC_MB)))
+ nMultiplier = BYTES_PER_MB;
+ else
+ nMultiplier = BYTES_PER_GB;
+
+ if (bDevice && !(bHiddenVol && !bHiddenVolHost)) // If raw device but not a hidden volume
+ {
+ lTmp = nVolumeSize;
+ i = 1;
+ }
+ else
+ {
+ i = nMultiplier;
+ lTmp = _atoi64 (szTmp);
+
+ int sectorSize = GetFormatSectorSize();
+ uint32 sectorSizeRem = (lTmp * nMultiplier) % sectorSize;
+
+ if (sectorSizeRem != 0)
+ lTmp = (lTmp * nMultiplier + (sectorSize - sectorSizeRem)) / nMultiplier;
+ }
+
+ if (bEnable)
+ {
+ if (lTmp * i < (bHiddenVolHost ? TC_MIN_HIDDEN_VOLUME_HOST_SIZE : (bHiddenVol ? TC_MIN_HIDDEN_VOLUME_SIZE : TC_MIN_VOLUME_SIZE)))
+ bEnable = FALSE;
+
+ if (!bHiddenVolHost && bHiddenVol)
+ {
+ if (lTmp * i > nMaximumHiddenVolSize)
+ bEnable = FALSE;
+ }
+ else
+ {
+ if (lTmp * i > (bHiddenVolHost ? TC_MAX_HIDDEN_VOLUME_HOST_SIZE : TC_MAX_VOLUME_SIZE))
+ bEnable = FALSE;
+ }
+ }
+
+ if (bUpdate)
+ {
+ nUIVolumeSize = lTmp;
+
+ if (!bDevice || (bHiddenVol && !bHiddenVolHost)) // Update only if it's not a raw device or if it's a hidden volume
+ nVolumeSize = i * lTmp;
+ }
+
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), bEnable);
+
+ if (nVolumeSize != nLastVolumeSize)
+ {
+ // Change of volume size may make some file systems allowed or disallowed, so the default filesystem must
+ // be reselected.
+ fileSystem = FILESYS_NONE;
+ nLastVolumeSize = nVolumeSize;
+ }
+}
+
+static void UpdateWizardModeControls (HWND hwndDlg, int setWizardMode)
+{
+ SendMessage (GetDlgItem (hwndDlg, IDC_FILE_CONTAINER),
+ BM_SETCHECK,
+ setWizardMode == WIZARD_MODE_FILE_CONTAINER ? BST_CHECKED : BST_UNCHECKED,
+ 0);
+
+ SendMessage (GetDlgItem (hwndDlg, IDC_NONSYS_DEVICE),
+ BM_SETCHECK,
+ setWizardMode == WIZARD_MODE_NONSYS_DEVICE ? BST_CHECKED : BST_UNCHECKED,
+ 0);
+
+ SendMessage (GetDlgItem (hwndDlg, IDC_SYS_DEVICE),
+ BM_SETCHECK,
+ setWizardMode == WIZARD_MODE_SYS_DEVICE ? BST_CHECKED : BST_UNCHECKED,
+ 0);
+}
+
+static int GetSelectedWizardMode (HWND hwndDlg)
+{
+ if (IsButtonChecked (GetDlgItem (hwndDlg, IDC_FILE_CONTAINER)))
+ return WIZARD_MODE_FILE_CONTAINER;
+
+ if (IsButtonChecked (GetDlgItem (hwndDlg, IDC_NONSYS_DEVICE)))
+ return WIZARD_MODE_NONSYS_DEVICE;
+
+ if (IsButtonChecked (GetDlgItem (hwndDlg, IDC_SYS_DEVICE)))
+ return WIZARD_MODE_SYS_DEVICE;
+
+ return DEFAULT_VOL_CREATION_WIZARD_MODE;
+}
+
+static void RefreshMultiBootControls (HWND hwndDlg)
+{
+#ifdef DEBUG
+ if (nMultiBoot == 0)
+ nMultiBoot = 1;
+#endif
+
+ SendMessage (GetDlgItem (hwndDlg, IDC_SINGLE_BOOT),
+ BM_SETCHECK,
+ nMultiBoot == 1 ? BST_CHECKED : BST_UNCHECKED,
+ 0);
+
+ SendMessage (GetDlgItem (hwndDlg, IDC_MULTI_BOOT),
+ BM_SETCHECK,
+ nMultiBoot > 1 ? BST_CHECKED : BST_UNCHECKED,
+ 0);
+}
+
+// -1 = Undecided or error, 0 = No, 1 = Yes
+static int Get2RadButtonPageAnswer (void)
+{
+ if (IsButtonChecked (GetDlgItem (hCurPage, IDC_CHOICE1)))
+ return 1;
+
+ if (IsButtonChecked (GetDlgItem (hCurPage, IDC_CHOICE2)))
+ return 0;
+
+ return -1;
+}
+
+// 0 = No, 1 = Yes
+static void Update2RadButtonPage (int answer)
+{
+ SendMessage (GetDlgItem (hCurPage, IDC_CHOICE1),
+ BM_SETCHECK,
+ answer == 1 ? BST_CHECKED : BST_UNCHECKED,
+ 0);
+
+ SendMessage (GetDlgItem (hCurPage, IDC_CHOICE2),
+ BM_SETCHECK,
+ answer == 0 ? BST_CHECKED : BST_UNCHECKED,
+ 0);
+}
+
+// -1 = Undecided, 0 = No, 1 = Yes
+static void Init2RadButtonPageYesNo (int answer)
+{
+ SetWindowTextW (GetDlgItem (hCurPage, IDC_CHOICE1), GetString ("UISTR_YES"));
+ SetWindowTextW (GetDlgItem (hCurPage, IDC_CHOICE2), GetString ("UISTR_NO"));
+
+ SetWindowTextW (GetDlgItem (MainDlg, IDC_NEXT), GetString ("NEXT"));
+ SetWindowTextW (GetDlgItem (MainDlg, IDC_PREV), GetString ("PREV"));
+ SetWindowTextW (GetDlgItem (MainDlg, IDCANCEL), GetString ("CANCEL"));
+
+ EnableWindow (GetDlgItem (MainDlg, IDC_NEXT), answer >= 0);
+ EnableWindow (GetDlgItem (MainDlg, IDC_PREV), TRUE);
+
+ Update2RadButtonPage (answer);
+}
+
+static void UpdateSysEncProgressBar (void)
+{
+ BootEncryptionStatus locBootEncStatus;
+
+ try
+ {
+ locBootEncStatus = BootEncObj->GetStatus();
+ }
+ catch (...)
+ {
+ return;
+ }
+
+ if (locBootEncStatus.EncryptedAreaEnd == -1
+ || locBootEncStatus.EncryptedAreaStart == -1)
+ {
+ UpdateProgressBarProc (0);
+ }
+ else
+ {
+ UpdateProgressBarProc (locBootEncStatus.EncryptedAreaEnd - locBootEncStatus.EncryptedAreaStart + 1);
+
+ if (locBootEncStatus.SetupInProgress)
+ {
+ wchar_t tmpStr[100];
+
+ // Status
+
+ if (locBootEncStatus.TransformWaitingForIdle)
+ wcscpy (tmpStr, GetString ("PROGRESS_STATUS_WAITING"));
+ else
+ wcscpy (tmpStr, GetString (SystemEncryptionStatus == SYSENC_STATUS_DECRYPTING ? "PROGRESS_STATUS_DECRYPTING" : "PROGRESS_STATUS_ENCRYPTING"));
+
+ wcscat (tmpStr, L" ");
+
+ SetWindowTextW (GetDlgItem (hCurPage, IDC_WRITESPEED), tmpStr);
+ }
+ }
+}
+
+static void InitSysEncProgressBar (void)
+{
+ BootEncryptionStatus locBootEncStatus;
+
+ try
+ {
+ locBootEncStatus = BootEncObj->GetStatus();
+ }
+ catch (...)
+ {
+ return;
+ }
+
+ if (locBootEncStatus.ConfiguredEncryptedAreaEnd == -1
+ || locBootEncStatus.ConfiguredEncryptedAreaStart == -1)
+ return;
+
+ InitProgressBar (locBootEncStatus.ConfiguredEncryptedAreaEnd
+ - locBootEncStatus.ConfiguredEncryptedAreaStart + 1,
+ (locBootEncStatus.EncryptedAreaEnd == locBootEncStatus.EncryptedAreaStart || locBootEncStatus.EncryptedAreaEnd == -1) ?
+ 0 : locBootEncStatus.EncryptedAreaEnd - locBootEncStatus.EncryptedAreaStart + 1,
+ SystemEncryptionStatus == SYSENC_STATUS_DECRYPTING,
+ TRUE,
+ TRUE,
+ TRUE);
+}
+
+static void UpdateSysEncControls (void)
+{
+ BootEncryptionStatus locBootEncStatus;
+
+ try
+ {
+ locBootEncStatus = BootEncObj->GetStatus();
+ }
+ catch (...)
+ {
+ return;
+ }
+
+ EnableWindow (GetDlgItem (hCurPage, IDC_WIPE_MODE),
+ !locBootEncStatus.SetupInProgress
+ && SystemEncryptionStatus == SYSENC_STATUS_ENCRYPTING);
+
+ SetWindowTextW (GetDlgItem (hCurPage, IDC_PAUSE),
+ GetString (locBootEncStatus.SetupInProgress ? "IDC_PAUSE" : "RESUME"));
+
+ EnableWindow (GetDlgItem (MainDlg, IDC_NEXT), !locBootEncStatus.SetupInProgress && !bFirstSysEncResumeDone);
+
+ if (!locBootEncStatus.SetupInProgress)
+ {
+ wchar_t tmpStr[100];
+
+ wcscpy (tmpStr, GetString ((SysDriveOrPartitionFullyEncrypted (TRUE) || !locBootEncStatus.DriveMounted) ?
+ "PROGRESS_STATUS_FINISHED" : "PROGRESS_STATUS_PAUSED"));
+ wcscat (tmpStr, L" ");
+
+ // Status
+ SetWindowTextW (GetDlgItem (hCurPage, IDC_WRITESPEED), tmpStr);
+
+ if (SysDriveOrPartitionFullyEncrypted (TRUE) || SystemEncryptionStatus == SYSENC_STATUS_NONE)
+ {
+ wcscpy (tmpStr, GetString ("PROCESSED_PORTION_100_PERCENT"));
+ wcscat (tmpStr, L" ");
+
+ SetWindowTextW (GetDlgItem (hCurPage, IDC_BYTESWRITTEN), tmpStr);
+ }
+
+ SetWindowText (GetDlgItem (hCurPage, IDC_TIMEREMAIN), " ");
+ }
+}
+
+static void SysEncPause (void)
+{
+ BootEncryptionStatus locBootEncStatus;
+
+ if (CreateSysEncMutex ())
+ {
+ EnableWindow (GetDlgItem (hCurPage, IDC_PAUSE), FALSE);
+
+ try
+ {
+ locBootEncStatus = BootEncObj->GetStatus();
+ }
+ catch (Exception &e)
+ {
+ e.Show (MainDlg);
+ Error ("ERR_GETTING_SYSTEM_ENCRYPTION_STATUS");
+ EnableWindow (GetDlgItem (hCurPage, IDC_PAUSE), TRUE);
+ return;
+ }
+
+ if (!locBootEncStatus.SetupInProgress)
+ {
+ EnableWindow (GetDlgItem (hCurPage, IDC_PAUSE), TRUE);
+ return;
+ }
+
+ WaitCursor ();
+
+ try
+ {
+ int attempts = SYSENC_PAUSE_RETRIES;
+
+ BootEncObj->AbortSetup ();
+
+ locBootEncStatus = BootEncObj->GetStatus();
+
+ while (locBootEncStatus.SetupInProgress && attempts > 0)
+ {
+ Sleep (SYSENC_PAUSE_RETRY_INTERVAL);
+ attempts--;
+ locBootEncStatus = BootEncObj->GetStatus();
+ }
+
+ if (!locBootEncStatus.SetupInProgress)
+ BootEncObj->CheckEncryptionSetupResult ();
+
+ }
+ catch (Exception &e)
+ {
+ e.Show (MainDlg);
+ }
+
+ NormalCursor ();
+
+ if (locBootEncStatus.SetupInProgress)
+ {
+ SetTimer (MainDlg, TIMER_ID_SYSENC_PROGRESS, TIMER_INTERVAL_SYSENC_PROGRESS, NULL);
+ EnableWindow (GetDlgItem (hCurPage, IDC_PAUSE), TRUE);
+ Error ("FAILED_TO_INTERRUPT_SYSTEM_ENCRYPTION");
+ return;
+ }
+
+ UpdateSysEncControls ();
+ EnableWindow (GetDlgItem (hCurPage, IDC_PAUSE), TRUE);
+ }
+ else
+ Error ("SYSTEM_ENCRYPTION_IN_PROGRESS_ELSEWHERE");
+}
+
+
+static void SysEncResume (void)
+{
+ BootEncryptionStatus locBootEncStatus;
+
+ if (CreateSysEncMutex ())
+ {
+ EnableWindow (GetDlgItem (hCurPage, IDC_PAUSE), FALSE);
+
+ try
+ {
+ locBootEncStatus = BootEncObj->GetStatus();
+ }
+ catch (Exception &e)
+ {
+ e.Show (MainDlg);
+ Error ("ERR_GETTING_SYSTEM_ENCRYPTION_STATUS");
+ EnableWindow (GetDlgItem (hCurPage, IDC_PAUSE), TRUE);
+ return;
+ }
+
+ if (locBootEncStatus.SetupInProgress)
+ {
+ // Prevent the OS from entering Sleep mode when idle
+ SetThreadExecutionState (ES_CONTINUOUS | ES_SYSTEM_REQUIRED);
+
+ bSystemEncryptionInProgress = TRUE;
+ UpdateSysEncControls ();
+ SetTimer (MainDlg, TIMER_ID_SYSENC_PROGRESS, TIMER_INTERVAL_SYSENC_PROGRESS, NULL);
+ EnableWindow (GetDlgItem (hCurPage, IDC_PAUSE), TRUE);
+ return;
+ }
+
+ bSystemEncryptionInProgress = FALSE;
+ WaitCursor ();
+
+ try
+ {
+ switch (SystemEncryptionStatus)
+ {
+ case SYSENC_STATUS_ENCRYPTING:
+
+ BootEncObj->StartEncryption (nWipeMode, bTryToCorrectReadErrors ? true : false);
+ break;
+
+ case SYSENC_STATUS_DECRYPTING:
+
+ if (locBootEncStatus.DriveMounted) // If the drive is not encrypted we will just deinstall
+ BootEncObj->StartDecryption (DiscardUnreadableEncryptedSectors);
+
+ break;
+ }
+
+ bSystemEncryptionInProgress = TRUE;
+ }
+ catch (Exception &e)
+ {
+ e.Show (MainDlg);
+ }
+
+ NormalCursor ();
+
+ if (!bSystemEncryptionInProgress)
+ {
+ // Allow the OS to enter Sleep mode when idle
+ SetThreadExecutionState (ES_CONTINUOUS);
+
+ EnableWindow (GetDlgItem (hCurPage, IDC_PAUSE), TRUE);
+ Error ("FAILED_TO_RESUME_SYSTEM_ENCRYPTION");
+ return;
+ }
+
+ // Prevent the OS from entering Sleep mode when idle
+ SetThreadExecutionState (ES_CONTINUOUS | ES_SYSTEM_REQUIRED);
+
+ bFirstSysEncResumeDone = TRUE;
+ InitSysEncProgressBar ();
+ UpdateSysEncProgressBar ();
+ UpdateSysEncControls ();
+ EnableWindow (GetDlgItem (hCurPage, IDC_PAUSE), TRUE);
+ SetTimer (MainDlg, TIMER_ID_SYSENC_PROGRESS, TIMER_INTERVAL_SYSENC_PROGRESS, NULL);
+ }
+ else
+ Error ("SYSTEM_ENCRYPTION_IN_PROGRESS_ELSEWHERE");
+}
+
+
+static BOOL GetDevicePathForHiddenOS (void)
+{
+ BOOL tmpbDevice = FALSE;
+
+ try
+ {
+ strncpy (szFileName, BootEncObj->GetPartitionForHiddenOS().DevicePath.c_str(), sizeof(szFileName));
+
+ CreateFullVolumePath (szDiskFile, szFileName, &tmpbDevice);
+ }
+ catch (Exception &e)
+ {
+ e.Show (MainDlg);
+ return FALSE;
+ }
+
+ return (szFileName[0] != 0
+ && szDiskFile[0] != 0
+ && tmpbDevice);
+}
+
+
+// Returns TRUE if there is unallocated space greater than 64 MB (max possible slack space size) between the
+// boot partition and the first partition behind it. If there's none or if an error occurs, returns FALSE.
+static BOOL CheckGapBetweenSysAndHiddenOS (void)
+{
+ try
+ {
+ SystemDriveConfiguration sysDriveCfg = BootEncObj->GetSystemDriveConfiguration();
+
+ return (sysDriveCfg.SystemPartition.Info.StartingOffset.QuadPart
+ + sysDriveCfg.SystemPartition.Info.PartitionLength.QuadPart
+ + 64 * BYTES_PER_MB
+ + 128 * BYTES_PER_KB
+ <= BootEncObj->GetPartitionForHiddenOS().Info.StartingOffset.QuadPart);
+ }
+ catch (Exception &e)
+ {
+ e.Show (MainDlg);
+ }
+
+ return FALSE;
+}
+
+
+static void NonSysInplaceEncPause (void)
+{
+ bVolTransformThreadCancel = TRUE;
+
+ WaitCursor ();
+
+ int waitThreshold = 100; // Do not block GUI events for more than 10 seconds. IMPORTANT: This prevents deadlocks when the thread calls us back e.g. to update GUI!
+
+ while (bVolTransformThreadRunning || bVolTransformThreadToRun)
+ {
+ MSG guiMsg;
+
+ bVolTransformThreadCancel = TRUE;
+
+ if (waitThreshold <= 0)
+ {
+ while (PeekMessage (&guiMsg, NULL, 0, 0, PM_REMOVE) != 0)
+ {
+ DispatchMessage (&guiMsg);
+ }
+ }
+ else
+ waitThreshold--;
+
+ Sleep (100);
+ }
+}
+
+
+static void NonSysInplaceEncResume (void)
+{
+ if (bVolTransformThreadRunning || bVolTransformThreadToRun || bVolTransformThreadCancel)
+ return;
+
+ if (!bInPlaceEncNonSysResumed
+ && !FinalPreTransformPrompts ())
+ {
+ return;
+ }
+
+ CreateNonSysInplaceEncMutex ();
+
+ bFirstNonSysInPlaceEncResumeDone = TRUE;
+
+ SetTimer (MainDlg, TIMER_ID_NONSYS_INPLACE_ENC_PROGRESS, TIMER_INTERVAL_NONSYS_INPLACE_ENC_PROGRESS, NULL);
+
+ bVolTransformThreadCancel = FALSE;
+ bVolTransformThreadToRun = TRUE;
+
+ UpdateNonSysInPlaceEncControls ();
+
+ LastDialogId = "NONSYS_INPLACE_ENC_IN_PROGRESS";
+
+ _beginthread (volTransformThreadFunction, 0, MainDlg);
+
+ return;
+}
+
+
+void ShowNonSysInPlaceEncUIStatus (void)
+{
+ wchar_t nonSysInplaceEncUIStatus [300] = {0};
+
+ switch (NonSysInplaceEncStatus)
+ {
+ case NONSYS_INPLACE_ENC_STATUS_PAUSED:
+ wcscpy (nonSysInplaceEncUIStatus, GetString ("PROGRESS_STATUS_PAUSED"));
+ break;
+ case NONSYS_INPLACE_ENC_STATUS_PREPARING:
+ wcscpy (nonSysInplaceEncUIStatus, GetString ("PROGRESS_STATUS_PREPARING"));
+ break;
+ case NONSYS_INPLACE_ENC_STATUS_RESIZING:
+ wcscpy (nonSysInplaceEncUIStatus, GetString ("PROGRESS_STATUS_RESIZING"));
+ break;
+ case NONSYS_INPLACE_ENC_STATUS_ENCRYPTING:
+ wcscpy (nonSysInplaceEncUIStatus, GetString ("PROGRESS_STATUS_ENCRYPTING"));
+ break;
+ case NONSYS_INPLACE_ENC_STATUS_FINALIZING:
+ wcscpy (nonSysInplaceEncUIStatus, GetString ("PROGRESS_STATUS_FINALIZING"));
+ break;
+ case NONSYS_INPLACE_ENC_STATUS_FINISHED:
+ wcscpy (nonSysInplaceEncUIStatus, GetString ("PROGRESS_STATUS_FINISHED"));
+ break;
+ case NONSYS_INPLACE_ENC_STATUS_ERROR:
+ wcscpy (nonSysInplaceEncUIStatus, GetString ("PROGRESS_STATUS_ERROR"));
+ break;
+ }
+
+ wcscat (nonSysInplaceEncUIStatus, L" ");
+
+ SetWindowTextW (GetDlgItem (hCurPage, IDC_WRITESPEED), nonSysInplaceEncUIStatus);
+}
+
+
+void UpdateNonSysInPlaceEncControls (void)
+{
+ EnableWindow (GetDlgItem (hCurPage, IDC_WIPE_MODE), !(bVolTransformThreadRunning || bVolTransformThreadToRun));
+
+ SetWindowTextW (GetDlgItem (hCurPage, IDC_PAUSE),
+ GetString ((bVolTransformThreadRunning || bVolTransformThreadToRun) ? "IDC_PAUSE" : "RESUME"));
+
+ SetWindowTextW (GetDlgItem (MainDlg, IDCANCEL), GetString (bInPlaceEncNonSysResumed ? "DEFER" : "CANCEL"));
+
+ EnableWindow (GetDlgItem (hCurPage, IDC_PAUSE), bFirstNonSysInPlaceEncResumeDone
+ && NonSysInplaceEncStatus != NONSYS_INPLACE_ENC_STATUS_FINALIZING
+ && NonSysInplaceEncStatus != NONSYS_INPLACE_ENC_STATUS_FINISHED);
+
+ EnableWindow (GetDlgItem (MainDlg, IDC_NEXT), !(bVolTransformThreadRunning || bVolTransformThreadToRun) && !bFirstNonSysInPlaceEncResumeDone);
+ EnableWindow (GetDlgItem (MainDlg, IDC_PREV), !(bVolTransformThreadRunning || bVolTransformThreadToRun) && !bInPlaceEncNonSysResumed);
+ EnableWindow (GetDlgItem (MainDlg, IDCANCEL),
+ !(bVolTransformThreadToRun
+ || NonSysInplaceEncStatus == NONSYS_INPLACE_ENC_STATUS_PREPARING
+ || NonSysInplaceEncStatus == NONSYS_INPLACE_ENC_STATUS_RESIZING
+ || NonSysInplaceEncStatus == NONSYS_INPLACE_ENC_STATUS_FINALIZING
+ || NonSysInplaceEncStatus == NONSYS_INPLACE_ENC_STATUS_FINISHED));
+
+ if (bVolTransformThreadRunning || bVolTransformThreadToRun)
+ {
+ switch (NonSysInplaceEncStatus)
+ {
+ case NONSYS_INPLACE_ENC_STATUS_PREPARING:
+ case NONSYS_INPLACE_ENC_STATUS_RESIZING:
+ case NONSYS_INPLACE_ENC_STATUS_FINALIZING:
+ ArrowWaitCursor ();
+ break;
+
+ case NONSYS_INPLACE_ENC_STATUS_ENCRYPTING:
+ NormalCursor ();
+ break;
+
+ default:
+ NormalCursor ();
+ break;
+ }
+
+ if (bVolTransformThreadCancel)
+ WaitCursor ();
+ }
+ else
+ {
+ NormalCursor ();
+
+ if (bInPlaceEncNonSysResumed)
+ {
+ SetNonSysInplaceEncUIStatus (NONSYS_INPLACE_ENC_STATUS_PAUSED);
+ }
+ else
+ SetWindowText (GetDlgItem (hCurPage, IDC_WRITESPEED), " ");
+
+ SetWindowText (GetDlgItem (hCurPage, IDC_TIMEREMAIN), " ");
+ }
+
+ ShowNonSysInPlaceEncUIStatus ();
+
+ UpdateNonSysInplaceEncProgressBar ();
+}
+
+
+static void UpdateNonSysInplaceEncProgressBar (void)
+{
+ static int lastNonSysInplaceEncStatus = NONSYS_INPLACE_ENC_STATUS_NONE;
+ int nonSysInplaceEncStatus = NonSysInplaceEncStatus;
+ __int64 totalSize = NonSysInplaceEncTotalSize;
+
+ if (bVolTransformThreadRunning
+ && (nonSysInplaceEncStatus == NONSYS_INPLACE_ENC_STATUS_ENCRYPTING
+ || nonSysInplaceEncStatus == NONSYS_INPLACE_ENC_STATUS_FINALIZING
+ || nonSysInplaceEncStatus == NONSYS_INPLACE_ENC_STATUS_FINISHED))
+ {
+ if (lastNonSysInplaceEncStatus != nonSysInplaceEncStatus
+ && nonSysInplaceEncStatus == NONSYS_INPLACE_ENC_STATUS_ENCRYPTING)
+ {
+ InitNonSysInplaceEncProgressBar ();
+ }
+ else
+ {
+ if (totalSize <= 0 && nVolumeSize > 0)
+ totalSize = nVolumeSize;
+
+ if (totalSize > 0)
+ UpdateProgressBarProc (NonSysInplaceEncBytesDone);
+ }
+ }
+
+ ShowNonSysInPlaceEncUIStatus ();
+
+ lastNonSysInplaceEncStatus = nonSysInplaceEncStatus;
+}
+
+
+static void InitNonSysInplaceEncProgressBar (void)
+{
+ __int64 totalSize = NonSysInplaceEncTotalSize;
+
+ if (totalSize <= 0)
+ {
+ if (nVolumeSize <= 0)
+ return;
+
+ totalSize = nVolumeSize;
+ }
+
+ InitProgressBar (totalSize,
+ NonSysInplaceEncBytesDone,
+ FALSE,
+ TRUE,
+ TRUE,
+ TRUE);
+}
+
+
+void DisplayRandPool (HWND hPoolDisplay, BOOL bShow)
+{
+ unsigned char tmp[4];
+ unsigned char tmpByte;
+ int col, row;
+ static BOOL bRandPoolDispAscii = FALSE;
+
+ if (!bShow)
+ {
+ SetWindowText (hPoolDisplay, "");
+ return;
+ }
+
+ RandpeekBytes (randPool, sizeof (randPool));
+
+ if (memcmp (lastRandPool, randPool, sizeof(lastRandPool)) != 0)
+ {
+ outRandPoolDispBuffer[0] = 0;
+
+ for (row = 0; row < RANDPOOL_DISPLAY_ROWS; row++)
+ {
+ for (col = 0; col < RANDPOOL_DISPLAY_COLUMNS; col++)
+ {
+ tmpByte = randPool[row * RANDPOOL_DISPLAY_COLUMNS + col];
+
+ sprintf ((char *) tmp, bRandPoolDispAscii ? ((tmpByte >= 32 && tmpByte < 255 && tmpByte != '&') ? " %c " : " . ") : "%02X ", tmpByte);
+ strcat ((char *) outRandPoolDispBuffer, (char *) tmp);
+ }
+ strcat ((char *) outRandPoolDispBuffer, "\n");
+ }
+ SetWindowText (hPoolDisplay, (char *) outRandPoolDispBuffer);
+
+ memcpy (lastRandPool, randPool, sizeof(lastRandPool));
+ }
+}
+
+
+void DisplayPortionsOfKeys (HWND headerKeyHandle, HWND masterKeyHandle, char *headerKeyStr, char *masterKeyStr, BOOL hideKeys)
+{
+ const wchar_t *hiddenKey = L"******************************** ";
+
+ SetWindowTextW (headerKeyHandle, hideKeys ? hiddenKey : (SingleStringToWide (headerKeyStr) + GetString ("TRIPLE_DOT_GLYPH_ELLIPSIS")).c_str());
+ SetWindowTextW (masterKeyHandle, hideKeys ? hiddenKey : (SingleStringToWide (masterKeyStr) + GetString ("TRIPLE_DOT_GLYPH_ELLIPSIS")).c_str());
+}
+
+
+static void WipeAbort (void)
+{
+ EnableWindow (GetDlgItem (hCurPage, IDC_ABORT_BUTTON), FALSE);
+
+ if (bHiddenOS && IsHiddenOSRunning())
+ {
+ /* Decoy system partition wipe */
+
+ DecoySystemWipeStatus decoySysPartitionWipeStatus;
+
+ try
+ {
+ decoySysPartitionWipeStatus = BootEncObj->GetDecoyOSWipeStatus();
+ }
+ catch (Exception &e)
+ {
+ e.Show (MainDlg);
+ EnableWindow (GetDlgItem (hCurPage, IDC_ABORT_BUTTON), TRUE);
+ return;
+ }
+
+ if (!decoySysPartitionWipeStatus.WipeInProgress)
+ {
+ EnableWindow (GetDlgItem (hCurPage, IDC_ABORT_BUTTON), TRUE);
+ return;
+ }
+
+ WaitCursor ();
+
+ try
+ {
+ int attempts = SYSENC_PAUSE_RETRIES;
+
+ BootEncObj->AbortDecoyOSWipe ();
+
+ decoySysPartitionWipeStatus = BootEncObj->GetDecoyOSWipeStatus();
+
+ while (decoySysPartitionWipeStatus.WipeInProgress && attempts > 0)
+ {
+ Sleep (SYSENC_PAUSE_RETRY_INTERVAL);
+ attempts--;
+ decoySysPartitionWipeStatus = BootEncObj->GetDecoyOSWipeStatus();
+ }
+
+ if (!decoySysPartitionWipeStatus.WipeInProgress)
+ BootEncObj->CheckDecoyOSWipeResult ();
+
+ }
+ catch (Exception &e)
+ {
+ e.Show (MainDlg);
+ }
+
+ NormalCursor ();
+
+ if (decoySysPartitionWipeStatus.WipeInProgress)
+ {
+ SetTimer (MainDlg, TIMER_ID_WIPE_PROGRESS, TIMER_INTERVAL_WIPE_PROGRESS, NULL);
+ EnableWindow (GetDlgItem (hCurPage, IDC_ABORT_BUTTON), TRUE);
+ Error ("FAILED_TO_INTERRUPT_WIPING");
+ return;
+ }
+ }
+ else
+ {
+ /* Regular device wipe (not decoy system partition wipe) */
+ }
+
+ UpdateWipeControls ();
+ EnableWindow (GetDlgItem (hCurPage, IDC_ABORT_BUTTON), TRUE);
+}
+
+
+static void WipeStart (void)
+{
+ if (bHiddenOS && IsHiddenOSRunning())
+ {
+ /* Decoy system partition wipe */
+
+ EnableWindow (GetDlgItem (hCurPage, IDC_ABORT_BUTTON), FALSE);
+
+ bDeviceWipeInProgress = FALSE;
+ WaitCursor ();
+
+ try
+ {
+ BootEncObj->StartDecoyOSWipe (nWipeMode);
+
+ bDeviceWipeInProgress = TRUE;
+ }
+ catch (Exception &e)
+ {
+ e.Show (MainDlg);
+ }
+
+ NormalCursor ();
+
+ if (!bDeviceWipeInProgress)
+ {
+ EnableWindow (GetDlgItem (hCurPage, IDC_ABORT_BUTTON), TRUE);
+ Error ("FAILED_TO_START_WIPING");
+ return;
+ }
+ }
+ else
+ {
+ /* Regular device wipe (not decoy system partition wipe) */
+ }
+
+ InitWipeProgressBar ();
+ UpdateWipeProgressBar ();
+ UpdateWipeControls ();
+ EnableWindow (GetDlgItem (hCurPage, IDC_ABORT_BUTTON), TRUE);
+ SetTimer (MainDlg, TIMER_ID_WIPE_PROGRESS, TIMER_INTERVAL_WIPE_PROGRESS, NULL);
+}
+
+
+static void UpdateWipeProgressBar (void)
+{
+ if (bHiddenOS && IsHiddenOSRunning())
+ {
+ /* Decoy system partition wipe */
+
+ DecoySystemWipeStatus decoySysPartitionWipeStatus;
+
+ try
+ {
+ decoySysPartitionWipeStatus = BootEncObj->GetDecoyOSWipeStatus();
+ BootEncStatus = BootEncObj->GetStatus();
+ }
+ catch (...)
+ {
+ return;
+ }
+
+ if (decoySysPartitionWipeStatus.WipedAreaEnd == -1)
+ UpdateProgressBarProc (0);
+ else
+ UpdateProgressBarProc (decoySysPartitionWipeStatus.WipedAreaEnd - BootEncStatus.ConfiguredEncryptedAreaStart + 1);
+ }
+ else
+ {
+ /* Regular device wipe (not decoy system partition wipe) */
+ }
+}
+
+
+static void InitWipeProgressBar (void)
+{
+ if (bHiddenOS && IsHiddenOSRunning())
+ {
+ /* Decoy system partition wipe */
+
+ DecoySystemWipeStatus decoySysPartitionWipeStatus;
+
+ try
+ {
+ decoySysPartitionWipeStatus = BootEncObj->GetDecoyOSWipeStatus();
+ BootEncStatus = BootEncObj->GetStatus();
+ }
+ catch (...)
+ {
+ return;
+ }
+
+ if (BootEncStatus.ConfiguredEncryptedAreaEnd == -1
+ || BootEncStatus.ConfiguredEncryptedAreaStart == -1)
+ return;
+
+ InitProgressBar (BootEncStatus.ConfiguredEncryptedAreaEnd - BootEncStatus.ConfiguredEncryptedAreaStart + 1,
+ (decoySysPartitionWipeStatus.WipedAreaEnd == BootEncStatus.ConfiguredEncryptedAreaStart || decoySysPartitionWipeStatus.WipedAreaEnd == -1) ?
+ 0 : decoySysPartitionWipeStatus.WipedAreaEnd - BootEncStatus.ConfiguredEncryptedAreaStart + 1,
+ FALSE,
+ TRUE,
+ FALSE,
+ TRUE);
+ }
+ else
+ {
+ /* Regular device wipe (not decoy system partition wipe) */
+ }
+}
+
+
+static void UpdateWipeControls (void)
+{
+ if (bHiddenOS && IsHiddenOSRunning())
+ {
+ /* Decoy system partition wipe */
+
+ DecoySystemWipeStatus decoySysPartitionWipeStatus;
+
+ try
+ {
+ decoySysPartitionWipeStatus = BootEncObj->GetDecoyOSWipeStatus();
+ BootEncStatus = BootEncObj->GetStatus();
+ }
+ catch (...)
+ {
+ return;
+ }
+
+ EnableWindow (GetDlgItem (MainDlg, IDC_NEXT), !decoySysPartitionWipeStatus.WipeInProgress);
+ }
+ else
+ {
+ /* Regular device wipe (not decoy system partition wipe) */
+
+ EnableWindow (GetDlgItem (MainDlg, IDC_NEXT), bDeviceWipeInProgress);
+
+ if (!bDeviceWipeInProgress)
+ {
+ SetWindowText (GetDlgItem (hCurPage, IDC_TIMEREMAIN), " ");
+ }
+ }
+
+ EnableWindow (GetDlgItem (hCurPage, IDC_ABORT_BUTTON), bDeviceWipeInProgress);
+ EnableWindow (GetDlgItem (MainDlg, IDC_PREV), !bDeviceWipeInProgress);
+
+ bConfirmQuit = bDeviceWipeInProgress;
+}
+
+
+
+static void __cdecl sysEncDriveAnalysisThread (void *hwndDlgArg)
+{
+ // Mark the detection process as 'in progress'
+ HiddenSectorDetectionStatus = 1;
+ SaveSettings (NULL);
+ BroadcastSysEncCfgUpdate ();
+
+ try
+ {
+ BootEncObj->ProbeRealSystemDriveSize ();
+ bSysEncDriveAnalysisTimeOutOccurred = FALSE;
+ }
+ catch (TimeOut &)
+ {
+ bSysEncDriveAnalysisTimeOutOccurred = TRUE;
+ }
+ catch (Exception &e)
+ {
+ // There was a problem but the system did not freeze. Mark the detection process as completed.
+ HiddenSectorDetectionStatus = 0;
+ SaveSettings (NULL);
+ BroadcastSysEncCfgUpdate ();
+
+ e.Show (NULL);
+ EndMainDlg (MainDlg);
+ exit(0);
+ }
+
+ // Mark the detection process as completed
+ HiddenSectorDetectionStatus = 0;
+ SaveSettings (NULL);
+ BroadcastSysEncCfgUpdate ();
+
+ // This artificial delay prevents user confusion on systems where the analysis ends almost instantly
+ Sleep (3000);
+
+ bSysEncDriveAnalysisInProgress = FALSE;
+}
+
+static void __cdecl volTransformThreadFunction (void *hwndDlgArg)
+{
+ int nStatus;
+ DWORD dwWin32FormatError;
+ BOOL bHidden;
+ HWND hwndDlg = (HWND) hwndDlgArg;
+ volatile FORMAT_VOL_PARAMETERS *volParams = (FORMAT_VOL_PARAMETERS *) malloc (sizeof(FORMAT_VOL_PARAMETERS));
+
+ if (volParams == NULL)
+ AbortProcess ("ERR_MEM_ALLOC");
+
+ VirtualLock ((LPVOID) volParams, sizeof(FORMAT_VOL_PARAMETERS));
+
+ bVolTransformThreadRunning = TRUE;
+ bVolTransformThreadToRun = FALSE;
+
+ // Check administrator privileges
+ if (!IsAdmin () && !IsUacSupported ())
+ {
+ if (fileSystem == FILESYS_NTFS)
+ {
+ if (MessageBoxW (hwndDlg, GetString ("ADMIN_PRIVILEGES_WARN_NTFS"), lpszTitle, MB_OKCANCEL|MB_ICONWARNING|MB_DEFBUTTON2) == IDCANCEL)
+ goto cancel;
+ }
+ if (bDevice)
+ {
+ if (MessageBoxW (hwndDlg, GetString ("ADMIN_PRIVILEGES_WARN_DEVICES"), lpszTitle, MB_OKCANCEL|MB_ICONWARNING|MB_DEFBUTTON2) == IDCANCEL)
+ goto cancel;
+ }
+ }
+
+ if (!bInPlaceEncNonSys)
+ {
+ if (!bDevice)
+ {
+ int x = _access (szDiskFile, 06);
+ if (x == 0 || errno != ENOENT)
+ {
+ wchar_t szTmp[512];
+
+ if (! ((bHiddenVol && !bHiddenVolHost) && errno != EACCES)) // Only ask ask for permission to overwrite an existing volume if we're not creating a hidden volume
+ {
+ _snwprintf (szTmp, sizeof szTmp / 2,
+ GetString (errno == EACCES ? "READONLYPROMPT" : "OVERWRITEPROMPT"),
+ szDiskFile);
+
+ x = MessageBoxW (hwndDlg, szTmp, lpszTitle, YES_NO|MB_ICONWARNING|MB_DEFBUTTON2);
+
+ if (x != IDYES)
+ goto cancel;
+ }
+ }
+
+ if (_access (szDiskFile, 06) != 0)
+ {
+ if (errno == EACCES)
+ {
+ if (_chmod (szDiskFile, _S_IREAD | _S_IWRITE) != 0)
+ {
+ MessageBoxW (hwndDlg, GetString ("ACCESSMODEFAIL"), lpszTitle, ICON_HAND);
+ goto cancel;
+ }
+ }
+ }
+
+ }
+ else
+ {
+ // Partition / device / dynamic volume
+
+ if (!FinalPreTransformPrompts ())
+ goto cancel;
+ }
+ }
+
+ // Prevent the OS from entering Sleep mode when idle
+ SetThreadExecutionState (ES_CONTINUOUS | ES_SYSTEM_REQUIRED);
+
+ bHidden = bHiddenVol && !bHiddenVolHost;
+
+ volParams->bDevice = bDevice;
+ volParams->hiddenVol = bHidden;
+ volParams->volumePath = szDiskFile;
+ volParams->size = nVolumeSize;
+ volParams->hiddenVolHostSize = nHiddenVolHostSize;
+ volParams->ea = nVolumeEA;
+ volParams->pkcs5 = hash_algo;
+ volParams->headerFlags = CreatingHiddenSysVol() ? TC_HEADER_FLAG_ENCRYPTED_SYSTEM : 0;
+ volParams->fileSystem = fileSystem;
+ volParams->clusterSize = clusterSize;
+ volParams->sparseFileSwitch = bSparseFileSwitch;
+ volParams->quickFormat = quickFormat;
+ volParams->sectorSize = GetFormatSectorSize();
+ volParams->realClusterSize = &realClusterSize;
+ volParams->password = &volumePassword;
+ volParams->hwndDlg = hwndDlg;
+
+ if (bInPlaceEncNonSys)
+ {
+ HANDLE hPartition = INVALID_HANDLE_VALUE;
+
+ SetNonSysInplaceEncUIStatus (NONSYS_INPLACE_ENC_STATUS_PREPARING);
+
+ if (!bInPlaceEncNonSysResumed)
+ {
+ bTryToCorrectReadErrors = FALSE;
+
+ nStatus = EncryptPartitionInPlaceBegin (volParams, &hPartition, nWipeMode);
+
+ if (nStatus == ERR_SUCCESS)
+ {
+ nStatus = EncryptPartitionInPlaceResume (hPartition, volParams, nWipeMode, &bTryToCorrectReadErrors);
+ }
+ else if (hPartition != INVALID_HANDLE_VALUE)
+ {
+ CloseHandle (hPartition);
+ hPartition = INVALID_HANDLE_VALUE;
+ }
+ }
+ else
+ {
+ nStatus = EncryptPartitionInPlaceResume (INVALID_HANDLE_VALUE, volParams, nWipeMode, &bTryToCorrectReadErrors);
+ }
+ }
+ else
+ {
+ InitProgressBar (GetVolumeDataAreaSize (bHidden, nVolumeSize), 0, FALSE, FALSE, FALSE, TRUE);
+
+ nStatus = TCFormatVolume (volParams);
+ }
+
+ // Allow the OS to enter Sleep mode when idle
+ SetThreadExecutionState (ES_CONTINUOUS);
+
+ if (nStatus == ERR_OUTOFMEMORY)
+ {
+ AbortProcess ("OUTOFMEMORY");
+ }
+
+ if (bInPlaceEncNonSys
+ && nStatus == ERR_USER_ABORT
+ && NonSysInplaceEncStatus == NONSYS_INPLACE_ENC_STATUS_FINISHED)
+ {
+ // Ignore user abort if non-system in-place encryption successfully finished
+ nStatus = ERR_SUCCESS;
+ }
+
+
+ dwWin32FormatError = GetLastError ();
+
+ if (bHiddenVolHost && !bVolTransformThreadCancel && nStatus == 0)
+ {
+ /* Auto mount the newly created hidden volume host */
+ switch (MountHiddenVolHost (hwndDlg, szDiskFile, &hiddenVolHostDriveNo, &volumePassword, FALSE))
+ {
+ case ERR_NO_FREE_DRIVES:
+ MessageBoxW (hwndDlg, GetString ("NO_FREE_DRIVE_FOR_OUTER_VOL"), lpszTitle, ICON_HAND);
+ bVolTransformThreadCancel = TRUE;
+ break;
+ case ERR_VOL_MOUNT_FAILED:
+ case ERR_PASSWORD_WRONG:
+ MessageBoxW (hwndDlg, GetString ("CANT_MOUNT_OUTER_VOL"), lpszTitle, ICON_HAND);
+ bVolTransformThreadCancel = TRUE;
+ break;
+ }
+ }
+
+ SetLastError (dwWin32FormatError);
+
+ if ((bVolTransformThreadCancel || nStatus == ERR_USER_ABORT)
+ && !(bInPlaceEncNonSys && NonSysInplaceEncStatus == NONSYS_INPLACE_ENC_STATUS_FINISHED)) // Ignore user abort if non-system in-place encryption successfully finished.
+ {
+ if (!bDevice && !(bHiddenVol && !bHiddenVolHost)) // If we're not creating a hidden volume and if it's a file container
+ {
+ remove (szDiskFile); // Delete the container
+ }
+
+ goto cancel;
+ }
+
+ if (nStatus != ERR_USER_ABORT)
+ {
+ if (nStatus != 0)
+ {
+ /* An error occurred */
+
+ wchar_t szMsg[8192];
+
+ handleError (hwndDlg, nStatus);
+
+ if (bInPlaceEncNonSys)
+ {
+ if (bInPlaceEncNonSysResumed)
+ {
+ SetNonSysInplaceEncUIStatus (NONSYS_INPLACE_ENC_STATUS_PAUSED);
+ Error ("INPLACE_ENC_GENERIC_ERR_RESUME");
+ }
+ else
+ {
+ SetNonSysInplaceEncUIStatus (NONSYS_INPLACE_ENC_STATUS_ERROR);
+ ShowInPlaceEncErrMsgWAltSteps ("INPLACE_ENC_GENERIC_ERR_ALT_STEPS", TRUE);
+ }
+ }
+ else if (!(bHiddenVolHost && hiddenVolHostDriveNo < 0)) // If the error was not that the hidden volume host could not be mounted (this error has already been reported to the user)
+ {
+ swprintf (szMsg, GetString ("CREATE_FAILED"), szDiskFile);
+ MessageBoxW (hwndDlg, szMsg, lpszTitle, ICON_HAND);
+ }
+
+ if (!bDevice && !(bHiddenVol && !bHiddenVolHost)) // If we're not creating a hidden volume and if it's a file container
+ {
+ remove (szDiskFile); // Delete the container
+ }
+
+ goto cancel;
+ }
+ else
+ {
+ /* Volume successfully created */
+
+ RestoreDefaultKeyFilesParam ();
+
+ if (bDevice && !bInPlaceEncNonSys)
+ {
+ // Handle assigned drive letter (if any)
+
+ HandleOldAssignedDriveLetter ();
+ }
+
+ if (!bHiddenVolHost)
+ {
+ if (bHiddenVol)
+ {
+ bHiddenVolFinished = TRUE;
+
+ if (!bHiddenOS)
+ Warning ("HIDVOL_FORMAT_FINISHED_HELP");
+ }
+ else if (bInPlaceEncNonSys)
+ {
+ Warning ("NONSYS_INPLACE_ENC_FINISHED_INFO");
+
+ HandleOldAssignedDriveLetter ();
+ }
+ else
+ {
+ Info("FORMAT_FINISHED_INFO");
+
+ if (bSparseFileSwitch && quickFormat)
+ Warning("SPARSE_FILE_SIZE_NOTE");
+ }
+ }
+ else
+ {
+ /* We've just created an outer volume (to host a hidden volume within) */
+
+ bHiddenVolHost = FALSE;
+ bHiddenVolFinished = FALSE;
+ nHiddenVolHostSize = nVolumeSize;
+
+ // Clear the outer volume password
+ memset(&szVerify[0], 0, sizeof (szVerify));
+ memset(&szRawPassword[0], 0, sizeof (szRawPassword));
+
+ MessageBeep (MB_OK);
+ }
+
+ if (!bInPlaceEncNonSys)
+ SetTimer (hwndDlg, TIMER_ID_RANDVIEW, TIMER_INTERVAL_RANDVIEW, NULL);
+
+ if (volParams != NULL)
+ {
+ burn ((LPVOID) volParams, sizeof(FORMAT_VOL_PARAMETERS));
+ VirtualUnlock ((LPVOID) volParams, sizeof(FORMAT_VOL_PARAMETERS));
+ free ((LPVOID) volParams);
+ volParams = NULL;
+ }
+
+ bVolTransformThreadRunning = FALSE;
+ bVolTransformThreadCancel = FALSE;
+
+ PostMessage (hwndDlg, bInPlaceEncNonSys ? TC_APPMSG_NONSYS_INPLACE_ENC_FINISHED : TC_APPMSG_FORMAT_FINISHED, 0, 0);
+
+ LastDialogId = "FORMAT_FINISHED";
+ _endthread ();
+ }
+ }
+
+cancel:
+
+ LastDialogId = (bInPlaceEncNonSys ? "NONSYS_INPLACE_ENC_CANCELED" : "FORMAT_CANCELED");
+
+ if (!bInPlaceEncNonSys)
+ SetTimer (hwndDlg, TIMER_ID_RANDVIEW, TIMER_INTERVAL_RANDVIEW, NULL);
+
+ if (volParams != NULL)
+ {
+ burn ((LPVOID) volParams, sizeof(FORMAT_VOL_PARAMETERS));
+ VirtualUnlock ((LPVOID) volParams, sizeof(FORMAT_VOL_PARAMETERS));
+ free ((LPVOID) volParams);
+ volParams = NULL;
+ }
+
+ bVolTransformThreadRunning = FALSE;
+ bVolTransformThreadCancel = FALSE;
+
+ // Allow the OS to enter Sleep mode when idle
+ SetThreadExecutionState (ES_CONTINUOUS);
+
+ PostMessage (hwndDlg, TC_APPMSG_VOL_TRANSFORM_THREAD_ENDED, 0, 0);
+
+ if (bHiddenVolHost && hiddenVolHostDriveNo < -1 && !bVolTransformThreadCancel) // If hidden volume host could not be mounted
+ AbortProcessSilent ();
+
+ _endthread ();
+}
+
+static void LoadPage (HWND hwndDlg, int nPageNo)
+{
+ RECT rD, rW;
+
+ nLastPageNo = nCurPageNo;
+
+ if (hCurPage != NULL)
+ {
+ // WARNING: nCurPageNo must be set to a non-existent ID here before wiping the password fields below in
+ // this function, etc. Otherwise, such actions (SetWindowText) would invoke the EN_CHANGE handlers, which
+ // would, if keyfiles were applied, e.g. use strlen() on a buffer full of random data, in most cases
+ // not null-terminated.
+ nCurPageNo = -1;
+
+
+ // Place here any actions that need to be performed at the latest possible time when leaving a wizard page
+ // (i.e. right before "destroying" the page). Also, code that needs to be executed both on IDC_NEXT and
+ // on IDC_PREV can be placed here so as to avoid code doubling.
+
+ switch (nLastPageNo)
+ {
+ case PASSWORD_PAGE:
+ {
+ char tmp[MAX_PASSWORD+1];
+
+ // Attempt to wipe passwords stored in the input field buffers. This is performed here (and
+ // not in the IDC_PREV or IDC_NEXT sections) in order to prevent certain race conditions
+ // when keyfiles are used.
+ memset (tmp, 'X', MAX_PASSWORD);
+ tmp [MAX_PASSWORD] = 0;
+ SetWindowText (hPasswordInputField, tmp);
+ SetWindowText (hVerifyPasswordInputField, tmp);
+ }
+ break;
+ }
+
+ DestroyWindow (hCurPage);
+ hCurPage = NULL;
+ }
+
+ // This prevents the mouse pointer from remaining as the "hand" cursor when the user presses Enter
+ // while hovering over a hyperlink.
+ bHyperLinkBeingTracked = FALSE;
+ NormalCursor();
+
+ GetWindowRect (GetDlgItem (hwndDlg, IDC_POS_BOX), &rW);
+
+
+ nCurPageNo = nPageNo;
+
+
+ switch (nPageNo)
+ {
+ case INTRO_PAGE:
+ hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_INTRO_PAGE_DLG), hwndDlg,
+ (DLGPROC) PageDialogProc);
+ break;
+
+ case SYSENC_TYPE_PAGE:
+ hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_SYSENC_TYPE_PAGE_DLG), hwndDlg,
+ (DLGPROC) PageDialogProc);
+ break;
+
+ case SYSENC_HIDDEN_OS_REQ_CHECK_PAGE:
+ hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_SYSENC_HIDDEN_OS_REQ_CHECK_PAGE_DLG), hwndDlg,
+ (DLGPROC) PageDialogProc);
+ break;
+
+ case SYSENC_SPAN_PAGE:
+ hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_SYSENC_SPAN_PAGE_DLG), hwndDlg,
+ (DLGPROC) PageDialogProc);
+ break;
+
+ case SYSENC_PRE_DRIVE_ANALYSIS_PAGE:
+ hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_UNIVERSAL_DUAL_CHOICE_PAGE_DLG), hwndDlg,
+ (DLGPROC) PageDialogProc);
+ break;
+
+ case SYSENC_DRIVE_ANALYSIS_PAGE:
+ hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_SYSENC_DRIVE_ANALYSIS_PAGE_DLG), hwndDlg,
+ (DLGPROC) PageDialogProc);
+ break;
+
+ case SYSENC_MULTI_BOOT_MODE_PAGE:
+ hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_SYSENC_MULTI_BOOT_MODE_PAGE_DLG), hwndDlg,
+ (DLGPROC) PageDialogProc);
+ break;
+
+ case SYSENC_MULTI_BOOT_SYS_EQ_BOOT_PAGE:
+ case SYSENC_MULTI_BOOT_NBR_SYS_DRIVES_PAGE:
+ case SYSENC_MULTI_BOOT_ADJACENT_SYS_PAGE:
+ case SYSENC_MULTI_BOOT_NONWIN_BOOT_LOADER_PAGE:
+ hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_UNIVERSAL_DUAL_CHOICE_PAGE_DLG), hwndDlg,
+ (DLGPROC) PageDialogProc);
+ break;
+
+ case SYSENC_MULTI_BOOT_OUTCOME_PAGE:
+ hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_INFO_PAGE_DLG), hwndDlg,
+ (DLGPROC) PageDialogProc);
+ break;
+
+ case VOLUME_TYPE_PAGE:
+ hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_VOLUME_TYPE_PAGE_DLG), hwndDlg,
+ (DLGPROC) PageDialogProc);
+ break;
+
+ case HIDDEN_VOL_WIZARD_MODE_PAGE:
+ hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_HIDDEN_VOL_WIZARD_MODE_PAGE_DLG), hwndDlg,
+ (DLGPROC) PageDialogProc);
+ break;
+
+ case VOLUME_LOCATION_PAGE:
+ hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_VOLUME_LOCATION_PAGE_DLG), hwndDlg,
+ (DLGPROC) PageDialogProc);
+
+ EnableWindow (GetDlgItem(hCurPage, IDC_NO_HISTORY), !bHistoryCmdLine);
+
+ EnableWindow (GetDlgItem (hwndDlg, IDC_NEXT),
+ GetWindowTextLength (GetDlgItem (hCurPage, IDC_COMBO_BOX)) > 0);
+
+ break;
+
+ case DEVICE_TRANSFORM_MODE_PAGE:
+ hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_DEVICE_TRANSFORM_MODE_DLG), hwndDlg,
+ (DLGPROC) PageDialogProc);
+ break;
+ case HIDDEN_VOL_HOST_PRE_CIPHER_PAGE:
+ hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_INFO_PAGE_DLG), hwndDlg,
+ (DLGPROC) PageDialogProc);
+ break;
+ case HIDDEN_VOL_PRE_CIPHER_PAGE:
+ hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_INFO_PAGE_DLG), hwndDlg,
+ (DLGPROC) PageDialogProc);
+ break;
+ case CIPHER_PAGE:
+ hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_CIPHER_PAGE_DLG), hwndDlg,
+ (DLGPROC) PageDialogProc);
+ break;
+ case SIZE_PAGE:
+ hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_SIZE_PAGE_DLG), hwndDlg,
+ (DLGPROC) PageDialogProc);
+ break;
+ case HIDDEN_VOL_HOST_PASSWORD_PAGE:
+ hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_PASSWORD_ENTRY_PAGE_DLG), hwndDlg,
+ (DLGPROC) PageDialogProc);
+ break;
+ case PASSWORD_PAGE:
+ hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_PASSWORD_PAGE_DLG), hwndDlg,
+ (DLGPROC) PageDialogProc);
+ break;
+ case FILESYS_PAGE:
+ hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_UNIVERSAL_DUAL_CHOICE_PAGE_DLG), hwndDlg,
+ (DLGPROC) PageDialogProc);
+ break;
+ case SYSENC_COLLECTING_RANDOM_DATA_PAGE:
+ case NONSYS_INPLACE_ENC_RAND_DATA_PAGE:
+ hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_SYSENC_COLLECTING_RANDOM_DATA_DLG), hwndDlg,
+ (DLGPROC) PageDialogProc);
+ break;
+ case SYSENC_KEYS_GEN_PAGE:
+ hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_SYSENC_KEYS_GEN_PAGE_DLG), hwndDlg,
+ (DLGPROC) PageDialogProc);
+ break;
+ case SYSENC_RESCUE_DISK_CREATION_PAGE:
+ hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_SYSENC_RESCUE_DISK_CREATION_DLG), hwndDlg,
+ (DLGPROC) PageDialogProc);
+ break;
+ case SYSENC_RESCUE_DISK_BURN_PAGE:
+ hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_SYSENC_RESCUE_DISK_BURN_PAGE_DLG), hwndDlg,
+ (DLGPROC) PageDialogProc);
+ break;
+ case SYSENC_RESCUE_DISK_VERIFIED_PAGE:
+ hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_INFO_PAGE_DLG), hwndDlg,
+ (DLGPROC) PageDialogProc);
+ break;
+ case SYSENC_WIPE_MODE_PAGE:
+ case NONSYS_INPLACE_ENC_WIPE_MODE_PAGE:
+ hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_SYSENC_WIPE_MODE_PAGE_DLG), hwndDlg,
+ (DLGPROC) PageDialogProc);
+ break;
+ case SYSENC_PRETEST_INFO_PAGE:
+ hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_INFO_PAGE_DLG), hwndDlg,
+ (DLGPROC) PageDialogProc);
+ break;
+ case SYSENC_PRETEST_RESULT_PAGE:
+ hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_INFO_PAGE_DLG), hwndDlg,
+ (DLGPROC) PageDialogProc);
+ break;
+ case SYSENC_ENCRYPTION_PAGE:
+ hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_INPLACE_ENCRYPTION_PAGE_DLG), hwndDlg,
+ (DLGPROC) PageDialogProc);
+ break;
+
+ case NONSYS_INPLACE_ENC_RESUME_PASSWORD_PAGE:
+ hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_PASSWORD_ENTRY_PAGE_DLG), hwndDlg,
+ (DLGPROC) PageDialogProc);
+ break;
+
+ case NONSYS_INPLACE_ENC_RESUME_PARTITION_SEL_PAGE:
+ hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_EXPANDED_LIST_SELECT_PAGE_DLG), hwndDlg,
+ (DLGPROC) PageDialogProc);
+ break;
+
+ case NONSYS_INPLACE_ENC_ENCRYPTION_PAGE:
+ hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_INPLACE_ENCRYPTION_PAGE_DLG), hwndDlg,
+ (DLGPROC) PageDialogProc);
+ break;
+
+ case NONSYS_INPLACE_ENC_ENCRYPTION_FINISHED_PAGE:
+ hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_INFO_PAGE_DLG), hwndDlg,
+ (DLGPROC) PageDialogProc);
+ break;
+
+ case FORMAT_PAGE:
+ hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_FORMAT_PAGE_DLG), hwndDlg,
+ (DLGPROC) PageDialogProc);
+ break;
+ case FORMAT_FINISHED_PAGE:
+ hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW ((bHiddenVol && !bHiddenVolHost && !bHiddenVolFinished) ? IDD_HIDVOL_HOST_FILL_PAGE_DLG : IDD_INFO_PAGE_DLG), hwndDlg,
+ (DLGPROC) PageDialogProc);
+ break;
+
+ case SYSENC_HIDDEN_OS_INITIAL_INFO_PAGE:
+ hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_INFO_PAGE_DLG), hwndDlg, (DLGPROC) PageDialogProc);
+ break;
+
+ case SYSENC_HIDDEN_OS_WIPE_INFO_PAGE:
+ hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_INFO_PAGE_DLG), hwndDlg, (DLGPROC) PageDialogProc);
+ break;
+
+ case DEVICE_WIPE_MODE_PAGE:
+ hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_DEVICE_WIPE_MODE_PAGE_DLG), hwndDlg, (DLGPROC) PageDialogProc);
+ break;
+
+ case DEVICE_WIPE_PAGE:
+ hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_DEVICE_WIPE_PAGE_DLG), hwndDlg, (DLGPROC) PageDialogProc);
+ break;
+ }
+
+ rD.left = 162;
+ rD.top = 25;
+ rD.right = 0;
+ rD.bottom = 0;
+ MapDialogRect (hwndDlg, &rD);
+
+ if (hCurPage != NULL)
+ {
+ MoveWindow (hCurPage, rD.left, rD.top, rW.right - rW.left, rW.bottom - rW.top, TRUE);
+ ShowWindow (hCurPage, SW_SHOWNORMAL);
+
+ // Place here any message boxes that need to be displayed as soon as a new page is displayed. This
+ // ensures that the page is fully rendered (otherwise it would remain blank, until the message box
+ // is closed).
+ switch (nPageNo)
+ {
+ case PASSWORD_PAGE:
+
+ CheckCapsLock (hwndDlg, FALSE);
+
+ if (CreatingHiddenSysVol())
+ Warning ("PASSWORD_HIDDEN_OS_NOTE");
+
+ break;
+
+ case CIPHER_PAGE:
+
+ if (CreatingHiddenSysVol())
+ Warning ("HIDDEN_OS_PRE_CIPHER_WARNING");
+
+ break;
+ }
+ }
+}
+
+
+int PrintFreeSpace (HWND hwndTextBox, char *lpszDrive, PLARGE_INTEGER lDiskFree)
+{
+ char *nResourceString;
+ int nMultiplier;
+ wchar_t szTmp2[256];
+
+ if (lDiskFree->QuadPart < BYTES_PER_KB)
+ nMultiplier = 1;
+ else if (lDiskFree->QuadPart < BYTES_PER_MB)
+ nMultiplier = BYTES_PER_KB;
+ else if (lDiskFree->QuadPart < BYTES_PER_GB)
+ nMultiplier = BYTES_PER_MB;
+ else
+ nMultiplier = BYTES_PER_GB;
+
+ if (nMultiplier == 1)
+ {
+ if (bHiddenVol && !bHiddenVolHost) // If it's a hidden volume
+ nResourceString = "MAX_HIDVOL_SIZE_BYTES";
+ else if (bDevice)
+ nResourceString = "DEVICE_FREE_BYTES";
+ else
+ nResourceString = "DISK_FREE_BYTES";
+ }
+ else if (nMultiplier == BYTES_PER_KB)
+ {
+ if (bHiddenVol && !bHiddenVolHost) // If it's a hidden volume
+ nResourceString = "MAX_HIDVOL_SIZE_KB";
+ else if (bDevice)
+ nResourceString = "DEVICE_FREE_KB";
+ else
+ nResourceString = "DISK_FREE_KB";
+ }
+ else if (nMultiplier == BYTES_PER_MB)
+ {
+ if (bHiddenVol && !bHiddenVolHost) // If it's a hidden volume
+ nResourceString = "MAX_HIDVOL_SIZE_MB";
+ else if (bDevice)
+ nResourceString = "DEVICE_FREE_MB";
+ else
+ nResourceString = "DISK_FREE_MB";
+ }
+ else
+ {
+ if (bHiddenVol && !bHiddenVolHost) // If it's a hidden volume
+ nResourceString = "MAX_HIDVOL_SIZE_GB";
+ else if (bDevice)
+ nResourceString = "DEVICE_FREE_GB";
+ else
+ nResourceString = "DISK_FREE_GB";
+ }
+
+ if (bHiddenVol && !bHiddenVolHost) // If it's a hidden volume
+ {
+ _snwprintf (szTmp2, sizeof szTmp2 / 2, GetString (nResourceString), ((double) lDiskFree->QuadPart) / nMultiplier);
+ SetWindowTextW (GetDlgItem (hwndTextBox, IDC_SIZEBOX), szTmp2);
+ }
+ else
+ _snwprintf (szTmp2, sizeof szTmp2 / 2, GetString (nResourceString), lpszDrive, ((double) lDiskFree->QuadPart) / nMultiplier);
+
+ SetWindowTextW (hwndTextBox, szTmp2);
+
+ if (lDiskFree->QuadPart % (__int64) BYTES_PER_MB != 0)
+ nMultiplier = BYTES_PER_KB;
+
+ return nMultiplier;
+}
+
+void DisplaySizingErrorText (HWND hwndTextBox)
+{
+ wchar_t szTmp[1024];
+
+ if (translateWin32Error (szTmp, sizeof (szTmp) / sizeof(szTmp[0])))
+ {
+ wchar_t szTmp2[1024];
+ wsprintfW (szTmp2, L"%s\n%s", GetString ("CANNOT_CALC_SPACE"), szTmp);
+ SetWindowTextW (hwndTextBox, szTmp2);
+ }
+ else
+ {
+ SetWindowText (hwndTextBox, "");
+ }
+}
+
+void EnableDisableFileNext (HWND hComboBox, HWND hMainButton)
+{
+ LPARAM nIndex = SendMessage (hComboBox, CB_GETCURSEL, 0, 0);
+ if (bHistory && nIndex == CB_ERR)
+ {
+ EnableWindow (hMainButton, FALSE);
+ SetFocus (hComboBox);
+ }
+ else
+ {
+ EnableWindow (hMainButton, TRUE);
+ SetFocus (hMainButton);
+ }
+}
+
+// Returns TRUE if the file is a sparse file. If it's not a sparse file or in case of any error, returns FALSE.
+BOOL IsSparseFile (HWND hwndDlg)
+{
+ HANDLE hFile;
+ BY_HANDLE_FILE_INFORMATION bhFileInfo;
+
+ FILETIME ftLastAccessTime;
+ BOOL bTimeStampValid = FALSE;
+
+ BOOL retCode = FALSE;
+
+ hFile = CreateFile (szFileName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
+
+ if (hFile == INVALID_HANDLE_VALUE)
+ {
+ MessageBoxW (hwndDlg, GetString ("CANT_ACCESS_VOL"), lpszTitle, ICON_HAND);
+ return FALSE;
+ }
+
+ if (bPreserveTimestamp)
+ {
+ if (GetFileTime (hFile, NULL, &ftLastAccessTime, NULL) == 0)
+ bTimeStampValid = FALSE;
+ else
+ bTimeStampValid = TRUE;
+ }
+
+ bhFileInfo.dwFileAttributes = 0;
+
+ GetFileInformationByHandle(hFile, &bhFileInfo);
+
+ retCode = bhFileInfo.dwFileAttributes & FILE_ATTRIBUTE_SPARSE_FILE;
+
+ if (bTimeStampValid)
+ SetFileTime (hFile, NULL, &ftLastAccessTime, NULL);
+
+ CloseHandle (hFile);
+ return retCode;
+}
+
+
+// Note: GetFileVolSize is not to be used for devices (only for file-hosted volumes)
+BOOL GetFileVolSize (HWND hwndDlg, unsigned __int64 *size)
+{
+ LARGE_INTEGER fileSize;
+ HANDLE hFile;
+
+ FILETIME ftLastAccessTime;
+ BOOL bTimeStampValid = FALSE;
+
+ hFile = CreateFile (szFileName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
+
+ if (hFile == INVALID_HANDLE_VALUE)
+ {
+ MessageBoxW (hwndDlg, GetString ("CANT_ACCESS_VOL"), lpszTitle, ICON_HAND);
+ return FALSE;
+ }
+
+ if (bPreserveTimestamp)
+ {
+ if (GetFileTime (hFile, NULL, &ftLastAccessTime, NULL) == 0)
+ bTimeStampValid = FALSE;
+ else
+ bTimeStampValid = TRUE;
+ }
+
+ if (GetFileSizeEx(hFile, &fileSize) == 0)
+ {
+ MessageBoxW (hwndDlg, GetString ("CANT_GET_VOLSIZE"), lpszTitle, ICON_HAND);
+
+ if (bTimeStampValid)
+ SetFileTime (hFile, NULL, &ftLastAccessTime, NULL);
+
+ CloseHandle (hFile);
+ return FALSE;
+ }
+
+ if (bTimeStampValid)
+ SetFileTime (hFile, NULL, &ftLastAccessTime, NULL);
+
+ CloseHandle (hFile);
+ *size = fileSize.QuadPart;
+ return TRUE;
+}
+
+
+BOOL QueryFreeSpace (HWND hwndDlg, HWND hwndTextBox, BOOL display)
+{
+ if (bHiddenVol && !bHiddenVolHost) // If it's a hidden volume
+ {
+ LARGE_INTEGER lDiskFree;
+ char szTmp[TC_MAX_PATH];
+
+ lDiskFree.QuadPart = nMaximumHiddenVolSize;
+
+ if (display)
+ PrintFreeSpace (hwndTextBox, szTmp, &lDiskFree);
+
+ return TRUE;
+ }
+ else if (bDevice == FALSE)
+ {
+ char root[TC_MAX_PATH];
+ ULARGE_INTEGER free;
+
+ if (!GetVolumePathName (szFileName, root, sizeof (root)))
+ {
+ handleWin32Error (hwndDlg);
+ return FALSE;
+ }
+
+ if (!GetDiskFreeSpaceEx (root, &free, 0, 0))
+ {
+ if (display)
+ DisplaySizingErrorText (hwndTextBox);
+
+ return FALSE;
+ }
+ else
+ {
+ LARGE_INTEGER lDiskFree;
+ lDiskFree.QuadPart = free.QuadPart;
+
+ if (display)
+ PrintFreeSpace (hwndTextBox, root, &lDiskFree);
+
+ return TRUE;
+ }
+ }
+ else
+ {
+ DISK_GEOMETRY driveInfo;
+ PARTITION_INFORMATION diskInfo;
+ BOOL piValid = FALSE;
+ BOOL gValid = FALSE;
+
+ // Query partition size
+ piValid = GetPartitionInfo (szDiskFile, &diskInfo);
+ gValid = GetDriveGeometry (szDiskFile, &driveInfo);
+
+ if (!piValid && !gValid)
+ {
+ if (display)
+ DisplaySizingErrorText (hwndTextBox);
+
+ return FALSE;
+ }
+
+ int sectorSize = GetFormatSectorSize();
+
+ if (sectorSize < TC_MIN_VOLUME_SECTOR_SIZE
+ || sectorSize > TC_MAX_VOLUME_SECTOR_SIZE
+ || sectorSize % ENCRYPTION_DATA_UNIT_SIZE != 0)
+ {
+ Error ("SECTOR_SIZE_UNSUPPORTED");
+ return FALSE;
+ }
+
+ if (piValid)
+ {
+ nVolumeSize = diskInfo.PartitionLength.QuadPart;
+
+ if(display)
+ nMultiplier = PrintFreeSpace (hwndTextBox, szDiskFile, &diskInfo.PartitionLength);
+
+ nUIVolumeSize = diskInfo.PartitionLength.QuadPart / nMultiplier;
+
+ if (nVolumeSize == 0)
+ {
+ if (display)
+ SetWindowTextW (hwndTextBox, GetString ("EXT_PARTITION"));
+
+ return FALSE;
+ }
+ }
+ else
+ {
+ LARGE_INTEGER lDiskFree;
+
+ // Drive geometry info is used only when GetPartitionInfo() fails
+ lDiskFree.QuadPart = driveInfo.Cylinders.QuadPart * driveInfo.BytesPerSector *
+ driveInfo.SectorsPerTrack * driveInfo.TracksPerCylinder;
+
+ nVolumeSize = lDiskFree.QuadPart;
+
+ if (display)
+ nMultiplier = PrintFreeSpace (hwndTextBox, szDiskFile, &lDiskFree);
+
+ nUIVolumeSize = lDiskFree.QuadPart / nMultiplier;
+ }
+
+ return TRUE;
+ }
+}
+
+
+static BOOL FinalPreTransformPrompts (void)
+{
+ int x;
+ wchar_t szTmp[4096];
+ int driveNo;
+ WCHAR deviceName[MAX_PATH];
+
+ strcpy ((char *)deviceName, szFileName);
+ ToUNICODE ((char *)deviceName);
+
+ driveNo = GetDiskDeviceDriveLetter (deviceName);
+
+ if (!(bHiddenVol && !bHiddenVolHost)) // Do not ask for permission to overwrite an existing volume if we're creating a hidden volume within it
+ {
+ wchar_t drive[128];
+ wchar_t volumeLabel[128];
+ wchar_t *type;
+ BOOL bTmpIsPartition = FALSE;
+
+ type = GetPathType (szFileName, !bInPlaceEncNonSys, &bTmpIsPartition);
+
+ if (driveNo != -1)
+ {
+ if (!GetDriveLabel (driveNo, volumeLabel, sizeof (volumeLabel)))
+ volumeLabel[0] = 0;
+
+ swprintf_s (drive, sizeof (drive)/2, volumeLabel[0] ? L" (%hc: '%s')" : L" (%hc:%s)", 'A' + driveNo, volumeLabel[0] ? volumeLabel : L"");
+ }
+ else
+ {
+ drive[0] = 0;
+ volumeLabel[0] = 0;
+ }
+
+ if (bHiddenOS && bHiddenVolHost)
+ swprintf (szTmp, GetString ("OVERWRITEPROMPT_DEVICE_HIDDEN_OS_PARTITION"), szFileName, drive);
+ else
+ swprintf (szTmp, GetString (bInPlaceEncNonSys ? "NONSYS_INPLACE_ENC_CONFIRM" : "OVERWRITEPROMPT_DEVICE"), type, szFileName, drive);
+
+
+ x = MessageBoxW (MainDlg, szTmp, lpszTitle, YES_NO | MB_ICONWARNING | (bInPlaceEncNonSys ? MB_DEFBUTTON1 : MB_DEFBUTTON2));
+ if (x != IDYES)
+ return FALSE;
+
+
+ if (driveNo != -1 && bTmpIsPartition && !bInPlaceEncNonSys)
+ {
+ float percentFreeSpace = 100.0;
+ __int64 occupiedBytes = 0;
+
+ // Do a second check. If we find that the partition contains more than 1GB of data or more than 12%
+ // of its space is occupied, we will display an extra warning, however, this time it won't be a Yes/No
+ // dialog box (because users often ignore such dialog boxes).
+
+ if (GetStatsFreeSpaceOnPartition (szFileName, &percentFreeSpace, &occupiedBytes, TRUE) != -1)
+ {
+ if (occupiedBytes > BYTES_PER_GB && percentFreeSpace < 99.99 // "percentFreeSpace < 99.99" is needed because an NTFS filesystem larger than several terabytes can have more than 1GB of data in use, even if there are no files stored on it.
+ || percentFreeSpace < 88) // A 24-MB NTFS filesystem has 11.5% of space in use even if there are no files stored on it.
+ {
+ wchar_t tmpMcMsg [8000];
+ wchar_t tmpMcOption1 [500];
+ wchar_t tmpMcOptionCancel [50];
+
+ wcscpy (tmpMcMsg, GetString("OVERWRITEPROMPT_DEVICE_SECOND_WARNING_LOTS_OF_DATA"));
+ wcscpy (tmpMcOption1, GetString("ERASE_FILES_BY_CREATING_VOLUME"));
+ wcscpy (tmpMcOptionCancel, GetString("CANCEL"));
+
+ wcscat (tmpMcMsg, L"\n\n");
+ wcscat (tmpMcMsg, GetString("DRIVE_LETTER_ITEM"));
+ swprintf_s (szTmp, sizeof (szTmp)/2, L"%hc:", 'A' + driveNo);
+ wcscat (tmpMcMsg, szTmp);
+
+ wcscat (tmpMcMsg, L"\n");
+ wcscat (tmpMcMsg, GetString("LABEL_ITEM"));
+ wcscat (tmpMcMsg, volumeLabel[0] != 0 ? volumeLabel : GetString("NOT_APPLICABLE_OR_NOT_AVAILABLE"));
+
+ wcscat (tmpMcMsg, L"\n");
+ wcscat (tmpMcMsg, GetString("SIZE_ITEM"));
+ GetSizeString (nVolumeSize, szTmp);
+ wcscat (tmpMcMsg, szTmp);
+
+ wcscat (tmpMcMsg, L"\n");
+ wcscat (tmpMcMsg, GetString("PATH_ITEM"));
+ wcscat (tmpMcMsg, deviceName);
+
+ wchar_t *tmpStr[] = {L"", tmpMcMsg, tmpMcOption1, tmpMcOptionCancel, 0};
+ switch (AskMultiChoice ((void **) tmpStr, TRUE))
+ {
+ case 1:
+ // Proceed
+
+ // NOP
+ break;
+
+ default:
+ return FALSE;
+ }
+ }
+ }
+ }
+ }
+ return TRUE;
+}
+
+void HandleOldAssignedDriveLetter (void)
+{
+ if (bDevice)
+ {
+ // Handle assigned drive letter (if any)
+
+ WCHAR deviceName[MAX_PATH];
+ int driveLetter = -1;
+
+ strcpy ((char *)deviceName, szDiskFile);
+ ToUNICODE ((char *)deviceName);
+ driveLetter = GetDiskDeviceDriveLetter (deviceName);
+
+ if (!bHiddenVolHost
+ && !bHiddenOS
+ && driveLetter > 1) // If a drive letter is assigned to the device, but not A: or B:
+ {
+ char rootPath[] = { (char) driveLetter + 'A', ':', '\\', 0 };
+ wchar_t szTmp[8192];
+
+ swprintf (szTmp, GetString ("AFTER_FORMAT_DRIVE_LETTER_WARN"), rootPath[0], rootPath[0], rootPath[0], rootPath[0]);
+ MessageBoxW (MainDlg, szTmp, lpszTitle, MB_ICONWARNING);
+ }
+ }
+}
+
+
+// Returns TRUE if it makes sense to ask the user whether he wants to store files larger than 4GB in the volume.
+static BOOL FileSize4GBLimitQuestionNeeded (void)
+{
+ uint64 dataAreaSize = GetVolumeDataAreaSize (bHiddenVol && !bHiddenVolHost, nVolumeSize);
+
+ return (dataAreaSize > 4 * BYTES_PER_GB + TC_MIN_FAT_FS_SIZE
+ && dataAreaSize <= TC_MAX_FAT_SECTOR_COUNT * GetFormatSectorSize());
+}
+
+
+/* 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 */
+BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ static char PageDebugId[128];
+ WORD lw = LOWORD (wParam);
+ WORD hw = HIWORD (wParam);
+
+ hCurPage = hwndDlg;
+
+ switch (uMsg)
+ {
+ case WM_INITDIALOG:
+ LocalizeDialog (hwndDlg, "IDD_VOL_CREATION_WIZARD_DLG");
+
+ sprintf (PageDebugId, "FORMAT_PAGE_%d", nCurPageNo);
+ LastDialogId = PageDebugId;
+
+ switch (nCurPageNo)
+ {
+ case INTRO_PAGE:
+
+ SendMessage (GetDlgItem (hwndDlg, IDC_FILE_CONTAINER), WM_SETFONT, (WPARAM) hUserBoldFont, (LPARAM) TRUE);
+ SendMessage (GetDlgItem (hwndDlg, IDC_NONSYS_DEVICE), WM_SETFONT, (WPARAM) hUserBoldFont, (LPARAM) TRUE);
+ SendMessage (GetDlgItem (hwndDlg, IDC_SYS_DEVICE), WM_SETFONT, (WPARAM) hUserBoldFont, (LPARAM) TRUE);
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("INTRO_TITLE"));
+
+ ToHyperlink (hwndDlg, IDC_MORE_INFO_ON_CONTAINERS);
+ ToHyperlink (hwndDlg, IDC_MORE_INFO_ON_SYS_ENCRYPTION);
+
+ EnableWindow (GetDlgItem (hwndDlg, IDC_STD_VOL), TRUE);
+ EnableWindow (GetDlgItem (hwndDlg, IDC_HIDDEN_VOL), TRUE);
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDCANCEL), GetString ("CANCEL"));
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), FALSE);
+
+ UpdateWizardModeControls (hwndDlg, WizardMode);
+ break;
+
+ case SYSENC_TYPE_PAGE:
+
+ bHiddenVolHost = bHiddenVol = bHiddenOS;
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("SYSENC_TYPE_PAGE_TITLE"));
+
+ SendMessage (GetDlgItem (hwndDlg, IDC_SYSENC_HIDDEN), WM_SETFONT, (WPARAM) hUserBoldFont, (LPARAM) TRUE);
+ SendMessage (GetDlgItem (hwndDlg, IDC_SYSENC_NORMAL), WM_SETFONT, (WPARAM) hUserBoldFont, (LPARAM) TRUE);
+
+ CheckButton (GetDlgItem (hwndDlg, bHiddenOS ? IDC_SYSENC_HIDDEN : IDC_SYSENC_NORMAL));
+
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString ("SYSENC_HIDDEN_TYPE_HELP"));
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP_SYSENC_NORMAL), GetString ("SYSENC_NORMAL_TYPE_HELP"));
+
+ ToHyperlink (hwndDlg, IDC_HIDDEN_SYSENC_INFO_LINK);
+
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), !bDirectSysEncMode);
+
+ SetWindowTextW (GetDlgItem (MainDlg, IDC_NEXT), GetString ("NEXT"));
+ SetWindowTextW (GetDlgItem (MainDlg, IDC_PREV), GetString ("PREV"));
+ SetWindowTextW (GetDlgItem (MainDlg, IDCANCEL), GetString ("CANCEL"));
+ break;
+
+ case SYSENC_HIDDEN_OS_REQ_CHECK_PAGE:
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("SYSENC_HIDDEN_OS_REQ_CHECK_PAGE_TITLE"));
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString ("SYSENC_HIDDEN_OS_REQ_CHECK_PAGE_HELP"));
+ SetWindowTextW (GetDlgItem (MainDlg, IDC_NEXT), GetString ("NEXT"));
+ SetWindowTextW (GetDlgItem (MainDlg, IDC_PREV), GetString ("PREV"));
+ SetWindowTextW (GetDlgItem (MainDlg, IDCANCEL), GetString ("CANCEL"));
+
+ EnableWindow (GetDlgItem (MainDlg, IDC_NEXT), TRUE);
+ EnableWindow (GetDlgItem (MainDlg, IDC_PREV), bDirectSysEncModeCommand != SYSENC_COMMAND_CREATE_HIDDEN_OS && bDirectSysEncModeCommand != SYSENC_COMMAND_CREATE_HIDDEN_OS_ELEV);
+
+ ToHyperlink (hwndDlg, IDC_HIDDEN_SYSENC_INFO_LINK);
+ break;
+
+ case SYSENC_SPAN_PAGE:
+
+ SendMessage (GetDlgItem (hwndDlg, IDC_WHOLE_SYS_DRIVE), WM_SETFONT, (WPARAM) hUserBoldFont, (LPARAM) TRUE);
+ SendMessage (GetDlgItem (hwndDlg, IDC_SYS_PARTITION), WM_SETFONT, (WPARAM) hUserBoldFont, (LPARAM) TRUE);
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("SYS_ENCRYPTION_SPAN_TITLE"));
+
+ SetWindowTextW (GetDlgItem (hwndDlg, IDT_WHOLE_SYS_DRIVE), GetString ("SYS_ENCRYPTION_SPAN_WHOLE_SYS_DRIVE_HELP"));
+
+ CheckButton (GetDlgItem (hwndDlg, bWholeSysDrive ? IDC_WHOLE_SYS_DRIVE : IDC_SYS_PARTITION));
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDCANCEL), GetString ("CANCEL"));
+
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), TRUE);
+ break;
+
+
+ case SYSENC_PRE_DRIVE_ANALYSIS_PAGE:
+
+ Init2RadButtonPageYesNo (SysEncDetectHiddenSectors);
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("SYSENC_PRE_DRIVE_ANALYSIS_TITLE"));
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString ("SYSENC_PRE_DRIVE_ANALYSIS_HELP"));
+ break;
+
+
+ case SYSENC_DRIVE_ANALYSIS_PAGE:
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("SYSENC_DRIVE_ANALYSIS_TITLE"));
+ SetWindowTextW (GetDlgItem (hwndDlg, IDT_SYSENC_DRIVE_ANALYSIS_INFO), GetString ("SYSENC_DRIVE_ANALYSIS_INFO"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDCANCEL), GetString ("CANCEL"));
+ EnableWindow (GetDlgItem (MainDlg, IDC_NEXT), FALSE);
+ EnableWindow (GetDlgItem (MainDlg, IDC_PREV), FALSE);
+ EnableWindow (GetDlgItem (MainDlg, IDCANCEL), FALSE);
+
+ LoadSettings (hwndDlg);
+
+ if (HiddenSectorDetectionStatus == 1)
+ {
+ // Detection of hidden sectors was already in progress but it did not finish successfully.
+ // Ask the user if he wants to try again (to prevent repeated system freezing, etc.)
+
+ char *tmpStr[] = {0, "HIDDEN_SECTOR_DETECTION_FAILED_PREVIOUSLY", "SKIP_HIDDEN_SECTOR_DETECTION", "RETRY_HIDDEN_SECTOR_DETECTION", "IDC_EXIT", 0};
+ switch (AskMultiChoice ((void **) tmpStr, FALSE))
+ {
+ case 1:
+ // Do not try again
+ LoadPage (MainDlg, SYSENC_DRIVE_ANALYSIS_PAGE + 1);
+ return 0;
+
+ case 2:
+ // Try again
+ break;
+
+ default:
+ EndMainDlg (MainDlg);
+ return 0;
+ }
+ }
+
+ SetTimer (MainDlg, TIMER_ID_SYSENC_DRIVE_ANALYSIS_PROGRESS, TIMER_INTERVAL_SYSENC_DRIVE_ANALYSIS_PROGRESS, NULL);
+ bSysEncDriveAnalysisInProgress = TRUE;
+ ArrowWaitCursor ();
+ SysEncDriveAnalysisStart = GetTickCount ();
+ InitProgressBar (SYSENC_DRIVE_ANALYSIS_ETA, 0, FALSE, FALSE, FALSE, TRUE);
+
+ _beginthread (sysEncDriveAnalysisThread, 0, hwndDlg);
+
+ break;
+
+
+ case SYSENC_MULTI_BOOT_MODE_PAGE:
+
+ SendMessage (GetDlgItem (hwndDlg, IDC_SINGLE_BOOT), WM_SETFONT, (WPARAM) hUserBoldFont, (LPARAM) TRUE);
+ SendMessage (GetDlgItem (hwndDlg, IDC_MULTI_BOOT), WM_SETFONT, (WPARAM) hUserBoldFont, (LPARAM) TRUE);
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("SYS_MULTI_BOOT_MODE_TITLE"));
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDCANCEL), GetString ("CANCEL"));
+
+ RefreshMultiBootControls (hwndDlg);
+
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), nMultiBoot > 0);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), TRUE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDCANCEL), TRUE);
+ break;
+
+
+ case SYSENC_MULTI_BOOT_SYS_EQ_BOOT_PAGE:
+
+ Init2RadButtonPageYesNo (SysEncMultiBootCfg.SystemOnBootDrive);
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("SYSENC_MULTI_BOOT_SYS_EQ_BOOT_TITLE"));
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString ("SYSENC_MULTI_BOOT_SYS_EQ_BOOT_HELP"));
+ break;
+
+
+ case SYSENC_MULTI_BOOT_NBR_SYS_DRIVES_PAGE:
+
+ SetWindowTextW (GetDlgItem (hCurPage, IDC_CHOICE1), GetString ("DIGIT_ONE"));
+ SetWindowTextW (GetDlgItem (hCurPage, IDC_CHOICE2), GetString ("TWO_OR_MORE"));
+
+ SetWindowTextW (GetDlgItem (MainDlg, IDC_NEXT), GetString ("NEXT"));
+ SetWindowTextW (GetDlgItem (MainDlg, IDC_PREV), GetString ("PREV"));
+ SetWindowTextW (GetDlgItem (MainDlg, IDCANCEL), GetString ("CANCEL"));
+
+ EnableWindow (GetDlgItem (MainDlg, IDC_NEXT), SysEncMultiBootCfg.NumberOfSysDrives > 0);
+ EnableWindow (GetDlgItem (MainDlg, IDC_PREV), TRUE);
+
+ if (SysEncMultiBootCfg.NumberOfSysDrives == 2)
+ Update2RadButtonPage (0); // 2 or more drives contain an OS
+ else if (SysEncMultiBootCfg.NumberOfSysDrives == 1)
+ Update2RadButtonPage (1); // Only 1 drive contains an OS
+ else
+ Update2RadButtonPage (-1);
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("SYSENC_MULTI_BOOT_NBR_SYS_DRIVES_TITLE"));
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString ("SYSENC_MULTI_BOOT_NBR_SYS_DRIVES_HELP"));
+ break;
+
+
+ case SYSENC_MULTI_BOOT_ADJACENT_SYS_PAGE:
+
+ Init2RadButtonPageYesNo (SysEncMultiBootCfg.MultipleSystemsOnDrive);
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("SYSENC_MULTI_BOOT_ADJACENT_SYS_TITLE"));
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString ("SYSENC_MULTI_BOOT_ADJACENT_SYS_HELP"));
+ break;
+
+
+ case SYSENC_MULTI_BOOT_NONWIN_BOOT_LOADER_PAGE:
+
+ Init2RadButtonPageYesNo (SysEncMultiBootCfg.BootLoaderBrand);
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("SYSENC_MULTI_BOOT_NONWIN_BOOT_LOADER_TITLE"));
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString ("SYSENC_MULTI_BOOT_NONWIN_BOOT_LOADER_HELP"));
+ break;
+
+
+ case SYSENC_MULTI_BOOT_OUTCOME_PAGE:
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("SYSENC_MULTI_BOOT_OUTCOME_TITLE"));
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), SysEncMultiBootCfgOutcome);
+ SetWindowTextW (GetDlgItem (MainDlg, IDC_NEXT), GetString ("NEXT"));
+ SetWindowTextW (GetDlgItem (MainDlg, IDC_PREV), GetString ("PREV"));
+ SetWindowTextW (GetDlgItem (MainDlg, IDCANCEL), GetString ("CANCEL"));
+ EnableWindow (GetDlgItem (MainDlg, IDC_NEXT), TRUE);
+ EnableWindow (GetDlgItem (MainDlg, IDC_PREV), TRUE);
+ break;
+
+
+ case VOLUME_TYPE_PAGE:
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("VOLUME_TYPE_TITLE"));
+
+ SendMessage (GetDlgItem (hwndDlg, IDC_HIDDEN_VOL), WM_SETFONT, (WPARAM) hUserBoldFont, (LPARAM) TRUE);
+ SendMessage (GetDlgItem (hwndDlg, IDC_STD_VOL), WM_SETFONT, (WPARAM) hUserBoldFont, (LPARAM) TRUE);
+
+ CheckButton (GetDlgItem (hwndDlg, bHiddenVol ? IDC_HIDDEN_VOL : IDC_STD_VOL));
+
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString ("HIDDEN_VOLUME_TYPE_HELP"));
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP_NORMAL_VOL), GetString ("NORMAL_VOLUME_TYPE_HELP"));
+
+ ToHyperlink (hwndDlg, IDC_HIDDEN_VOL_HELP);
+
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), TRUE);
+
+ SetWindowTextW (GetDlgItem (MainDlg, IDC_NEXT), GetString ("NEXT"));
+ SetWindowTextW (GetDlgItem (MainDlg, IDC_PREV), GetString ("PREV"));
+ SetWindowTextW (GetDlgItem (MainDlg, IDCANCEL), GetString ("CANCEL"));
+ break;
+
+ case HIDDEN_VOL_WIZARD_MODE_PAGE:
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("HIDDEN_VOL_WIZARD_MODE_TITLE"));
+
+ SendMessage (GetDlgItem (hwndDlg, IDC_HIDVOL_WIZ_MODE_DIRECT), WM_SETFONT, (WPARAM) hUserBoldFont, (LPARAM) TRUE);
+ SendMessage (GetDlgItem (hwndDlg, IDC_HIDVOL_WIZ_MODE_FULL), WM_SETFONT, (WPARAM) hUserBoldFont, (LPARAM) TRUE);
+
+ CheckButton (GetDlgItem (hwndDlg, bHiddenVolDirect ? IDC_HIDVOL_WIZ_MODE_DIRECT : IDC_HIDVOL_WIZ_MODE_FULL));
+
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString ("HIDDEN_VOL_WIZARD_MODE_NORMAL_HELP"));
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP2), GetString ("HIDDEN_VOL_WIZARD_MODE_DIRECT_HELP"));
+
+ EnableWindow (GetDlgItem (hwndDlg, IDC_HIDVOL_WIZ_MODE_DIRECT), TRUE);
+ EnableWindow (GetDlgItem (hwndDlg, IDC_HIDVOL_WIZ_MODE_FULL), TRUE);
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDCANCEL), GetString ("CANCEL"));
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), TRUE);
+
+ break;
+
+ case VOLUME_LOCATION_PAGE:
+ {
+ char *nID;
+
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_SELECT_VOLUME_LOCATION),
+ GetString (bDevice ? "IDC_SELECT_DEVICE" : "IDC_SELECT_FILE"));
+
+ if (bHiddenVolDirect && bHiddenVolHost)
+ {
+ nID = "FILE_HELP_HIDDEN_HOST_VOL_DIRECT";
+ }
+ else
+ {
+ if (bDevice)
+ nID = bHiddenVolHost ? "DEVICE_HELP_HIDDEN_HOST_VOL" : "DEVICE_HELP";
+ else
+ nID = bHiddenVolHost ? "FILE_HELP_HIDDEN_HOST_VOL" : "FILE_HELP";
+ }
+
+ SendMessage (GetDlgItem (hwndDlg, IDC_COMBO_BOX), CB_RESETCONTENT, 0, 0);
+
+ SendMessage (GetDlgItem (hwndDlg, IDC_COMBO_BOX), CB_LIMITTEXT, TC_MAX_PATH, 0);
+
+ LoadCombo (GetDlgItem (hwndDlg, IDC_COMBO_BOX));
+
+ SendMessage (GetDlgItem (hwndDlg, IDC_NO_HISTORY), BM_SETCHECK, bHistory ? BST_UNCHECKED : BST_CHECKED, 0);
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("FILE_TITLE"));
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString (nID));
+
+ SetFocus (GetDlgItem (hwndDlg, IDC_COMBO_BOX));
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), TRUE);
+
+ AddComboItem (GetDlgItem (hwndDlg, IDC_COMBO_BOX), szFileName, bHistory);
+
+ EnableDisableFileNext (GetDlgItem (hwndDlg, IDC_COMBO_BOX),
+ GetDlgItem (GetParent (hwndDlg), IDC_NEXT));
+
+ }
+ break;
+
+ case DEVICE_TRANSFORM_MODE_PAGE:
+
+ if (!bDeviceTransformModeChoiceMade && !bInPlaceEncNonSys)
+ {
+ // The user has not chosen whether to perform in-place encryption or format yet.
+ // We will preselect in-place encryption if the requirements are met and if the
+ // filesystem does not appear empty.
+
+ WaitCursor();
+
+ if (CheckRequirementsForNonSysInPlaceEnc (szDiskFile, TRUE))
+ {
+ bInPlaceEncNonSys = (FileSystemAppearsEmpty (szDiskFile) == 0);
+ }
+ }
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("DEVICE_TRANSFORM_MODE_PAGE_TITLE"));
+
+ SendMessage (GetDlgItem (hwndDlg, IDC_DEVICE_TRANSFORM_MODE_INPLACE), WM_SETFONT, (WPARAM) hUserBoldFont, (LPARAM) TRUE);
+ SendMessage (GetDlgItem (hwndDlg, IDC_DEVICE_TRANSFORM_MODE_FORMAT), WM_SETFONT, (WPARAM) hUserBoldFont, (LPARAM) TRUE);
+
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString ("DEVICE_TRANSFORM_MODE_PAGE_FORMAT_HELP"));
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP2), GetString ("DEVICE_TRANSFORM_MODE_PAGE_INPLACE_HELP"));
+
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), TRUE);
+
+ CheckButton (GetDlgItem (hwndDlg, bInPlaceEncNonSys ? IDC_DEVICE_TRANSFORM_MODE_INPLACE : IDC_DEVICE_TRANSFORM_MODE_FORMAT));
+
+ NormalCursor();
+
+ break;
+
+ case HIDDEN_VOL_HOST_PRE_CIPHER_PAGE:
+ {
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("HIDVOL_HOST_PRE_CIPHER_TITLE"));
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString (bHiddenOS ? "HIDVOL_HOST_PRE_CIPHER_HELP_SYSENC" : "HIDVOL_HOST_PRE_CIPHER_HELP"));
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), TRUE);
+
+ if (bHiddenOS)
+ {
+ if (!GetDevicePathForHiddenOS())
+ AbortProcess ("INVALID_PATH");
+ }
+ }
+ break;
+
+ case HIDDEN_VOL_PRE_CIPHER_PAGE:
+ {
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), FALSE);
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("HIDVOL_PRE_CIPHER_TITLE"));
+
+ if (bHiddenOS)
+ {
+ // Verify whether the clone of the OS fits in the hidden volume (the hidden
+ // volume is to host a hidden OS).
+ if (nMaximumHiddenVolSize - TC_HIDDEN_VOLUME_HOST_FS_RESERVED_END_AREA_SIZE_HIGH < GetSystemPartitionSize())
+ {
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString ("HIDDEN_VOLUME_TOO_SMALL_FOR_OS_CLONE"));
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDCANCEL), GetString ("EXIT"));
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDCANCEL), TRUE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), FALSE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), FALSE);
+
+ bConfirmQuit = FALSE;
+ bConfirmQuitSysEncPretest = FALSE;
+ }
+ else
+ {
+ // The hidden volume must be as large as the system partition
+ nVolumeSize = GetSystemPartitionSize() + TC_HIDDEN_VOLUME_HOST_FS_RESERVED_END_AREA_SIZE_HIGH;
+
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString ("HIDDEN_OS_PRE_CIPHER_HELP"));
+ }
+ }
+ else
+ {
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString ("HIDVOL_PRE_CIPHER_HELP"));
+ }
+ }
+ break;
+
+ case CIPHER_PAGE:
+ {
+ int ea, hid;
+ char buf[100];
+
+ // Encryption algorithms
+
+ SendMessage (GetDlgItem (hwndDlg, IDC_COMBO_BOX), CB_RESETCONTENT, 0, 0);
+
+ if (bHiddenVol)
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString (bHiddenVolHost ? "CIPHER_HIDVOL_HOST_TITLE" : "CIPHER_HIDVOL_TITLE"));
+ else
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("CIPHER_TITLE"));
+
+ for (ea = EAGetFirst (); ea != 0; ea = EAGetNext (ea))
+ {
+ if (EAIsFormatEnabled (ea))
+ AddComboPair (GetDlgItem (hwndDlg, IDC_COMBO_BOX), EAGetName (buf, ea), ea);
+ }
+
+ SelectAlgo (GetDlgItem (hwndDlg, IDC_COMBO_BOX), &nVolumeEA);
+ ComboSelChangeEA (hwndDlg);
+ SetFocus (GetDlgItem (hwndDlg, IDC_COMBO_BOX));
+
+ ToHyperlink (hwndDlg, IDC_LINK_MORE_INFO_ABOUT_CIPHER);
+
+ // Hash algorithms
+
+ if (SysEncInEffect ())
+ {
+ hash_algo = DEFAULT_HASH_ALGORITHM_BOOT;
+ RandSetHashFunction (DEFAULT_HASH_ALGORITHM_BOOT);
+ }
+ else
+ hash_algo = RandGetHashFunction();
+
+ for (hid = FIRST_PRF_ID; hid <= LAST_PRF_ID; hid++)
+ {
+ if (!HashIsDeprecated (hid))
+ AddComboPair (GetDlgItem (hwndDlg, IDC_COMBO_BOX_HASH_ALGO), HashGetName(hid), hid);
+ }
+ SelectAlgo (GetDlgItem (hwndDlg, IDC_COMBO_BOX_HASH_ALGO), &hash_algo);
+
+ ToHyperlink (hwndDlg, IDC_LINK_HASH_INFO);
+
+ // Wizard buttons
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), TRUE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
+ }
+ break;
+
+ case SIZE_PAGE:
+ {
+ wchar_t str[1000];
+
+ if (bHiddenVolHost)
+ {
+ wcsncpy (str, GetString ("SIZE_HELP_HIDDEN_HOST_VOL"), sizeof (str) / 2);
+ }
+ else
+ {
+ wcsncpy (str, GetString (bHiddenVol ? "SIZE_HELP_HIDDEN_VOL" : "SIZE_HELP"), sizeof (str) / 2);
+ }
+
+ if (bDevice && !(bHiddenVol && !bHiddenVolHost)) // If raw device but not a hidden volume
+ {
+ _snwprintf (str, sizeof str / 2, L"%s%s",
+ GetString ((bHiddenOS && bHiddenVol) ? "SIZE_PARTITION_HIDDEN_SYSENC_HELP" : "SIZE_PARTITION_HELP"),
+ (bHiddenVolHost && !bHiddenOS) ? GetString ("SIZE_PARTITION_HIDDEN_VOL_HELP") : L"");
+ }
+
+ SendMessage (GetDlgItem (hwndDlg, IDC_SPACE_LEFT), WM_SETFONT, (WPARAM) hBoldFont, (LPARAM) TRUE);
+ SendMessage (GetDlgItem (hwndDlg, IDC_SIZEBOX), EM_LIMITTEXT, 12, 0);
+
+ if(!QueryFreeSpace (hwndDlg, GetDlgItem (hwndDlg, IDC_SPACE_LEFT), TRUE))
+ {
+ nUIVolumeSize=0;
+ nVolumeSize=0;
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_SIZEBOX), GetString ("UNKNOWN"));
+ EnableWindow (GetDlgItem (hwndDlg, IDC_SIZEBOX), FALSE);
+ EnableWindow (GetDlgItem (hwndDlg, IDC_KB), FALSE);
+ EnableWindow (GetDlgItem (hwndDlg, IDC_MB), FALSE);
+ EnableWindow (GetDlgItem (hwndDlg, IDC_GB), FALSE);
+
+ }
+ else if (bDevice && !(bHiddenVol && !bHiddenVolHost)) // If raw device but not a hidden volume
+ {
+ EnableWindow (GetDlgItem (hwndDlg, IDC_SIZEBOX), FALSE);
+ EnableWindow (GetDlgItem (hwndDlg, IDC_KB), FALSE);
+ EnableWindow (GetDlgItem (hwndDlg, IDC_MB), FALSE);
+ EnableWindow (GetDlgItem (hwndDlg, IDC_GB), FALSE);
+ }
+ else
+ {
+ EnableWindow (GetDlgItem (hwndDlg, IDC_SIZEBOX), TRUE);
+ EnableWindow (GetDlgItem (hwndDlg, IDC_KB), TRUE);
+ EnableWindow (GetDlgItem (hwndDlg, IDC_MB), TRUE);
+ EnableWindow (GetDlgItem (hwndDlg, IDC_GB), TRUE);
+ }
+
+ SendMessage (GetDlgItem (hwndDlg, IDC_KB), BM_SETCHECK, BST_UNCHECKED, 0);
+ SendMessage (GetDlgItem (hwndDlg, IDC_MB), BM_SETCHECK, BST_UNCHECKED, 0);
+ SendMessage (GetDlgItem (hwndDlg, IDC_GB), BM_SETCHECK, BST_UNCHECKED, 0);
+
+ switch (nMultiplier)
+ {
+ case BYTES_PER_KB:
+ SendMessage (GetDlgItem (hwndDlg, IDC_KB), BM_SETCHECK, BST_CHECKED, 0);
+ break;
+ case BYTES_PER_MB:
+ SendMessage (GetDlgItem (hwndDlg, IDC_MB), BM_SETCHECK, BST_CHECKED, 0);
+ break;
+ case BYTES_PER_GB:
+ SendMessage (GetDlgItem (hwndDlg, IDC_GB), BM_SETCHECK, BST_CHECKED, 0);
+ break;
+ }
+
+ if (nUIVolumeSize != 0)
+ {
+ char szTmp[32];
+ sprintf (szTmp, "%I64u", nUIVolumeSize);
+ SetWindowText (GetDlgItem (hwndDlg, IDC_SIZEBOX), szTmp);
+ }
+
+ SetFocus (GetDlgItem (hwndDlg, IDC_SIZEBOX));
+
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), str);
+
+ if (bHiddenVol)
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString (bHiddenVolHost ? "SIZE_HIDVOL_HOST_TITLE" : "SIZE_HIDVOL_TITLE"));
+ else
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("SIZE_TITLE"));
+
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
+
+
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), TRUE);
+
+ VerifySizeAndUpdate (hwndDlg, FALSE);
+ }
+ break;
+
+ case HIDDEN_VOL_HOST_PASSWORD_PAGE:
+ case NONSYS_INPLACE_ENC_RESUME_PASSWORD_PAGE:
+
+ SendMessage (GetDlgItem (hwndDlg, IDC_PASSWORD_DIRECT), EM_LIMITTEXT, MAX_PASSWORD, 0);
+
+ SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD_DIRECT), szRawPassword);
+
+ SetFocus (GetDlgItem (hwndDlg, IDC_PASSWORD_DIRECT));
+
+ SetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE, KeyFilesEnable);
+
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString (bInPlaceEncNonSys ? "NONSYS_INPLACE_ENC_RESUME_PASSWORD_PAGE_HELP" : "PASSWORD_HIDDENVOL_HOST_DIRECT_HELP"));
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString (bInPlaceEncNonSys ? "PASSWORD" : "PASSWORD_HIDVOL_HOST_TITLE"));
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
+
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), !bInPlaceEncNonSys);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
+
+ break;
+
+ case PASSWORD_PAGE:
+ {
+ wchar_t str[1000];
+
+ hPasswordInputField = GetDlgItem (hwndDlg, IDC_PASSWORD);
+ hVerifyPasswordInputField = GetDlgItem (hwndDlg, IDC_VERIFY);
+
+ if (SysEncInEffect ())
+ {
+ ToBootPwdField (hwndDlg, IDC_PASSWORD);
+ ToBootPwdField (hwndDlg, IDC_VERIFY);
+
+ sprintf (OrigKeyboardLayout, "%08X", (DWORD) GetKeyboardLayout (NULL) & 0xFFFF);
+
+ if ((DWORD) GetKeyboardLayout (NULL) != 0x00000409 && (DWORD) GetKeyboardLayout (NULL) != 0x04090409)
+ {
+ DWORD keybLayout = (DWORD) LoadKeyboardLayout ("00000409", KLF_ACTIVATE);
+
+ if (keybLayout != 0x00000409 && keybLayout != 0x04090409)
+ {
+ Error ("CANT_CHANGE_KEYB_LAYOUT_FOR_SYS_ENCRYPTION");
+ EndMainDlg (MainDlg);
+ return 1;
+ }
+ bKeyboardLayoutChanged = TRUE;
+ }
+
+ ShowWindow(GetDlgItem(hwndDlg, IDC_SHOW_PASSWORD), SW_HIDE);
+
+ if (SetTimer (MainDlg, TIMER_ID_KEYB_LAYOUT_GUARD, TIMER_INTERVAL_KEYB_LAYOUT_GUARD, NULL) == 0)
+ {
+ Error ("CANNOT_SET_TIMER");
+ EndMainDlg (MainDlg);
+ return 1;
+ }
+ }
+
+ if (bHiddenVolHost)
+ {
+ wcsncpy (str, GetString (bHiddenOS ? "PASSWORD_SYSENC_OUTERVOL_HELP" : "PASSWORD_HIDDENVOL_HOST_HELP"), sizeof (str) / 2);
+ }
+ else if (bHiddenVol)
+ {
+ _snwprintf (str, sizeof str / 2, L"%s%s",
+ GetString (bHiddenOS ? "PASSWORD_HIDDEN_OS_HELP" : "PASSWORD_HIDDENVOL_HELP"),
+ GetString ("PASSWORD_HELP"));
+ }
+ else
+ {
+ wcsncpy (str, GetString ("PASSWORD_HELP"), sizeof (str) / 2);
+ }
+
+ SendMessage (GetDlgItem (hwndDlg, IDC_PASSWORD), EM_LIMITTEXT, MAX_PASSWORD, 0);
+ SendMessage (GetDlgItem (hwndDlg, IDC_VERIFY), EM_LIMITTEXT, MAX_PASSWORD, 0);
+
+ SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), szRawPassword);
+ SetWindowText (GetDlgItem (hwndDlg, IDC_VERIFY), szVerify);
+
+ SetFocus (GetDlgItem (hwndDlg, IDC_PASSWORD));
+
+ SetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE, KeyFilesEnable && !SysEncInEffect());
+ EnableWindow (GetDlgItem (hwndDlg, IDC_KEY_FILES), KeyFilesEnable);
+
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), str);
+
+ if (CreatingHiddenSysVol())
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("PASSWORD_HIDDEN_OS_TITLE"));
+ else if (bHiddenVol)
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString (bHiddenVolHost ? "PASSWORD_HIDVOL_HOST_TITLE" : "PASSWORD_HIDVOL_TITLE"));
+ else if (WizardMode == WIZARD_MODE_SYS_DEVICE)
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("PASSWORD"));
+ else
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("PASSWORD_TITLE"));
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
+
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), TRUE);
+
+ VerifyPasswordAndUpdate (hwndDlg, GetDlgItem (GetParent (hwndDlg), IDC_NEXT),
+ GetDlgItem (hwndDlg, IDC_PASSWORD),
+ GetDlgItem (hwndDlg, IDC_VERIFY),
+ NULL,
+ NULL,
+ KeyFilesEnable && FirstKeyFile!=NULL && !SysEncInEffect());
+ volumePassword.Length = strlen ((char *) volumePassword.Text);
+ }
+ break;
+
+ case FILESYS_PAGE:
+ {
+ wchar_t szTmp[8192];
+
+ Init2RadButtonPageYesNo (nNeedToStoreFilesOver4GB);
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("FILESYS_PAGE_TITLE"));
+
+ wcscpy (szTmp, GetString ("FILESYS_PAGE_HELP_QUESTION"));
+
+ if (bHiddenVolHost)
+ wcscat (szTmp, L"\n\n");
+ else
+ {
+ wcscat (szTmp, L"\n\n\n");
+ wcscat (szTmp, GetString ("NOTE_BEGINNING"));
+ }
+
+ wcscat (szTmp, GetString ("FILESYS_PAGE_HELP_EXPLANATION"));
+
+ if (bHiddenVolHost)
+ {
+ wcscat (szTmp, L" ");
+ wcscat (szTmp, GetString ("FILESYS_PAGE_HELP_EXPLANATION_HIDVOL"));
+ }
+
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), szTmp);
+ }
+ break;
+
+ case SYSENC_COLLECTING_RANDOM_DATA_PAGE:
+ case NONSYS_INPLACE_ENC_RAND_DATA_PAGE:
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("COLLECTING_RANDOM_DATA_TITLE"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), TRUE);
+
+ SetTimer (GetParent (hwndDlg), TIMER_ID_RANDVIEW, TIMER_INTERVAL_RANDVIEW, NULL);
+
+ hRandPoolSys = GetDlgItem (hwndDlg, IDC_SYS_POOL_CONTENTS);
+
+ SendMessage (GetDlgItem (hwndDlg, IDC_SYS_POOL_CONTENTS), WM_SETFONT, (WPARAM) hFixedDigitFont, (LPARAM) TRUE);
+
+ SendMessage (GetDlgItem (hwndDlg, IDC_DISPLAY_POOL_CONTENTS), BM_SETCHECK, showKeys ? BST_CHECKED : BST_UNCHECKED, 0);
+
+ DisplayRandPool (hRandPoolSys, showKeys);
+
+ break;
+
+ case SYSENC_KEYS_GEN_PAGE:
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("KEYS_GEN_TITLE"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), TRUE);
+
+ hMasterKey = GetDlgItem (hwndDlg, IDC_DISK_KEY);
+ hHeaderKey = GetDlgItem (hwndDlg, IDC_HEADER_KEY);
+
+ SendMessage (GetDlgItem (hwndDlg, IDC_DISK_KEY), WM_SETFONT, (WPARAM) hFixedDigitFont, (LPARAM) TRUE);
+ SendMessage (GetDlgItem (hwndDlg, IDC_HEADER_KEY), WM_SETFONT, (WPARAM) hFixedDigitFont, (LPARAM) TRUE);
+
+ SendMessage (GetDlgItem (hwndDlg, IDC_DISPLAY_KEYS), BM_SETCHECK, showKeys ? BST_CHECKED : BST_UNCHECKED, 0);
+
+ DisplayPortionsOfKeys (hHeaderKey, hMasterKey, HeaderKeyGUIView, MasterKeyGUIView, !showKeys);
+
+ break;
+
+ case SYSENC_RESCUE_DISK_CREATION_PAGE:
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("RESCUE_DISK"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
+ SetWindowTextW (GetDlgItem (hwndDlg, IDT_RESCUE_DISK_INFO), GetString ("RESCUE_DISK_INFO"));
+ SetDlgItemText (hwndDlg, IDC_RESCUE_DISK_ISO_PATH, szRescueDiskISO);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), (GetWindowTextLength (GetDlgItem (hwndDlg, IDC_RESCUE_DISK_ISO_PATH)) > 1));
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), TRUE);
+
+ break;
+
+ case SYSENC_RESCUE_DISK_BURN_PAGE:
+ {
+ wchar_t szTmp[8192];
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString (bDontVerifyRescueDisk ? "RESCUE_DISK_CREATED_TITLE" : "RESCUE_DISK_RECORDING_TITLE"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
+
+ _snwprintf (szTmp, sizeof szTmp / 2,
+ GetString (bDontVerifyRescueDisk ? "RESCUE_DISK_BURN_INFO_NO_CHECK" : "RESCUE_DISK_BURN_INFO"),
+ szRescueDiskISO, IsWindowsIsoBurnerAvailable() ? L"" : GetString ("RESCUE_DISK_BURN_INFO_NONWIN_ISO_BURNER"));
+
+ SetWindowTextW (GetDlgItem (hwndDlg, IDT_RESCUE_DISK_BURN_INFO), szTmp);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
+
+ /* The 'Back' button must be disabled now because the user could burn a Rescue Disk, then go back, and
+ generate a different master key, which would cause the Rescue Disk verification to fail (the result
+ would be confusion and bug reports). */
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), FALSE);
+
+ if (IsWindowsIsoBurnerAvailable())
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_DOWNLOAD_CD_BURN_SOFTWARE), GetString ("LAUNCH_WIN_ISOBURN"));
+
+ ToHyperlink (hwndDlg, IDC_DOWNLOAD_CD_BURN_SOFTWARE);
+
+ if (IsWindowsIsoBurnerAvailable() && !bDontVerifyRescueDisk)
+ LaunchWindowsIsoBurner (hwndDlg, szRescueDiskISO);
+ }
+ break;
+
+ case SYSENC_RESCUE_DISK_VERIFIED_PAGE:
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("RESCUE_DISK_DISK_VERIFIED_TITLE"));
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString ("RESCUE_DISK_VERIFIED_INFO"));
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
+
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
+
+ // Rescue Disk has been verified, no need to go back
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), FALSE);
+
+ // Prevent losing the burned rescue disk by inadvertent exit
+ bConfirmQuit = TRUE;
+
+ break;
+
+ case SYSENC_WIPE_MODE_PAGE:
+ case NONSYS_INPLACE_ENC_WIPE_MODE_PAGE:
+ {
+ if (nWipeMode == TC_WIPE_1_RAND)
+ nWipeMode = TC_WIPE_NONE;
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("WIPE_MODE_TITLE"));
+ SetWindowTextW (GetDlgItem (hwndDlg, IDT_WIPE_MODE_INFO), GetString ("INPLACE_ENC_WIPE_MODE_INFO"));
+
+ PopulateWipeModeCombo (GetDlgItem (hwndDlg, IDC_WIPE_MODE),
+ SystemEncryptionStatus == SYSENC_STATUS_DECRYPTING && !bInPlaceEncNonSys,
+ TRUE);
+
+ SelectAlgo (GetDlgItem (hwndDlg, IDC_WIPE_MODE), (int *) &nWipeMode);
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT"));
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), TRUE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
+ }
+ break;
+
+ case SYSENC_PRETEST_INFO_PAGE:
+
+ if (bHiddenOS)
+ {
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("HIDDEN_OS_CREATION_PREINFO_TITLE"));
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString ("HIDDEN_OS_CREATION_PREINFO_HELP"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("START"));
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), FALSE);
+ }
+ else
+ {
+ wchar_t finalMsg[8024] = {0};
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("SYS_ENCRYPTION_PRETEST_TITLE"));
+
+ try
+ {
+ wsprintfW (finalMsg,
+ GetString ("SYS_ENCRYPTION_PRETEST_INFO"),
+ BootEncObj->GetSystemDriveConfiguration().DriveNumber);
+ }
+ catch (Exception &e)
+ {
+ e.Show (hwndDlg);
+ EndMainDlg (MainDlg);
+ return 0;
+ }
+
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), finalMsg);
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("TEST"));
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), TRUE);
+ }
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
+
+ break;
+
+ case SYSENC_PRETEST_RESULT_PAGE:
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("SYS_ENCRYPTION_PRETEST_RESULT_TITLE"));
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString ("SYS_ENCRYPTION_PRETEST_RESULT_INFO"));
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("ENCRYPT"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDCANCEL), GetString ("DEFER"));
+
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), FALSE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDCANCEL), TRUE);
+
+ break;
+
+ case SYSENC_ENCRYPTION_PAGE:
+
+ if (CreateSysEncMutex ())
+ {
+ try
+ {
+ BootEncStatus = BootEncObj->GetStatus();
+ bSystemEncryptionInProgress = BootEncStatus.SetupInProgress;
+ }
+ catch (Exception &e)
+ {
+ e.Show (hwndDlg);
+ Error ("ERR_GETTING_SYSTEM_ENCRYPTION_STATUS");
+ EndMainDlg (MainDlg);
+ return 0;
+ }
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE),
+ GetString (SystemEncryptionStatus != SYSENC_STATUS_DECRYPTING ? "ENCRYPTION" : "DECRYPTION"));
+
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString ("SYSENC_ENCRYPTION_PAGE_INFO"));
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDCANCEL), GetString ("DEFER"));
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT),
+ GetString (SystemEncryptionStatus != SYSENC_STATUS_DECRYPTING ? "ENCRYPT" : "DECRYPT"));
+
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_PAUSE),
+ GetString (bSystemEncryptionInProgress ? "IDC_PAUSE" : "RESUME"));
+
+ EnableWindow (GetDlgItem (hwndDlg, IDC_PAUSE), BootEncStatus.DriveEncrypted);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), FALSE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), !BootEncStatus.SetupInProgress);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDCANCEL), TRUE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDHELP), TRUE);
+
+ ToHyperlink (hwndDlg, IDC_MORE_INFO_SYS_ENCRYPTION);
+
+ if (SystemEncryptionStatus == SYSENC_STATUS_DECRYPTING)
+ {
+ nWipeMode = TC_WIPE_NONE;
+ EnableWindow (GetDlgItem (hwndDlg, IDC_WIPE_MODE), FALSE);
+ EnableWindow (GetDlgItem (hwndDlg, IDT_WIPE_MODE), FALSE);
+ PopulateWipeModeCombo (GetDlgItem (hwndDlg, IDC_WIPE_MODE), TRUE, TRUE);
+ SelectAlgo (GetDlgItem (hwndDlg, IDC_WIPE_MODE), (int *) &nWipeMode);
+ }
+ else
+ {
+ EnableWindow (GetDlgItem (hwndDlg, IDC_WIPE_MODE), !bSystemEncryptionInProgress);
+ PopulateWipeModeCombo (GetDlgItem (hwndDlg, IDC_WIPE_MODE), FALSE, TRUE);
+ SelectAlgo (GetDlgItem (hwndDlg, IDC_WIPE_MODE), (int *) &nWipeMode);
+ }
+
+ PostMessage (hwndDlg, TC_APPMSG_PERFORM_POST_SYSENC_WMINIT_TASKS, 0, 0);
+ }
+ else
+ {
+ Error ("SYSTEM_ENCRYPTION_IN_PROGRESS_ELSEWHERE");
+ EndMainDlg (MainDlg);
+ return 0;
+ }
+ return 0;
+
+ case NONSYS_INPLACE_ENC_RESUME_PARTITION_SEL_PAGE:
+
+ {
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("FILE_TITLE"));
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString ("NONSYS_INPLACE_ENC_RESUME_VOL_SELECT_HELP"));
+
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), TRUE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), FALSE);
+
+ foreach (const HostDevice &device, DeferredNonSysInPlaceEncDevices)
+ {
+ SendMessage (GetDlgItem (hwndDlg, IDC_LIST_BOX), LB_ADDSTRING, 0, (LPARAM) device.Path.c_str());
+ }
+
+ // Deselect all
+ SendMessage (GetDlgItem (hwndDlg, IDC_LIST_BOX), LB_SETCURSEL, (WPARAM) -1, 0);
+ }
+
+ break;
+
+ case NONSYS_INPLACE_ENC_ENCRYPTION_PAGE:
+
+ if (bInPlaceEncNonSysResumed)
+ {
+ WipeAlgorithmId savedWipeAlgorithm = TC_WIPE_NONE;
+
+ if (LoadNonSysInPlaceEncSettings (&savedWipeAlgorithm) != 0)
+ nWipeMode = savedWipeAlgorithm;
+ }
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("ENCRYPTION"));
+
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString ("NONSYS_INPLACE_ENC_ENCRYPTION_PAGE_INFO"));
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDCANCEL), GetString (bInPlaceEncNonSysResumed ? "DEFER" : "CANCEL"));
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString (bInPlaceEncNonSysResumed ? "RESUME" : "ENCRYPT"));
+
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_PAUSE), GetString ("IDC_PAUSE"));
+
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), !bInPlaceEncNonSysResumed);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDCANCEL), TRUE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDHELP), TRUE);
+ EnableWindow (GetDlgItem (hwndDlg, IDC_PAUSE), FALSE);
+
+ ShowWindow (GetDlgItem (hwndDlg, IDC_MORE_INFO_SYS_ENCRYPTION), SW_HIDE);
+
+ EnableWindow (GetDlgItem (hwndDlg, IDC_WIPE_MODE), TRUE);
+ PopulateWipeModeCombo (GetDlgItem (hwndDlg, IDC_WIPE_MODE), FALSE, TRUE);
+ SelectAlgo (GetDlgItem (hwndDlg, IDC_WIPE_MODE), (int *) &nWipeMode);
+
+ break;
+
+ case NONSYS_INPLACE_ENC_ENCRYPTION_FINISHED_PAGE:
+
+ bConfirmQuit = FALSE;
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("NONSYS_INPLACE_ENC_FINISHED_TITLE"));
+
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString ("NONSYS_INPLACE_ENC_FINISHED_INFO"));
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("FINALIZE"));
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), FALSE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDCANCEL), GetString ("EXIT"));
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDCANCEL), FALSE);
+
+ break;
+
+ case FORMAT_PAGE:
+ {
+ BOOL bNTFSallowed = FALSE;
+ BOOL bFATallowed = FALSE;
+ BOOL bNoFSallowed = FALSE;
+
+ SetTimer (GetParent (hwndDlg), TIMER_ID_RANDVIEW, TIMER_INTERVAL_RANDVIEW, NULL);
+
+ hMasterKey = GetDlgItem (hwndDlg, IDC_DISK_KEY);
+ hHeaderKey = GetDlgItem (hwndDlg, IDC_HEADER_KEY);
+ hRandPool = GetDlgItem (hwndDlg, IDC_RANDOM_BYTES);
+
+ SendMessage (GetDlgItem (hwndDlg, IDC_RANDOM_BYTES), WM_SETFONT, (WPARAM) hFixedDigitFont, (LPARAM) TRUE);
+ SendMessage (GetDlgItem (hwndDlg, IDC_DISK_KEY), WM_SETFONT, (WPARAM) hFixedDigitFont, (LPARAM) TRUE);
+ SendMessage (GetDlgItem (hwndDlg, IDC_HEADER_KEY), WM_SETFONT, (WPARAM) hFixedDigitFont, (LPARAM) TRUE);
+
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP),
+ GetString (bHiddenVolHost ? "FORMAT_HIDVOL_HOST_HELP" : "FORMAT_HELP"));
+
+ if (bHiddenVol)
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString (bHiddenVolHost ? "FORMAT_HIDVOL_HOST_TITLE" : "FORMAT_HIDVOL_TITLE"));
+ else
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("FORMAT_TITLE"));
+
+ /* Quick/Dynamic */
+
+ if (bHiddenVol)
+ {
+ quickFormat = !bHiddenVolHost;
+ bSparseFileSwitch = FALSE;
+
+ SetCheckBox (hwndDlg, IDC_QUICKFORMAT, quickFormat);
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_QUICKFORMAT), GetString ((bDevice || !bHiddenVolHost) ? "IDC_QUICKFORMAT" : "SPARSE_FILE"));
+ EnableWindow (GetDlgItem (hwndDlg, IDC_QUICKFORMAT), bDevice && bHiddenVolHost);
+ }
+ else
+ {
+ if (bDevice)
+ {
+ bSparseFileSwitch = FALSE;
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_QUICKFORMAT), GetString("IDC_QUICKFORMAT"));
+ EnableWindow (GetDlgItem (hwndDlg, IDC_QUICKFORMAT), TRUE);
+ }
+ else
+ {
+ char root[TC_MAX_PATH];
+ DWORD fileSystemFlags = 0;
+
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_QUICKFORMAT), GetString("SPARSE_FILE"));
+
+ /* Check if the host file system supports sparse files */
+
+ if (GetVolumePathName (szFileName, root, sizeof (root)))
+ {
+ GetVolumeInformation (root, NULL, 0, NULL, NULL, &fileSystemFlags, NULL, 0);
+ bSparseFileSwitch = fileSystemFlags & FILE_SUPPORTS_SPARSE_FILES;
+ }
+ else
+ bSparseFileSwitch = FALSE;
+
+ EnableWindow (GetDlgItem (hwndDlg, IDC_QUICKFORMAT), bSparseFileSwitch);
+ }
+ }
+
+ SendMessage (GetDlgItem (hwndDlg, IDC_SHOW_KEYS), BM_SETCHECK, showKeys ? BST_CHECKED : BST_UNCHECKED, 0);
+ SetWindowText (GetDlgItem (hwndDlg, IDC_RANDOM_BYTES), showKeys ? "" : "******************************** ");
+ SetWindowText (GetDlgItem (hwndDlg, IDC_HEADER_KEY), showKeys ? "" : "******************************** ");
+ SetWindowText (GetDlgItem (hwndDlg, IDC_DISK_KEY), showKeys ? "" : "******************************** ");
+
+ SendMessage (GetDlgItem (hwndDlg, IDC_CLUSTERSIZE), CB_RESETCONTENT, 0, 0);
+ AddComboPairW (GetDlgItem (hwndDlg, IDC_CLUSTERSIZE), GetString ("DEFAULT"), 0);
+
+ for (int i = 1; i <= 128; i *= 2)
+ {
+ wstringstream s;
+ int size = GetFormatSectorSize() * i;
+
+ if (size > TC_MAX_FAT_CLUSTER_SIZE)
+ break;
+
+ if (size == 512)
+ s << L"0.5";
+ else
+ s << size / BYTES_PER_KB;
+
+ s << L" " << GetString ("KB");
+
+ AddComboPairW (GetDlgItem (hwndDlg, IDC_CLUSTERSIZE), s.str().c_str(), i);
+ }
+
+ SendMessage (GetDlgItem (hwndDlg, IDC_CLUSTERSIZE), CB_SETCURSEL, 0, 0);
+
+ EnableWindow (GetDlgItem (hwndDlg, IDC_CLUSTERSIZE), TRUE);
+
+ /* Filesystems */
+
+ bNTFSallowed = FALSE;
+ bFATallowed = FALSE;
+ bNoFSallowed = FALSE;
+
+ SendMessage (GetDlgItem (hwndDlg, IDC_FILESYS), CB_RESETCONTENT, 0, 0);
+
+ EnableWindow (GetDlgItem (hwndDlg, IDC_FILESYS), TRUE);
+
+ uint64 dataAreaSize = GetVolumeDataAreaSize (bHiddenVol && !bHiddenVolHost, nVolumeSize);
+
+ if (!CreatingHiddenSysVol())
+ {
+ if (dataAreaSize >= TC_MIN_NTFS_FS_SIZE && dataAreaSize <= TC_MAX_NTFS_FS_SIZE)
+ {
+ AddComboPair (GetDlgItem (hwndDlg, IDC_FILESYS), "NTFS", FILESYS_NTFS);
+ bNTFSallowed = TRUE;
+ }
+
+ if (dataAreaSize >= TC_MIN_FAT_FS_SIZE && dataAreaSize <= TC_MAX_FAT_SECTOR_COUNT * GetFormatSectorSize())
+ {
+ AddComboPair (GetDlgItem (hwndDlg, IDC_FILESYS), "FAT", FILESYS_FAT);
+ bFATallowed = TRUE;
+ }
+ }
+ else
+ {
+ // We're creating a hidden volume for a hidden OS, so we don't need to format it with
+ // any filesystem (the entire OS will be copied to the hidden volume sector by sector).
+ EnableWindow (GetDlgItem (hwndDlg, IDC_FILESYS), FALSE);
+ EnableWindow (GetDlgItem (hwndDlg, IDC_CLUSTERSIZE), FALSE);
+ }
+
+ if (!bHiddenVolHost)
+ {
+ AddComboPairW (GetDlgItem (hwndDlg, IDC_FILESYS), GetString ("NONE"), FILESYS_NONE);
+ bNoFSallowed = TRUE;
+ }
+
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
+
+ if (fileSystem == FILESYS_NONE) // If no file system has been previously selected
+ {
+ // Set default file system
+
+ if (bFATallowed && !(nNeedToStoreFilesOver4GB == 1 && bNTFSallowed))
+ fileSystem = FILESYS_FAT;
+ else if (bNTFSallowed)
+ fileSystem = FILESYS_NTFS;
+ else if (bNoFSallowed)
+ fileSystem = FILESYS_NONE;
+ else
+ {
+ AddComboPair (GetDlgItem (hwndDlg, IDC_FILESYS), "---", 0);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), FALSE);
+ }
+ }
+
+ SendMessage (GetDlgItem (hwndDlg, IDC_FILESYS), CB_SETCURSEL, 0, 0);
+ SelectAlgo (GetDlgItem (hwndDlg, IDC_FILESYS), (int *) &fileSystem);
+
+ EnableWindow (GetDlgItem (hwndDlg, IDC_ABORT_BUTTON), FALSE);
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("FORMAT"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
+
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), TRUE);
+
+ SetFocus (GetDlgItem (GetParent (hwndDlg), IDC_NEXT));
+ }
+ break;
+
+ case FORMAT_FINISHED_PAGE:
+ {
+ if (!bHiddenVolHost && bHiddenVol && !bHiddenVolFinished)
+ {
+ wchar_t msg[4096];
+
+ nNeedToStoreFilesOver4GB = -1;
+
+ if (bHiddenOS)
+ {
+ wchar_t szMaxRecomOuterVolFillSize[100];
+
+ __int64 maxRecomOuterVolFillSize = 0;
+
+ // Determine the maximum recommended total size of files that can be copied to the outer volume
+ // while leaving enough space for the hidden volume, which must contain a clone of the OS
+
+ maxRecomOuterVolFillSize = nVolumeSize - GetSystemPartitionSize();
+
+ // -50% reserve for filesystem "peculiarities"
+ maxRecomOuterVolFillSize /= 2;
+
+ swprintf (szMaxRecomOuterVolFillSize, L"%I64d %s", maxRecomOuterVolFillSize / BYTES_PER_MB, GetString ("MB"));
+
+ swprintf (msg, GetString ("HIDVOL_HOST_FILLING_HELP_SYSENC"), hiddenVolHostDriveNo + 'A', szMaxRecomOuterVolFillSize);
+ }
+ else
+ swprintf (msg, GetString ("HIDVOL_HOST_FILLING_HELP"), hiddenVolHostDriveNo + 'A');
+
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), msg);
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("HIDVOL_HOST_FILLING_TITLE"));
+ }
+ else
+ {
+ if (bHiddenOS)
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString ("SYSENC_HIDDEN_VOL_FORMAT_FINISHED_HELP"));
+ else
+ {
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString (bInPlaceEncNonSys ? "NONSYS_INPLACE_ENC_FINISHED_INFO" : "FORMAT_FINISHED_HELP"));
+ bConfirmQuit = FALSE;
+ }
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString (bHiddenVol ? "HIDVOL_FORMAT_FINISHED_TITLE" : "FORMAT_FINISHED_TITLE"));
+ }
+
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), (!bHiddenVol || bHiddenVolFinished) && !bHiddenOS && !bInPlaceEncNonSys);
+
+ if ((!bHiddenVol || bHiddenVolFinished) && !bHiddenOS)
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDCANCEL), GetString ("EXIT"));
+ }
+ break;
+
+ case SYSENC_HIDDEN_OS_INITIAL_INFO_PAGE:
+
+ if (!IsHiddenOSRunning() || !bHiddenOS)
+ {
+ ReportUnexpectedState (SRC_POS);
+ EndMainDlg (MainDlg);
+ return 0;
+ }
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("SYSENC_HIDDEN_OS_INITIAL_INFO_TITLE"));
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString ("FIRST_HIDDEN_OS_BOOT_INFO"));
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDCANCEL), GetString ("DEFER"));
+
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), FALSE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDCANCEL), TRUE);
+ break;
+
+ case SYSENC_HIDDEN_OS_WIPE_INFO_PAGE:
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("SYSENC_HIDDEN_OS_WIPE_INFO_TITLE"));
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString ("SYSENC_HIDDEN_OS_WIPE_INFO"));
+
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), TRUE);
+
+ break;
+
+ case DEVICE_WIPE_MODE_PAGE:
+
+ if (nWipeMode == TC_WIPE_NONE)
+ nWipeMode = TC_WIPE_1_RAND;
+
+ if (bHiddenOS && IsHiddenOSRunning())
+ {
+ // Decoy system partition wipe
+
+ WipeAbort(); // In case the GUI previously crashed and the driver is still wiping
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDCANCEL), GetString ("CANCEL"));
+ }
+ else
+ {
+ // Regular device wipe (not decoy system partition wipe)
+
+ // Title bar
+ SetWindowText (MainDlg, TC_APP_NAME);
+
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), FALSE);
+ }
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("WIPE_MODE_TITLE"));
+ SetWindowTextW (GetDlgItem (hwndDlg, IDT_WIPE_MODE_INFO), GetString ("WIPE_MODE_INFO"));
+
+ PopulateWipeModeCombo (GetDlgItem (hwndDlg, IDC_WIPE_MODE), FALSE, FALSE);
+
+ SelectAlgo (GetDlgItem (hwndDlg, IDC_WIPE_MODE), (int *) &nWipeMode);
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
+
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDCANCEL), TRUE);
+
+ break;
+
+ case DEVICE_WIPE_PAGE:
+
+ if (bHiddenOS && IsHiddenOSRunning())
+ {
+ // Decoy system partition wipe
+
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString ("DEVICE_WIPE_PAGE_INFO_HIDDEN_OS"));
+ }
+ else
+ {
+ // Regular device wipe (not decoy system partition wipe)
+
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString ("DEVICE_WIPE_PAGE_INFO"));
+ }
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("DEVICE_WIPE_PAGE_TITLE"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("WIPE"));
+ SetWindowTextW (GetDlgItem (hCurPage, IDC_WIPE_MODE), (wstring (L" ") + GetWipeModeName (nWipeMode)).c_str());
+
+ EnableWindow (GetDlgItem (hwndDlg, IDC_ABORT_BUTTON), FALSE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), TRUE);
+
+ break;
+ }
+ return 0;
+
+ case WM_HELP:
+ OpenPageHelp (GetParent (hwndDlg), nCurPageNo);
+ return 1;
+
+ case TC_APPMSG_PERFORM_POST_SYSENC_WMINIT_TASKS:
+ AfterSysEncProgressWMInitTasks (hwndDlg);
+ return 1;
+
+ case WM_COMMAND:
+
+ if (nCurPageNo == INTRO_PAGE)
+ {
+ switch (lw)
+ {
+ case IDC_FILE_CONTAINER:
+ UpdateWizardModeControls (hwndDlg, WIZARD_MODE_FILE_CONTAINER);
+ return 1;
+
+ case IDC_NONSYS_DEVICE:
+ UpdateWizardModeControls (hwndDlg, WIZARD_MODE_NONSYS_DEVICE);
+ return 1;
+
+ case IDC_SYS_DEVICE:
+ UpdateWizardModeControls (hwndDlg, WIZARD_MODE_SYS_DEVICE);
+ return 1;
+
+ case IDC_MORE_INFO_ON_CONTAINERS:
+ Applink ("introcontainer", TRUE, "");
+ return 1;
+
+ case IDC_MORE_INFO_ON_SYS_ENCRYPTION:
+ Applink ("introsysenc", TRUE, "");
+ return 1;
+ }
+ }
+
+ if (nCurPageNo == SYSENC_TYPE_PAGE)
+ {
+ switch (lw)
+ {
+ case IDC_SYSENC_HIDDEN:
+ bHiddenOS = TRUE;
+ bHiddenVol = TRUE;
+ bHiddenVolHost = TRUE;
+ return 1;
+
+ case IDC_SYSENC_NORMAL:
+ bHiddenOS = FALSE;
+ bHiddenVol = FALSE;
+ bHiddenVolHost = FALSE;
+ return 1;
+
+ case IDC_HIDDEN_SYSENC_INFO_LINK:
+ Applink ("hiddensysenc", TRUE, "");
+ return 1;
+ }
+ }
+
+ if (nCurPageNo == SYSENC_HIDDEN_OS_REQ_CHECK_PAGE && lw == IDC_HIDDEN_SYSENC_INFO_LINK)
+ {
+ Applink ("hiddensysenc", TRUE, "");
+ return 1;
+ }
+
+ if (nCurPageNo == SYSENC_SPAN_PAGE)
+ {
+ switch (lw)
+ {
+ case IDC_WHOLE_SYS_DRIVE:
+ bWholeSysDrive = TRUE;
+ return 1;
+ case IDC_SYS_PARTITION:
+ bWholeSysDrive = FALSE;
+ return 1;
+ }
+
+ }
+
+ if (nCurPageNo == SYSENC_MULTI_BOOT_MODE_PAGE)
+ {
+ switch (lw)
+ {
+ case IDC_SINGLE_BOOT:
+ nMultiBoot = 1;
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
+ return 1;
+ case IDC_MULTI_BOOT:
+ nMultiBoot = 2;
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
+ return 1;
+ }
+ }
+
+ // Dual choice pages
+ switch (nCurPageNo)
+ {
+ case SYSENC_MULTI_BOOT_SYS_EQ_BOOT_PAGE:
+ case SYSENC_MULTI_BOOT_NBR_SYS_DRIVES_PAGE:
+ case SYSENC_MULTI_BOOT_ADJACENT_SYS_PAGE:
+ case SYSENC_MULTI_BOOT_NONWIN_BOOT_LOADER_PAGE:
+ case SYSENC_PRE_DRIVE_ANALYSIS_PAGE:
+
+ if (lw == IDC_CHOICE1 || lw == IDC_CHOICE2)
+ {
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
+ return 1;
+ }
+ break;
+ }
+
+ if (nCurPageNo == FILESYS_PAGE && (lw == IDC_CHOICE1 || lw == IDC_CHOICE2))
+ {
+ if (bWarnOuterVolSuitableFileSys && lw == IDC_CHOICE1 && bHiddenVolHost)
+ {
+ wchar_t szTmp [4096];
+
+ bWarnOuterVolSuitableFileSys = FALSE; // Do not show this warning anymore (this also prevents potential endless repetition due to some race conditions)
+
+ wcscpy (szTmp, GetString ("FILESYS_PAGE_HELP_EXPLANATION_HIDVOL"));
+ wcscat (szTmp, L"\n\n");
+ wcscat (szTmp, GetString ("FILESYS_PAGE_HELP_EXPLANATION_HIDVOL_CONFIRM"));
+
+ if (MessageBoxW (MainDlg, szTmp, lpszTitle, MB_ICONWARNING | MB_YESNO | MB_DEFBUTTON2) == IDNO)
+ {
+ nNeedToStoreFilesOver4GB = 0;
+ Init2RadButtonPageYesNo (nNeedToStoreFilesOver4GB);
+ }
+ }
+
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
+ return 1;
+ }
+
+ if (lw == IDC_HIDDEN_VOL && nCurPageNo == VOLUME_TYPE_PAGE)
+ {
+ bHiddenVol = TRUE;
+ bHiddenVolHost = TRUE;
+ bInPlaceEncNonSys = FALSE;
+ return 1;
+ }
+
+ if (lw == IDC_STD_VOL && nCurPageNo == VOLUME_TYPE_PAGE)
+ {
+ bHiddenVol = FALSE;
+ bHiddenVolHost = FALSE;
+ return 1;
+ }
+
+ if (nCurPageNo == SYSENC_ENCRYPTION_PAGE)
+ {
+ BootEncryptionStatus locBootEncStatus;
+
+ switch (lw)
+ {
+ case IDC_PAUSE:
+ try
+ {
+ locBootEncStatus = BootEncObj->GetStatus();
+
+ if (locBootEncStatus.SetupInProgress)
+ SysEncPause ();
+ else
+ SysEncResume ();
+ }
+ catch (Exception &e)
+ {
+ e.Show (hwndDlg);
+ }
+ return 1;
+
+ case IDC_WIPE_MODE:
+ if (hw == CBN_SELCHANGE)
+ {
+ nWipeMode = (WipeAlgorithmId) SendMessage (GetDlgItem (hCurPage, IDC_WIPE_MODE),
+ CB_GETITEMDATA,
+ SendMessage (GetDlgItem (hCurPage, IDC_WIPE_MODE), CB_GETCURSEL, 0, 0),
+ 0);
+
+ return 1;
+ }
+ break;
+
+ case IDC_MORE_INFO_SYS_ENCRYPTION:
+ Applink ("sysencprogressinfo", TRUE, "");
+ return 1;
+ }
+ }
+
+ if (bInPlaceEncNonSys)
+ {
+ switch (nCurPageNo)
+ {
+ case NONSYS_INPLACE_ENC_RESUME_PARTITION_SEL_PAGE:
+
+ if (lw == IDC_LIST_BOX
+ && (hw == LBN_SELCHANGE || hw == LBN_DBLCLK))
+ {
+ BOOL tmpbDevice = FALSE;
+
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), FALSE);
+
+ int selPartitionItemId = (int) SendMessage (GetDlgItem (hwndDlg, IDC_LIST_BOX), LB_GETCURSEL, 0, 0);
+
+ if (selPartitionItemId == LB_ERR)
+ {
+ // Deselect all
+ SendMessage (GetDlgItem (hwndDlg, IDC_LIST_BOX), LB_SETCURSEL, (WPARAM) -1, 0);
+
+ SetFocus (GetDlgItem (MainDlg, IDC_NEXT));
+ return 1;
+ }
+
+ SetFocus (GetDlgItem (MainDlg, IDC_NEXT));
+
+ strcpy (szFileName, DeferredNonSysInPlaceEncDevices [selPartitionItemId].Path.c_str());
+ CreateFullVolumePath (szDiskFile, szFileName, &tmpbDevice);
+
+ nVolumeSize = GetDeviceSize (szDiskFile);
+ if (nVolumeSize == -1)
+ {
+ handleWin32Error (MainDlg);
+ return 1;
+ }
+
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
+
+ return 1;
+ }
+ break;
+
+ case NONSYS_INPLACE_ENC_ENCRYPTION_PAGE:
+ {
+ switch (lw)
+ {
+ case IDC_PAUSE:
+
+ // Pause/resume non-system in-place encryption
+
+ if (bVolTransformThreadRunning || bVolTransformThreadToRun)
+ {
+ EnableWindow (GetDlgItem (hCurPage, IDC_PAUSE), FALSE);
+ NonSysInplaceEncPause ();
+ }
+ else
+ NonSysInplaceEncResume ();
+
+ return 1;
+
+ case IDC_WIPE_MODE:
+ if (hw == CBN_SELCHANGE)
+ {
+ nWipeMode = (WipeAlgorithmId) SendMessage (GetDlgItem (hCurPage, IDC_WIPE_MODE),
+ CB_GETITEMDATA,
+ SendMessage (GetDlgItem (hCurPage, IDC_WIPE_MODE), CB_GETCURSEL, 0, 0),
+ 0);
+
+ return 1;
+ }
+ break;
+ }
+ }
+ break;
+ }
+ }
+
+
+ if (lw == IDC_OPEN_OUTER_VOLUME && nCurPageNo == FORMAT_FINISHED_PAGE)
+ {
+ OpenVolumeExplorerWindow (hiddenVolHostDriveNo);
+ return 1;
+ }
+
+ if (lw == IDC_HIDDEN_VOL_HELP && nCurPageNo == VOLUME_TYPE_PAGE)
+ {
+ Applink ("hiddenvolume", TRUE, "");
+ return 1;
+ }
+
+ if (lw == IDC_ABORT_BUTTON && nCurPageNo == FORMAT_PAGE)
+ {
+ if (MessageBoxW (hwndDlg, GetString ("FORMAT_ABORT"), lpszTitle, MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON2 ) == IDYES)
+ bVolTransformThreadCancel = TRUE;
+ return 1;
+ }
+
+ if (lw == IDC_CIPHER_TEST && nCurPageNo == CIPHER_PAGE)
+ {
+ LPARAM nIndex;
+ int c;
+
+ nIndex = SendMessage (GetDlgItem (hCurPage, IDC_COMBO_BOX), CB_GETCURSEL, 0, 0);
+ nVolumeEA = SendMessage (GetDlgItem (hCurPage, IDC_COMBO_BOX), CB_GETITEMDATA, nIndex, 0);
+
+ for (c = EAGetLastCipher (nVolumeEA); c != 0; c = EAGetPreviousCipher (nVolumeEA, c))
+ {
+ DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_CIPHER_TEST_DLG),
+ GetParent (hwndDlg), (DLGPROC) CipherTestDialogProc, (LPARAM) c);
+ }
+ return 1;
+ }
+
+ if (lw == IDC_BENCHMARK && nCurPageNo == CIPHER_PAGE)
+ {
+ // Reduce CPU load
+ bFastPollEnabled = FALSE;
+ bRandmixEnabled = FALSE;
+
+ DialogBoxParamW (hInst,
+ MAKEINTRESOURCEW (IDD_BENCHMARK_DLG), hwndDlg,
+ (DLGPROC) BenchmarkDlgProc, (LPARAM) NULL);
+
+ bFastPollEnabled = TRUE;
+ bRandmixEnabled = TRUE;
+
+ return 1;
+ }
+
+ if (lw == IDC_LINK_MORE_INFO_ABOUT_CIPHER && nCurPageNo == CIPHER_PAGE)
+ {
+ char name[100];
+
+ int nIndex = SendMessage (GetDlgItem (hCurPage, IDC_COMBO_BOX), CB_GETCURSEL, 0, 0);
+ nIndex = SendMessage (GetDlgItem (hCurPage, IDC_COMBO_BOX), CB_GETITEMDATA, nIndex, 0);
+ EAGetName (name, nIndex);
+
+ if (strcmp (name, "AES") == 0)
+ Applink ("aes", FALSE, "");
+ else if (strcmp (name, "Serpent") == 0)
+ Applink ("serpent", FALSE, "");
+ else if (strcmp (name, "Twofish") == 0)
+ Applink ("twofish", FALSE, "");
+ else if (EAGetCipherCount (nIndex) > 1)
+ Applink ("cascades", TRUE, "");
+
+ return 1;
+ }
+
+ if (lw == IDC_LINK_HASH_INFO && nCurPageNo == CIPHER_PAGE)
+ {
+ Applink ("hashalgorithms", TRUE, "");
+ return 1;
+ }
+
+ if (hw == CBN_EDITCHANGE && nCurPageNo == VOLUME_LOCATION_PAGE)
+ {
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT),
+ GetWindowTextLength (GetDlgItem (hCurPage, IDC_COMBO_BOX)) > 0);
+
+ bDeviceTransformModeChoiceMade = FALSE;
+ bInPlaceEncNonSys = FALSE;
+
+ return 1;
+ }
+
+ if (hw == CBN_SELCHANGE && nCurPageNo == VOLUME_LOCATION_PAGE)
+ {
+ LPARAM nIndex;
+
+ nIndex = MoveEditToCombo ((HWND) lParam, bHistory);
+ nIndex = UpdateComboOrder (GetDlgItem (hwndDlg, IDC_COMBO_BOX));
+
+ if (nIndex != CB_ERR)
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
+ else
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), FALSE);
+
+ bDeviceTransformModeChoiceMade = FALSE;
+ bInPlaceEncNonSys = FALSE;
+
+ return 1;
+ }
+
+ if (hw == EN_CHANGE && nCurPageNo == SIZE_PAGE)
+ {
+ VerifySizeAndUpdate (hwndDlg, FALSE);
+ return 1;
+ }
+
+ if (hw == EN_CHANGE && nCurPageNo == PASSWORD_PAGE)
+ {
+ VerifyPasswordAndUpdate (hwndDlg, GetDlgItem (GetParent (hwndDlg), IDC_NEXT),
+ GetDlgItem (hwndDlg, IDC_PASSWORD),
+ GetDlgItem (hwndDlg, IDC_VERIFY),
+ NULL,
+ NULL,
+ KeyFilesEnable && FirstKeyFile!=NULL && !SysEncInEffect());
+ volumePassword.Length = strlen ((char *) volumePassword.Text);
+
+ return 1;
+ }
+
+ if (lw == IDC_SHOW_PASSWORD && nCurPageNo == PASSWORD_PAGE)
+ {
+ SendMessage (GetDlgItem (hwndDlg, IDC_PASSWORD),
+ EM_SETPASSWORDCHAR,
+ GetCheckBox (hwndDlg, IDC_SHOW_PASSWORD) ? 0 : '*',
+ 0);
+ SendMessage (GetDlgItem (hwndDlg, IDC_VERIFY),
+ EM_SETPASSWORDCHAR,
+ GetCheckBox (hwndDlg, IDC_SHOW_PASSWORD) ? 0 : '*',
+ 0);
+ InvalidateRect (GetDlgItem (hwndDlg, IDC_PASSWORD), NULL, TRUE);
+ InvalidateRect (GetDlgItem (hwndDlg, IDC_VERIFY), NULL, TRUE);
+ return 1;
+ }
+
+ if (nCurPageNo == PASSWORD_PAGE
+ || nCurPageNo == HIDDEN_VOL_HOST_PASSWORD_PAGE
+ || nCurPageNo == NONSYS_INPLACE_ENC_RESUME_PASSWORD_PAGE)
+ {
+ if (lw == IDC_KEY_FILES)
+ {
+ if (SysEncInEffect())
+ {
+ Warning ("KEYFILES_NOT_SUPPORTED_FOR_SYS_ENCRYPTION");
+ return 1;
+ }
+
+ KeyFilesDlgParam param;
+ param.EnableKeyFiles = KeyFilesEnable;
+ param.FirstKeyFile = FirstKeyFile;
+
+ if (IDOK == DialogBoxParamW (hInst,
+ MAKEINTRESOURCEW (IDD_KEYFILES), hwndDlg,
+ (DLGPROC) KeyFilesDlgProc, (LPARAM) ¶m))
+ {
+ KeyFilesEnable = param.EnableKeyFiles;
+ FirstKeyFile = param.FirstKeyFile;
+
+ SetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE, KeyFilesEnable);
+
+ if (nCurPageNo != HIDDEN_VOL_HOST_PASSWORD_PAGE && nCurPageNo != NONSYS_INPLACE_ENC_RESUME_PASSWORD_PAGE)
+ EnableWindow (GetDlgItem (hwndDlg, IDC_KEY_FILES), KeyFilesEnable);
+
+ if (nCurPageNo != HIDDEN_VOL_HOST_PASSWORD_PAGE && nCurPageNo != NONSYS_INPLACE_ENC_RESUME_PASSWORD_PAGE)
+ {
+ VerifyPasswordAndUpdate (hwndDlg, GetDlgItem (GetParent (hwndDlg), IDC_NEXT),
+ GetDlgItem (hCurPage, IDC_PASSWORD),
+ GetDlgItem (hCurPage, IDC_VERIFY),
+ volumePassword.Text, szVerify, KeyFilesEnable && FirstKeyFile!=NULL);
+ }
+ }
+
+ return 1;
+ }
+
+ if (lw == IDC_KEYFILES_ENABLE)
+ {
+ KeyFilesEnable = GetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE);
+
+ if (nCurPageNo != HIDDEN_VOL_HOST_PASSWORD_PAGE && nCurPageNo != NONSYS_INPLACE_ENC_RESUME_PASSWORD_PAGE)
+ {
+ EnableWindow (GetDlgItem (hwndDlg, IDC_KEY_FILES), KeyFilesEnable);
+
+ VerifyPasswordAndUpdate (hwndDlg, GetDlgItem (GetParent (hwndDlg), IDC_NEXT),
+ GetDlgItem (hCurPage, IDC_PASSWORD),
+ GetDlgItem (hCurPage, IDC_VERIFY),
+ volumePassword.Text, szVerify, KeyFilesEnable && FirstKeyFile!=NULL);
+ }
+
+ return 1;
+ }
+ }
+
+ if (nCurPageNo == HIDDEN_VOL_HOST_PASSWORD_PAGE
+ || nCurPageNo == NONSYS_INPLACE_ENC_RESUME_PASSWORD_PAGE)
+ {
+ if (hw == EN_CHANGE)
+ {
+ GetWindowText (GetDlgItem (hCurPage, IDC_PASSWORD_DIRECT), (char *) volumePassword.Text, sizeof (volumePassword.Text));
+ volumePassword.Length = strlen ((char *) volumePassword.Text);
+ return 1;
+ }
+
+ if (lw == IDC_SHOW_PASSWORD_SINGLE)
+ {
+ SendMessage (GetDlgItem (hwndDlg, IDC_PASSWORD_DIRECT),
+ EM_SETPASSWORDCHAR,
+ GetCheckBox (hwndDlg, IDC_SHOW_PASSWORD_SINGLE) ? 0 : '*',
+ 0);
+ InvalidateRect (GetDlgItem (hwndDlg, IDC_PASSWORD_DIRECT), NULL, TRUE);
+ return 1;
+ }
+ }
+
+ if ((lw == IDC_KB || lw == IDC_MB || lw == IDC_GB) && nCurPageNo == SIZE_PAGE)
+ {
+ SendMessage (GetDlgItem (hwndDlg, IDC_KB), BM_SETCHECK, BST_UNCHECKED, 0);
+ SendMessage (GetDlgItem (hwndDlg, IDC_MB), BM_SETCHECK, BST_UNCHECKED, 0);
+ SendMessage (GetDlgItem (hwndDlg, IDC_GB), BM_SETCHECK, BST_UNCHECKED, 0);
+
+ switch (lw)
+ {
+ case IDC_KB:
+ SendMessage (GetDlgItem (hwndDlg, IDC_KB), BM_SETCHECK, BST_CHECKED, 0);
+ break;
+ case IDC_MB:
+ SendMessage (GetDlgItem (hwndDlg, IDC_MB), BM_SETCHECK, BST_CHECKED, 0);
+ break;
+ case IDC_GB:
+ SendMessage (GetDlgItem (hwndDlg, IDC_GB), BM_SETCHECK, BST_CHECKED, 0);
+ break;
+ }
+
+ VerifySizeAndUpdate (hwndDlg, FALSE);
+ return 1;
+ }
+
+ if (lw == IDC_HIDVOL_WIZ_MODE_DIRECT && nCurPageNo == HIDDEN_VOL_WIZARD_MODE_PAGE)
+ {
+ bHiddenVolDirect = TRUE;
+ return 1;
+ }
+
+ if (lw == IDC_HIDVOL_WIZ_MODE_FULL && nCurPageNo == HIDDEN_VOL_WIZARD_MODE_PAGE)
+ {
+ bHiddenVolDirect = FALSE;
+ return 1;
+ }
+
+ if (lw == IDC_SELECT_VOLUME_LOCATION && nCurPageNo == VOLUME_LOCATION_PAGE)
+ {
+ if (!bDevice)
+ {
+ // Select file
+
+ if (BrowseFiles (hwndDlg, "OPEN_TITLE", szFileName, bHistory, !bHiddenVolDirect, NULL) == FALSE)
+ return 1;
+
+ AddComboItem (GetDlgItem (hwndDlg, IDC_COMBO_BOX), szFileName, bHistory);
+
+ EnableDisableFileNext (GetDlgItem (hwndDlg, IDC_COMBO_BOX),
+ GetDlgItem (GetParent (hwndDlg), IDC_NEXT));
+
+ return 1;
+ }
+ else
+ {
+ // Select device
+
+ int nResult = DialogBoxParamW (hInst,
+ MAKEINTRESOURCEW (IDD_RAWDEVICES_DLG), GetParent (hwndDlg),
+ (DLGPROC) RawDevicesDlgProc, (LPARAM) & szFileName[0]);
+
+ // Check administrator privileges
+ if (!strstr (szFileName, "Floppy") && !IsAdmin() && !IsUacSupported ())
+ MessageBoxW (hwndDlg, GetString ("ADMIN_PRIVILEGES_WARN_DEVICES"), lpszTitle, MB_OK|MB_ICONWARNING);
+
+ if (nResult == IDOK && strlen (szFileName) > 0)
+ {
+ AddComboItem (GetDlgItem (hwndDlg, IDC_COMBO_BOX), szFileName, bHistory);
+
+ EnableDisableFileNext (GetDlgItem (hwndDlg, IDC_COMBO_BOX),
+ GetDlgItem (GetParent (hwndDlg), IDC_NEXT));
+
+ bDeviceTransformModeChoiceMade = FALSE;
+ bInPlaceEncNonSys = FALSE;
+ }
+ return 1;
+ }
+ }
+
+ if (nCurPageNo == DEVICE_TRANSFORM_MODE_PAGE)
+ {
+ switch (lw)
+ {
+ case IDC_DEVICE_TRANSFORM_MODE_FORMAT:
+
+ bInPlaceEncNonSys = FALSE;
+ bDeviceTransformModeChoiceMade = TRUE;
+
+ return 1;
+
+ case IDC_DEVICE_TRANSFORM_MODE_INPLACE:
+
+ bInPlaceEncNonSys = TRUE;
+ bDeviceTransformModeChoiceMade = TRUE;
+
+ bHiddenVol = FALSE;
+ bHiddenVolDirect = FALSE;
+ bHiddenVolHost = FALSE;
+ bSparseFileSwitch = FALSE;
+ quickFormat = FALSE;
+
+ return 1;
+ }
+ }
+
+ if (lw == IDC_HIDVOL_WIZ_MODE_FULL && nCurPageNo == HIDDEN_VOL_WIZARD_MODE_PAGE)
+ {
+ bHiddenVolDirect = FALSE;
+ return 1;
+ }
+
+ if (hw == CBN_SELCHANGE && nCurPageNo == CIPHER_PAGE)
+ {
+ switch (lw)
+ {
+ case IDC_COMBO_BOX:
+ ComboSelChangeEA (hwndDlg);
+ break;
+
+ case IDC_COMBO_BOX_HASH_ALGO:
+ if (SysEncInEffect ()
+ && SendMessage (GetDlgItem (hwndDlg, IDC_COMBO_BOX_HASH_ALGO), CB_GETITEMDATA,
+ SendMessage (GetDlgItem (hwndDlg, IDC_COMBO_BOX_HASH_ALGO), CB_GETCURSEL, 0, 0), 0)
+ != DEFAULT_HASH_ALGORITHM_BOOT)
+ {
+ hash_algo = DEFAULT_HASH_ALGORITHM_BOOT;
+ RandSetHashFunction (DEFAULT_HASH_ALGORITHM_BOOT);
+ Info ("ALGO_NOT_SUPPORTED_FOR_SYS_ENCRYPTION");
+ SelectAlgo (GetDlgItem (hwndDlg, IDC_COMBO_BOX_HASH_ALGO), &hash_algo);
+ }
+ break;
+ }
+ return 1;
+
+ }
+
+ if (lw == IDC_QUICKFORMAT && IsButtonChecked (GetDlgItem (hCurPage, IDC_QUICKFORMAT)))
+ {
+ if (bSparseFileSwitch)
+ {
+ if (AskWarnYesNo("CONFIRM_SPARSE_FILE") == IDNO)
+ SetCheckBox (hwndDlg, IDC_QUICKFORMAT, FALSE);
+ }
+ else
+ {
+ if (AskWarnYesNo("WARN_QUICK_FORMAT") == IDNO)
+ SetCheckBox (hwndDlg, IDC_QUICKFORMAT, FALSE);
+ }
+ return 1;
+ }
+
+ if (lw == IDC_FILESYS && hw == CBN_SELCHANGE)
+ {
+ fileSystem = SendMessage (GetDlgItem (hCurPage, IDC_FILESYS), CB_GETITEMDATA,
+ SendMessage (GetDlgItem (hCurPage, IDC_FILESYS), CB_GETCURSEL, 0, 0) , 0);
+
+ return 1;
+ }
+
+ if (lw == IDC_SHOW_KEYS && nCurPageNo == FORMAT_PAGE)
+ {
+ showKeys = IsButtonChecked (GetDlgItem (hCurPage, IDC_SHOW_KEYS));
+
+ SetWindowText (GetDlgItem (hCurPage, IDC_RANDOM_BYTES), showKeys ? " " : "******************************** ");
+ SetWindowText (GetDlgItem (hCurPage, IDC_HEADER_KEY), showKeys ? "" : "******************************** ");
+ SetWindowText (GetDlgItem (hCurPage, IDC_DISK_KEY), showKeys ? "" : "******************************** ");
+ return 1;
+ }
+
+ if (lw == IDC_DISPLAY_POOL_CONTENTS
+ && (nCurPageNo == SYSENC_COLLECTING_RANDOM_DATA_PAGE || nCurPageNo == NONSYS_INPLACE_ENC_RAND_DATA_PAGE))
+ {
+ showKeys = IsButtonChecked (GetDlgItem (hCurPage, IDC_DISPLAY_POOL_CONTENTS));
+ DisplayRandPool (hRandPoolSys, showKeys);
+
+ return 1;
+ }
+
+ if (lw == IDC_DISPLAY_KEYS && nCurPageNo == SYSENC_KEYS_GEN_PAGE)
+ {
+ showKeys = IsButtonChecked (GetDlgItem (hCurPage, IDC_DISPLAY_KEYS));
+
+ DisplayPortionsOfKeys (GetDlgItem (hwndDlg, IDC_HEADER_KEY), GetDlgItem (hwndDlg, IDC_DISK_KEY), HeaderKeyGUIView, MasterKeyGUIView, !showKeys);
+ return 1;
+ }
+
+ if (nCurPageNo == SYSENC_RESCUE_DISK_CREATION_PAGE)
+ {
+ if (lw == IDC_BROWSE)
+ {
+ char tmpszRescueDiskISO [TC_MAX_PATH+1];
+
+ if (!BrowseFiles (hwndDlg, "OPEN_TITLE", tmpszRescueDiskISO, FALSE, TRUE, NULL))
+ return 1;
+
+ strcpy (szRescueDiskISO, tmpszRescueDiskISO);
+
+ SetDlgItemText (hwndDlg, IDC_RESCUE_DISK_ISO_PATH, szRescueDiskISO);
+ EnableWindow (GetDlgItem (MainDlg, IDC_NEXT), (GetWindowTextLength (GetDlgItem (hwndDlg, IDC_RESCUE_DISK_ISO_PATH)) > 1));
+ return 1;
+ }
+
+ if ( hw == EN_CHANGE )
+ {
+ GetDlgItemText (hwndDlg, IDC_RESCUE_DISK_ISO_PATH, szRescueDiskISO, sizeof(szRescueDiskISO));
+ EnableWindow (GetDlgItem (MainDlg, IDC_NEXT), (GetWindowTextLength (GetDlgItem (hwndDlg, IDC_RESCUE_DISK_ISO_PATH)) > 1));
+ return 1;
+ }
+ }
+
+ if (nCurPageNo == SYSENC_RESCUE_DISK_BURN_PAGE && lw == IDC_DOWNLOAD_CD_BURN_SOFTWARE)
+ {
+ if (IsWindowsIsoBurnerAvailable())
+ LaunchWindowsIsoBurner (hwndDlg, szRescueDiskISO);
+ else
+ Applink ("isoburning", TRUE, "");
+
+ return 1;
+ }
+
+ if ((nCurPageNo == SYSENC_WIPE_MODE_PAGE
+ || nCurPageNo == NONSYS_INPLACE_ENC_WIPE_MODE_PAGE
+ || nCurPageNo == DEVICE_WIPE_MODE_PAGE)
+ && hw == CBN_SELCHANGE)
+ {
+ nWipeMode = (WipeAlgorithmId) SendMessage (GetDlgItem (hCurPage, IDC_WIPE_MODE),
+ CB_GETITEMDATA,
+ SendMessage (GetDlgItem (hCurPage, IDC_WIPE_MODE), CB_GETCURSEL, 0, 0),
+ 0);
+
+ return 1;
+ }
+
+ if (nCurPageNo == DEVICE_WIPE_PAGE)
+ {
+ switch (lw)
+ {
+ case IDC_ABORT_BUTTON:
+
+ if (AskWarnNoYes ("CONFIRM_WIPE_ABORT") == IDYES)
+ WipeAbort();
+
+ return 1;
+ }
+ }
+
+ if (lw == IDC_NO_HISTORY)
+ {
+ if (!(bHistory = !IsButtonChecked (GetDlgItem (hCurPage, IDC_NO_HISTORY))))
+ ClearHistory (GetDlgItem (hCurPage, IDC_COMBO_BOX));
+
+ return 1;
+ }
+
+ return 0;
+ }
+
+ return 0;
+}
+
+/* Except in response to the WM_INITDIALOG and WM_ENDSESSION messages, the dialog box procedure
+ should return nonzero if it processes the message, and zero if it does not. - see DialogProc */
+BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ WORD lw = LOWORD (wParam);
+
+ int nNewPageNo = nCurPageNo;
+
+ switch (uMsg)
+ {
+ case WM_INITDIALOG:
+ {
+ MainDlg = hwndDlg;
+ InitDialog (hwndDlg);
+ LocalizeDialog (hwndDlg, "IDD_VOL_CREATION_WIZARD_DLG");
+
+ if (IsTrueCryptInstallerRunning())
+ AbortProcess ("TC_INSTALLER_IS_RUNNING");
+
+ // Resize the bitmap if the user has a non-default DPI
+ if (ScreenDPI != USER_DEFAULT_SCREEN_DPI)
+ {
+ hbmWizardBitmapRescaled = RenderBitmap (MAKEINTRESOURCE (IDB_WIZARD),
+ GetDlgItem (hwndDlg, IDC_BITMAP_WIZARD),
+ 0, 0, 0, 0, FALSE, FALSE);
+ }
+
+ LoadSettings (hwndDlg);
+
+ LoadDefaultKeyFilesParam ();
+ RestoreDefaultKeyFilesParam ();
+
+ SysEncMultiBootCfg.NumberOfSysDrives = -1;
+ SysEncMultiBootCfg.MultipleSystemsOnDrive = -1;
+ SysEncMultiBootCfg.BootLoaderLocation = -1;
+ SysEncMultiBootCfg.BootLoaderBrand = -1;
+ SysEncMultiBootCfg.SystemOnBootDrive = -1;
+
+ try
+ {
+ BootEncStatus = BootEncObj->GetStatus();
+ }
+ catch (Exception &e)
+ {
+ e.Show (hwndDlg);
+ Error ("ERR_GETTING_SYSTEM_ENCRYPTION_STATUS");
+ EndMainDlg (MainDlg);
+ return 0;
+ }
+
+ SendMessage (GetDlgItem (hwndDlg, IDC_BOX_TITLE), WM_SETFONT, (WPARAM) hTitleFont, (LPARAM) TRUE);
+ SetWindowTextW (hwndDlg, lpszTitle);
+
+ ExtractCommandLine (hwndDlg, (char *) lParam);
+
+ if (ComServerMode)
+ {
+ InitDialog (hwndDlg);
+
+ if (!ComServerFormat ())
+ {
+ handleWin32Error (hwndDlg);
+ exit (1);
+ }
+ exit (0);
+ }
+
+ SHGetFolderPath (NULL, CSIDL_MYDOCUMENTS, NULL, 0, szRescueDiskISO);
+ strcat (szRescueDiskISO, "\\TrueCrypt Rescue Disk.iso");
+
+ if (IsOSAtLeast (WIN_VISTA))
+ {
+ // Availability of in-place encryption (which is pre-selected by default whenever
+ // possible) makes partition-hosted volume creation safer.
+ bWarnDeviceFormatAdvanced = FALSE;
+ }
+
+#ifdef _DEBUG
+ // For faster testing
+ strcpy (szVerify, "q");
+ strcpy (szRawPassword, "q");
+#endif
+
+ PostMessage (hwndDlg, TC_APPMSG_PERFORM_POST_WMINIT_TASKS, 0, 0);
+ }
+ return 0;
+
+ case WM_SYSCOMMAND:
+ if (lw == IDC_ABOUT)
+ {
+ DialogBoxW (hInst, MAKEINTRESOURCEW (IDD_ABOUT_DLG), hwndDlg, (DLGPROC) AboutDlgProc);
+ return 1;
+ }
+ return 0;
+
+ case WM_TIMER:
+
+ switch (wParam)
+ {
+ case TIMER_ID_RANDVIEW:
+
+ if (WizardMode == WIZARD_MODE_SYS_DEVICE
+ || bInPlaceEncNonSys)
+ {
+ DisplayRandPool (hRandPoolSys, showKeys);
+ }
+ else
+ {
+ unsigned char tmp[17];
+ char tmp2[43];
+ int i;
+
+ if (!showKeys)
+ return 1;
+
+ RandpeekBytes (tmp, sizeof (tmp));
+
+ tmp2[0] = 0;
+
+ for (i = 0; i < sizeof (tmp); i++)
+ {
+ char tmp3[8];
+ sprintf (tmp3, "%02X", (int) (unsigned char) tmp[i]);
+ strcat (tmp2, tmp3);
+ }
+
+ tmp2[32] = 0;
+
+ SetWindowTextW (GetDlgItem (hCurPage, IDC_RANDOM_BYTES), (SingleStringToWide (tmp2) + GetString ("TRIPLE_DOT_GLYPH_ELLIPSIS")).c_str());
+
+ burn (tmp, sizeof(tmp));
+ burn (tmp2, sizeof(tmp2));
+ }
+ return 1;
+
+ case TIMER_ID_SYSENC_PROGRESS:
+ {
+ // Manage system encryption/decryption and update related GUI
+
+ try
+ {
+ BootEncStatus = BootEncObj->GetStatus();
+ }
+ catch (Exception &e)
+ {
+ KillTimer (MainDlg, TIMER_ID_SYSENC_PROGRESS);
+
+ try
+ {
+ BootEncObj->AbortSetup ();
+ }
+ catch (Exception &e)
+ {
+ e.Show (hwndDlg);
+ }
+
+ e.Show (hwndDlg);
+ Error ("ERR_GETTING_SYSTEM_ENCRYPTION_STATUS");
+ EndMainDlg (MainDlg);
+ return 1;
+ }
+
+ if (BootEncStatus.SetupInProgress)
+ UpdateSysEncProgressBar ();
+
+ if (bSystemEncryptionInProgress != BootEncStatus.SetupInProgress)
+ {
+ bSystemEncryptionInProgress = BootEncStatus.SetupInProgress;
+
+ UpdateSysEncProgressBar ();
+ UpdateSysEncControls ();
+
+ if (!bSystemEncryptionInProgress)
+ {
+ // The driver stopped encrypting/decrypting
+
+ // Allow the OS to enter Sleep mode when idle
+ SetThreadExecutionState (ES_CONTINUOUS);
+
+ KillTimer (hwndDlg, TIMER_ID_SYSENC_PROGRESS);
+
+ try
+ {
+ if (BootEncStatus.DriveMounted) // If we had been really encrypting/decrypting (not just proceeding to deinstall)
+ BootEncObj->CheckEncryptionSetupResult();
+ }
+ catch (SystemException &e)
+ {
+ if (!bTryToCorrectReadErrors
+ && SystemEncryptionStatus == SYSENC_STATUS_ENCRYPTING
+ && (IsDiskReadError (e.ErrorCode)))
+ {
+ bTryToCorrectReadErrors = (AskWarnYesNo ("ENABLE_BAD_SECTOR_ZEROING") == IDYES);
+
+ if (bTryToCorrectReadErrors)
+ {
+ SysEncResume();
+ return 1;
+ }
+ }
+ else if (!DiscardUnreadableEncryptedSectors
+ && SystemEncryptionStatus == SYSENC_STATUS_DECRYPTING
+ && (IsDiskReadError (e.ErrorCode)))
+ {
+ DiscardUnreadableEncryptedSectors = (AskWarnYesNo ("DISCARD_UNREADABLE_ENCRYPTED_SECTORS") == IDYES);
+
+ if (DiscardUnreadableEncryptedSectors)
+ {
+ SysEncResume();
+ return 1;
+ }
+ }
+
+ e.Show (hwndDlg);
+ }
+ catch (Exception &e)
+ {
+ e.Show (hwndDlg);
+ }
+
+ switch (SystemEncryptionStatus)
+ {
+ case SYSENC_STATUS_ENCRYPTING:
+
+ if (BootEncStatus.ConfiguredEncryptedAreaStart == BootEncStatus.EncryptedAreaStart
+ && BootEncStatus.ConfiguredEncryptedAreaEnd == BootEncStatus.EncryptedAreaEnd)
+ {
+ // The partition/drive has been fully encrypted
+
+ ManageStartupSeqWiz (TRUE, "");
+
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_NEXT), GetString ("FINALIZE"));
+ EnableWindow (GetDlgItem (hwndDlg, IDC_NEXT), TRUE);
+ EnableWindow (GetDlgItem (hwndDlg, IDCANCEL), FALSE);
+ EnableWindow (GetDlgItem (hCurPage, IDC_WIPE_MODE), FALSE);
+ EnableWindow (GetDlgItem (hCurPage, IDC_PAUSE), FALSE);
+
+ WipeHiddenOSCreationConfig(); // For extra conservative security
+
+ ChangeSystemEncryptionStatus (SYSENC_STATUS_NONE);
+
+ Info ("SYSTEM_ENCRYPTION_FINISHED");
+ return 1;
+ }
+ break;
+
+ case SYSENC_STATUS_DECRYPTING:
+
+ if (!BootEncStatus.DriveEncrypted)
+ {
+ // The partition/drive has been fully decrypted
+
+ try
+ {
+ // Finalize the process
+ BootEncObj->Deinstall ();
+ }
+ catch (Exception &e)
+ {
+ e.Show (hwndDlg);
+ }
+
+ ManageStartupSeqWiz (TRUE, "");
+ ChangeSystemEncryptionStatus (SYSENC_STATUS_NONE);
+
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_NEXT), GetString ("FINALIZE"));
+ EnableWindow (GetDlgItem (hwndDlg, IDC_NEXT), TRUE);
+ EnableWindow (GetDlgItem (hwndDlg, IDCANCEL), FALSE);
+ EnableWindow (GetDlgItem (hCurPage, IDC_PAUSE), FALSE);
+
+ Info ("SYSTEM_DECRYPTION_FINISHED");
+
+ // Reboot is required to enable uninstallation and hibernation
+ if (AskWarnYesNo ("CONFIRM_RESTART") == IDYES)
+ {
+ EndMainDlg (MainDlg);
+
+ try
+ {
+ BootEncObj->RestartComputer();
+ }
+ catch (Exception &e)
+ {
+ e.Show (hwndDlg);
+ }
+ }
+
+ return 1;
+ }
+ break;
+ }
+ }
+ }
+ }
+ return 1;
+
+ case TIMER_ID_NONSYS_INPLACE_ENC_PROGRESS:
+
+ if (bInPlaceEncNonSys)
+ {
+ // Non-system in-place encryption
+
+ if (!bVolTransformThreadRunning && !bVolTransformThreadToRun)
+ {
+ KillTimer (hwndDlg, TIMER_ID_NONSYS_INPLACE_ENC_PROGRESS);
+ }
+
+ UpdateNonSysInPlaceEncControls ();
+ }
+ return 1;
+
+ case TIMER_ID_KEYB_LAYOUT_GUARD:
+ if (SysEncInEffect ())
+ {
+ DWORD keybLayout = (DWORD) GetKeyboardLayout (NULL);
+
+ /* Watch the keyboard layout */
+
+ if (keybLayout != 0x00000409 && keybLayout != 0x04090409)
+ {
+ // Keyboard layout is not standard US
+
+ WipePasswordsAndKeyfiles ();
+
+ SetWindowText (GetDlgItem (hCurPage, IDC_PASSWORD), szRawPassword);
+ SetWindowText (GetDlgItem (hCurPage, IDC_VERIFY), szVerify);
+
+ keybLayout = (DWORD) LoadKeyboardLayout ("00000409", KLF_ACTIVATE);
+
+ if (keybLayout != 0x00000409 && keybLayout != 0x04090409)
+ {
+ KillTimer (hwndDlg, TIMER_ID_KEYB_LAYOUT_GUARD);
+ Error ("CANT_CHANGE_KEYB_LAYOUT_FOR_SYS_ENCRYPTION");
+ EndMainDlg (MainDlg);
+ return 1;
+ }
+
+ bKeyboardLayoutChanged = TRUE;
+
+ wchar_t szTmp [4096];
+ wcscpy (szTmp, GetString ("KEYB_LAYOUT_CHANGE_PREVENTED"));
+ wcscat (szTmp, L"\n\n");
+ wcscat (szTmp, GetString ("KEYB_LAYOUT_SYS_ENC_EXPLANATION"));
+ MessageBoxW (MainDlg, szTmp, lpszTitle, MB_ICONWARNING | MB_SETFOREGROUND | MB_TOPMOST);
+ }
+
+ /* Watch the right Alt key (which is used to enter various characters on non-US keyboards) */
+
+ if (bKeyboardLayoutChanged && !bKeybLayoutAltKeyWarningShown)
+ {
+ if (GetAsyncKeyState (VK_RMENU) < 0)
+ {
+ bKeybLayoutAltKeyWarningShown = TRUE;
+
+ wchar_t szTmp [4096];
+ wcscpy (szTmp, GetString ("ALT_KEY_CHARS_NOT_FOR_SYS_ENCRYPTION"));
+ wcscat (szTmp, L"\n\n");
+ wcscat (szTmp, GetString ("KEYB_LAYOUT_SYS_ENC_EXPLANATION"));
+ MessageBoxW (MainDlg, szTmp, lpszTitle, MB_ICONINFORMATION | MB_SETFOREGROUND | MB_TOPMOST);
+ }
+ }
+ }
+ return 1;
+
+ case TIMER_ID_SYSENC_DRIVE_ANALYSIS_PROGRESS:
+
+ if (bSysEncDriveAnalysisInProgress)
+ {
+ UpdateProgressBarProc (GetTickCount() - SysEncDriveAnalysisStart);
+
+ if (GetTickCount() - SysEncDriveAnalysisStart > SYSENC_DRIVE_ANALYSIS_ETA)
+ {
+ // It's taking longer than expected -- reinit the progress bar
+ SysEncDriveAnalysisStart = GetTickCount ();
+ InitProgressBar (SYSENC_DRIVE_ANALYSIS_ETA, 0, FALSE, FALSE, FALSE, TRUE);
+ }
+
+ ArrowWaitCursor ();
+ }
+ else
+ {
+ KillTimer (hwndDlg, TIMER_ID_SYSENC_DRIVE_ANALYSIS_PROGRESS);
+ UpdateProgressBarProc (SYSENC_DRIVE_ANALYSIS_ETA);
+ Sleep (1500); // User-friendly GUI
+
+ if (bSysEncDriveAnalysisTimeOutOccurred)
+ Warning ("SYS_DRIVE_SIZE_PROBE_TIMEOUT");
+
+ LoadPage (hwndDlg, SYSENC_DRIVE_ANALYSIS_PAGE + 1);
+ }
+ return 1;
+
+ case TIMER_ID_WIPE_PROGRESS:
+
+ // Manage device wipe and update related GUI
+
+ if (bHiddenOS && IsHiddenOSRunning())
+ {
+ // Decoy system partition wipe
+
+ DecoySystemWipeStatus decoySysPartitionWipeStatus;
+
+ try
+ {
+ decoySysPartitionWipeStatus = BootEncObj->GetDecoyOSWipeStatus();
+ BootEncStatus = BootEncObj->GetStatus();
+ }
+ catch (Exception &e)
+ {
+ KillTimer (MainDlg, TIMER_ID_WIPE_PROGRESS);
+
+ try
+ {
+ BootEncObj->AbortDecoyOSWipe ();
+ }
+ catch (Exception &e)
+ {
+ e.Show (hwndDlg);
+ }
+
+ e.Show (hwndDlg);
+ EndMainDlg (MainDlg);
+ return 1;
+ }
+
+ if (decoySysPartitionWipeStatus.WipeInProgress)
+ {
+ ArrowWaitCursor ();
+
+ UpdateWipeProgressBar ();
+ }
+
+ if (bDeviceWipeInProgress != decoySysPartitionWipeStatus.WipeInProgress)
+ {
+ bDeviceWipeInProgress = decoySysPartitionWipeStatus.WipeInProgress;
+
+ UpdateWipeProgressBar ();
+ UpdateWipeControls ();
+
+ if (!bDeviceWipeInProgress)
+ {
+ // The driver stopped wiping
+
+ KillTimer (hwndDlg, TIMER_ID_WIPE_PROGRESS);
+
+ try
+ {
+ BootEncObj->CheckDecoyOSWipeResult();
+ }
+ catch (Exception &e)
+ {
+ e.Show (hwndDlg);
+ AbortProcessSilent();
+ }
+
+ if (BootEncStatus.ConfiguredEncryptedAreaEnd == decoySysPartitionWipeStatus.WipedAreaEnd)
+ {
+ // Decoy system partition has been fully wiped
+
+ ChangeHiddenOSCreationPhase (TC_HIDDEN_OS_CREATION_PHASE_WIPED);
+
+ SetWindowTextW (GetDlgItem (MainDlg, IDCANCEL), GetString ("EXIT"));
+ EnableWindow (GetDlgItem (MainDlg, IDCANCEL), TRUE);
+ EnableWindow (GetDlgItem (MainDlg, IDC_PREV), FALSE);
+ EnableWindow (GetDlgItem (MainDlg, IDC_NEXT), FALSE);
+ EnableWindow (GetDlgItem (hCurPage, IDC_ABORT_BUTTON), FALSE);
+
+ Info ("WIPE_FINISHED_DECOY_SYSTEM_PARTITION");
+
+ TextInfoDialogBox (TC_TBXID_DECOY_OS_INSTRUCTIONS);
+
+ if (BootEncObj->GetSystemDriveConfiguration().ExtraBootPartitionPresent)
+ Warning ("DECOY_OS_VERSION_WARNING");
+
+ return 1;
+ }
+ }
+ }
+ }
+ else
+ {
+ // Regular device wipe (not decoy system partition wipe)
+
+ //Info ("WIPE_FINISHED");
+ }
+ return 1;
+ }
+
+ return 0;
+
+
+ case TC_APPMSG_PERFORM_POST_WMINIT_TASKS:
+
+ AfterWMInitTasks (hwndDlg);
+ return 1;
+
+ case TC_APPMSG_FORMAT_FINISHED:
+ {
+ char tmp[RNG_POOL_SIZE*2+1];
+
+ EnableWindow (GetDlgItem (hCurPage, IDC_ABORT_BUTTON), FALSE);
+ EnableWindow (GetDlgItem (hwndDlg, IDC_PREV), TRUE);
+ EnableWindow (GetDlgItem (hwndDlg, IDHELP), TRUE);
+ EnableWindow (GetDlgItem (hwndDlg, IDCANCEL), TRUE);
+ EnableWindow (GetDlgItem (hwndDlg, IDC_NEXT), TRUE);
+ SetFocus (GetDlgItem (hwndDlg, IDC_NEXT));
+
+ if (nCurPageNo == FORMAT_PAGE)
+ KillTimer (hwndDlg, TIMER_ID_RANDVIEW);
+
+ // Attempt to wipe the GUI fields showing portions of randpool, of the master and header keys
+ memset (tmp, 'X', sizeof(tmp));
+ tmp [sizeof(tmp)-1] = 0;
+ SetWindowText (hRandPool, tmp);
+ SetWindowText (hMasterKey, tmp);
+ SetWindowText (hHeaderKey, tmp);
+
+ LoadPage (hwndDlg, FORMAT_FINISHED_PAGE);
+ }
+ return 1;
+
+ case TC_APPMSG_NONSYS_INPLACE_ENC_FINISHED:
+
+ // A partition has just been fully encrypted in place
+
+ KillTimer (hwndDlg, TIMER_ID_NONSYS_INPLACE_ENC_PROGRESS);
+
+ LoadPage (hwndDlg, NONSYS_INPLACE_ENC_ENCRYPTION_FINISHED_PAGE);
+
+ return 1;
+
+ case TC_APPMSG_VOL_TRANSFORM_THREAD_ENDED:
+
+ if (bInPlaceEncNonSys)
+ {
+ // In-place encryption was interrupted/paused (did not finish)
+
+ KillTimer (hwndDlg, TIMER_ID_NONSYS_INPLACE_ENC_PROGRESS);
+
+ UpdateNonSysInPlaceEncControls ();
+ }
+ else
+ {
+ // Format has been aborted (did not finish)
+
+ EnableWindow (GetDlgItem (hCurPage, IDC_QUICKFORMAT), (bDevice || bSparseFileSwitch) && !(bHiddenVol && !bHiddenVolHost));
+ EnableWindow (GetDlgItem (hCurPage, IDC_FILESYS), TRUE);
+ EnableWindow (GetDlgItem (hCurPage, IDC_CLUSTERSIZE), TRUE);
+ EnableWindow (GetDlgItem (hwndDlg, IDC_PREV), TRUE);
+ EnableWindow (GetDlgItem (hwndDlg, IDHELP), TRUE);
+ EnableWindow (GetDlgItem (hwndDlg, IDCANCEL), TRUE);
+ EnableWindow (GetDlgItem (hCurPage, IDC_ABORT_BUTTON), FALSE);
+ EnableWindow (GetDlgItem (hwndDlg, IDC_NEXT), TRUE);
+ SendMessage (GetDlgItem (hCurPage, IDC_PROGRESS_BAR), PBM_SETPOS, 0, 0L);
+ SetFocus (GetDlgItem (hwndDlg, IDC_NEXT));
+ }
+
+ NormalCursor ();
+ return 1;
+
+ case WM_HELP:
+
+ OpenPageHelp (hwndDlg, nCurPageNo);
+ return 1;
+
+ case TC_APPMSG_FORMAT_USER_QUIT:
+
+ if (nCurPageNo == NONSYS_INPLACE_ENC_ENCRYPTION_PAGE
+ && (bVolTransformThreadRunning || bVolTransformThreadToRun || bInPlaceEncNonSysResumed))
+ {
+ // Non-system encryption in progress
+ if (AskNoYes ("NONSYS_INPLACE_ENC_DEFER_CONFIRM") == IDYES)
+ {
+ NonSysInplaceEncPause ();
+
+ EndMainDlg (hwndDlg);
+ return 1;
+ }
+ else
+ return 1; // Disallow close
+ }
+ else if (bVolTransformThreadRunning || bVolTransformThreadToRun)
+ {
+ // Format (non-in-place encryption) in progress
+ if (AskNoYes ("FORMAT_ABORT") == IDYES)
+ {
+ bVolTransformThreadCancel = TRUE;
+
+ EndMainDlg (hwndDlg);
+ return 1;
+ }
+ else
+ return 1; // Disallow close
+ }
+ else if ((nCurPageNo == SYSENC_ENCRYPTION_PAGE || nCurPageNo == SYSENC_PRETEST_RESULT_PAGE)
+ && SystemEncryptionStatus != SYSENC_STATUS_NONE
+ && InstanceHasSysEncMutex ())
+ {
+ // System encryption/decryption in progress
+
+ if (AskYesNo (SystemEncryptionStatus == SYSENC_STATUS_DECRYPTING ?
+ "SYSTEM_DECRYPTION_DEFER_CONFIRM" : "SYSTEM_ENCRYPTION_DEFER_CONFIRM") == IDYES)
+ {
+ if (nCurPageNo == SYSENC_PRETEST_RESULT_PAGE)
+ TextInfoDialogBox (TC_TBXID_SYS_ENC_RESCUE_DISK);
+
+ try
+ {
+ BootEncStatus = BootEncObj->GetStatus();
+
+ if (BootEncStatus.SetupInProgress)
+ {
+ BootEncObj->AbortSetupWait ();
+ Sleep (200);
+ BootEncStatus = BootEncObj->GetStatus();
+ }
+
+ if (!BootEncStatus.SetupInProgress)
+ {
+ EndMainDlg (MainDlg);
+ return 1;
+ }
+ else
+ {
+ Error ("FAILED_TO_INTERRUPT_SYSTEM_ENCRYPTION");
+ return 1; // Disallow close
+ }
+ }
+ catch (Exception &e)
+ {
+ e.Show (hwndDlg);
+ }
+ return 1; // Disallow close
+ }
+ else
+ return 1; // Disallow close
+ }
+ else if (bConfirmQuitSysEncPretest)
+ {
+ if (AskWarnNoYes (bHiddenOS ? "CONFIRM_CANCEL_HIDDEN_OS_CREATION" : "CONFIRM_CANCEL_SYS_ENC_PRETEST") == IDNO)
+ return 1; // Disallow close
+ }
+ else if (bConfirmQuit)
+ {
+ if (AskWarnNoYes ("CONFIRM_EXIT_UNIVERSAL") == IDNO)
+ return 1; // Disallow close
+ }
+
+ if (hiddenVolHostDriveNo > -1)
+ {
+ CloseVolumeExplorerWindows (hwndDlg, hiddenVolHostDriveNo);
+ UnmountVolume (hwndDlg, hiddenVolHostDriveNo, TRUE);
+ }
+
+ EndMainDlg (hwndDlg);
+ return 1;
+
+
+ case WM_COMMAND:
+
+ if (lw == IDHELP)
+ {
+ OpenPageHelp (hwndDlg, nCurPageNo);
+ return 1;
+ }
+ else if (lw == IDCANCEL)
+ {
+ PostMessage (hwndDlg, TC_APPMSG_FORMAT_USER_QUIT, 0, 0);
+ return 1;
+ }
+ else if (lw == IDC_NEXT)
+ {
+ if (nCurPageNo == INTRO_PAGE)
+ {
+ switch (GetSelectedWizardMode (hCurPage))
+ {
+ case WIZARD_MODE_FILE_CONTAINER:
+
+ if (CurrentOSMajor >= 6 && IsUacSupported() && IsAdmin() && !IsBuiltInAdmin() && !IsNonInstallMode())
+ {
+ static bool warningConfirmed = false;
+ if (!warningConfirmed)
+ {
+ if (AskWarnYesNo ("CONTAINER_ADMIN_WARNING") == IDYES)
+ exit (0);
+
+ warningConfirmed = true;
+ }
+ }
+
+ WaitCursor ();
+ CloseSysEncMutex ();
+ ChangeWizardMode (WIZARD_MODE_FILE_CONTAINER);
+ bHiddenOS = FALSE;
+ bInPlaceEncNonSys = FALSE;
+ nNewPageNo = VOLUME_TYPE_PAGE - 1; // Skip irrelevant pages
+ break;
+
+ case WIZARD_MODE_NONSYS_DEVICE:
+
+ WaitCursor ();
+ CloseSysEncMutex ();
+
+ if (!ChangeWizardMode (WIZARD_MODE_NONSYS_DEVICE))
+ {
+ NormalCursor ();
+ return 1;
+ }
+
+ bHiddenOS = FALSE;
+ nNewPageNo = VOLUME_TYPE_PAGE - 1; // Skip irrelevant pages
+ break;
+
+ case WIZARD_MODE_SYS_DEVICE:
+
+ WaitCursor ();
+ bHiddenVol = FALSE;
+ bInPlaceEncNonSys = FALSE;
+ SwitchWizardToSysEncMode ();
+ return 1;
+ }
+ }
+ else if (nCurPageNo == SYSENC_TYPE_PAGE)
+ {
+ if (bHiddenOS)
+ {
+ bWholeSysDrive = FALSE;
+ bHiddenVolDirect = FALSE;
+ }
+
+ if (!bHiddenOS)
+ nNewPageNo = SYSENC_SPAN_PAGE - 1; // Skip irrelevant pages
+ }
+ else if (nCurPageNo == SYSENC_HIDDEN_OS_REQ_CHECK_PAGE)
+ {
+ WaitCursor ();
+ try
+ {
+ BootEncObj->CheckRequirementsHiddenOS ();
+
+ if (CheckGapBetweenSysAndHiddenOS ())
+ Warning ("GAP_BETWEEN_SYS_AND_HIDDEN_OS_PARTITION");
+ }
+ catch (Exception &e)
+ {
+ e.Show (hwndDlg);
+ NormalCursor ();
+ return 1;
+ }
+
+ if (AskWarnYesNo ("DECOY_OS_REINSTALL_WARNING") == IDNO)
+ {
+ NormalCursor ();
+ return 1;
+ }
+
+ WarningDirect ((wstring (GetString ("HIDDEN_OS_WRITE_PROTECTION_BRIEF_INFO"))
+ + L"\n\n"
+ + GetString ("HIDDEN_OS_WRITE_PROTECTION_EXPLANATION")).c_str());
+
+ if (!IsAdmin() && IsUacSupported())
+ {
+ // If UAC elevation is needed, we need to elevate the complete wizard process here, because
+ // we will need to switch to the non-sys-device mode, which requires the whole wizard process
+ // to have admin rights.
+
+ CloseSysEncMutex ();
+
+ if (!ElevateWholeWizardProcess ("/r"))
+ {
+ // Failed to obtain admin rights
+
+ NormalCursor ();
+
+ if (!CreateSysEncMutex ())
+ AbortProcess ("SYSTEM_ENCRYPTION_IN_PROGRESS_ELSEWHERE");
+
+ return 1;
+ }
+ }
+
+ // This check requires admin rights
+ try
+ {
+ BootEncObj->InitialSecurityChecksForHiddenOS ();
+ }
+ catch (Exception &e)
+ {
+ e.Show (hwndDlg);
+ EndMainDlg (MainDlg); // Some of the checks need the wizard to be restarted (results are cached until exit and the checks would fail even if the issues were rectified).
+ return 1;
+ }
+
+ nNewPageNo = SYSENC_MULTI_BOOT_MODE_PAGE - 1; // Skip irrelevant pages
+ }
+ else if (nCurPageNo == SYSENC_SPAN_PAGE)
+ {
+ try
+ {
+ if (bWholeSysDrive && !BootEncObj->SystemPartitionCoversWholeDrive())
+ {
+ if (BootEncObj->SystemDriveContainsNonStandardPartitions())
+ {
+ if (AskWarnYesNoString ((wstring (GetString ("SYSDRIVE_NON_STANDARD_PARTITIONS")) + L"\n\n" + GetString ("ASK_ENCRYPT_PARTITION_INSTEAD_OF_DRIVE")).c_str()) == IDYES)
+ bWholeSysDrive = FALSE;
+ }
+
+ if (!IsOSAtLeast (WIN_VISTA) && bWholeSysDrive)
+ {
+ if (BootEncObj->SystemDriveContainsExtendedPartition())
+ {
+ Error ("WDE_UNSUPPORTED_FOR_EXTENDED_PARTITIONS");
+
+ if (AskYesNo ("ASK_ENCRYPT_PARTITION_INSTEAD_OF_DRIVE") == IDNO)
+ return 1;
+
+ bWholeSysDrive = FALSE;
+ }
+ else
+ Warning ("WDE_EXTENDED_PARTITIONS_WARNING");
+ }
+ }
+
+ if (!bWholeSysDrive && BootEncObj->SystemPartitionCoversWholeDrive())
+ bWholeSysDrive = (AskYesNo ("WHOLE_SYC_DEVICE_RECOM") == IDYES);
+ }
+ catch (Exception &e)
+ {
+ e.Show (hwndDlg);
+ NormalCursor ();
+ return 1;
+ }
+
+ if (!bWholeSysDrive)
+ nNewPageNo = SYSENC_MULTI_BOOT_MODE_PAGE - 1; // Skip irrelevant pages
+ }
+ else if (nCurPageNo == SYSENC_PRE_DRIVE_ANALYSIS_PAGE)
+ {
+ if ((SysEncDetectHiddenSectors = Get2RadButtonPageAnswer()) != 1)
+ {
+ // Skip drive analysis
+ nNewPageNo = SYSENC_DRIVE_ANALYSIS_PAGE;
+
+ // If the user had already searched for hidden sectors, we must clear (invalidate) the
+ // result because now he changed his mind and no longer wishes to encrypt the hidden sectors.
+ try
+ {
+ BootEncObj->InvalidateCachedSysDriveProperties ();
+ }
+ catch (Exception &e)
+ {
+ e.Show (MainDlg);
+ EndMainDlg (MainDlg);
+ exit(0);
+ }
+ }
+ }
+ else if (nCurPageNo == SYSENC_MULTI_BOOT_MODE_PAGE)
+ {
+ if (nMultiBoot > 1)
+ {
+ // Multi-boot
+
+ if (AskWarnNoYes ("MULTI_BOOT_FOR_ADVANCED_ONLY") == IDNO)
+ return 1;
+
+ if (bHiddenOS)
+ {
+ if (AskWarnNoYes ("HIDDEN_OS_MULTI_BOOT") == IDNO)
+ {
+ Error ("UNSUPPORTED_HIDDEN_OS_MULTI_BOOT_CFG");
+ return 1;
+ }
+ }
+ }
+
+ if (bHiddenOS)
+ {
+ if (IsOSAtLeast (WIN_7)
+ && BootEncObj->GetSystemDriveConfiguration().ExtraBootPartitionPresent
+ && AskWarnYesNo ("CONFIRM_HIDDEN_OS_EXTRA_BOOT_PARTITION") == IDNO)
+ {
+ TextInfoDialogBox (TC_TBXID_EXTRA_BOOT_PARTITION_REMOVAL_INSTRUCTIONS);
+ NormalCursor ();
+ return 1;
+ }
+
+ if (AskWarnYesNo ("DECOY_OS_REQUIREMENTS") == IDNO)
+ {
+ NormalCursor ();
+ return 1;
+ }
+
+ if (!ChangeWizardMode (WIZARD_MODE_NONSYS_DEVICE))
+ {
+ NormalCursor ();
+ return 1;
+ }
+
+ // Skip irrelevant pages
+ nNewPageNo = HIDDEN_VOL_HOST_PRE_CIPHER_PAGE - 1;
+ }
+ else if (nMultiBoot <= 1)
+ {
+ // Single-boot (not creating a hidden OS)
+
+ // Skip irrelevant pages
+ nNewPageNo = CIPHER_PAGE - 1;
+ }
+ }
+ else if (nCurPageNo == SYSENC_MULTI_BOOT_SYS_EQ_BOOT_PAGE)
+ {
+ SysEncMultiBootCfg.SystemOnBootDrive = Get2RadButtonPageAnswer ();
+
+ if (!SysEncMultiBootCfg.SystemOnBootDrive)
+ {
+ Error ("SYS_PARTITION_MUST_BE_ON_BOOT_DRIVE");
+ EndMainDlg (MainDlg);
+ return 1;
+ }
+ }
+ else if (nCurPageNo == SYSENC_MULTI_BOOT_NBR_SYS_DRIVES_PAGE)
+ {
+ if (Get2RadButtonPageAnswer () == 0)
+ {
+ // 2 or more drives contain an OS
+
+ SysEncMultiBootCfg.NumberOfSysDrives = 2;
+ }
+ else if (Get2RadButtonPageAnswer () == 1)
+ {
+ // Only 1 drive contains an OS
+
+ SysEncMultiBootCfg.NumberOfSysDrives = 1;
+
+ if (bWholeSysDrive)
+ {
+ // Whole-system-drive encryption is currently not supported if the drive contains
+ // more than one system
+ Error ("WDE_UNSUPPORTED_FOR_MULTIPLE_SYSTEMS_ON_ONE_DRIVE");
+ return 1;
+ }
+
+ // Ask whether there is a non-Windows boot loader in the MBR
+ nNewPageNo = SYSENC_MULTI_BOOT_NONWIN_BOOT_LOADER_PAGE - 1;
+ }
+ }
+ else if (nCurPageNo == SYSENC_MULTI_BOOT_ADJACENT_SYS_PAGE)
+ {
+ SysEncMultiBootCfg.MultipleSystemsOnDrive = Get2RadButtonPageAnswer ();
+
+ if (SysEncMultiBootCfg.MultipleSystemsOnDrive && bWholeSysDrive)
+ {
+ // Whole-system-drive encryption is currently not supported if the drive contains
+ // more than one system
+ Error ("WDE_UNSUPPORTED_FOR_MULTIPLE_SYSTEMS_ON_ONE_DRIVE");
+ return 1;
+ }
+ }
+
+ else if (nCurPageNo == SYSENC_MULTI_BOOT_NONWIN_BOOT_LOADER_PAGE)
+ {
+ SysEncMultiBootCfg.BootLoaderBrand = Get2RadButtonPageAnswer ();
+
+ if (SysEncMultiBootCfg.BootLoaderBrand)
+ {
+ // A non-Windows boot manager in the MBR
+ Error ("CUSTOM_BOOT_MANAGERS_IN_MBR_UNSUPPORTED");
+ EndMainDlg (MainDlg);
+ return 1;
+ }
+ else
+ {
+ // Either a standard Windows boot manager or no boot manager
+ wcscpy_s (SysEncMultiBootCfgOutcome, sizeof(SysEncMultiBootCfgOutcome) / 2, GetString ("WINDOWS_BOOT_LOADER_HINTS"));
+ }
+ }
+
+ else if (nCurPageNo == SYSENC_MULTI_BOOT_OUTCOME_PAGE)
+ {
+ if (bHiddenOS)
+ {
+ if (!ChangeWizardMode (WIZARD_MODE_NONSYS_DEVICE))
+ {
+ NormalCursor ();
+ return 1;
+ }
+
+ nNewPageNo = HIDDEN_VOL_HOST_PRE_CIPHER_PAGE - 1; // Skip irrelevant pages
+ }
+ else
+ nNewPageNo = CIPHER_PAGE - 1; // Skip irrelevant pages
+ }
+
+ else if (nCurPageNo == VOLUME_TYPE_PAGE)
+ {
+ if (IsButtonChecked (GetDlgItem (hCurPage, IDC_HIDDEN_VOL)))
+ {
+ if (!IsAdmin() && !IsUacSupported ()
+ && IDNO == MessageBoxW (hwndDlg, GetString ("ADMIN_PRIVILEGES_WARN_HIDVOL"),
+ lpszTitle, MB_ICONWARNING|MB_YESNO|MB_DEFBUTTON2))
+ {
+ return 1;
+ }
+ else
+ {
+ bHiddenVol = TRUE;
+ bHiddenVolHost = TRUE;
+ bInPlaceEncNonSys = FALSE;
+ }
+ }
+ else
+ {
+ bHiddenVol = FALSE;
+ bHiddenVolHost = FALSE;
+ bHiddenVolDirect = FALSE;
+ nNewPageNo = VOLUME_LOCATION_PAGE - 1; // Skip the hidden volume creation wizard mode selection
+ }
+ }
+
+ else if (nCurPageNo == HIDDEN_VOL_WIZARD_MODE_PAGE)
+ {
+ if (IsButtonChecked (GetDlgItem (hCurPage, IDC_HIDVOL_WIZ_MODE_DIRECT)))
+ bHiddenVolDirect = TRUE;
+ else
+ {
+ if (IsHiddenOSRunning())
+ {
+ WarningDirect ((wstring (GetString ("HIDDEN_VOL_CREATION_UNDER_HIDDEN_OS_HOWTO"))
+ + L"\n\n"
+ + GetString ("NOTE_BEGINNING")
+ + GetString ("HIDDEN_OS_WRITE_PROTECTION_BRIEF_INFO")
+ + L" "
+ + GetString ("HIDDEN_OS_WRITE_PROTECTION_EXPLANATION")).c_str());
+ NormalCursor ();
+ return 1;
+ }
+
+ bHiddenVolDirect = FALSE;
+ }
+ }
+
+ else if (nCurPageNo == VOLUME_LOCATION_PAGE)
+ {
+ BOOL tmpbDevice;
+
+ WaitCursor();
+
+ GetWindowText (GetDlgItem (hCurPage, IDC_COMBO_BOX), szFileName, sizeof (szFileName));
+ RelativePath2Absolute (szFileName);
+ CreateFullVolumePath (szDiskFile, szFileName, &tmpbDevice);
+
+ if (tmpbDevice != bDevice)
+ {
+ if (bDevice)
+ {
+ // Not a valid device path
+ Error ("CANNOT_CALC_SPACE");
+ NormalCursor ();
+ return 1;
+ }
+ else
+ {
+ if (AskWarnYesNo ("DEVICE_SELECTED_IN_NON_DEVICE_MODE") == IDNO)
+ {
+ NormalCursor ();
+ return 1;
+ }
+
+ SwitchWizardToNonSysDeviceMode ();
+ NormalCursor ();
+ return 1;
+ }
+ }
+
+ MoveEditToCombo (GetDlgItem (hCurPage, IDC_COMBO_BOX), bHistory);
+
+ if (IsMountedVolume (szDiskFile))
+ {
+ Error ("ALREADY_MOUNTED");
+ NormalCursor ();
+ return 1;
+ }
+
+ if (bDevice)
+ {
+ switch (IsSystemDevicePath (szDiskFile, hCurPage, TRUE))
+ {
+ case 1:
+ case 2:
+ case 3:
+ if (AskYesNo ("CONFIRM_SYSTEM_ENCRYPTION_MODE") == IDNO)
+ {
+ NormalCursor ();
+ return 1;
+ }
+ szFileName[0] = 0;
+ szDiskFile[0] = 0;
+ SwitchWizardToSysEncMode ();
+ NormalCursor ();
+ return 1;
+
+ case -1:
+ // In some environments (such as PE), the system volume is not located on a hard drive.
+ // Therefore, we must interpret this return code as "Not a system device path" (otherwise,
+ // non-system devices could not be TC-formatted in such environments). Note that this is
+ // rather safe, because bReliableRequired is set to TRUE.
+
+ // NOP
+ break;
+ }
+ }
+ else
+ {
+ if (CheckFileExtension(szFileName)
+ && AskWarnNoYes ("EXE_FILE_EXTENSION_CONFIRM") == IDNO)
+ {
+ NormalCursor ();
+ return 1;
+ }
+ }
+
+ bHistory = !IsButtonChecked (GetDlgItem (hCurPage, IDC_NO_HISTORY));
+
+ SaveSettings (hCurPage);
+
+ if (bHiddenVolDirect && bHiddenVolHost)
+ {
+ nNewPageNo = HIDDEN_VOL_HOST_PASSWORD_PAGE - 1;
+
+ if (bDevice)
+ {
+ if(!QueryFreeSpace (hwndDlg, GetDlgItem (hwndDlg, IDC_SPACE_LEFT), FALSE))
+ {
+ MessageBoxW (hwndDlg, GetString ("CANT_GET_VOLSIZE"), lpszTitle, ICON_HAND);
+ NormalCursor ();
+ return 1;
+ }
+ else
+ nHiddenVolHostSize = nVolumeSize;
+ }
+ else
+ {
+ if (!GetFileVolSize (hwndDlg, &nHiddenVolHostSize))
+ {
+ NormalCursor ();
+ return 1;
+ }
+ else if (IsSparseFile (hwndDlg))
+ {
+ // Hidden volumes must not be created within sparse file containers
+ Warning ("HIDDEN_VOL_HOST_SPARSE");
+ NormalCursor ();
+ return 1;
+ }
+ }
+ }
+ else
+ {
+ if (!bHiddenVol && !bDevice)
+ nNewPageNo = CIPHER_PAGE - 1;
+ else if (bHiddenVol)
+ nNewPageNo = (bHiddenVolHost ? HIDDEN_VOL_HOST_PRE_CIPHER_PAGE : HIDDEN_VOL_PRE_CIPHER_PAGE) - 1;
+ }
+ }
+
+ else if (nCurPageNo == DEVICE_TRANSFORM_MODE_PAGE)
+ {
+ if (bInPlaceEncNonSys)
+ {
+ // Check requirements for non-system in-place encryption
+
+ if (!CheckRequirementsForNonSysInPlaceEnc (szDiskFile, FALSE))
+ {
+ return 1;
+ }
+
+ // We are going to skip the Size page so we must get the size here
+ nVolumeSize = GetDeviceSize (szDiskFile);
+
+ if (nVolumeSize == -1)
+ {
+ handleWin32Error (MainDlg);
+ return 1;
+ }
+
+ if (AskWarnYesNo ("NONSYS_INPLACE_ENC_CONFIRM_BACKUP") == IDNO)
+ return 1;
+ }
+ nNewPageNo = CIPHER_PAGE - 1;
+ }
+
+ else if (nCurPageNo == HIDDEN_VOL_HOST_PRE_CIPHER_PAGE)
+ {
+ if (bHiddenVolHost)
+ nNewPageNo = CIPHER_PAGE - 1; // Skip the info on the hiddem volume
+ }
+
+ else if (nCurPageNo == CIPHER_PAGE)
+ {
+ LPARAM nIndex;
+ nIndex = SendMessage (GetDlgItem (hCurPage, IDC_COMBO_BOX), CB_GETCURSEL, 0, 0);
+ nVolumeEA = SendMessage (GetDlgItem (hCurPage, IDC_COMBO_BOX), CB_GETITEMDATA, nIndex, 0);
+
+ if (SysEncInEffect ()
+ && EAGetCipherCount (nVolumeEA) > 1) // Cascade?
+ {
+ if (AskWarnNoYes ("CONFIRM_CASCADE_FOR_SYS_ENCRYPTION") == IDNO)
+ return 1;
+
+ if (!bHiddenOS)
+ Info ("NOTE_CASCADE_FOR_SYS_ENCRYPTION");
+ }
+
+ nIndex = SendMessage (GetDlgItem (hCurPage, IDC_COMBO_BOX_HASH_ALGO), CB_GETCURSEL, 0, 0);
+ hash_algo = SendMessage (GetDlgItem (hCurPage, IDC_COMBO_BOX_HASH_ALGO), CB_GETITEMDATA, nIndex, 0);
+
+ RandSetHashFunction (hash_algo);
+
+ if (SysEncInEffect () || bInPlaceEncNonSys)
+ nNewPageNo = PASSWORD_PAGE - 1; // Skip irrelevant pages
+ }
+
+ else if (nCurPageNo == SIZE_PAGE)
+ {
+ char szFileSystemNameBuffer[256];
+
+ VerifySizeAndUpdate (hCurPage, TRUE);
+
+ if (!bDevice)
+ {
+ /* Verify that the volume would not be too large for the host file system */
+
+ char root[TC_MAX_PATH];
+
+ if (GetVolumePathName (szDiskFile, root, sizeof (root))
+ && GetVolumeInformation (root, NULL, 0, NULL, NULL, NULL, szFileSystemNameBuffer, sizeof(szFileSystemNameBuffer))
+ && !strncmp (szFileSystemNameBuffer, "FAT32", 5))
+ {
+ // The host file system is FAT32
+ if (nUIVolumeSize * nMultiplier >= 4 * BYTES_PER_GB)
+ {
+ Error ("VOLUME_TOO_LARGE_FOR_FAT32");
+ return 1;
+ }
+ }
+
+ /* Verify that the volume would not be too large for the operating system */
+
+ if (!IsOSAtLeast (WIN_VISTA)
+ && nUIVolumeSize * nMultiplier > 2 * BYTES_PER_TB)
+ {
+ Warning ("VOLUME_TOO_LARGE_FOR_WINXP");
+ }
+ }
+
+ if (bHiddenVol && !bHiddenVolHost) // If it's a hidden volume
+ {
+ /* Ask for confirmation if the hidden volume is too large for the user to be
+ able to write much more data to the outer volume. */
+
+ if (((double) nUIVolumeSize / (nMaximumHiddenVolSize / nMultiplier)) > 0.85) // 85%
+ {
+ if (AskWarnNoYes ("FREE_SPACE_FOR_WRITING_TO_OUTER_VOLUME") == IDNO)
+ return 1;
+ }
+ }
+
+ if (!(bHiddenVolDirect && bHiddenVolHost))
+ nNewPageNo = PASSWORD_PAGE - 1;
+ }
+
+ else if (nCurPageNo == PASSWORD_PAGE)
+ {
+ VerifyPasswordAndUpdate (hwndDlg, GetDlgItem (MainDlg, IDC_NEXT),
+ GetDlgItem (hCurPage, IDC_PASSWORD),
+ GetDlgItem (hCurPage, IDC_VERIFY),
+ volumePassword.Text,
+ szVerify,
+ KeyFilesEnable && FirstKeyFile!=NULL && !SysEncInEffect());
+
+ volumePassword.Length = strlen ((char *) volumePassword.Text);
+
+ if (volumePassword.Length > 0)
+ {
+ // Password character encoding
+ if (!CheckPasswordCharEncoding (GetDlgItem (hCurPage, IDC_PASSWORD), NULL))
+ {
+ Error ("UNSUPPORTED_CHARS_IN_PWD");
+ return 1;
+ }
+ // Check password length (do not check if it's for an outer volume).
+ else if (!bHiddenVolHost
+ && !CheckPasswordLength (hwndDlg, GetDlgItem (hCurPage, IDC_PASSWORD)))
+ {
+ return 1;
+ }
+ }
+
+ // Store the password in case we need to restore it after keyfile is applied to it
+ GetWindowText (GetDlgItem (hCurPage, IDC_PASSWORD), szRawPassword, sizeof (szRawPassword));
+
+ if (!SysEncInEffect ())
+ {
+ if (KeyFilesEnable)
+ {
+ WaitCursor ();
+
+ if (!KeyFilesApply (&volumePassword, FirstKeyFile))
+ {
+ NormalCursor ();
+ return 1;
+ }
+
+ NormalCursor ();
+ }
+
+ }
+ else
+ {
+ KillTimer (hwndDlg, TIMER_ID_KEYB_LAYOUT_GUARD);
+
+ if (bKeyboardLayoutChanged)
+ {
+ // Restore the original keyboard layout
+ if (LoadKeyboardLayout (OrigKeyboardLayout, KLF_ACTIVATE | KLF_SUBSTITUTE_OK) == NULL)
+ Warning ("CANNOT_RESTORE_KEYBOARD_LAYOUT");
+ else
+ bKeyboardLayoutChanged = FALSE;
+ }
+
+ nNewPageNo = SYSENC_COLLECTING_RANDOM_DATA_PAGE - 1; // Skip irrelevant pages
+ }
+
+ if (bInPlaceEncNonSys)
+ {
+ nNewPageNo = NONSYS_INPLACE_ENC_RAND_DATA_PAGE - 1; // Skip irrelevant pages
+ }
+ else if (WizardMode != WIZARD_MODE_SYS_DEVICE
+ && !FileSize4GBLimitQuestionNeeded ()
+ || CreatingHiddenSysVol()) // If we're creating a hidden volume for a hidden OS, we don't need to format it with any filesystem (the entire OS will be copied to the hidden volume sector by sector).
+ {
+ nNewPageNo = FORMAT_PAGE - 1; // Skip irrelevant pages
+ }
+ }
+
+ else if (nCurPageNo == HIDDEN_VOL_HOST_PASSWORD_PAGE
+ || nCurPageNo == NONSYS_INPLACE_ENC_RESUME_PASSWORD_PAGE)
+ {
+ WaitCursor ();
+
+ GetWindowText (GetDlgItem (hCurPage, IDC_PASSWORD_DIRECT), (char *) volumePassword.Text, sizeof (volumePassword.Text));
+ volumePassword.Length = strlen ((char *) volumePassword.Text);
+
+ // Store the password in case we need to restore it after keyfile is applied to it
+ GetWindowText (GetDlgItem (hCurPage, IDC_PASSWORD_DIRECT), szRawPassword, sizeof (szRawPassword));
+
+ if (KeyFilesEnable)
+ {
+ KeyFilesApply (&volumePassword, FirstKeyFile);
+ }
+
+ if (!bInPlaceEncNonSys)
+ {
+
+ /* Mount the volume which is to host the new hidden volume as read only */
+
+ if (hiddenVolHostDriveNo >= 0) // If the hidden volume host is currently mounted (e.g. after previous unsuccessful dismount attempt)
+ {
+ BOOL tmp_result;
+
+ // Dismount the hidden volume host (in order to remount it as read-only subsequently)
+ while (!(tmp_result = UnmountVolume (hwndDlg, hiddenVolHostDriveNo, TRUE)))
+ {
+ if (MessageBoxW (hwndDlg, GetString ("CANT_DISMOUNT_OUTER_VOL"), lpszTitle, MB_RETRYCANCEL) != IDRETRY)
+ {
+ // Cancel
+ NormalCursor();
+ return 1;
+ }
+ }
+ if (tmp_result) // If dismounted
+ hiddenVolHostDriveNo = -1;
+ }
+
+ if (hiddenVolHostDriveNo < 0) // If the hidden volume host is not mounted
+ {
+ int retCode;
+
+ // Mount the hidden volume host as read-only (to ensure consistent and secure
+ // results of the volume bitmap scanning)
+ switch (MountHiddenVolHost (hwndDlg, szDiskFile, &hiddenVolHostDriveNo, &volumePassword, TRUE))
+ {
+ case ERR_NO_FREE_DRIVES:
+ NormalCursor ();
+ MessageBoxW (hwndDlg, GetString ("NO_FREE_DRIVE_FOR_OUTER_VOL"), lpszTitle, ICON_HAND);
+ return 1;
+ case ERR_VOL_MOUNT_FAILED:
+ case ERR_PASSWORD_WRONG:
+ NormalCursor ();
+ return 1;
+ case 0:
+
+ /* Hidden volume host successfully mounted as read-only */
+
+ WaitCursor ();
+
+ // Verify that the outer volume contains a suitable file system, retrieve cluster size, and
+ // scan the volume bitmap
+ if (!IsAdmin () && IsUacSupported ())
+ retCode = UacAnalyzeHiddenVolumeHost (hwndDlg, &hiddenVolHostDriveNo, GetVolumeDataAreaSize (FALSE, nHiddenVolHostSize), &realClusterSize, &nbrFreeClusters);
+ else
+ retCode = AnalyzeHiddenVolumeHost (hwndDlg, &hiddenVolHostDriveNo, GetVolumeDataAreaSize (FALSE, nHiddenVolHostSize), &realClusterSize, &nbrFreeClusters);
+
+ switch (retCode)
+ {
+ case -1: // Fatal error
+ CloseVolumeExplorerWindows (hwndDlg, hiddenVolHostDriveNo);
+
+ if (UnmountVolume (hwndDlg, hiddenVolHostDriveNo, TRUE))
+ hiddenVolHostDriveNo = -1;
+
+ AbortProcessSilent ();
+ break;
+
+ case 0: // Unsupported file system (or other non-fatal error which has already been reported)
+ if (bHiddenVolDirect)
+ {
+ CloseVolumeExplorerWindows (hwndDlg, hiddenVolHostDriveNo);
+
+ if (UnmountVolume (hwndDlg, hiddenVolHostDriveNo, TRUE))
+ hiddenVolHostDriveNo = -1;
+ }
+ NormalCursor ();
+ return 1;
+
+ case 1:
+
+ // Determine the maximum possible size of the hidden volume
+ if (DetermineMaxHiddenVolSize (hwndDlg) < 1)
+ {
+ // Non-fatal error while determining maximum possible size of the hidden volume
+ NormalCursor();
+ return 1;
+ }
+ else
+ {
+ BOOL tmp_result;
+
+ /* Maximum possible size of the hidden volume successfully determined */
+
+ // Dismount the hidden volume host
+ while (!(tmp_result = UnmountVolume (hwndDlg, hiddenVolHostDriveNo, TRUE)))
+ {
+ if (MessageBoxW (hwndDlg, GetString ("CANT_DISMOUNT_OUTER_VOL"), lpszTitle, MB_RETRYCANCEL) != IDRETRY)
+ {
+ // Cancel
+ NormalCursor();
+ return 1;
+ }
+ }
+
+ if (tmp_result) // If dismounted
+ {
+ hiddenVolHostDriveNo = -1;
+
+ bHiddenVolHost = FALSE;
+ bHiddenVolFinished = FALSE;
+
+ // Clear the outer volume password
+ WipePasswordsAndKeyfiles ();
+
+ RestoreDefaultKeyFilesParam ();
+
+ EnableWindow (GetDlgItem (MainDlg, IDC_NEXT), TRUE);
+ NormalCursor ();
+
+ nNewPageNo = HIDDEN_VOL_HOST_PRE_CIPHER_PAGE;
+ }
+ }
+ break;
+ }
+ break;
+ }
+ }
+ }
+ else
+ {
+ /* Scan all available partitions to discover all partitions where non-system in-place
+ encryption has been interrupted. */
+
+ BOOL tmpbDevice;
+ DeferredNonSysInPlaceEncDevices.clear();
+
+ foreach (const HostDevice &device, GetAvailableHostDevices (true, true))
+ {
+ if (device.IsPartition || device.DynamicVolume)
+ {
+ OpenVolumeContext volume;
+
+ if (OpenVolume (&volume, device.Path.c_str(), &volumePassword, FALSE, FALSE, TRUE) == ERR_SUCCESS)
+ {
+ if ((volume.CryptoInfo->HeaderFlags & TC_HEADER_FLAG_NONSYS_INPLACE_ENC) != 0
+ && volume.CryptoInfo->EncryptedAreaLength.Value != volume.CryptoInfo->VolumeSize.Value)
+ {
+ DeferredNonSysInPlaceEncDevices.push_back (device);
+ }
+
+ CloseVolume (&volume);
+ }
+ }
+ }
+
+ if (DeferredNonSysInPlaceEncDevices.empty())
+ {
+ Warning ("FOUND_NO_PARTITION_W_DEFERRED_INPLACE_ENC");
+
+ NormalCursor();
+ return 1;
+ }
+ else if (DeferredNonSysInPlaceEncDevices.size() == 1)
+ {
+ CreateFullVolumePath (szDiskFile, DeferredNonSysInPlaceEncDevices.front().Path.c_str(), &tmpbDevice);
+
+ nVolumeSize = GetDeviceSize (szDiskFile);
+ if (nVolumeSize == -1)
+ {
+ handleWin32Error (MainDlg);
+ NormalCursor();
+ return 1;
+ }
+
+ nNewPageNo = NONSYS_INPLACE_ENC_ENCRYPTION_PAGE - 1; // Skip irrelevant pages
+ }
+
+ NormalCursor();
+ }
+
+ }
+
+ else if (nCurPageNo == FILESYS_PAGE)
+ {
+ if (!bHiddenVol && IsHiddenOSRunning() && Get2RadButtonPageAnswer() == 1)
+ {
+ // The user wants to store files larger than 4GB on the non-hidden volume about to be created and a hidden OS is running
+
+ WarningDirect ((wstring (GetString ("CANNOT_SATISFY_OVER_4G_FILE_SIZE_REQ"))
+ + L" "
+ + GetString ("CANNOT_CREATE_NON_HIDDEN_NTFS_VOLUMES_UNDER_HIDDEN_OS")
+ + L"\n\n"
+ + GetString ("NOTE_BEGINNING")
+ + GetString ("HIDDEN_OS_WRITE_PROTECTION_BRIEF_INFO")
+ + L" "
+ + GetString ("HIDDEN_OS_WRITE_PROTECTION_EXPLANATION")).c_str());
+
+ return 1;
+ }
+
+ if (nNeedToStoreFilesOver4GB != Get2RadButtonPageAnswer())
+ fileSystem = FILESYS_NONE; // The user may have gone back and changed the answer, so default file system must be reselected
+
+ nNeedToStoreFilesOver4GB = Get2RadButtonPageAnswer();
+
+ nNewPageNo = FORMAT_PAGE - 1; // Skip irrelevant pages
+ }
+
+ else if (nCurPageNo == SYSENC_COLLECTING_RANDOM_DATA_PAGE
+ || nCurPageNo == NONSYS_INPLACE_ENC_RAND_DATA_PAGE)
+ {
+ char tmp[RANDPOOL_DISPLAY_SIZE+1];
+
+ if (!bInPlaceEncNonSys)
+ {
+ /* Generate master key and other related data (except the rescue disk) for system encryption. */
+
+ try
+ {
+ WaitCursor();
+ BootEncObj->PrepareInstallation (!bWholeSysDrive, volumePassword, nVolumeEA, FIRST_MODE_OF_OPERATION_ID, hash_algo, "");
+ }
+ catch (Exception &e)
+ {
+ e.Show (hwndDlg);
+ NormalCursor ();
+ return 1;
+ }
+ }
+
+ KillTimer (hwndDlg, TIMER_ID_RANDVIEW);
+
+ // Attempt to wipe the GUI field showing portions of randpool
+ memset (tmp, 'X', sizeof(tmp));
+ tmp [sizeof(tmp)-1] = 0;
+ SetWindowText (hRandPoolSys, tmp);
+
+ NormalCursor ();
+ }
+
+ else if (nCurPageNo == SYSENC_KEYS_GEN_PAGE)
+ {
+ char tmp[KEY_GUI_VIEW_SIZE+1];
+
+ // Attempt to wipe the GUI fields showing portions of the master and header keys
+ memset (tmp, 'X', sizeof(tmp));
+ tmp [sizeof(tmp)-1] = 0;
+ SetWindowText (hMasterKey, tmp);
+ SetWindowText (hHeaderKey, tmp);
+ }
+
+ else if (nCurPageNo == SYSENC_RESCUE_DISK_CREATION_PAGE)
+ {
+ /* Generate rescue disk for boot encryption */
+
+ GetWindowText (GetDlgItem (hCurPage, IDC_RESCUE_DISK_ISO_PATH), szRescueDiskISO, sizeof (szRescueDiskISO));
+
+ try
+ {
+ WaitCursor();
+ BootEncObj->CreateRescueIsoImage (true, szRescueDiskISO);
+
+ }
+ catch (Exception &e)
+ {
+ e.Show (hwndDlg);
+ NormalCursor ();
+ return 1;
+ }
+
+retryCDDriveCheck:
+ if (!bDontVerifyRescueDisk && !BootEncObj->IsCDDrivePresent())
+ {
+ char *multiChoiceStr[] = { 0, "CD_BURNER_NOT_PRESENT",
+ "CD_BURNER_NOT_PRESENT_WILL_STORE_ISO",
+ "CD_BURNER_NOT_PRESENT_WILL_CONNECT_LATER",
+ "CD_BURNER_NOT_PRESENT_CONNECTED_NOW",
+ 0 };
+
+ switch (AskMultiChoice ((void **) multiChoiceStr, FALSE))
+ {
+ case 1:
+ wchar_t msg[8192];
+ swprintf_s (msg, array_capacity (msg), GetString ("CD_BURNER_NOT_PRESENT_WILL_STORE_ISO_INFO"), SingleStringToWide (szRescueDiskISO).c_str());
+ WarningDirect (msg);
+
+ Warning ("RESCUE_DISK_BURN_NO_CHECK_WARN");
+ bDontVerifyRescueDisk = TRUE;
+ nNewPageNo = SYSENC_RESCUE_DISK_VERIFIED_PAGE;
+ break;
+
+ case 2:
+ AbortProcessSilent();
+
+ case 3:
+ break;
+
+ default:
+ goto retryCDDriveCheck;
+ }
+ }
+
+ if (IsWindowsIsoBurnerAvailable() && !bDontVerifyRescueDisk)
+ Info ("RESCUE_DISK_WIN_ISOBURN_PRELAUNCH_NOTE");
+
+ NormalCursor ();
+ }
+
+ else if (nCurPageNo == SYSENC_RESCUE_DISK_BURN_PAGE)
+ {
+ if (!bDontVerifyRescueDisk)
+ {
+ /* Verify that the rescue disk has been written correctly */
+
+ try
+ {
+ WaitCursor();
+ if (!BootEncObj->VerifyRescueDisk ())
+ {
+ wchar_t szTmp[8000];
+
+ swprintf (szTmp, GetString ("RESCUE_DISK_CHECK_FAILED"),
+ IsWindowsIsoBurnerAvailable () ? L"" : GetString ("RESCUE_DISK_CHECK_FAILED_SENTENCE_APPENDIX"));
+
+ ErrorDirect (szTmp);
+
+ NormalCursor ();
+#ifndef _DEBUG
+ return 1;
+#endif
+ }
+ }
+ catch (Exception &e)
+ {
+ e.Show (hwndDlg);
+ NormalCursor ();
+ return 1;
+ }
+ NormalCursor ();
+ }
+ else
+ {
+ Warning ("RESCUE_DISK_BURN_NO_CHECK_WARN");
+ nNewPageNo = SYSENC_RESCUE_DISK_VERIFIED_PAGE; // Skip irrelevant pages
+ }
+ }
+
+ else if (nCurPageNo == SYSENC_WIPE_MODE_PAGE
+ || nCurPageNo == NONSYS_INPLACE_ENC_WIPE_MODE_PAGE)
+ {
+ if (nWipeMode > 0
+ && AskWarnYesNo ("WIPE_MODE_WARN") == IDNO)
+ return 1;
+ }
+
+ else if (nCurPageNo == SYSENC_PRETEST_INFO_PAGE)
+ {
+ if (LocalizationActive
+ && AskWarnYesNo ("PREBOOT_NOT_LOCALIZED") == IDNO)
+ return 1;
+
+ bConfirmQuitSysEncPretest = TRUE;
+
+ if (!bHiddenOS) // This text is not tailored to hidden OS
+ TextInfoDialogBox (TC_TBXID_SYS_ENCRYPTION_PRETEST);
+
+ if (AskWarnYesNo ("CONFIRM_RESTART") == IDNO)
+ return 1;
+
+ /* Install the pre-boot authentication component and initiate the system encryption pretest.
+ If we are creating a hidden OS, pretest is omitted and OS cloning will follow. */
+
+ try
+ {
+ WaitCursor();
+
+#if 0
+ // Make sure the Rescue Disk is not in the drive
+ while (BootEncObj->VerifyRescueDisk ())
+ {
+ Error ("REMOVE_RESCUE_DISK_FROM_DRIVE");
+ }
+#endif
+
+ BootEncObj->Install (bHiddenOS ? true : false);
+ }
+ catch (Exception &e)
+ {
+ e.Show (hwndDlg);
+ Error (bHiddenOS ? "CANNOT_INITIATE_HIDDEN_OS_CREATION" : "CANNOT_INITIATE_SYS_ENCRYPTION_PRETEST");
+ NormalCursor ();
+ return 1;
+ }
+
+
+ /* Add the main TrueCrypt app to the system startup sequence (the TrueCrypt Background Task), which
+ we need e.g. for notifications about prevented hibernation, about hidden OS leak protection, about
+ inconsistent hidden OS installs (TrueCrypt upgraded in the decoy system but not in the hidden one), etc.
+ Note that this must be done before calling ChangeSystemEncryptionStatus(), which broadcasts the change,
+ so that the main app (if it's running with different cached settings) will not overwrite our new
+ settings when it exits. */
+ bStartOnLogon = TRUE;
+ SaveSettings (NULL);
+ ManageStartupSeq ();
+
+
+ if (bHiddenOS)
+ {
+ /* When we are going to create a hidden OS, the system encryption status is set
+ to SYSENC_STATUS_PRETEST (not to any special hidden-OS status), in case the XML
+ configuration file and its properties somehow leaks somewhere outside the system
+ partition (which will be wiped later on) indicating that a hidden OS has been created
+ on the computer. Instead, we update our raw config flags in the master boot record
+ (which is also altered when our boot loader is installed). */
+
+ if (!ChangeSystemEncryptionStatus (SYSENC_STATUS_PRETEST)
+ || !ChangeHiddenOSCreationPhase (TC_HIDDEN_OS_CREATION_PHASE_CLONING))
+ {
+ ChangeSystemEncryptionStatus (SYSENC_STATUS_NONE);
+ Error ("CANNOT_INITIATE_HIDDEN_OS_CREATION");
+ NormalCursor ();
+ return 1;
+ }
+ }
+ else if (!ChangeSystemEncryptionStatus (SYSENC_STATUS_PRETEST))
+ {
+ Error ("CANNOT_INITIATE_SYS_ENCRYPTION_PRETEST");
+ NormalCursor ();
+ return 1;
+ }
+
+ // Add the wizard to the system startup sequence
+ ManageStartupSeqWiz (FALSE, "/acsysenc");
+
+ EndMainDlg (MainDlg);
+
+ try
+ {
+ BootEncObj->RestartComputer ();
+ }
+ catch (Exception &e)
+ {
+ e.Show (hwndDlg);
+ }
+
+ return 1;
+ }
+
+ else if (nCurPageNo == SYSENC_PRETEST_RESULT_PAGE)
+ {
+ TextInfoDialogBox (TC_TBXID_SYS_ENC_RESCUE_DISK);
+
+ // Begin the actual encryption process
+
+ ChangeSystemEncryptionStatus (SYSENC_STATUS_ENCRYPTING);
+ }
+
+ else if (nCurPageNo == SYSENC_ENCRYPTION_PAGE
+ && CreateSysEncMutex ())
+ {
+ // The 'Next' button functions as Finish or Resume
+
+ if (SystemEncryptionStatus != SYSENC_STATUS_NONE)
+ {
+ try
+ {
+ // Resume
+ SysEncResume ();
+ }
+ catch (Exception &e)
+ {
+ e.Show (hwndDlg);
+ }
+ }
+ else
+ {
+ // Finish
+ PostMessage (hwndDlg, TC_APPMSG_FORMAT_USER_QUIT, 0, 0);
+ }
+
+ return 1;
+ }
+ else if (nCurPageNo == NONSYS_INPLACE_ENC_RESUME_PARTITION_SEL_PAGE)
+ {
+ nNewPageNo = NONSYS_INPLACE_ENC_ENCRYPTION_PAGE - 1; // Skip irrelevant pages
+ }
+ else if (nCurPageNo == NONSYS_INPLACE_ENC_ENCRYPTION_PAGE)
+ {
+ /* In-place encryption start (the 'Next' button has been clicked) */
+
+ NonSysInplaceEncResume ();
+ return 1;
+ }
+ else if (nCurPageNo == NONSYS_INPLACE_ENC_ENCRYPTION_FINISHED_PAGE)
+ {
+ PostMessage (hwndDlg, TC_APPMSG_FORMAT_USER_QUIT, 0, 0);
+ return 1;
+ }
+ else if (nCurPageNo == FORMAT_PAGE)
+ {
+ /* Format start (the 'Next' button has been clicked on the Format page) */
+
+ if (bVolTransformThreadRunning || bVolTransformThreadToRun)
+ return 1;
+
+ bVolTransformThreadCancel = FALSE;
+
+ bVolTransformThreadToRun = TRUE;
+
+ fileSystem = SendMessage (GetDlgItem (hCurPage, IDC_FILESYS), CB_GETITEMDATA,
+ SendMessage (GetDlgItem (hCurPage, IDC_FILESYS), CB_GETCURSEL, 0, 0) , 0);
+
+ clusterSize = SendMessage (GetDlgItem (hCurPage, IDC_CLUSTERSIZE), CB_GETITEMDATA,
+ SendMessage (GetDlgItem (hCurPage, IDC_CLUSTERSIZE), CB_GETCURSEL, 0, 0) , 0);
+
+ quickFormat = IsButtonChecked (GetDlgItem (hCurPage, IDC_QUICKFORMAT));
+
+
+ if (!bHiddenVol && IsHiddenOSRunning())
+ {
+ // Creating a non-hidden volume under a hidden OS
+
+ if (fileSystem == FILESYS_NTFS)
+ {
+ WarningDirect ((wstring (GetString ("CANNOT_CREATE_NON_HIDDEN_NTFS_VOLUMES_UNDER_HIDDEN_OS"))
+ + L"\n\n"
+ + GetString ("NOTE_BEGINNING")
+ + GetString ("HIDDEN_OS_WRITE_PROTECTION_BRIEF_INFO")
+ + L" "
+ + GetString ("HIDDEN_OS_WRITE_PROTECTION_EXPLANATION")).c_str());
+
+ if (GetVolumeDataAreaSize (FALSE, nVolumeSize) <= TC_MAX_FAT_SECTOR_COUNT * GetFormatSectorSize()
+ && AskYesNo("OFFER_FAT_FORMAT_ALTERNATIVE") == IDYES)
+ {
+ fileSystem = FILESYS_FAT;
+ SelectAlgo (GetDlgItem (hCurPage, IDC_FILESYS), (int *) &fileSystem);
+ }
+ else
+ {
+ if (GetVolumeDataAreaSize (FALSE, nVolumeSize) > TC_MAX_FAT_SECTOR_COUNT * GetFormatSectorSize())
+ Info ("FAT_NOT_AVAILABLE_FOR_SO_LARGE_VOLUME");
+
+ bVolTransformThreadToRun = FALSE;
+ return 1;
+ }
+ }
+ }
+
+ if (bHiddenVolHost)
+ {
+ hiddenVolHostDriveNo = -1;
+ nMaximumHiddenVolSize = 0;
+
+ if (fileSystem == FILESYS_NTFS)
+ {
+ if (bHiddenOS
+ && (double) nVolumeSize / GetSystemPartitionSize() < MIN_HIDDENOS_DECOY_PARTITION_SIZE_RATIO_NTFS)
+ {
+ Error("OUTER_VOLUME_TOO_SMALL_FOR_HIDDEN_OS_NTFS");
+
+ if (GetVolumeDataAreaSize (FALSE, nVolumeSize) <= TC_MAX_FAT_SECTOR_COUNT * GetFormatSectorSize()
+ && AskYesNo("OFFER_FAT_FORMAT_ALTERNATIVE") == IDYES)
+ {
+ fileSystem = FILESYS_FAT;
+ SelectAlgo (GetDlgItem (hCurPage, IDC_FILESYS), (int *) &fileSystem);
+ }
+ else
+ {
+ if (GetVolumeDataAreaSize (FALSE, nVolumeSize) > TC_MAX_FAT_SECTOR_COUNT * GetFormatSectorSize())
+ Info ("FAT_NOT_AVAILABLE_FOR_SO_LARGE_VOLUME");
+
+ bVolTransformThreadToRun = FALSE;
+ return 1;
+ }
+ }
+
+ if (fileSystem == FILESYS_NTFS) // The file system may have been changed in the previous block
+ {
+ if (nCurrentOS == WIN_2000)
+ {
+ Error("HIDDEN_VOL_HOST_UNSUPPORTED_FILESYS_WIN2000");
+ bVolTransformThreadToRun = FALSE;
+ return 1;
+ }
+ else if (GetVolumeDataAreaSize (FALSE, nVolumeSize) <= TC_MAX_FAT_SECTOR_COUNT * GetFormatSectorSize()
+ && AskYesNo("HIDDEN_VOL_HOST_NTFS_ASK") == IDNO)
+ {
+ bVolTransformThreadToRun = FALSE;
+ return 1;
+ }
+ }
+ }
+ }
+ else if (bHiddenVol)
+ {
+ // Hidden volume is always quick-formatted (if, however, the meaning of quickFormat is
+ // whether to create a sparse file, it must be set to FALSE).
+ quickFormat = !bSparseFileSwitch;
+ }
+
+
+ if (fileSystem == FILESYS_FAT
+ && nNeedToStoreFilesOver4GB == 1
+ && AskWarnNoYes("CONFIRM_FAT_FOR_FILES_OVER_4GB") == IDNO)
+ {
+ bVolTransformThreadToRun = FALSE;
+ return 1;
+ }
+
+ EnableWindow (GetDlgItem (hwndDlg, IDC_PREV), FALSE);
+ EnableWindow (GetDlgItem (hwndDlg, IDC_NEXT), FALSE);
+ EnableWindow (GetDlgItem (hwndDlg, IDHELP), FALSE);
+ EnableWindow (GetDlgItem (hwndDlg, IDCANCEL), FALSE);
+ EnableWindow (GetDlgItem (hCurPage, IDC_QUICKFORMAT), FALSE);
+ EnableWindow (GetDlgItem (hCurPage, IDC_CLUSTERSIZE), FALSE);
+ EnableWindow (GetDlgItem (hCurPage, IDC_FILESYS), FALSE);
+ EnableWindow (GetDlgItem (hCurPage, IDC_ABORT_BUTTON), TRUE);
+ SetFocus (GetDlgItem (hCurPage, IDC_ABORT_BUTTON));
+
+ // Increase cluster size if it's too small for this volume size (causes size of
+ // free space to be 0). Note that the below constant 0x2000000 is based on
+ // results of tests performed under Windows XP.
+ if (fileSystem == FILESYS_FAT && clusterSize > 0)
+ {
+ BOOL fixed = FALSE;
+ while (clusterSize < 128
+ && nVolumeSize / (clusterSize * GetFormatSectorSize()) > 0x2000000)
+ {
+ clusterSize *= 2;
+ fixed = TRUE;
+ }
+ if (fixed)
+ MessageBoxW (hwndDlg, GetString ("CLUSTER_TOO_SMALL"), lpszTitle, MB_ICONWARNING);
+ }
+
+ LastDialogId = "FORMAT_IN_PROGRESS";
+ ArrowWaitCursor ();
+ _beginthread (volTransformThreadFunction, 0, MainDlg);
+
+ return 1;
+ }
+
+ else if (nCurPageNo == FORMAT_FINISHED_PAGE)
+ {
+ if (!bHiddenVol || bHiddenVolFinished)
+ {
+ /* Wizard loop restart */
+
+ if (bHiddenOS)
+ {
+ if (!ChangeWizardMode (WIZARD_MODE_SYS_DEVICE))
+ return 1;
+
+ // Hidden volume for hidden OS has been created. Now we will prepare our boot loader
+ // that will handle the OS cloning.
+ try
+ {
+ WaitCursor();
+
+ BootEncObj->PrepareHiddenOSCreation (nVolumeEA, FIRST_MODE_OF_OPERATION_ID, hash_algo);
+ }
+ catch (Exception &e)
+ {
+ e.Show (MainDlg);
+ NormalCursor();
+ return 1;
+ }
+
+ bHiddenVol = FALSE;
+
+ LoadPage (hwndDlg, SYSENC_PRETEST_INFO_PAGE);
+ }
+ else
+ LoadPage (hwndDlg, INTRO_PAGE);
+
+ SetWindowTextW (GetDlgItem (MainDlg, IDCANCEL), GetString ("CANCEL"));
+ bHiddenVolFinished = FALSE;
+ WipePasswordsAndKeyfiles ();
+
+ return 1;
+ }
+ else
+ {
+ /* We're going to scan the bitmap of the hidden volume host (in the non-Direct hidden volume wizard mode) */
+ int retCode;
+ WaitCursor ();
+
+ if (hiddenVolHostDriveNo != -1) // If the hidden volume host is mounted
+ {
+ BOOL tmp_result;
+
+ // Dismount the hidden volume host (in order to remount it as read-only subsequently)
+ CloseVolumeExplorerWindows (hwndDlg, hiddenVolHostDriveNo);
+ while (!(tmp_result = UnmountVolume (hwndDlg, hiddenVolHostDriveNo, TRUE)))
+ {
+ if (MessageBoxW (hwndDlg, GetString ("CANT_DISMOUNT_OUTER_VOL"), lpszTitle, MB_RETRYCANCEL | MB_ICONERROR | MB_SETFOREGROUND) != IDRETRY)
+ {
+ // Cancel
+ NormalCursor();
+ return 1;
+ }
+ }
+ if (tmp_result) // If dismounted
+ hiddenVolHostDriveNo = -1;
+ }
+
+ if (hiddenVolHostDriveNo < 0) // If the hidden volume host is not mounted
+ {
+ // Remount the hidden volume host as read-only (to ensure consistent and secure
+ // results of the volume bitmap scanning)
+ switch (MountHiddenVolHost (hwndDlg, szDiskFile, &hiddenVolHostDriveNo, &volumePassword, TRUE))
+ {
+ case ERR_NO_FREE_DRIVES:
+ MessageBoxW (hwndDlg, GetString ("NO_FREE_DRIVE_FOR_OUTER_VOL"), lpszTitle, ICON_HAND);
+ NormalCursor ();
+ return 1;
+
+ case ERR_VOL_MOUNT_FAILED:
+ case ERR_PASSWORD_WRONG:
+ NormalCursor ();
+ return 1;
+
+ case 0:
+
+ /* Hidden volume host successfully mounted as read-only */
+
+ // Verify that the outer volume contains a suitable file system, retrieve cluster size, and
+ // scan the volume bitmap
+ if (!IsAdmin () && IsUacSupported ())
+ retCode = UacAnalyzeHiddenVolumeHost (hwndDlg, &hiddenVolHostDriveNo, GetVolumeDataAreaSize (FALSE, nHiddenVolHostSize), &realClusterSize, &nbrFreeClusters);
+ else
+ retCode = AnalyzeHiddenVolumeHost (hwndDlg, &hiddenVolHostDriveNo, GetVolumeDataAreaSize (FALSE, nHiddenVolHostSize), &realClusterSize, &nbrFreeClusters);
+
+ switch (retCode)
+ {
+ case -1: // Fatal error
+ CloseVolumeExplorerWindows (hwndDlg, hiddenVolHostDriveNo);
+
+ if (UnmountVolume (hwndDlg, hiddenVolHostDriveNo, TRUE))
+ hiddenVolHostDriveNo = -1;
+
+ AbortProcessSilent ();
+ break;
+
+ case 0: // Unsupported file system (or other non-fatal error which has already been reported)
+ NormalCursor ();
+ return 1;
+
+ case 1: // Success
+ {
+ BOOL tmp_result;
+
+ // Determine the maximum possible size of the hidden volume
+ if (DetermineMaxHiddenVolSize (hwndDlg) < 1)
+ {
+ NormalCursor ();
+ goto ovf_end;
+ }
+
+ /* Maximum possible size of the hidden volume successfully determined */
+
+ // Dismount the hidden volume host
+ while (!(tmp_result = UnmountVolume (hwndDlg, hiddenVolHostDriveNo, TRUE)))
+ {
+ if (MessageBoxW (hwndDlg, GetString ("CANT_DISMOUNT_OUTER_VOL"), lpszTitle, MB_RETRYCANCEL) != IDRETRY)
+ {
+ // Cancel
+ NormalCursor ();
+ goto ovf_end;
+ }
+ }
+
+ // Prevent having to recreate the outer volume due to inadvertent exit
+ bConfirmQuit = TRUE;
+
+ hiddenVolHostDriveNo = -1;
+
+ nNewPageNo = HIDDEN_VOL_HOST_PRE_CIPHER_PAGE;
+
+ // Clear the outer volume password
+ WipePasswordsAndKeyfiles ();
+
+ EnableWindow (GetDlgItem (MainDlg, IDC_NEXT), TRUE);
+ NormalCursor ();
+
+ }
+ break;
+ }
+ break;
+ }
+ }
+ }
+ }
+
+ else if (nCurPageNo == DEVICE_WIPE_PAGE)
+ {
+ if (AskWarnOkCancel (bHiddenOS && IsHiddenOSRunning() ? "CONFIRM_WIPE_START_DECOY_SYS_PARTITION" : "CONFIRM_WIPE_START") == IDOK)
+ {
+ WipeStart ();
+ ArrowWaitCursor();
+ }
+ return 1;
+ }
+
+ LoadPage (hwndDlg, nNewPageNo + 1);
+ovf_end:
+ return 1;
+ }
+ else if (lw == IDC_PREV)
+ {
+ if (nCurPageNo == SYSENC_SPAN_PAGE)
+ {
+ // Skip irrelevant pages when going back
+ if (!bHiddenOS)
+ nNewPageNo = SYSENC_TYPE_PAGE + 1;
+ }
+ if (nCurPageNo == SYSENC_MULTI_BOOT_MODE_PAGE)
+ {
+ // Skip the drive analysis page(s) or other irrelevant pages when going back
+ if (bHiddenOS)
+ nNewPageNo = SYSENC_HIDDEN_OS_REQ_CHECK_PAGE + 1;
+ else if (bWholeSysDrive)
+ nNewPageNo = SYSENC_PRE_DRIVE_ANALYSIS_PAGE + 1;
+ else
+ nNewPageNo = SYSENC_SPAN_PAGE + 1;
+ }
+ else if (nCurPageNo == SYSENC_MULTI_BOOT_NONWIN_BOOT_LOADER_PAGE)
+ {
+ if (SysEncMultiBootCfg.NumberOfSysDrives == 1)
+ {
+ // We can skip SYSENC_MULTI_BOOT_ADJACENT_SYS_PAGE (it is implied that there are multiple systems on the drive)
+ nNewPageNo = SYSENC_MULTI_BOOT_NBR_SYS_DRIVES_PAGE + 1;
+ }
+ }
+ else if (nCurPageNo == HIDDEN_VOL_HOST_PRE_CIPHER_PAGE)
+ {
+ if (bHiddenOS)
+ {
+ if (!ChangeWizardMode (WIZARD_MODE_SYS_DEVICE))
+ {
+ NormalCursor ();
+ return 1;
+ }
+
+ // Skip irrelevant pages.
+ // Note that we're ignoring nMultiBoot here, as the multi-boot question pages are skipped
+ // when creating a hidden OS (only a single message box is displayed with requirements).
+ nNewPageNo = SYSENC_MULTI_BOOT_MODE_PAGE + 1;
+ }
+ else
+ {
+ nNewPageNo = VOLUME_LOCATION_PAGE + 1;
+ }
+ }
+ else if (nCurPageNo == HIDDEN_VOL_WIZARD_MODE_PAGE)
+ {
+ if (IsButtonChecked (GetDlgItem (hCurPage, IDC_HIDVOL_WIZ_MODE_DIRECT)))
+ bHiddenVolDirect = TRUE;
+ else
+ bHiddenVolDirect = FALSE;
+ }
+ else if (nCurPageNo == VOLUME_TYPE_PAGE)
+ {
+ if (WizardMode != WIZARD_MODE_SYS_DEVICE)
+ nNewPageNo = INTRO_PAGE + 1; // Skip irrelevant pages
+ }
+ else if (nCurPageNo == VOLUME_LOCATION_PAGE)
+ {
+ BOOL tmpbDevice;
+
+ GetWindowText (GetDlgItem (hCurPage, IDC_COMBO_BOX), szFileName, sizeof (szFileName));
+ CreateFullVolumePath (szDiskFile, szFileName, &tmpbDevice);
+
+ if (tmpbDevice == bDevice)
+ {
+ MoveEditToCombo (GetDlgItem (hCurPage, IDC_COMBO_BOX), bHistory);
+ SaveSettings (hCurPage);
+ }
+
+ if (!bHiddenVol)
+ nNewPageNo = VOLUME_TYPE_PAGE + 1; // Skip the hidden volume creation wizard mode selection
+ }
+
+ else if (nCurPageNo == CIPHER_PAGE)
+ {
+ LPARAM nIndex;
+ nIndex = SendMessage (GetDlgItem (hCurPage, IDC_COMBO_BOX), CB_GETCURSEL, 0, 0);
+ nVolumeEA = SendMessage (GetDlgItem (hCurPage, IDC_COMBO_BOX), CB_GETITEMDATA, nIndex, 0);
+
+ nIndex = SendMessage (GetDlgItem (hCurPage, IDC_COMBO_BOX_HASH_ALGO), CB_GETCURSEL, 0, 0);
+ hash_algo = SendMessage (GetDlgItem (hCurPage, IDC_COMBO_BOX_HASH_ALGO), CB_GETITEMDATA, nIndex, 0);
+
+ RandSetHashFunction (hash_algo);
+
+ if (WizardMode == WIZARD_MODE_SYS_DEVICE)
+ {
+ if (nMultiBoot > 1)
+ nNewPageNo = SYSENC_MULTI_BOOT_OUTCOME_PAGE + 1; // Skip irrelevant pages
+ else
+ nNewPageNo = SYSENC_MULTI_BOOT_MODE_PAGE + 1; // Skip irrelevant pages
+ }
+ else if (!bHiddenVol)
+ nNewPageNo = (bDevice ? DEVICE_TRANSFORM_MODE_PAGE : VOLUME_LOCATION_PAGE) + 1;
+ else if (bHiddenVolHost)
+ nNewPageNo = HIDDEN_VOL_HOST_PRE_CIPHER_PAGE + 1; // Skip the info on the hidden volume
+ }
+
+ else if (nCurPageNo == SIZE_PAGE)
+ {
+ VerifySizeAndUpdate (hCurPage, TRUE);
+ }
+
+ else if (nCurPageNo == FILESYS_PAGE)
+ {
+ if (nNeedToStoreFilesOver4GB != Get2RadButtonPageAnswer())
+ fileSystem = FILESYS_NONE; // The user may have gone back and changed the answer, so default file system must be reselected
+
+ nNeedToStoreFilesOver4GB = Get2RadButtonPageAnswer();
+ }
+
+ else if (nCurPageNo == PASSWORD_PAGE)
+ {
+ // Store the password in case we need to restore it after keyfile is applied to it
+ GetWindowText (GetDlgItem (hCurPage, IDC_PASSWORD), szRawPassword, sizeof (szRawPassword));
+
+ VerifyPasswordAndUpdate (hwndDlg, GetDlgItem (MainDlg, IDC_NEXT),
+ GetDlgItem (hCurPage, IDC_PASSWORD),
+ GetDlgItem (hCurPage, IDC_VERIFY),
+ volumePassword.Text,
+ szVerify,
+ KeyFilesEnable && FirstKeyFile!=NULL && !SysEncInEffect ());
+
+ volumePassword.Length = strlen ((char *) volumePassword.Text);
+
+ nNewPageNo = SIZE_PAGE + 1; // Skip the hidden volume host password page
+
+ if (SysEncInEffect ())
+ {
+ nNewPageNo = CIPHER_PAGE + 1; // Skip irrelevant pages
+
+ KillTimer (hwndDlg, TIMER_ID_KEYB_LAYOUT_GUARD);
+
+ if (bKeyboardLayoutChanged)
+ {
+ // Restore the original keyboard layout
+ if (LoadKeyboardLayout (OrigKeyboardLayout, KLF_ACTIVATE | KLF_SUBSTITUTE_OK) == NULL)
+ Warning ("CANNOT_RESTORE_KEYBOARD_LAYOUT");
+ else
+ bKeyboardLayoutChanged = FALSE;
+ }
+ }
+ else if (bInPlaceEncNonSys)
+ nNewPageNo = CIPHER_PAGE + 1;
+ }
+
+ else if (nCurPageNo == HIDDEN_VOL_HOST_PASSWORD_PAGE
+ || nCurPageNo == NONSYS_INPLACE_ENC_RESUME_PASSWORD_PAGE)
+ {
+ // Store the password in case we need to restore it after keyfile is applied to it
+ GetWindowText (GetDlgItem (hCurPage, IDC_PASSWORD_DIRECT), szRawPassword, sizeof (szRawPassword));
+
+ GetWindowText (GetDlgItem (hCurPage, IDC_PASSWORD_DIRECT), (char *) volumePassword.Text, sizeof (volumePassword.Text));
+ volumePassword.Length = strlen ((char *) volumePassword.Text);
+
+ if (!bInPlaceEncNonSys)
+ nNewPageNo = VOLUME_LOCATION_PAGE + 1;
+ }
+
+ else if (nCurPageNo == SYSENC_COLLECTING_RANDOM_DATA_PAGE
+ || nCurPageNo == NONSYS_INPLACE_ENC_RAND_DATA_PAGE)
+ {
+ char tmp[RANDPOOL_DISPLAY_SIZE+1];
+
+ KillTimer (hwndDlg, TIMER_ID_RANDVIEW);
+
+ // Attempt to wipe the GUI field showing portions of randpool
+ memset (tmp, 'X', sizeof(tmp));
+ tmp [sizeof(tmp)-1] = 0;
+ SetWindowText (hRandPoolSys, tmp);
+
+ nNewPageNo = PASSWORD_PAGE + 1; // Skip irrelevant pages
+ }
+
+ else if (nCurPageNo == SYSENC_KEYS_GEN_PAGE)
+ {
+ char tmp[KEY_GUI_VIEW_SIZE+1];
+
+ // Attempt to wipe the GUI fields showing portions of the master and header keys
+ memset (tmp, 'X', sizeof(tmp));
+ tmp [sizeof(tmp)-1] = 0;
+ SetWindowText (hMasterKey, tmp);
+ SetWindowText (hHeaderKey, tmp);
+ }
+
+ else if (nCurPageNo == SYSENC_WIPE_MODE_PAGE)
+ {
+ if (bDontVerifyRescueDisk)
+ nNewPageNo = SYSENC_RESCUE_DISK_VERIFIED_PAGE; // Skip irrelevant pages
+ }
+
+ else if (nCurPageNo == FORMAT_PAGE)
+ {
+ char tmp[RNG_POOL_SIZE*2+1];
+
+ KillTimer (hwndDlg, TIMER_ID_RANDVIEW);
+
+ // Attempt to wipe the GUI fields showing portions of randpool, of the master and header keys
+ memset (tmp, 'X', sizeof(tmp));
+ tmp [sizeof(tmp)-1] = 0;
+ SetWindowText (hRandPool, tmp);
+ SetWindowText (hMasterKey, tmp);
+ SetWindowText (hHeaderKey, tmp);
+
+ if (WizardMode != WIZARD_MODE_SYS_DEVICE)
+ {
+ // Skip irrelevant pages
+
+ if (FileSize4GBLimitQuestionNeeded ()
+ && !CreatingHiddenSysVol() // If we're creating a hidden volume for a hidden OS, we don't need to format it with any filesystem (the entire OS will be copied to the hidden volume sector by sector).
+ && !bInPlaceEncNonSys)
+ {
+ nNewPageNo = FILESYS_PAGE + 1;
+ }
+ else
+ nNewPageNo = PASSWORD_PAGE + 1;
+ }
+ }
+
+ LoadPage (hwndDlg, nNewPageNo - 1);
+
+ return 1;
+ }
+
+ return 0;
+
+ case WM_ENDSESSION:
+ EndMainDlg (MainDlg);
+ localcleanup ();
+ return 0;
+
+ case WM_CLOSE:
+ PostMessage (hwndDlg, TC_APPMSG_FORMAT_USER_QUIT, 0, 0);
+ return 1;
+ }
+
+ return 0;
+}
+
+void ExtractCommandLine (HWND hwndDlg, char *lpszCommandLine)
+{
+ char **lpszCommandLineArgs; /* Array of command line arguments */
+ int nNoCommandLineArgs; /* The number of arguments in the array */
+
+ if (_stricmp (lpszCommandLine, "-Embedding") == 0)
+ {
+ ComServerMode = TRUE;
+ return;
+ }
+
+ /* Extract command line arguments */
+ nNoCommandLineArgs = Win32CommandLine (lpszCommandLine, &lpszCommandLineArgs);
+ if (nNoCommandLineArgs > 0)
+ {
+ int i;
+
+ for (i = 0; i < nNoCommandLineArgs; i++)
+ {
+ enum
+ {
+ OptionHistory,
+ OptionNoIsoCheck,
+ OptionQuit,
+ OptionTokenLib,
+ CommandResumeSysEncLogOn,
+ CommandResumeSysEnc,
+ CommandDecryptSysEnc,
+ CommandEncDev,
+ CommandHiddenSys,
+ CommandResumeInplaceLogOn,
+ CommandResumeHiddenSys,
+ CommandSysEnc,
+ CommandResumeInplace,
+ };
+
+ argument args[]=
+ {
+ { OptionHistory, "/history", "/h", FALSE },
+ { OptionNoIsoCheck, "/noisocheck", "/n", FALSE },
+ { OptionQuit, "/quit", "/q", FALSE },
+ { OptionTokenLib, "/tokenlib", NULL, FALSE },
+
+ { CommandResumeSysEncLogOn, "/acsysenc", "/a", TRUE },
+ { CommandResumeSysEnc, "/csysenc", "/c", TRUE },
+ { CommandDecryptSysEnc, "/dsysenc", "/d", TRUE },
+ { CommandEncDev, "/encdev", "/e", TRUE },
+ { CommandHiddenSys, "/isysenc", "/i", TRUE },
+ { CommandResumeInplaceLogOn, "/prinplace", "/p", TRUE },
+ { CommandResumeHiddenSys, "/risysenc", "/r", TRUE },
+ { CommandSysEnc, "/sysenc", "/s", TRUE },
+ { CommandResumeInplace, "/zinplace", "/z", TRUE }
+ };
+
+ argumentspec as;
+
+ int nArgPos;
+ int x;
+
+ if (lpszCommandLineArgs[i] == NULL)
+ continue;
+
+ as.args = args;
+ as.arg_cnt = sizeof(args)/ sizeof(args[0]);
+
+ x = GetArgumentID (&as, lpszCommandLineArgs[i], &nArgPos);
+
+ switch (x)
+ {
+ case CommandSysEnc:
+ // Encrypt system partition/drive (passed by Mount if system encryption hasn't started or to reverse decryption)
+
+ // From now on, we should be the only instance of the TC wizard allowed to deal with system encryption
+ if (CreateSysEncMutex ())
+ {
+ bDirectSysEncMode = TRUE;
+ bDirectSysEncModeCommand = SYSENC_COMMAND_ENCRYPT;
+ ChangeWizardMode (WIZARD_MODE_SYS_DEVICE);
+ }
+ else
+ {
+ Warning ("SYSTEM_ENCRYPTION_IN_PROGRESS_ELSEWHERE");
+ exit(0);
+ }
+
+ break;
+
+ case CommandDecryptSysEnc:
+ // Decrypt system partition/drive (passed by Mount, also to reverse encryption in progress, when paused)
+
+ // From now on, we should be the only instance of the TC wizard allowed to deal with system encryption
+ if (CreateSysEncMutex ())
+ {
+ bDirectSysEncMode = TRUE;
+ bDirectSysEncModeCommand = SYSENC_COMMAND_DECRYPT;
+ ChangeWizardMode (WIZARD_MODE_SYS_DEVICE);
+ }
+ else
+ {
+ Warning ("SYSTEM_ENCRYPTION_IN_PROGRESS_ELSEWHERE");
+ exit(0);
+ }
+ break;
+
+ case CommandHiddenSys:
+ // Create a hidden operating system (passed by Mount when the user selects System -> Create Hidden Operating System)
+
+ // From now on, we should be the only instance of the TC wizard allowed to deal with system encryption
+ if (CreateSysEncMutex ())
+ {
+ bDirectSysEncMode = TRUE;
+ bDirectSysEncModeCommand = SYSENC_COMMAND_CREATE_HIDDEN_OS;
+ ChangeWizardMode (WIZARD_MODE_SYS_DEVICE);
+ }
+ else
+ {
+ Warning ("SYSTEM_ENCRYPTION_IN_PROGRESS_ELSEWHERE");
+ exit(0);
+ }
+
+ break;
+
+ case CommandResumeHiddenSys:
+ // Resume process of creation of a hidden operating system (passed by Wizard when the user needs to UAC-elevate the whole wizard process)
+
+ // From now on, we should be the only instance of the TC wizard allowed to deal with system encryption
+ if (CreateSysEncMutex ())
+ {
+ bDirectSysEncMode = TRUE;
+ bDirectSysEncModeCommand = SYSENC_COMMAND_CREATE_HIDDEN_OS_ELEV;
+ ChangeWizardMode (WIZARD_MODE_SYS_DEVICE);
+ }
+ else
+ {
+ Warning ("SYSTEM_ENCRYPTION_IN_PROGRESS_ELSEWHERE");
+ exit(0);
+ }
+
+ break;
+
+ case CommandResumeSysEnc:
+ // Resume previous system-encryption operation (passed by Mount) e.g. encryption, decryption, or pretest
+
+ // From now on, we should be the only instance of the TC wizard allowed to deal with system encryption
+ if (CreateSysEncMutex ())
+ {
+ bDirectSysEncMode = TRUE;
+ bDirectSysEncModeCommand = SYSENC_COMMAND_RESUME;
+ ChangeWizardMode (WIZARD_MODE_SYS_DEVICE);
+ }
+ else
+ {
+ Warning ("SYSTEM_ENCRYPTION_IN_PROGRESS_ELSEWHERE");
+ exit(0);
+ }
+ break;
+
+ case CommandResumeSysEncLogOn:
+ // Same as csysenc but passed only by the system (from the startup sequence)
+
+ // From now on, we should be the only instance of the TC wizard allowed to deal with system encryption
+ if (CreateSysEncMutex ())
+ {
+ bDirectSysEncMode = TRUE;
+ bDirectSysEncModeCommand = SYSENC_COMMAND_STARTUP_SEQ_RESUME;
+ ChangeWizardMode (WIZARD_MODE_SYS_DEVICE);
+ }
+ else
+ {
+ Warning ("SYSTEM_ENCRYPTION_IN_PROGRESS_ELSEWHERE");
+ exit(0);
+ }
+ break;
+
+ case CommandEncDev:
+ // Resume process of creation of a non-sys-device-hosted volume (passed by Wizard when the user needs to UAC-elevate)
+ DirectDeviceEncMode = TRUE;
+ break;
+
+ case CommandResumeInplace:
+ // Resume interrupted process of non-system in-place encryption of a partition
+ DirectNonSysInplaceEncResumeMode = TRUE;
+ break;
+
+ case CommandResumeInplaceLogOn:
+ // Ask the user whether to resume interrupted process of non-system in-place encryption of a partition
+ // This switch is passed only by the system (from the startup sequence).
+ DirectPromptNonSysInplaceEncResumeMode = TRUE;
+ break;
+
+ case OptionNoIsoCheck:
+ bDontVerifyRescueDisk = TRUE;
+ break;
+
+ case OptionHistory:
+ {
+ char szTmp[8];
+ GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs,
+ szTmp, sizeof (szTmp));
+ if (!_stricmp(szTmp,"y") || !_stricmp(szTmp,"yes"))
+ {
+ bHistory = TRUE;
+ bHistoryCmdLine = TRUE;
+ }
+
+ if (!_stricmp(szTmp,"n") || !_stricmp(szTmp,"no"))
+ {
+ bHistory = FALSE;
+ bHistoryCmdLine = TRUE;
+ }
+ }
+ break;
+
+ case OptionTokenLib:
+ if (GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs, SecurityTokenLibraryPath, sizeof (SecurityTokenLibraryPath)) == HAS_ARGUMENT)
+ InitSecurityTokenLibrary();
+ else
+ Error ("COMMAND_LINE_ERROR");
+
+ break;
+
+ case OptionQuit:
+ {
+ // Used to indicate non-install elevation
+ char szTmp[32];
+ GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs, szTmp, sizeof (szTmp));
+ }
+ break;
+
+ default:
+ DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_COMMANDHELP_DLG), hwndDlg, (DLGPROC)
+ CommandHelpDlgProc, (LPARAM) &as);
+
+ exit(0);
+ }
+ }
+ }
+
+ /* Free up the command line arguments */
+ while (--nNoCommandLineArgs >= 0)
+ {
+ free (lpszCommandLineArgs[nNoCommandLineArgs]);
+ }
+}
+
+
+int DetermineMaxHiddenVolSize (HWND hwndDlg)
+{
+ __int64 nbrReserveBytes;
+
+ if (nbrFreeClusters * realClusterSize < TC_MIN_HIDDEN_VOLUME_SIZE)
+ {
+ MessageBoxW (hwndDlg, GetString ("NO_SPACE_FOR_HIDDEN_VOL"), lpszTitle, ICON_HAND);
+ UnmountVolume (hwndDlg, hiddenVolHostDriveNo, TRUE);
+ AbortProcessSilent ();
+ }
+
+ // Add a reserve (in case the user mounts the outer volume and creates new files
+ // on it by accident or OS writes some new data behind his or her back, such as
+ // System Restore etc.)
+ nbrReserveBytes = GetVolumeDataAreaSize (FALSE, nHiddenVolHostSize) / 200;
+ if (nbrReserveBytes > BYTES_PER_MB * 10)
+ nbrReserveBytes = BYTES_PER_MB * 10;
+
+ // Compute the final value
+
+ nMaximumHiddenVolSize = nbrFreeClusters * realClusterSize - TC_HIDDEN_VOLUME_HOST_FS_RESERVED_END_AREA_SIZE - nbrReserveBytes;
+ nMaximumHiddenVolSize -= nMaximumHiddenVolSize % realClusterSize; // Must be a multiple of the sector size
+
+ if (nMaximumHiddenVolSize < TC_MIN_HIDDEN_VOLUME_SIZE)
+ {
+ MessageBoxW (hwndDlg, GetString ("NO_SPACE_FOR_HIDDEN_VOL"), lpszTitle, ICON_HAND);
+ UnmountVolume (hwndDlg, hiddenVolHostDriveNo, TRUE);
+ AbortProcessSilent ();
+ }
+
+ // Prepare the hidden volume size parameters
+ if (nMaximumHiddenVolSize < BYTES_PER_MB)
+ nMultiplier = BYTES_PER_KB;
+ else if (nMaximumHiddenVolSize < BYTES_PER_GB)
+ nMultiplier = BYTES_PER_MB;
+ else
+ nMultiplier = BYTES_PER_GB;
+
+ nUIVolumeSize = 0; // Set the initial value for the hidden volume size input field to the max
+ nVolumeSize = nUIVolumeSize * nMultiplier; // Chop off possible remainder
+
+ return 1;
+}
+
+
+// Tests whether the file system of the given volume is suitable to host a hidden volume,
+// retrieves the cluster size, and scans the volume cluster bitmap. In addition, checks
+// the TrueCrypt volume format version and the type of volume.
+int AnalyzeHiddenVolumeHost (HWND hwndDlg, int *driveNo, __int64 hiddenVolHostSize, int *realClusterSize, __int64 *pnbrFreeClusters)
+{
+ HANDLE hDevice;
+ DWORD bytesReturned;
+ DWORD dwSectorsPerCluster, dwBytesPerSector, dwNumberOfFreeClusters, dwTotalNumberOfClusters;
+ DWORD dwResult;
+ int result;
+ char szFileSystemNameBuffer[256];
+ char tmpPath[7] = {'\\','\\','.','\\',(char) *driveNo + 'A',':',0};
+ char szRootPathName[4] = {(char) *driveNo + 'A', ':', '\\', 0};
+ BYTE readBuffer[TC_MAX_VOLUME_SECTOR_SIZE * 2];
+ LARGE_INTEGER offset, offsetNew;
+ VOLUME_PROPERTIES_STRUCT volProp;
+
+ memset (&volProp, 0, sizeof(volProp));
+ volProp.driveNo = *driveNo;
+ if (!DeviceIoControl (hDriver, TC_IOCTL_GET_VOLUME_PROPERTIES, &volProp, sizeof (volProp), &volProp, sizeof (volProp), &dwResult, NULL) || dwResult == 0)
+ {
+ handleWin32Error (hwndDlg);
+ Error ("CANT_ACCESS_OUTER_VOL");
+ goto efsf_error;
+ }
+
+ if (volProp.volFormatVersion < TC_VOLUME_FORMAT_VERSION)
+ {
+ // We do not support creating hidden volumes within volumes created by TrueCrypt 5.1a or earlier.
+ Error ("ERR_VOL_FORMAT_BAD");
+ return 0;
+ }
+
+ if (volProp.hiddenVolume)
+ {
+ // The user entered a password for a hidden volume
+ Error ("ERR_HIDDEN_NOT_NORMAL_VOLUME");
+ return 0;
+ }
+
+ if (volProp.volumeHeaderFlags & TC_HEADER_FLAG_NONSYS_INPLACE_ENC
+ || volProp.volumeHeaderFlags & TC_HEADER_FLAG_ENCRYPTED_SYSTEM)
+ {
+ Warning ("ERR_HIDDEN_VOL_HOST_ENCRYPTED_INPLACE");
+ return 0;
+ }
+
+ hDevice = CreateFile (tmpPath, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
+
+ if (hDevice == INVALID_HANDLE_VALUE)
+ {
+ MessageBoxW (hwndDlg, GetString ("CANT_ACCESS_OUTER_VOL"), lpszTitle, ICON_HAND);
+ goto efsf_error;
+ }
+
+ offset.QuadPart = 0;
+
+ if (SetFilePointerEx (hDevice, offset, &offsetNew, FILE_BEGIN) == 0)
+ {
+ handleWin32Error (hwndDlg);
+ goto efs_error;
+ }
+
+ result = ReadFile (hDevice, &readBuffer, TC_MAX_VOLUME_SECTOR_SIZE, &bytesReturned, NULL);
+
+ if (result == 0)
+ {
+ handleWin32Error (hwndDlg);
+ MessageBoxW (hwndDlg, GetString ("CANT_ACCESS_OUTER_VOL"), lpszTitle, ICON_HAND);
+ goto efs_error;
+ }
+
+ CloseHandle (hDevice);
+ hDevice = INVALID_HANDLE_VALUE;
+
+ // Determine file system type
+
+ GetVolumeInformation(szRootPathName, NULL, 0, NULL, NULL, NULL, szFileSystemNameBuffer, sizeof(szFileSystemNameBuffer));
+
+ // The Windows API sometimes fails to indentify the file system correctly so we're using "raw" analysis too.
+ if (!strncmp (szFileSystemNameBuffer, "FAT", 3)
+ || (readBuffer[0x36] == 'F' && readBuffer[0x37] == 'A' && readBuffer[0x38] == 'T')
+ || (readBuffer[0x52] == 'F' && readBuffer[0x53] == 'A' && readBuffer[0x54] == 'T'))
+ {
+ // FAT12/FAT16/FAT32
+
+ // Retrieve the cluster size
+ *realClusterSize = ((int) readBuffer[0xb] + ((int) readBuffer[0xc] << 8)) * (int) readBuffer[0xd];
+
+ // Get the map of the clusters that are free and in use on the outer volume.
+ // The map will be scanned to determine the size of the uninterrupted block of free
+ // space (provided there is any) whose end is aligned with the end of the volume.
+ // The value will then be used to determine the maximum possible size of the hidden volume.
+
+ return ScanVolClusterBitmap (hwndDlg,
+ driveNo,
+ hiddenVolHostSize / *realClusterSize,
+ pnbrFreeClusters);
+ }
+ else if (!strncmp (szFileSystemNameBuffer, "NTFS", 4))
+ {
+ // NTFS
+
+ if (nCurrentOS == WIN_2000)
+ {
+ Error("HIDDEN_VOL_HOST_UNSUPPORTED_FILESYS_WIN2000");
+ return 0;
+ }
+
+ if (bHiddenVolDirect && GetVolumeDataAreaSize (FALSE, hiddenVolHostSize) <= TC_MAX_FAT_SECTOR_COUNT * GetFormatSectorSize())
+ Info ("HIDDEN_VOL_HOST_NTFS");
+
+ if (!GetDiskFreeSpace(szRootPathName,
+ &dwSectorsPerCluster,
+ &dwBytesPerSector,
+ &dwNumberOfFreeClusters,
+ &dwTotalNumberOfClusters))
+ {
+ handleWin32Error (hwndDlg);
+ Error ("CANT_GET_OUTER_VOL_INFO");
+ return -1;
+ };
+
+ *realClusterSize = dwBytesPerSector * dwSectorsPerCluster;
+
+ // Get the map of the clusters that are free and in use on the outer volume.
+ // The map will be scanned to determine the size of the uninterrupted block of free
+ // space (provided there is any) whose end is aligned with the end of the volume.
+ // The value will then be used to determine the maximum possible size of the hidden volume.
+
+ return ScanVolClusterBitmap (hwndDlg,
+ driveNo,
+ hiddenVolHostSize / *realClusterSize,
+ pnbrFreeClusters);
+ }
+ else
+ {
+ // Unsupported file system
+
+ Error ((nCurrentOS == WIN_2000) ? "HIDDEN_VOL_HOST_UNSUPPORTED_FILESYS_WIN2000" : "HIDDEN_VOL_HOST_UNSUPPORTED_FILESYS");
+ return 0;
+ }
+
+efs_error:
+ CloseHandle (hDevice);
+
+efsf_error:
+ CloseVolumeExplorerWindows (hwndDlg, *driveNo);
+
+ return -1;
+}
+
+
+// Mounts a volume within which the user intends to create a hidden volume
+int MountHiddenVolHost (HWND hwndDlg, char *volumePath, int *driveNo, Password *password, BOOL bReadOnly)
+{
+ MountOptions mountOptions;
+ ZeroMemory (&mountOptions, sizeof (mountOptions));
+
+ *driveNo = GetLastAvailableDrive ();
+
+ if (*driveNo == -1)
+ {
+ *driveNo = -2;
+ return ERR_NO_FREE_DRIVES;
+ }
+
+ mountOptions.ReadOnly = bReadOnly;
+ mountOptions.Removable = ConfigReadInt ("MountVolumesRemovable", FALSE);
+ mountOptions.ProtectHiddenVolume = FALSE;
+ mountOptions.PreserveTimestamp = bPreserveTimestamp;
+ mountOptions.PartitionInInactiveSysEncScope = FALSE;
+ mountOptions.UseBackupHeader = FALSE;
+
+ if (MountVolume (hwndDlg, *driveNo, volumePath, password, FALSE, TRUE, &mountOptions, FALSE, TRUE) < 1)
+ {
+ *driveNo = -3;
+ return ERR_VOL_MOUNT_FAILED;
+ }
+ return 0;
+}
+
+
+/* Gets the map of the clusters that are free and in use on a volume that is to host
+ a hidden volume. The map is scanned to determine the size of the uninterrupted
+ area of free space (provided there is any) whose end is aligned with the end
+ of the volume. The value will then be used to determine the maximum possible size
+ of the hidden volume. */
+int ScanVolClusterBitmap (HWND hwndDlg, int *driveNo, __int64 nbrClusters, __int64 *nbrFreeClusters)
+{
+ PVOLUME_BITMAP_BUFFER lpOutBuffer;
+ STARTING_LCN_INPUT_BUFFER lpInBuffer;
+
+ HANDLE hDevice;
+ DWORD lBytesReturned;
+ BYTE rmnd;
+ char tmpPath[7] = {'\\','\\','.','\\', (char) *driveNo + 'A', ':', 0};
+
+ DWORD bufLen;
+ __int64 bitmapCnt;
+
+ hDevice = CreateFile (tmpPath, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
+
+ if (hDevice == INVALID_HANDLE_VALUE)
+ {
+ MessageBoxW (hwndDlg, GetString ("CANT_ACCESS_OUTER_VOL"), lpszTitle, ICON_HAND);
+ goto vcmf_error;
+ }
+
+ bufLen = (DWORD) (nbrClusters / 8 + 2 * sizeof(LARGE_INTEGER));
+ bufLen += 100000 + bufLen/10; // Add reserve
+
+ lpOutBuffer = (PVOLUME_BITMAP_BUFFER) malloc (bufLen);
+
+ if (lpOutBuffer == NULL)
+ {
+ MessageBoxW (hwndDlg, GetString ("ERR_MEM_ALLOC"), lpszTitle, ICON_HAND);
+ goto vcmf_error;
+ }
+
+ lpInBuffer.StartingLcn.QuadPart = 0;
+
+ if ( !DeviceIoControl (hDevice,
+ FSCTL_GET_VOLUME_BITMAP,
+ &lpInBuffer,
+ sizeof(lpInBuffer),
+ lpOutBuffer,
+ bufLen,
+ &lBytesReturned,
+ NULL))
+ {
+ handleWin32Error (hwndDlg);
+ MessageBoxW (hwndDlg, GetString ("CANT_GET_CLUSTER_BITMAP"), lpszTitle, ICON_HAND);
+
+ goto vcm_error;
+ }
+
+ rmnd = (BYTE) (lpOutBuffer->BitmapSize.QuadPart % 8);
+
+ if ((rmnd != 0)
+ && ((lpOutBuffer->Buffer[lpOutBuffer->BitmapSize.QuadPart / 8] & ((1 << rmnd)-1) ) != 0))
+ {
+ *nbrFreeClusters = 0;
+ }
+ else
+ {
+ *nbrFreeClusters = lpOutBuffer->BitmapSize.QuadPart;
+ bitmapCnt = lpOutBuffer->BitmapSize.QuadPart / 8;
+
+ // Scan the bitmap from the end
+ while (--bitmapCnt >= 0)
+ {
+ if (lpOutBuffer->Buffer[bitmapCnt] != 0)
+ {
+ // There might be up to 7 extra free clusters in this byte of the bitmap.
+ // These are ignored because there is always a cluster reserve added anyway.
+ *nbrFreeClusters = lpOutBuffer->BitmapSize.QuadPart - ((bitmapCnt + 1) * 8);
+ break;
+ }
+ }
+ }
+
+ CloseHandle (hDevice);
+ free(lpOutBuffer);
+ return 1;
+
+vcm_error:
+ CloseHandle (hDevice);
+ free(lpOutBuffer);
+
+vcmf_error:
+ return -1;
+}
+
+
+// Wipe the hidden OS config flag bits in the MBR
+static BOOL WipeHiddenOSCreationConfig (void)
+{
+ if (!IsHiddenOSRunning())
+ {
+ try
+ {
+ WaitCursor();
+ finally_do ({ NormalCursor(); });
+
+ BootEncObj->WipeHiddenOSCreationConfig();
+ }
+ catch (Exception &e)
+ {
+ e.Show (MainDlg);
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+}
+
+
+// Tasks that need to be performed after the WM_INITDIALOG message for the SYSENC_ENCRYPTION_PAGE dialog is
+// handled should be done here (otherwise the UAC prompt causes the GUI to be only half-rendered).
+static void AfterSysEncProgressWMInitTasks (HWND hwndDlg)
+{
+ try
+ {
+ switch (SystemEncryptionStatus)
+ {
+ case SYSENC_STATUS_ENCRYPTING:
+
+ if (BootEncStatus.ConfiguredEncryptedAreaStart == BootEncStatus.EncryptedAreaStart
+ && BootEncStatus.ConfiguredEncryptedAreaEnd == BootEncStatus.EncryptedAreaEnd)
+ {
+ // The partition/drive had been fully encrypted
+
+ ManageStartupSeqWiz (TRUE, "");
+ WipeHiddenOSCreationConfig(); // For extra conservative security
+ ChangeSystemEncryptionStatus (SYSENC_STATUS_NONE);
+
+ Info ("SYSTEM_ENCRYPTION_FINISHED");
+ EndMainDlg (MainDlg);
+ return;
+ }
+ else
+ {
+ SysEncResume ();
+ }
+
+ break;
+
+ case SYSENC_STATUS_DECRYPTING:
+ SysEncResume ();
+ break;
+
+ default:
+
+ // Unexpected mode here -- fix the inconsistency
+
+ ManageStartupSeqWiz (TRUE, "");
+ ChangeSystemEncryptionStatus (SYSENC_STATUS_NONE);
+ EndMainDlg (MainDlg);
+ InconsistencyResolved (SRC_POS);
+ return;
+ }
+ }
+ catch (Exception &e)
+ {
+ e.Show (hwndDlg);
+ EndMainDlg (MainDlg);
+ return;
+ }
+
+ InitSysEncProgressBar ();
+
+ UpdateSysEncProgressBar ();
+
+ UpdateSysEncControls ();
+}
+
+
+// Tasks that need to be performed after the WM_INITDIALOG message is handled must be done here.
+// For example, any tasks that may invoke the UAC prompt (otherwise the UAC dialog box would not be on top).
+static void AfterWMInitTasks (HWND hwndDlg)
+{
+ // Note that if bDirectSysEncModeCommand is not SYSENC_COMMAND_NONE, we already have the mutex.
+
+ // SYSENC_COMMAND_DECRYPT has the highest priority because it also performs uninstallation (restores the
+ // original contents of the first drive cylinder, etc.) so it must be attempted regardless of the phase
+ // or content of configuration files.
+ if (bDirectSysEncModeCommand == SYSENC_COMMAND_DECRYPT)
+ {
+ if (IsHiddenOSRunning())
+ {
+ Warning ("CANNOT_DECRYPT_HIDDEN_OS");
+ AbortProcessSilent();
+ }
+
+ // Add the wizard to the system startup sequence
+ ManageStartupSeqWiz (FALSE, "/acsysenc");
+
+ ChangeSystemEncryptionStatus (SYSENC_STATUS_DECRYPTING);
+ LoadPage (hwndDlg, SYSENC_ENCRYPTION_PAGE);
+ return;
+ }
+
+
+ if (SystemEncryptionStatus == SYSENC_STATUS_ENCRYPTING
+ || SystemEncryptionStatus == SYSENC_STATUS_DECRYPTING)
+ {
+ try
+ {
+ BootEncStatus = BootEncObj->GetStatus();
+
+ if (!BootEncStatus.DriveMounted)
+ {
+ if (!BootEncStatus.DeviceFilterActive)
+ {
+ // This is an inconsistent state. SystemEncryptionStatus should never be SYSENC_STATUS_ENCRYPTING
+ // or SYSENC_STATUS_DECRYPTING when the drive filter is not active. Possible causes: 1) corrupted
+ // or stale config file, 2) corrupted system
+
+ // Fix the inconsistency
+ ManageStartupSeqWiz (TRUE, "");
+ ChangeSystemEncryptionStatus (SYSENC_STATUS_NONE);
+ EndMainDlg (MainDlg);
+ InconsistencyResolved (SRC_POS);
+ return;
+ }
+ else if (bDirectSysEncMode)
+ {
+ // This is an inconsistent state. We have a direct system encryption command,
+ // SystemEncryptionStatus is SYSENC_STATUS_ENCRYPTING or SYSENC_STATUS_DECRYPTING, the
+ // system drive is not 'mounted' and drive filter is active. Possible causes: 1) The drive had
+ // been decrypted in the pre-boot environment. 2) The OS is not located on the lowest partition,
+ // the drive is to be fully encrypted, but the user rebooted before encryption reached the
+ // system partition and then pressed Esc in the boot loader screen. 3) Corrupted or stale config
+ // file. 4) Damaged system.
+
+ Warning ("SYSTEM_ENCRYPTION_SCHEDULED_BUT_PBA_FAILED");
+ EndMainDlg (MainDlg);
+ return;
+ }
+ }
+ }
+ catch (Exception &e)
+ {
+ e.Show (MainDlg);
+ }
+ }
+
+
+ if (SystemEncryptionStatus != SYSENC_STATUS_PRETEST)
+ {
+ // Handle system encryption command line arguments (if we're not in the Pretest phase).
+ // Note that if bDirectSysEncModeCommand is not SYSENC_COMMAND_NONE, we already have the mutex.
+ // Also note that SYSENC_COMMAND_DECRYPT is handled above.
+
+ switch (bDirectSysEncModeCommand)
+ {
+ case SYSENC_COMMAND_RESUME:
+ case SYSENC_COMMAND_STARTUP_SEQ_RESUME:
+
+ if (bDirectSysEncModeCommand == SYSENC_COMMAND_STARTUP_SEQ_RESUME
+ && AskWarnYesNo ("SYSTEM_ENCRYPTION_RESUME_PROMPT") == IDNO)
+ {
+ EndMainDlg (MainDlg);
+ return;
+ }
+
+ if (SysEncryptionOrDecryptionRequired ())
+ {
+ if (SystemEncryptionStatus != SYSENC_STATUS_ENCRYPTING
+ && SystemEncryptionStatus != SYSENC_STATUS_DECRYPTING)
+ {
+ // If the config file with status was lost or not written correctly, we
+ // don't know whether to encrypt or decrypt (but we know that encryption or
+ // decryption is required). Ask the user to select encryption, decryption,
+ // or cancel
+ if (!ResolveUnknownSysEncDirection ())
+ {
+ EndMainDlg (MainDlg);
+ return;
+ }
+ }
+
+ LoadPage (hwndDlg, SYSENC_ENCRYPTION_PAGE);
+ return;
+ }
+ else
+ {
+ // Nothing to resume
+ Warning ("NOTHING_TO_RESUME");
+ EndMainDlg (MainDlg);
+
+ return;
+ }
+ break;
+
+ case SYSENC_COMMAND_ENCRYPT:
+
+ if (SysDriveOrPartitionFullyEncrypted (FALSE))
+ {
+ Info ("SYS_PARTITION_OR_DRIVE_APPEARS_FULLY_ENCRYPTED");
+ EndMainDlg (MainDlg);
+ return;
+ }
+
+ if (SysEncryptionOrDecryptionRequired ())
+ {
+ // System partition/drive encryption process already initiated but is incomplete.
+ // If we were encrypting, resume the process directly. If we were decrypting, reverse
+ // the process and start encrypting.
+
+ ChangeSystemEncryptionStatus (SYSENC_STATUS_ENCRYPTING);
+ LoadPage (hwndDlg, SYSENC_ENCRYPTION_PAGE);
+ return;
+ }
+ else
+ {
+ // Initiate the Pretest preparation phase
+ if (!SwitchWizardToSysEncMode ())
+ {
+ bDirectSysEncMode = FALSE;
+ EndMainDlg (MainDlg);
+ }
+ return;
+ }
+
+ break;
+
+ case SYSENC_COMMAND_CREATE_HIDDEN_OS_ELEV:
+ case SYSENC_COMMAND_CREATE_HIDDEN_OS:
+
+ if (!SwitchWizardToHiddenOSMode ())
+ {
+ bDirectSysEncMode = FALSE;
+ EndMainDlg (MainDlg);
+ }
+ return;
+ }
+ }
+
+
+ if (!bDirectSysEncMode
+ || bDirectSysEncMode && SystemEncryptionStatus == SYSENC_STATUS_NONE)
+ {
+ // Handle system encryption cases where the wizard did not start even though it
+ // was added to the startup sequence, as well as other weird cases and "leftovers"
+
+ if (SystemEncryptionStatus != SYSENC_STATUS_NONE
+ && SystemEncryptionStatus != SYSENC_STATUS_PRETEST
+ && SysEncryptionOrDecryptionRequired ())
+ {
+ // System encryption/decryption had been in progress and did not finish
+
+ if (CreateSysEncMutex ()) // If no other instance is currently taking care of system encryption
+ {
+ if (AskWarnYesNo ("SYSTEM_ENCRYPTION_RESUME_PROMPT") == IDYES)
+ {
+ bDirectSysEncMode = TRUE;
+ ChangeWizardMode (WIZARD_MODE_SYS_DEVICE);
+ LoadPage (hwndDlg, SYSENC_ENCRYPTION_PAGE);
+ return;
+ }
+ else
+ CloseSysEncMutex ();
+ }
+ }
+
+ else if (SystemEncryptionStatus == SYSENC_STATUS_PRETEST)
+ {
+ // System pretest had been in progress but we were not launched during the startup seq
+
+ if (CreateSysEncMutex ()) // If no other instance is currently taking care of system encryption
+ {
+ // The pretest has "priority handling"
+ bDirectSysEncMode = TRUE;
+ ChangeWizardMode (WIZARD_MODE_SYS_DEVICE);
+
+ /* Do not return yet -- the principal pretest handler is below. */
+ }
+ }
+
+ else if ((SystemEncryptionStatus == SYSENC_STATUS_NONE || SystemEncryptionStatus == SYSENC_STATUS_DECRYPTING)
+ && !BootEncStatus.DriveEncrypted
+ && (BootEncStatus.DriveMounted || BootEncStatus.VolumeHeaderPresent))
+ {
+ // The pretest may have been in progress but we can't be sure (it is not in the config file).
+ // Another possibility is that the user had finished decrypting the drive, but the config file
+ // was not correctly updated. In both cases the best thing we can do is remove the header and
+ // deinstall. Otherwise, the result might be some kind of deadlock.
+
+ if (CreateSysEncMutex ()) // If no other instance is currently taking care of system encryption
+ {
+ WaitCursor ();
+
+ ForceRemoveSysEnc();
+
+ InconsistencyResolved (SRC_POS);
+
+ NormalCursor();
+ CloseSysEncMutex ();
+ }
+ }
+ }
+
+ if (bDirectSysEncMode && CreateSysEncMutex ())
+ {
+ // We were launched either by Mount or by the system (startup sequence). Most of such cases should have
+ // been handled above already. Here we handle only the pretest phase (which can also be a hidden OS
+ // creation phase actually) and possible inconsistencies.
+
+ switch (SystemEncryptionStatus)
+ {
+ case SYSENC_STATUS_PRETEST:
+ {
+ unsigned int hiddenOSCreationPhase = DetermineHiddenOSCreationPhase();
+
+ bHiddenOS = (hiddenOSCreationPhase != TC_HIDDEN_OS_CREATION_PHASE_NONE);
+
+ // Evaluate the results of the system encryption pretest (or of the hidden OS creation process)
+
+ try
+ {
+ BootEncStatus = BootEncObj->GetStatus();
+ }
+ catch (Exception &e)
+ {
+ e.Show (hwndDlg);
+ Error ("ERR_GETTING_SYSTEM_ENCRYPTION_STATUS");
+ EndMainDlg (MainDlg);
+ return;
+ }
+
+ if (BootEncStatus.DriveMounted)
+ {
+ /* Pretest successful or hidden OS has been booted during the process of hidden OS creation. */
+
+ switch (hiddenOSCreationPhase)
+ {
+ case TC_HIDDEN_OS_CREATION_PHASE_NONE:
+
+ // Pretest successful (or the hidden OS has been booted for the first time since the user started installing a new decoy OS)
+
+ if (IsHiddenOSRunning())
+ {
+ // The hidden OS has been booted for the first time since the user started installing a
+ // new decoy OS (presumably, our MBR config flags have been erased).
+
+ // As for things we are responsible for, the process of hidden OS creation is completed
+ // (the rest is up to the user).
+
+ ManageStartupSeqWiz (TRUE, "");
+ ChangeSystemEncryptionStatus (SYSENC_STATUS_NONE);
+
+ EndMainDlg (MainDlg);
+
+ return;
+ }
+
+ // Pretest successful (no hidden operating system involved)
+
+ LoadPage (hwndDlg, SYSENC_PRETEST_RESULT_PAGE);
+ return;
+
+ case TC_HIDDEN_OS_CREATION_PHASE_WIPING:
+
+ // Hidden OS has been booted when we are supposed to wipe the original OS
+
+ LoadPage (hwndDlg, SYSENC_HIDDEN_OS_INITIAL_INFO_PAGE);
+ return;
+
+ case TC_HIDDEN_OS_CREATION_PHASE_WIPED:
+
+ // Hidden OS has been booted and the original OS wiped. Now the user is required to install a new, decoy, OS.
+
+ TextInfoDialogBox (TC_TBXID_DECOY_OS_INSTRUCTIONS);
+
+ EndMainDlg (MainDlg);
+ return;
+
+ default:
+
+ // Unexpected/unknown status
+ ReportUnexpectedState (SRC_POS);
+ EndMainDlg (MainDlg);
+ return;
+ }
+ }
+ else
+ {
+ BOOL bAnswerTerminate = FALSE, bAnswerRetry = FALSE;
+
+ /* Pretest failed
+ or hidden OS cloning has been interrupted (and non-hidden OS is running)
+ or wiping of the original OS has not been started (and non-hidden OS is running) */
+
+ if (hiddenOSCreationPhase == TC_HIDDEN_OS_CREATION_PHASE_NONE)
+ {
+ // Pretest failed (no hidden operating system involved)
+
+ if (AskWarnYesNo ("BOOT_PRETEST_FAILED_RETRY") == IDYES)
+ {
+ // User wants to retry the pretest
+ bAnswerTerminate = FALSE;
+ bAnswerRetry = TRUE;
+ }
+ else
+ {
+ // User doesn't want to retry the pretest
+ bAnswerTerminate = TRUE;
+ bAnswerRetry = FALSE;
+ }
+ }
+ else
+ {
+ // Hidden OS cloning was interrupted or wiping of the original OS has not been started
+
+ char *tmpStr[] = {0,
+ hiddenOSCreationPhase == TC_HIDDEN_OS_CREATION_PHASE_WIPING ? "OS_WIPING_NOT_FINISHED_ASK" : "HIDDEN_OS_CREATION_NOT_FINISHED_ASK",
+ "HIDDEN_OS_CREATION_NOT_FINISHED_CHOICE_RETRY",
+ "HIDDEN_OS_CREATION_NOT_FINISHED_CHOICE_TERMINATE",
+ "HIDDEN_OS_CREATION_NOT_FINISHED_CHOICE_ASK_LATER",
+ 0};
+
+ switch (AskMultiChoice ((void **) tmpStr, FALSE))
+ {
+ case 1:
+ // User wants to restart and continue/retry
+ bAnswerTerminate = FALSE;
+ bAnswerRetry = TRUE;
+ break;
+
+ case 2:
+ // User doesn't want to retry but wants to terminate the entire process of hidden OS creation
+ bAnswerTerminate = TRUE;
+ bAnswerRetry = FALSE;
+ break;
+
+ default:
+ // User doesn't want to do anything now
+ bAnswerTerminate = FALSE;
+ bAnswerRetry = FALSE;
+ }
+ }
+
+
+ if (bAnswerRetry)
+ {
+ // User wants to restart and retry the pretest (or hidden OS creation)
+
+ // We re-register the driver for boot because the user may have selected
+ // "Last Known Good Configuration" from the Windows boot menu.
+ // Note that we need to do this even when creating a hidden OS (because
+ // the hidden OS needs our boot driver and it will be a clone of this OS).
+ try
+ {
+ BootEncObj->RegisterBootDriver (bHiddenOS ? true : false);
+ }
+ catch (Exception &e)
+ {
+ e.Show (NULL);
+ }
+
+ if (AskWarnYesNo ("CONFIRM_RESTART") == IDYES)
+ {
+ EndMainDlg (MainDlg);
+
+ try
+ {
+ BootEncObj->RestartComputer ();
+ }
+ catch (Exception &e)
+ {
+ e.Show (hwndDlg);
+ }
+
+ return;
+ }
+
+ EndMainDlg (MainDlg);
+ return;
+ }
+ else if (bAnswerTerminate)
+ {
+ // User doesn't want to retry pretest (or OS cloning), but to terminate the entire process
+
+ try
+ {
+ BootEncObj->Deinstall (true);
+ }
+ catch (Exception &e)
+ {
+ e.Show (hwndDlg);
+ AbortProcessSilent();
+ }
+
+ ManageStartupSeqWiz (TRUE, "");
+ ChangeSystemEncryptionStatus (SYSENC_STATUS_NONE);
+ EndMainDlg (MainDlg);
+ return;
+ }
+ else
+ {
+ // User doesn't want to take any action now
+
+ AbortProcessSilent();
+ }
+ }
+ }
+ break;
+
+ default:
+
+ // Unexpected progress status -- fix the inconsistency
+
+ ManageStartupSeqWiz (TRUE, "");
+ ChangeSystemEncryptionStatus (SYSENC_STATUS_NONE);
+ EndMainDlg (MainDlg);
+ InconsistencyResolved (SRC_POS);
+ return;
+ }
+ }
+ else
+ {
+ if (DirectDeviceEncMode)
+ {
+ SwitchWizardToNonSysDeviceMode();
+ return;
+ }
+
+ if (DirectPromptNonSysInplaceEncResumeMode
+ && !bInPlaceEncNonSysPending)
+ {
+ // This instance of the wizard has been launched via the system startup sequence to prompt for resume of
+ // a non-system in-place encryption process. However, no config file indicates that any such process
+ // has been interrupted. This inconsistency may occur, for example, when the process is finished
+ // but the wizard is not removed from the startup sequence because system encryption is in progress.
+ // Therefore, we remove it from the startup sequence now if possible.
+
+ if (!IsNonInstallMode () && SystemEncryptionStatus == SYSENC_STATUS_NONE)
+ ManageStartupSeqWiz (TRUE, "");
+
+ AbortProcessSilent ();
+ }
+
+ if (DirectNonSysInplaceEncResumeMode)
+ {
+ SwitchWizardToNonSysInplaceEncResumeMode();
+ return;
+ }
+ else if (DirectPromptNonSysInplaceEncResumeMode)
+ {
+ if (NonSysInplaceEncInProgressElsewhere ())
+ AbortProcessSilent ();
+
+ if (AskNonSysInPlaceEncryptionResume() == IDYES)
+ SwitchWizardToNonSysInplaceEncResumeMode();
+ else
+ AbortProcessSilent ();
+
+ return;
+ }
+ else if (bInPlaceEncNonSysPending
+ && !NonSysInplaceEncInProgressElsewhere ()
+ && AskNonSysInPlaceEncryptionResume() == IDYES)
+ {
+ SwitchWizardToNonSysInplaceEncResumeMode();
+ return;
+ }
+
+ LoadPage (hwndDlg, INTRO_PAGE);
+ }
+}
+
+int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, char *lpszCommandLine, int nCmdShow)
+{
+ int status;
+ atexit (localcleanup);
+
+ VirtualLock (&volumePassword, sizeof(volumePassword));
+ VirtualLock (szVerify, sizeof(szVerify));
+ VirtualLock (szRawPassword, sizeof(szRawPassword));
+
+ VirtualLock (MasterKeyGUIView, sizeof(MasterKeyGUIView));
+ VirtualLock (HeaderKeyGUIView, sizeof(HeaderKeyGUIView));
+
+ VirtualLock (randPool, sizeof(randPool));
+ VirtualLock (lastRandPool, sizeof(lastRandPool));
+ VirtualLock (outRandPoolDispBuffer, sizeof(outRandPoolDispBuffer));
+
+ VirtualLock (&szFileName, sizeof(szFileName));
+ VirtualLock (&szDiskFile, sizeof(szDiskFile));
+
+ try
+ {
+ BootEncObj = new BootEncryption (NULL);
+ }
+ catch (Exception &e)
+ {
+ e.Show (NULL);
+ }
+
+ if (BootEncObj == NULL)
+ AbortProcess ("INIT_SYS_ENC");
+
+ InitCommonControls ();
+ InitApp (hInstance, lpszCommandLine);
+
+ // Write block size greater than 64 KB causes a performance drop when writing to files on XP/Vista
+ if (!IsOSAtLeast (WIN_7))
+ FormatWriteBufferSize = 64 * 1024;
+
+#if TC_MAX_VOLUME_SECTOR_SIZE > 64 * 1024
+#error TC_MAX_VOLUME_SECTOR_SIZE > 64 * 1024
+#endif
+
+ nPbar = IDC_PROGRESS_BAR;
+
+ if (Randinit ())
+ AbortProcess ("INIT_RAND");
+
+ RegisterRedTick(hInstance);
+
+ /* Allocate, dup, then store away the application title */
+ lpszTitle = GetString ("IDD_VOL_CREATION_WIZARD_DLG");
+
+ status = DriverAttach ();
+ if (status != 0)
+ {
+ if (status == ERR_OS_ERROR)
+ handleWin32Error (NULL);
+ else
+ handleError (NULL, status);
+
+ AbortProcess ("NODRIVER");
+ }
+
+ if (!AutoTestAlgorithms())
+ AbortProcess ("ERR_SELF_TESTS_FAILED");
+
+ /* Create the main dialog box */
+ DialogBoxParamW (hInstance, MAKEINTRESOURCEW (IDD_VOL_CREATION_WIZARD_DLG), NULL, (DLGPROC) MainDialogProc,
+ (LPARAM)lpszCommandLine);
+
+ return 0;
+}
+
+
+static int GetFormatSectorSize ()
+{
+ if (!bDevice)
+ return TC_SECTOR_SIZE_FILE_HOSTED_VOLUME;
+
+ DISK_GEOMETRY geometry;
+
+ if (!GetDriveGeometry (szDiskFile, &geometry))
+ {
+ handleWin32Error (MainDlg);
+ AbortProcessSilent();
+ }
+
+ return geometry.BytesPerSector;
+}
diff --git a/src/Format/Tcformat.h b/src/Format/Tcformat.h new file mode 100644 index 00000000..14512607 --- /dev/null +++ b/src/Format/Tcformat.h @@ -0,0 +1,104 @@ +/*
+ Legal Notice: Some portions of the source code contained in this file were
+ derived 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 all other portions
+ of this file are Copyright (c) 2003-2009 TrueCrypt Developers Association
+ and are governed by the TrueCrypt License 3.0 the full text of which is
+ contained in the file License.txt included in TrueCrypt binary and source
+ code distribution packages. */
+
+#include "Common/Common.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define NBR_KEY_BYTES_TO_DISPLAY 16
+#define KEY_GUI_VIEW_SIZE 64 // Max characters of the key hex dump to display
+
+enum timer_ids
+{
+ TIMER_ID_RANDVIEW = 0xff,
+ TIMER_ID_SYSENC_PROGRESS,
+ TIMER_ID_NONSYS_INPLACE_ENC_PROGRESS,
+ TIMER_ID_WIPE_PROGRESS,
+ TIMER_ID_SYSENC_DRIVE_ANALYSIS_PROGRESS,
+ TIMER_ID_KEYB_LAYOUT_GUARD
+};
+
+static void localcleanup ( void );
+static void LoadSettings ( HWND hwndDlg );
+static void SaveSettings ( HWND hwndDlg );
+static void EndMainDlg ( HWND hwndDlg );
+void ComboSelChangeEA ( HWND hwndDlg );
+static void VerifySizeAndUpdate ( HWND hwndDlg , BOOL bUpdate );
+static void __cdecl sysEncDriveAnalysisThread (void *hwndDlgArg);
+static void __cdecl volTransformThreadFunction ( void *hwndDlg );
+static void LoadPage ( HWND hwndDlg , int nPageNo );
+int PrintFreeSpace ( HWND hwndTextBox , char *lpszDrive , PLARGE_INTEGER lDiskFree );
+void DisplaySizingErrorText ( HWND hwndTextBox );
+void EnableDisableFileNext ( HWND hComboBox , HWND hMainButton );
+BOOL QueryFreeSpace ( HWND hwndDlg , HWND hwndTextBox , BOOL display );
+static BOOL FinalPreTransformPrompts (void);
+void HandleOldAssignedDriveLetter (void);
+void AddCipher ( HWND hComboBox , char *lpszCipher , int nCipher );
+BOOL CALLBACK PageDialogProc ( HWND hwndDlg , UINT uMsg , WPARAM wParam , LPARAM lParam );
+BOOL CALLBACK MainDialogProc ( HWND hwndDlg , UINT uMsg , WPARAM wParam , LPARAM lParam );
+void ExtractCommandLine ( HWND hwndDlg , char *lpszCommandLine );
+void DisplayRandPool (HWND hPoolDisplay, BOOL bShow);
+void DisplayPortionsOfKeys (HWND headerKeyHandle, HWND masterKeyHandle, char *headerKeyStr, char *masterKeyStr, BOOL hideKeys);
+int DetermineMaxHiddenVolSize (HWND hwndDlg);
+BOOL IsSparseFile (HWND hwndDlg);
+BOOL GetFileVolSize (HWND hwndDlg, unsigned __int64 *size);
+BOOL SwitchWizardToSysEncMode (void);
+void SwitchWizardToFileContainerMode (void);
+static BOOL ResolveUnknownSysEncDirection (void);
+static BOOL WipeHiddenOSCreationConfig (void);
+static void AfterWMInitTasks (HWND hwndDlg);
+static void AfterSysEncProgressWMInitTasks (HWND hwndDlg);
+static void InitSysEncProgressBar (void);
+static void InitNonSysInplaceEncProgressBar (void);
+static void UpdateNonSysInplaceEncProgressBar (void);
+static BOOL SysEncInEffect (void);
+static BOOL CreatingHiddenSysVol(void);
+static void NonSysInplaceEncPause (void);
+static void NonSysInplaceEncResume (void);
+void ShowNonSysInPlaceEncUIStatus (void);
+void UpdateNonSysInPlaceEncControls (void);
+int MountHiddenVolHost ( HWND hwndDlg, char *volumePath, int *driveNo, Password *password, BOOL bReadOnly );
+int AnalyzeHiddenVolumeHost (HWND hwndDlg, int *driveNo, __int64 hiddenVolHostSize, int *realClusterSize, __int64 *pnbrFreeClusters);
+int ScanVolClusterBitmap ( HWND hwndDlg, int *driveNo, __int64 nbrClusters, __int64 *nbrFreeClusters);
+static void WipeStart (void);
+static void WipeAbort (void);
+static void UpdateWipeProgressBar (void);
+static void InitWipeProgressBar (void);
+static void UpdateWipeControls (void);
+static int GetFormatSectorSize ();
+
+extern BOOL showKeys;
+extern volatile HWND hMasterKey;
+extern volatile HWND hHeaderKey;
+extern volatile BOOL bHiddenVolHost;
+extern volatile BOOL bHiddenVolDirect;
+extern BOOL bRemovableHostDevice;
+extern BOOL bWarnDeviceFormatAdvanced;
+extern HWND hCurPage;
+extern HWND hProgressBar;
+extern volatile BOOL bVolTransformThreadCancel;
+extern volatile BOOL bInPlaceEncNonSysResumed;
+extern volatile BOOL bFirstNonSysInPlaceEncResumeDone;
+extern volatile BOOL bInPlaceEncNonSys;
+extern __int64 NonSysInplaceEncBytesDone;
+extern __int64 NonSysInplaceEncTotalSize;
+extern int nPbar;
+extern volatile int WizardMode;
+
+extern char HeaderKeyGUIView [KEY_GUI_VIEW_SIZE];
+extern char MasterKeyGUIView [KEY_GUI_VIEW_SIZE];
+extern volatile int NonSysInplaceEncStatus;
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/src/Format/TrueCrypt_Wizard.bmp b/src/Format/TrueCrypt_Wizard.bmp Binary files differnew file mode 100644 index 00000000..d291bfa3 --- /dev/null +++ b/src/Format/TrueCrypt_Wizard.bmp |