/* Legal Notice: Some portions of the source code contained in this file were derived from the source code of TrueCrypt 7.1a, which is Copyright (c) 2003-2012 TrueCrypt Developers Association and which is governed by the TrueCrypt License 3.0, also from the source code of Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux and which is governed by the 'License Agreement for Encryption for the Masses' Modifications and additions to the original source code (contained in this file) and all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source 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"cpu.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"Common/Pkcs5.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"#include"SecurityToken.h"#include<Strsafe.h>usingnamespaceVeraCrypt;enumwizard_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,PIM_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_TRANSFORM_PAGE,NONSYS_INPLACE_ENC_TRANSFORM_FINISHED_PAGE,NONSYS_INPLACE_DEC_TRANSFORM_FINISHED_DRIVE_LETTER_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 10enumsys_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};typedefstruct{intNumberOfSysDrives;// Number of drives that contain an operating system. -1: unknown, 1: one, 2: two or moreintMultipleSystemsOnDrive;// Multiple systems are installed on the drive where the currently running system resides. -1: unknown, 0: no, 1: yesintBootLoaderLocation;// Boot loader (boot manager) installed in: 1: MBR/1st cylinder, 0: partition/bootsector: -1: unknownintBootLoaderBrand;// -1: unknown, 0: Microsoft Windows, 1: any non-Windows boot manager/loaderintSystemOnBootDrive;// 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;BootEncryptionStatusBootEncStatus;HWNDhCurPage=NULL;/* Handle to current wizard page */intnCurPageNo=-1;/* The current wizard page */intnLastPageNo=-1;volatileintWizardMode=DEFAULT_VOL_CREATION_WIZARD_MODE;/* IMPORTANT: Never change this value directly -- always use ChangeWizardMode() instead. */volatileBOOLbHiddenOS=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()) */BOOLbDirectSysEncMode=FALSE;BOOLbDirectSysEncModeCommand=SYSENC_COMMAND_NONE;BOOLDirectDeviceEncMode=FALSE;BOOLDirectNonSysInplaceDecStartMode=FALSE;BOOLDirectNonSysInplaceEncResumeMode=FALSE;BOOLDirectNonSysInplaceDecResumeMode=FALSE;BOOLDirectPromptNonSysInplaceEncResumeMode=FALSE;BOOLDirectCreationMode=FALSE;volatileBOOLbInPlaceEncNonSys=FALSE;/* If TRUE, existing data on a non-system partition/volume are to be encrypted (or decrypted if bInPlaceDecNonSys is TRUE) in place (for system encryption, this flag is ignored) */volatileBOOLbInPlaceDecNonSys=FALSE;/* If TRUE, existing data on a non-system partition/volume are to be decrypted in place (for system encryption, this flag is ignored) */volatileBOOLbInPlaceEncNonSysResumed=FALSE;/* If TRUE, the wizard is supposed to resume (or has resumed) process of non-system in-place encryption/decryption. */volatileBOOLbFirstNonSysInPlaceEncResumeDone=FALSE;__int64NonSysInplaceEncBytesDone=0;__int64NonSysInplaceEncTotalSize=0;BOOLbDeviceTransformModeChoiceMade=FALSE;/* TRUE if the user has at least once manually selected the 'in-place' or 'format' option (on the 'device transform mode' page). */intnNeedToStoreFilesOver4GB=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 */intnVolumeEA=1;/* Default encryption algorithm */BOOLbSystemEncryptionInProgress=FALSE;/* TRUE when encrypting/decrypting the system partition/drive (FALSE when paused). */BOOLbWholeSysDrive=FALSE;/* Whether to encrypt the entire system drive or just the system partition. */staticBOOLbSystemEncryptionStatusChanged=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). */volatileBOOLbSysEncDriveAnalysisInProgress=FALSE;volatileBOOLbSysEncDriveAnalysisTimeOutOccurred=FALSE;intSysEncDetectHiddenSectors=-1;/* Whether the user wants us to detect and encrypt the Host Protect Area (if any): -1 = Undecided or error, 0 = No, 1 = Yes */intSysEncDriveAnalysisStart;BOOLbDontVerifyRescueDisk=FALSE;BOOLbFirstSysEncResumeDone=FALSE;intnMultiBoot=0;/* The number of operating systems installed on the computer, according to the user. 0: undetermined, 1: one, 2: two or more */volatileBOOLbHiddenVol=FALSE;/* If true, we are (or will be) creating a hidden volume. */volatileBOOLbHiddenVolHost=FALSE;/* If true, we are (or will be) creating the host volume (called "outer") for a hidden volume. */volatileBOOLbHiddenVolDirect=FALSE;/* If true, the wizard omits creating a host volume in the course of the process of hidden volume creation. */volatileBOOLbHiddenVolFinished=FALSE;inthiddenVolHostDriveNo=-1;/* Drive letter for the volume intended to host a hidden volume. */BOOLbRemovableHostDevice=FALSE;/* TRUE when creating a device/partition-hosted volume on a removable device. State undefined when creating file-hosted volumes. */intrealClusterSize;/* Parameter used when determining the maximum possible size of a hidden volume. */inthash_algo=DEFAULT_HASH_ALGORITHM;/* Which PRF to use in header key derivation (PKCS #5) and in the RNG. */unsigned__int64nUIVolumeSize=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__int64nVolumeSize=0;/* The volume size, in bytes. */unsigned__int64nHiddenVolHostSize=0;/* Size of the hidden volume host, in bytes */__int64nMaximumHiddenVolSize=0;/* Maximum possible size of the hidden volume, in bytes */__int64nbrFreeClusters=0;__int64nMultiplier=BYTES_PER_MB;/* Size selection multiplier. */wchar_tszFileName[TC_MAX_PATH+1];/* The file selected by the user */wchar_tszDiskFile[TC_MAX_PATH+1];/* Fully qualified name derived from szFileName */wchar_tszRescueDiskISO[TC_MAX_PATH+1];/* The filename and path to the Rescue Disk ISO file to be burned (for boot encryption) */BOOLbDeviceWipeInProgress=FALSE;volatileBOOLbTryToCorrectReadErrors=FALSE;volatileBOOLDiscardUnreadableEncryptedSectors=FALSE;volatileBOOLbVolTransformThreadCancel=FALSE;/* TRUE if the user cancels/pauses volume encryption/format */volatileBOOLbVolTransformThreadRunning=FALSE;/* Is the volume encryption/format thread running */volatileBOOLbVolTransformThreadToRun=FALSE;/* TRUE if the Format/Encrypt button has been clicked and we are proceeding towards launching the thread. */volatileBOOLbConfirmQuit=FALSE;/* If TRUE, the user is asked to confirm exit when he clicks the X icon, Exit, etc. */volatileBOOLbConfirmQuitSysEncPretest=FALSE;BOOLbDevice=FALSE;/* Is this a partition volume ? */BOOLshowKeys=FALSE;volatileHWNDhMasterKey=NULL;/* Text box showing hex dump of the master key */volatileHWNDhHeaderKey=NULL;/* Text box showing hex dump of the header key */volatileHWNDhRandPool=NULL;/* Text box showing hex dump of the random pool */volatileHWNDhRandPoolSys=NULL;/* Text box showing hex dump of the random pool for system encryption */volatileHWNDhPasswordInputField=NULL;/* Password input field */volatileHWNDhVerifyPasswordInputField=NULL;/* Verify-password input field */HBITMAPhbmWizardBitmapRescaled=NULL;wchar_tOrigKeyboardLayout[8+1]=L"00000409";BOOLbKeyboardLayoutChanged=FALSE;/* TRUE if the keyboard layout was changed to the standard US keyboard layout (from any other layout). */BOOLbKeybLayoutAltKeyWarningShown=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 _DEBUGBOOLbWarnDeviceFormatAdvanced=TRUE;#elseBOOLbWarnDeviceFormatAdvanced=FALSE;#endifBOOLbWarnOuterVolSuitableFileSys=TRUE;PasswordvolumePassword;/* User password */charszVerify[MAX_PASSWORD+1];/* Tmp password buffer */charszRawPassword[MAX_PASSWORD+1];/* Password before keyfile was applied to it */intvolumePim=0;BOOLbHistoryCmdLine=FALSE;/* History control is always disabled */BOOLComServerMode=FALSE;PasswordCmdVolumePassword={0};/* Password passed from command line */intCmdVolumeEA=0;intCmdVolumePkcs5=0;intCmdVolumePim=0;intCmdVolumeFilesystem=FILESYS_NONE;unsigned__int64CmdVolumeFileSize=0;BOOLCmdSparseFileSwitch=FALSE;BOOLbForceOperation=FALSE;BOOLbOperationSuccess=FALSE;BOOLbGuiMode=TRUE;BOOLbSystemIsGPT=FALSE;intnPbar=0;/* Control ID of progress bar:- for format code */wchar_tHeaderKeyGUIView[KEY_GUI_VIEW_SIZE];wchar_tMasterKeyGUIView[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)unsignedcharrandPool[RANDPOOL_DISPLAY_BYTE_PORTION];unsignedcharlastRandPool[RANDPOOL_DISPLAY_BYTE_PORTION];staticunsignedcharmaskRandPool[RANDPOOL_DISPLAY_BYTE_PORTION];staticBOOLbUseMask=FALSE;staticDWORDmouseEntropyGathered=0xFFFFFFFF;staticDWORDmouseEventsInitialCount=0;/* max value of entropy needed to fill all random pool = 8 * RNG_POOL_SIZE = 2560 bits */staticconstDWORDmaxEntropyLevel=RNG_POOL_SIZE*8;staticHWNDhEntropyBar=NULL;wchar_toutRandPoolDispBuffer[RANDPOOL_DISPLAY_SIZE];BOOLbDisplayPoolContents=TRUE;volatileBOOLbSparseFileSwitch=FALSE;volatileBOOLquickFormat=FALSE;/* WARNING: Meaning of this variable depends on bSparseFileSwitch. If bSparseFileSwitch is TRUE, this variable represents the sparse file flag. */volatileintfileSystem=FILESYS_NONE;volatileintclusterSize=0;SYSENC_MULTIBOOT_CFGSysEncMultiBootCfg;wchar_tSysEncMultiBootCfgOutcome[4096]={L'N',L'/',L'A',0};volatileintNonSysInplaceEncStatus=NONSYS_INPLACE_ENC_STATUS_NONE;vector<HostDevice>DeferredNonSysInPlaceEncDevices;// specific definitions and implementation for support of resume operation// in wait dialog mechanismvoidCALLBACKResumeInPlaceEncWaitThreadProc(void*pArg,HWNDhwndDlg){wchar_tszDevicePath[MAX_PATH]={0};RawDevicesDlgParamparam;param.devices=GetAvailableHostDevices(false,true,false);param.pszFileName=szDevicePath;DeferredNonSysInPlaceEncDevices.clear();if((IDOK==DialogBoxParamW(hInst,MAKEINTRESOURCEW(IDD_RAWDEVICES_DLG),hwndDlg,(DLGPROC)RawDevicesDlgProc,(LPARAM)&param))&&wcslen(szDevicePath)){foreach(constHostDevice&device,param.devices){if(device.Path==szDevicePath){OpenVolumeContextvolume;intstatus=OpenVolume(&volume,device.Path.c_str(),&volumePassword,hash_algo,volumePim,FALSE,FALSE,FALSE,TRUE);if(status==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);}elseif(volume.CryptoInfo->EncryptedAreaLength.Value==volume.CryptoInfo->VolumeSize.Value){WCHARszMsg[1024];StringCbPrintfW(szMsg,sizeof(szMsg),GetString("SELECTED_PARTITION_ALREADY_INPLACE_ENC"),volume.CryptoInfo->HeaderFlags);ErrorDirect(szMsg,hwndDlg);}else{WCHARszMsg[1024];StringCbPrintfW(szMsg,sizeof(szMsg),GetString("SELECTED_PARTITION_NOT_INPLACE_ENC"),volume.CryptoInfo->HeaderFlags);ErrorDirect(szMsg,hwndDlg);}CloseVolume(&volume);}else{handleError(hwndDlg,status,SRC_POS);}break;}}}else{foreach(constHostDevice&device,param.devices){if(!device.ContainsSystem&&(device.IsPartition||device.DynamicVolume||device.IsVirtualPartition||device.Partitions.empty())){OpenVolumeContextvolume;if(OpenVolume(&volume,device.Path.c_str(),&volumePassword,hash_algo,volumePim,FALSE,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);}}}}}staticBOOLElevateWholeWizardProcess(wstringarguments){wchar_tmodPath[MAX_PATH];if(IsAdmin())returnTRUE;if(!IsUacSupported())returnIsAdmin();GetModuleFileName(NULL,modPath,ARRAYSIZE(modPath));while(true){if((int)ShellExecute(MainDlg,L"runas",modPath,(wstring(L"/q UAC ")+arguments).c_str(),NULL,SW_SHOWNORMAL)>32){exit(0);}else{if(IDRETRY==ErrorRetryCancel("UAC_INIT_ERROR",MainDlg))continue;returnFALSE;}}}staticvoidWipePasswordsAndKeyfiles(void){wchar_ttmp[MAX_PASSWORD+1];// Attempt to wipe passwords stored in the input field bufferswmemset(tmp,L'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));burn(&volumePim,sizeof(volumePim));burn(&CmdVolumePassword,sizeof(CmdVolumePassword));burn(&CmdVolumePim,sizeof(CmdVolumePim));SetWindowText(hPasswordInputField,L"");SetWindowText(hVerifyPasswordInputField,L"");KeyFileRemoveAll(&FirstKeyFile);KeyFileRemoveAll(&defaultKeyFilesParam.FirstKeyFile);}staticvoidlocalcleanup(void){wchar_ttmp[RANDPOOL_DISPLAY_SIZE+1];// System encryptionif(WizardMode==WIZARD_MODE_SYS_DEVICE&&InstanceHasSysEncMutex()){try{BootEncStatus=BootEncObj->GetStatus();if(BootEncStatus.SetupInProgress){BootEncObj->AbortSetup();}}catch(...){// NOP}}// Mon-system in-place encryptionif(bInPlaceEncNonSys&&(bVolTransformThreadRunning||bVolTransformThreadToRun)){NonSysInplaceEncPause();}CloseNonSysInplaceEncMutex();// Device wipeif(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(&mouseEntropyGathered,sizeof(mouseEntropyGathered));burn(&mouseEventsInitialCount,sizeof(mouseEventsInitialCount));burn(maskRandPool,sizeof(maskRandPool));burn(szFileName,sizeof(szFileName));burn(szDiskFile,sizeof(szDiskFile));// Attempt to wipe the GUI fields showing portions of randpool, of the master and header keyswmemset(tmp,L'X',ARRAYSIZE(tmp));tmp[ARRAYSIZE(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 resourcescleanup();if(BootEncObj!=NULL){deleteBootEncObj;BootEncObj=NULL;}}staticBOOLCALLBACKBroadcastSysEncCfgUpdateCallb(HWNDhwnd,LPARAMlParam){LONG_PTRuserDataVal=GetWindowLongPtrW(hwnd,GWLP_USERDATA);if((userDataVal==(LONG_PTR)'VERA')||(userDataVal==(LONG_PTR)'TRUE'))// Prior to 1.0e, 'TRUE' was used for VeraCrypt dialogs{wchar_tname[1024]={0};GetWindowText(hwnd,name,ARRAYSIZE(name)-1);if(hwnd!=MainDlg&&wcsstr(name,L"VeraCrypt")){PostMessage(hwnd,TC_APPMSG_SYSENC_CONFIG_UPDATE,0,0);}}returnTRUE;}staticBOOLBroadcastSysEncCfgUpdate(void){BOOLbSuccess=FALSE;EnumWindows(BroadcastSysEncCfgUpdateCallb,(LPARAM)&bSuccess);returnbSuccess;}// IMPORTANT: This function may be called only by Format (other modules can only _read_ the system encryption config).// Returns TRUE if successful (otherwise FALSE)staticBOOLSaveSysEncSettings(HWNDhwndDlg){FILE*f;if(!bSystemEncryptionStatusChanged)returnTRUE;if(hwndDlg==NULL&&MainDlg!=NULL)hwndDlg=MainDlg;if(!CreateSysEncMutex())returnFALSE;// Only one instance that has the mutex can modify the system encryption settingsif(SystemEncryptionStatus==SYSENC_STATUS_NONE){if(_wremove(GetConfigPath(TC_APPD_FILENAME_SYSTEM_ENCRYPTION))!=0){Error("CANNOT_SAVE_SYS_ENCRYPTION_SETTINGS",hwndDlg);returnFALSE;}bSystemEncryptionStatusChanged=FALSE;BroadcastSysEncCfgUpdate();returnTRUE;}f=_wfopen(GetConfigPath(TC_APPD_FILENAME_SYSTEM_ENCRYPTION),L"w,ccs=UTF-8");if(f==NULL){Error("CANNOT_SAVE_SYS_ENCRYPTION_SETTINGS",hwndDlg);handleWin32Error(hwndDlg,SRC_POS);returnFALSE;}if(XmlWriteHeader(f)<0||fputws(L"\n\t<sysencryption>",f)<0||fwprintf(f,L"\n\t\t<config key=\"SystemEncryptionStatus\">%d</config>",SystemEncryptionStatus)<0||fwprintf(f,L"\n\t\t<config key=\"WipeMode\">%d</config>",(int)nWipeMode)<0||fputws(L"\n\t</sysencryption>",f)<0||XmlWriteFooter(f)<0){handleWin32Error(hwndDlg,SRC_POS);fclose(f);Error("CANNOT_SAVE_SYS_ENCRYPTION_SETTINGS",hwndDlg);returnFALSE;}TCFlushFile(f);fclose(f);bSystemEncryptionStatusChanged=FALSE;BroadcastSysEncCfgUpdate();returnTRUE;}// WARNING: This function may take a long time to finishstaticunsignedintDetermineHiddenOSCreationPhase(void){unsignedintphase=TC_HIDDEN_OS_CREATION_PHASE_NONE;try{phase=BootEncObj->GetHiddenOSCreationPhase();}catch(Exception&e){e.Show(MainDlg);AbortProcess("ERR_GETTING_SYSTEM_ENCRYPTION_STATUS");}returnphase;}// IMPORTANT: This function may be called only by Format (other modules can only _read_ the status).// Returns TRUE if successful (otherwise FALSE)staticBOOLChangeHiddenOSCreationPhase(intnewPhase){if(!CreateSysEncMutex()){Error("SYSTEM_ENCRYPTION_IN_PROGRESS_ELSEWHERE",MainDlg);returnFALSE;}try{BootEncObj->SetHiddenOSCreationPhase(newPhase);}catch(Exception&e){e.Show(MainDlg);returnFALSE;}//// 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;returnTRUE;}// IMPORTANT: This function may be called only by Format (other modules can only _read_ the system encryption status).// Returns TRUE if successful (otherwise FALSE)staticBOOLChangeSystemEncryptionStatus(intnewStatus){if(!CreateSysEncMutex()){Error("SYSTEM_ENCRYPTION_IN_PROGRESS_ELSEWHERE",MainDlg);returnFALSE;// 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))returnFALSE;WipeHiddenOSCreationConfig();}if(!SaveSysEncSettings(MainDlg)){returnFALSE;}returnTRUE;}// 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).staticBOOLChangeWizardMode(intnewWizardMode){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",MainDlg);returnFALSE;}}// 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;bInPlaceDecNonSys=FALSE;}if(newWizardMode==WIZARD_MODE_NONSYS_DEVICE&&!IsAdmin()&&IsUacSupported()){if(!ElevateWholeWizardProcess(L"/e"))returnFALSE;}// The contents of the following items may be inappropriate after a change of modeif(!(bInPlaceDecNonSys&&!bInPlaceEncNonSysResumed))// If we are starting (but not resuming) decryption of non-system volume, we actually need szFileName as it contains the command line param.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();}returnTRUE;}// 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.staticBOOLSysEncInEffect(void){return(WizardMode==WIZARD_MODE_SYS_DEVICE||CreatingHiddenSysVol());}staticBOOLCreatingHiddenSysVol(void){return(bHiddenOS&&bHiddenVol&&!bHiddenVolHost);}staticvoidLoadSettingsAndCheckModified(HWNDhwndDlg,BOOLbOnlyCheckModified,BOOL*pbSettingsModified,BOOL*pbHistoryModified){if(!bOnlyCheckModified)EnableHwEncryption((ReadDriverConfigurationFlags()&TC_DRIVER_CONFIG_DISABLE_HARDWARE_ENCRYPTION)?FALSE:TRUE);WipeAlgorithmIdsavedWipeAlgorithm=TC_WIPE_NONE;if(!bOnlyCheckModified)LoadSysEncSettings();if(!bOnlyCheckModified&&LoadNonSysInPlaceEncSettings(&savedWipeAlgorithm)!=0)bInPlaceEncNonSysPending=TRUE;if(!bOnlyCheckModified)defaultKeyFilesParam.EnableKeyFiles=FALSE;ConfigReadCompareInt("StartOnLogon",FALSE,&bStartOnLogon,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("HiddenSectorDetectionStatus",0,&HiddenSectorDetectionStatus,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("ShowDisconnectedNetworkDrives",FALSE,&bShowDisconnectedNetworkDrives,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("HideWaitingDialog",FALSE,&bHideWaitingDialog,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("SaveVolumeHistory",FALSE,&bHistory,bOnlyCheckModified,pbSettingsModified);{charszTmp[MAX_PATH]={0};WideCharToMultiByte(CP_UTF8,0,SecurityTokenLibraryPath,-1,szTmp,MAX_PATH,NULL,NULL);ConfigReadCompareString("SecurityTokenLibrary","",szTmp,sizeof(szTmp)-1,bOnlyCheckModified,pbSettingsModified);MultiByteToWideChar(CP_UTF8,0,szTmp,-1,SecurityTokenLibraryPath,ARRAYSIZE(SecurityTokenLibraryPath));if(!bOnlyCheckModified&&SecurityTokenLibraryPath[0])InitSecurityTokenLibrary(hwndDlg);}if(bOnlyCheckModified){charlangid[6]={0};if(!IsNonInstallMode()){ConfigReadString("Language","",langid,sizeof(langid));// when installed, if no preferred language set by user, English is selected defaultif(langid[0]==0)StringCbCopyA(langid,sizeof(langid),"en");if(pbSettingsModified&&strcmp(langid,GetPreferredLangId()))*pbSettingsModified=TRUE;}else{StringCbCopyA(langid,sizeof(langid),GetPreferredLangId());ConfigReadCompareString("Language","",langid,sizeof(langid),TRUE,pbSettingsModified);}}if(hwndDlg!=NULL){LoadCombo(GetDlgItem(hwndDlg,IDC_COMBO_BOX),bHistory,bOnlyCheckModified,pbHistoryModified);return;}if(bHistoryCmdLine)return;}staticvoidLoadSettings(HWNDhwndDlg){LoadSettingsAndCheckModified(hwndDlg,FALSE,NULL,NULL);}staticvoidSaveSettings(HWNDhwndDlg){WaitCursor();// Check first if modifications ocurred before writing to the settings and history files// This avoids leaking information about VeraCrypt usage when user only mount volumes without changing setttings or historyBOOLbSettingsChanged=FALSE;BOOLbHistoryChanged=FALSE;LoadSettingsAndCheckModified(hwndDlg,TRUE,&bSettingsChanged,&bHistoryChanged);if(bHistoryChanged&&hwndDlg!=NULL)DumpCombo(GetDlgItem(hwndDlg,IDC_COMBO_BOX),!bHistory);if(bSettingsChanged){ConfigWriteBegin();ConfigWriteInt("StartOnLogon",bStartOnLogon);ConfigWriteInt("HiddenSectorDetectionStatus",HiddenSectorDetectionStatus);ConfigWriteInt("SaveVolumeHistory",bHistory);ConfigWriteStringW("SecurityTokenLibrary",SecurityTokenLibraryPath[0]?SecurityTokenLibraryPath:L"");ConfigWriteString("Language",GetPreferredLangId());ConfigWriteEnd(hwndDlg);}NormalCursor();}// WARNING: This function does NOT cause immediate application exit (use e.g. return 1 after calling it// from a DialogProc function).staticvoidEndMainDlg(HWNDhwndDlg){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 completedstaticBOOLSysEncryptionOrDecryptionRequired(void){/* If you update this function, revise SysEncryptionOrDecryptionRequired() in Mount.c as well. */staticBootEncryptionStatuslocBootEncStatus;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 encryptedstaticBOOLSysDriveOrPartitionFullyEncrypted(BOOLbSilent){/* If you update this function, revise SysDriveOrPartitionFullyEncrypted() in Mount.c as well. */staticBootEncryptionStatuslocBootEncStatus;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).BOOLSwitchWizardToSysEncMode(void){WaitCursor();SystemDriveConfigurationconfig;try{BootEncStatus=BootEncObj->GetStatus();bWholeSysDrive=BootEncObj->SystemPartitionCoversWholeDrive();config=BootEncObj->GetSystemDriveConfiguration();}catch(Exception&e){e.Show(MainDlg);Error("ERR_GETTING_SYSTEM_ENCRYPTION_STATUS",MainDlg);NormalCursor();returnFALSE;}// From now on, we should be the only instance of the TC wizard allowed to deal with system encryptionif(!CreateSysEncMutex()){Warning("SYSTEM_ENCRYPTION_IN_PROGRESS_ELSEWHERE",MainDlg);NormalCursor();returnFALSE;}// User-mode app may have crashed and its mutex may have gotten lost, so we need to check the driver status tooif(BootEncStatus.SetupInProgress){if(AskWarnYesNo("SYSTEM_ENCRYPTION_RESUME_PROMPT",MainDlg)==IDYES){if(SystemEncryptionStatus!=SYSENC_STATUS_ENCRYPTING&&SystemEncryptionStatus!=SYSENC_STATUS_DECRYPTING){// The config file with status was lost or not written correctlyif(!ResolveUnknownSysEncDirection()){CloseSysEncMutex();NormalCursor();returnFALSE;}}bDirectSysEncMode=TRUE;ChangeWizardMode(WIZARD_MODE_SYS_DEVICE);LoadPage(MainDlg,SYSENC_ENCRYPTION_PAGE);NormalCursor();returnTRUE;}else{CloseSysEncMutex();Error("SYS_ENCRYPTION_OR_DECRYPTION_IN_PROGRESS",MainDlg);NormalCursor();returnFALSE;}}if(BootEncStatus.DriveMounted||BootEncStatus.DriveEncrypted||SysEncryptionOrDecryptionRequired()){if(!SysDriveOrPartitionFullyEncrypted(FALSE)&&AskWarnYesNo("SYSTEM_ENCRYPTION_RESUME_PROMPT",MainDlg)==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 cancelif(!ResolveUnknownSysEncDirection()){CloseSysEncMutex();NormalCursor();returnFALSE;}}bDirectSysEncMode=TRUE;ChangeWizardMode(WIZARD_MODE_SYS_DEVICE);LoadPage(MainDlg,SYSENC_ENCRYPTION_PAGE);NormalCursor();returnTRUE;}else{CloseSysEncMutex();Error("SETUP_FAILED_BOOT_DRIVE_ENCRYPTED",MainDlg);NormalCursor();returnFALSE;}}else{// Check compliance with requirements for boot encryptionif(!IsAdmin()){if(!IsUacSupported()){Warning("ADMIN_PRIVILEGES_WARN_DEVICES",MainDlg);}}try{BootEncObj->CheckRequirements();}catch(Exception&e){CloseSysEncMutex();e.Show(MainDlg);NormalCursor();returnFALSE;}if(!ChangeWizardMode(WIZARD_MODE_SYS_DEVICE)){NormalCursor();returnFALSE;}if(bSysDriveSelected||bSysPartitionSelected){// The user selected the non-sys-device wizard mode but then selected a system devicebWholeSysDrive=(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(),MainDlg)==IDYES)bWholeSysDrive=FALSE;}if(!IsOSAtLeast(WIN_VISTA)&&bWholeSysDrive){if(BootEncObj->SystemDriveContainsExtendedPartition()){bWholeSysDrive=FALSE;Error("WDE_UNSUPPORTED_FOR_EXTENDED_PARTITIONS",MainDlg);if(AskYesNo("ASK_ENCRYPT_PARTITION_INSTEAD_OF_DRIVE",MainDlg)==IDNO){ChangeWizardMode(WIZARD_MODE_NONSYS_DEVICE);returnFALSE;}}elseWarning("WDE_EXTENDED_PARTITIONS_WARNING",MainDlg);}}elseif(BootEncObj->SystemPartitionCoversWholeDrive()&&!bWholeSysDrive)bWholeSysDrive=(AskYesNo("WHOLE_SYC_DEVICE_RECOM",MainDlg)==IDYES);}}catch(Exception&e){e.Show(MainDlg);returnFALSE;}if(!bHiddenVol){// Skip SYSENC_SPAN_PAGE and SYSENC_TYPE_PAGE as the user already made the choiceLoadPage(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",MainDlg);bWholeSysDrive=FALSE;LoadPage(MainDlg,SYSENC_TYPE_PAGE);}}elseLoadPage(MainDlg,SYSENC_TYPE_PAGE);NormalCursor();returnTRUE;}}voidSwitchWizardToFileContainerMode(void){ChangeWizardMode(WIZARD_MODE_FILE_CONTAINER);LoadPage(MainDlg,VOLUME_LOCATION_PAGE);NormalCursor();}voidSwitchWizardToNonSysDeviceMode(void){ChangeWizardMode(WIZARD_MODE_NONSYS_DEVICE);LoadPage(MainDlg,VOLUME_TYPE_PAGE);NormalCursor();}BOOLSwitchWizardToHiddenOSMode(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;bInPlaceDecNonSys=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);returnFALSE;}LoadPage(MainDlg,SYSENC_MULTI_BOOT_MODE_PAGE);}elseLoadPage(MainDlg,SYSENC_HIDDEN_OS_REQ_CHECK_PAGE);NormalCursor();}elsereturnTRUE;}elsereturnFALSE;returnTRUE;}voidSwitchWizardToNonSysInplaceEncResumeMode(BOOLbDecrypt){if(!IsAdmin()&&IsUacSupported()){if(!ElevateWholeWizardProcess(bDecrypt?L"/resumeinplacedec":L"/zinplace"))AbortProcessSilent();}if(!IsAdmin())AbortProcess("ADMIN_PRIVILEGES_WARN_DEVICES");CreateNonSysInplaceEncMutex();bInPlaceEncNonSys=TRUE;bInPlaceDecNonSys=bDecrypt;bInPlaceEncNonSysResumed=TRUE;ChangeWizardMode(WIZARD_MODE_NONSYS_DEVICE);LoadPage(MainDlg,NONSYS_INPLACE_ENC_RESUME_PASSWORD_PAGE);}voidSwitchWizardToNonSysInplaceDecStartMode(wchar_t*volPath){if(!IsAdmin()&&IsUacSupported()){if(!ElevateWholeWizardProcess((wstring(L"/inplacedec \"")+volPath+L"\"").c_str()))AbortProcessSilent();}if(!IsAdmin())AbortProcess("ADMIN_PRIVILEGES_WARN_DEVICES");if(!CheckRequirementsForNonSysInPlaceDec(MainDlg,volPath,FALSE))AbortProcessSilent();CreateNonSysInplaceEncMutex();bInPlaceEncNonSys=TRUE;bInPlaceDecNonSys=TRUE;bInPlaceEncNonSysResumed=FALSE;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.staticBOOLResolveUnknownSysEncDirection(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",MainDlg);returnFALSE;}if(BootEncStatus.SetupInProgress){returnChangeSystemEncryptionStatus((BootEncStatus.SetupMode!=SetupDecryption)?SYSENC_STATUS_ENCRYPTING:SYSENC_STATUS_DECRYPTING);}else{// Ask the user to select encryption, decryption, or cancelchar*tmpStr[]={0,!BootEncStatus.DriveEncrypted?"CHOOSE_ENCRYPT_OR_DECRYPT_FINALIZE_DECRYPT_NOTE":"CHOOSE_ENCRYPT_OR_DECRYPT","ENCRYPT","DECRYPT","IDCANCEL",0};switch(AskMultiChoice((void**)tmpStr,FALSE,MainDlg)){case1:returnChangeSystemEncryptionStatus(SYSENC_STATUS_ENCRYPTING);case2:returnChangeSystemEncryptionStatus(SYSENC_STATUS_DECRYPTING);default:returnFALSE;}}}elsereturnTRUE;}else{Error("SYSTEM_ENCRYPTION_IN_PROGRESS_ELSEWHERE",MainDlg);returnFALSE;}}// 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.staticBOOLForceRemoveSysEnc(void){if(CreateSysEncMutex())// If no other instance is currently taking care of system encryption{BootEncryptionStatuslocBootEncStatus;try{locBootEncStatus=BootEncObj->GetStatus();if(locBootEncStatus.SetupInProgress)BootEncObj->AbortSetupWait();locBootEncStatus=BootEncObj->GetStatus();if(locBootEncStatus.DriveMounted){// Remove the headerBootEncObj->StartDecryption(DiscardUnreadableEncryptedSectors);locBootEncStatus=BootEncObj->GetStatus();while(locBootEncStatus.SetupInProgress){Sleep(100);locBootEncStatus=BootEncObj->GetStatus();}BootEncObj->CheckEncryptionSetupResult();}Sleep(50);}catch(Exception&e){e.Show(MainDlg);returnFALSE;}try{locBootEncStatus=BootEncObj->GetStatus();if(!locBootEncStatus.DriveMounted)BootEncObj->Deinstall(true);}catch(Exception&e){e.Show(MainDlg);returnFALSE;}returnTRUE;}elsereturnFALSE;}// Returns 0 if there's an error.__int64GetSystemPartitionSize(void){try{returnBootEncObj->GetSystemDriveConfiguration().SystemPartition.Info.PartitionLength.QuadPart;}catch(Exception&e){e.Show(MainDlg);return0;}}voidComboSelChangeEA(HWNDhwndDlg){intnIndex=(int)SendMessage(GetDlgItem(hwndDlg,IDC_COMBO_BOX),CB_GETCURSEL,0,0);if(nIndex==CB_ERR){SetWindowText(GetDlgItem(hwndDlg,IDC_BOX_HELP),L"");}else{wchar_tname[100];wchar_tauxLine[4096];wchar_thyperLink[256]={0};intcipherIDs[5];inti,cnt=0;nIndex=(int)SendMessage(GetDlgItem(hwndDlg,IDC_COMBO_BOX),CB_GETITEMDATA,nIndex,0);EAGetName(name,nIndex,0);if(wcscmp(name,L"AES")==0){StringCbPrintfW(hyperLink,sizeof(hyperLink)/2,GetString("MORE_INFO_ABOUT"),name);SetWindowTextW(GetDlgItem(hwndDlg,IDC_BOX_HELP),GetString("AES_HELP"));}elseif(wcscmp(name,L"Serpent")==0){StringCbPrintfW(hyperLink,sizeof(hyperLink)/2,GetString("MORE_INFO_ABOUT"),name);SetWindowTextW(GetDlgItem(hwndDlg,IDC_BOX_HELP),GetString("SERPENT_HELP"));}elseif(wcscmp(name,L"Twofish")==0){StringCbPrintfW(hyperLink,sizeof(hyperLink)/2,GetString("MORE_INFO_ABOUT"),name);SetWindowTextW(GetDlgItem(hwndDlg,IDC_BOX_HELP),GetString("TWOFISH_HELP"));}elseif(wcscmp(name,L"Kuznyechik")==0){StringCbPrintfW(hyperLink,sizeof(hyperLink)/2,GetString("MORE_INFO_ABOUT"),name);SetWindowTextW(GetDlgItem(hwndDlg,IDC_BOX_HELP),GetString("KUZNYECHIK_HELP"));}elseif(wcscmp(name,L"Camellia")==0){StringCbPrintfW(hyperLink,sizeof(hyperLink)/2,GetString("MORE_INFO_ABOUT"),name);SetWindowTextW(GetDlgItem(hwndDlg,IDC_BOX_HELP),GetString("CAMELLIA_HELP"));}elseif(EAGetCipherCount(nIndex)>1){// CascadecipherIDs[cnt++]=i=EAGetLastCipher(nIndex);while(i=EAGetPreviousCipher(nIndex,i)){cipherIDs[cnt]=i;cnt++;}switch(cnt)// Number of ciphers in the cascade{case2:StringCbPrintfW(auxLine,sizeof(auxLine),GetString("TWO_LAYER_CASCADE_HELP"),CipherGetName(cipherIDs[1]),CipherGetKeySize(cipherIDs[1])*8,CipherGetName(cipherIDs[0]),CipherGetKeySize(cipherIDs[0])*8);break;case3:StringCbPrintfW(auxLine,sizeof(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;}StringCbCopyW(hyperLink,sizeof(hyperLink),GetString("IDC_LINK_MORE_INFO_ABOUT_CIPHER"));SetWindowTextW(GetDlgItem(hwndDlg,IDC_BOX_HELP),auxLine);}else{// No info available for this encryption algorithmSetWindowTextW(GetDlgItem(hwndDlg,IDC_BOX_HELP),L"");}// Update hyperlinkSetWindowTextW(GetDlgItem(hwndDlg,IDC_LINK_MORE_INFO_ABOUT_CIPHER),hyperLink);AccommodateTextField(hwndDlg,IDC_LINK_MORE_INFO_ABOUT_CIPHER,FALSE,hUserUnderlineFont);}}staticvoidVerifySizeAndUpdate(HWNDhwndDlg,BOOLbUpdate){BOOLbEnable=TRUE;wchar_tszTmp[50];__int64lTmp;__int64i;staticunsigned__int64nLastVolumeSize=0;GetWindowText(GetDlgItem(hwndDlg,IDC_SIZEBOX),szTmp,ARRAYSIZE(szTmp));for(i=0;i<(__int64)wcslen(szTmp);i++){if(szTmp[i]>=L'0'&&szTmp[i]<=L'9')continue;else{bEnable=FALSE;break;}}if(IsButtonChecked(GetDlgItem(hwndDlg,IDC_KB)))nMultiplier=BYTES_PER_KB;elseif(IsButtonChecked(GetDlgItem(hwndDlg,IDC_MB)))nMultiplier=BYTES_PER_MB;elseif(IsButtonChecked(GetDlgItem(hwndDlg,IDC_GB)))nMultiplier=BYTES_PER_GB;elsenMultiplier=BYTES_PER_TB;if(bDevice&&!(bHiddenVol&&!bHiddenVolHost))// If raw device but not a hidden volume{lTmp=nVolumeSize;i=1;}else{i=nMultiplier;lTmp=_wtoi64(szTmp);DWORDsectorSize=GetFormatSectorSize();uint32sectorSizeRem=(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 volumenVolumeSize=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;}}staticvoidUpdateWizardModeControls(HWNDhwndDlg,intsetWizardMode){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);}staticintGetSelectedWizardMode(HWNDhwndDlg){if(IsButtonChecked(GetDlgItem(hwndDlg,IDC_FILE_CONTAINER)))returnWIZARD_MODE_FILE_CONTAINER;if(IsButtonChecked(GetDlgItem(hwndDlg,IDC_NONSYS_DEVICE)))returnWIZARD_MODE_NONSYS_DEVICE;if(IsButtonChecked(GetDlgItem(hwndDlg,IDC_SYS_DEVICE)))returnWIZARD_MODE_SYS_DEVICE;returnDEFAULT_VOL_CREATION_WIZARD_MODE;}staticvoidRefreshMultiBootControls(HWNDhwndDlg){#ifdef DEBUGif(nMultiBoot==0)nMultiBoot=1;#endif// For now, we force single configuration in wizardif(bSystemIsGPT&&nMultiBoot==0)nMultiBoot=1;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 = YesstaticintGet2RadButtonPageAnswer(void){if(IsButtonChecked(GetDlgItem(hCurPage,IDC_CHOICE1)))return1;if(IsButtonChecked(GetDlgItem(hCurPage,IDC_CHOICE2)))return0;return-1;}// 0 = No, 1 = YesstaticvoidUpdate2RadButtonPage(intanswer){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 = YesstaticvoidInit2RadButtonPageYesNo(intanswer){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);}staticvoidUpdateSysEncProgressBar(void){BootEncryptionStatuslocBootEncStatus;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_ttmpStr[100];// Statusif(locBootEncStatus.TransformWaitingForIdle)StringCbCopyW(tmpStr,sizeof(tmpStr),GetString("PROGRESS_STATUS_WAITING"));elseStringCbCopyW(tmpStr,sizeof(tmpStr),GetString(SystemEncryptionStatus==SYSENC_STATUS_DECRYPTING?"PROGRESS_STATUS_DECRYPTING":"PROGRESS_STATUS_ENCRYPTING"));StringCbCatW(tmpStr,sizeof(tmpStr),L" ");SetWindowTextW(GetDlgItem(hCurPage,IDC_WRITESPEED),tmpStr);}}}staticvoidInitSysEncProgressBar(void){BootEncryptionStatuslocBootEncStatus;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);}staticvoidUpdateSysEncControls(void){BootEncryptionStatuslocBootEncStatus;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_ttmpStr[100];StringCbCopyW(tmpStr,sizeof(tmpStr),GetString((SysDriveOrPartitionFullyEncrypted(TRUE)||!locBootEncStatus.DriveMounted)?"PROGRESS_STATUS_FINISHED":"PROGRESS_STATUS_PAUSED"));StringCbCatW(tmpStr,sizeof(tmpStr),L" ");// StatusSetWindowTextW(GetDlgItem(hCurPage,IDC_WRITESPEED),tmpStr);if(SysDriveOrPartitionFullyEncrypted(TRUE)||SystemEncryptionStatus==SYSENC_STATUS_NONE){StringCbCopyW(tmpStr,sizeof(tmpStr),GetString("PROCESSED_PORTION_100_PERCENT"));StringCbCatW(tmpStr,sizeof(tmpStr),L" ");SetWindowTextW(GetDlgItem(hCurPage,IDC_BYTESWRITTEN),tmpStr);}SetWindowText(GetDlgItem(hCurPage,IDC_TIMEREMAIN),L" ");}}staticvoidSysEncPause(void){BootEncryptionStatuslocBootEncStatus;if(CreateSysEncMutex()){EnableWindow(GetDlgItem(hCurPage,IDC_PAUSE),FALSE);try{locBootEncStatus=BootEncObj->GetStatus();}catch(Exception&e){e.Show(MainDlg);Error("ERR_GETTING_SYSTEM_ENCRYPTION_STATUS",MainDlg);EnableWindow(GetDlgItem(hCurPage,IDC_PAUSE),TRUE);return;}if(!locBootEncStatus.SetupInProgress){EnableWindow(GetDlgItem(hCurPage,IDC_PAUSE),TRUE);return;}WaitCursor();try{intattempts=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",MainDlg);return;}UpdateSysEncControls();EnableWindow(GetDlgItem(hCurPage,IDC_PAUSE),TRUE);}elseError("SYSTEM_ENCRYPTION_IN_PROGRESS_ELSEWHERE",MainDlg);}staticvoidSysEncResume(void){BootEncryptionStatuslocBootEncStatus;if(CreateSysEncMutex()){EnableWindow(GetDlgItem(hCurPage,IDC_PAUSE),FALSE);try{locBootEncStatus=BootEncObj->GetStatus();}catch(Exception&e){e.Show(MainDlg);Error("ERR_GETTING_SYSTEM_ENCRYPTION_STATUS",MainDlg);EnableWindow(GetDlgItem(hCurPage,IDC_PAUSE),TRUE);return;}if(locBootEncStatus.SetupInProgress){// Prevent the OS from entering Sleep mode when idleSetThreadExecutionState(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;}bVolTransformThreadCancel=FALSE;bSystemEncryptionInProgress=FALSE;WaitCursor();try{switch(SystemEncryptionStatus){caseSYSENC_STATUS_ENCRYPTING:BootEncObj->StartEncryption(nWipeMode,bTryToCorrectReadErrors?true:false);break;caseSYSENC_STATUS_DECRYPTING:if(locBootEncStatus.DriveMounted)// If the drive is not encrypted we will just deinstallBootEncObj->StartDecryption(DiscardUnreadableEncryptedSectors);break;}bSystemEncryptionInProgress=TRUE;}catch(Exception&e){e.Show(MainDlg);}NormalCursor();if(!bSystemEncryptionInProgress){// Allow the OS to enter Sleep mode when idleSetThreadExecutionState(ES_CONTINUOUS);EnableWindow(GetDlgItem(hCurPage,IDC_PAUSE),TRUE);Error("FAILED_TO_RESUME_SYSTEM_ENCRYPTION",MainDlg);return;}// Prevent the OS from entering Sleep mode when idleSetThreadExecutionState(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);}elseError("SYSTEM_ENCRYPTION_IN_PROGRESS_ELSEWHERE",MainDlg);}staticBOOLGetDevicePathForHiddenOS(void){BOOLtmpbDevice=FALSE;try{StringCbCopyW(szFileName,sizeof(szFileName),BootEncObj->GetPartitionForHiddenOS().DevicePath.c_str());CreateFullVolumePath(szDiskFile,sizeof(szDiskFile),szFileName,&tmpbDevice);}catch(Exception&e){e.Show(MainDlg);returnFALSE;}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.staticBOOLCheckGapBetweenSysAndHiddenOS(void){try{SystemDriveConfigurationsysDriveCfg=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);}returnFALSE;}staticvoidNonSysInplaceEncPause(void){bVolTransformThreadCancel=TRUE;WaitCursor();intwaitThreshold=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){MSGguiMsg;bVolTransformThreadCancel=TRUE;if(waitThreshold<=0){while(PeekMessageW(&guiMsg,NULL,0,0,PM_REMOVE)!=0){DispatchMessageW(&guiMsg);}}elsewaitThreshold--;Sleep(100);}}staticvoidNonSysInplaceEncResume(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;}voidShowNonSysInPlaceEncUIStatus(void){wchar_tnonSysInplaceEncUIStatus[300]={0};switch(NonSysInplaceEncStatus){caseNONSYS_INPLACE_ENC_STATUS_PAUSED:StringCbCopyW(nonSysInplaceEncUIStatus,sizeof(nonSysInplaceEncUIStatus),GetString("PROGRESS_STATUS_PAUSED"));break;caseNONSYS_INPLACE_ENC_STATUS_PREPARING:StringCbCopyW(nonSysInplaceEncUIStatus,sizeof(nonSysInplaceEncUIStatus),GetString("PROGRESS_STATUS_PREPARING"));break;caseNONSYS_INPLACE_ENC_STATUS_RESIZING:StringCbCopyW(nonSysInplaceEncUIStatus,sizeof(nonSysInplaceEncUIStatus),GetString("PROGRESS_STATUS_RESIZING"));break;caseNONSYS_INPLACE_ENC_STATUS_ENCRYPTING:StringCbCopyW(nonSysInplaceEncUIStatus,sizeof(nonSysInplaceEncUIStatus),GetString("PROGRESS_STATUS_ENCRYPTING"));break;caseNONSYS_INPLACE_ENC_STATUS_DECRYPTING:StringCbCopyW(nonSysInplaceEncUIStatus,sizeof(nonSysInplaceEncUIStatus),GetString("PROGRESS_STATUS_DECRYPTING"));break;caseNONSYS_INPLACE_ENC_STATUS_FINALIZING:StringCbCopyW(nonSysInplaceEncUIStatus,sizeof(nonSysInplaceEncUIStatus),GetString("PROGRESS_STATUS_FINALIZING"));break;caseNONSYS_INPLACE_ENC_STATUS_FINISHED:StringCbCopyW(nonSysInplaceEncUIStatus,sizeof(nonSysInplaceEncUIStatus),GetString("PROGRESS_STATUS_FINISHED"));break;caseNONSYS_INPLACE_ENC_STATUS_ERROR:StringCbCopyW(nonSysInplaceEncUIStatus,sizeof(nonSysInplaceEncUIStatus),GetString("PROGRESS_STATUS_ERROR"));break;}StringCbCatW(nonSysInplaceEncUIStatus,sizeof(nonSysInplaceEncUIStatus),L" ");SetWindowTextW(GetDlgItem(hCurPage,IDC_WRITESPEED),nonSysInplaceEncUIStatus);}voidUpdateNonSysInPlaceEncControls(void){// Reduce flickering by updating a GUI element only when a relevant change affects itstaticBOOLlastbVolTransformThreadRunning=!bVolTransformThreadRunning;staticBOOLlastbVolTransformThreadToRun=!bVolTransformThreadToRun;staticBOOLlastbInPlaceEncNonSysResumed=!bInPlaceEncNonSysResumed;EnableWindow(GetDlgItem(hCurPage,IDC_WIPE_MODE),!(bVolTransformThreadRunning||bVolTransformThreadToRun)&&!bInPlaceDecNonSys);if(lastbVolTransformThreadRunning!=bVolTransformThreadRunning||lastbVolTransformThreadToRun!=bVolTransformThreadToRun){SetWindowTextW(GetDlgItem(hCurPage,IDC_PAUSE),GetString((bVolTransformThreadRunning||bVolTransformThreadToRun)?"IDC_PAUSE":"RESUME"));lastbVolTransformThreadRunning=bVolTransformThreadRunning;lastbVolTransformThreadToRun=bVolTransformThreadToRun;}if(lastbInPlaceEncNonSysResumed!=bInPlaceEncNonSysResumed){SetWindowTextW(GetDlgItem(MainDlg,IDCANCEL),GetString(bInPlaceEncNonSysResumed?"DEFER":"CANCEL"));lastbInPlaceEncNonSysResumed=bInPlaceEncNonSysResumed;}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){caseNONSYS_INPLACE_ENC_STATUS_PREPARING:caseNONSYS_INPLACE_ENC_STATUS_RESIZING:caseNONSYS_INPLACE_ENC_STATUS_FINALIZING:ArrowWaitCursor();break;caseNONSYS_INPLACE_ENC_STATUS_ENCRYPTING:NormalCursor();break;default:NormalCursor();break;}if(bVolTransformThreadCancel)WaitCursor();}else{NormalCursor();if(bInPlaceEncNonSysResumed){SetNonSysInplaceEncUIStatus(NONSYS_INPLACE_ENC_STATUS_PAUSED);}elseSetWindowText(GetDlgItem(hCurPage,IDC_WRITESPEED),L" ");SetWindowText(GetDlgItem(hCurPage,IDC_TIMEREMAIN),L" ");}ShowNonSysInPlaceEncUIStatus();UpdateNonSysInplaceEncProgressBar();}staticvoidUpdateNonSysInplaceEncProgressBar(void){staticintlastNonSysInplaceEncStatus=NONSYS_INPLACE_ENC_STATUS_NONE;intnonSysInplaceEncStatus=NonSysInplaceEncStatus;__int64totalSize=NonSysInplaceEncTotalSize;if(bVolTransformThreadRunning&&(nonSysInplaceEncStatus==NONSYS_INPLACE_ENC_STATUS_ENCRYPTING||nonSysInplaceEncStatus==NONSYS_INPLACE_ENC_STATUS_DECRYPTING||nonSysInplaceEncStatus==NONSYS_INPLACE_ENC_STATUS_FINALIZING||nonSysInplaceEncStatus==NONSYS_INPLACE_ENC_STATUS_FINISHED)){if(lastNonSysInplaceEncStatus!=nonSysInplaceEncStatus&&(nonSysInplaceEncStatus==NONSYS_INPLACE_ENC_STATUS_ENCRYPTING||nonSysInplaceEncStatus==NONSYS_INPLACE_ENC_STATUS_DECRYPTING)){InitNonSysInplaceEncProgressBar();}else{if(totalSize<=0&&nVolumeSize>0)totalSize=nVolumeSize;if(totalSize>0)UpdateProgressBarProc(NonSysInplaceEncBytesDone);}}ShowNonSysInPlaceEncUIStatus();lastNonSysInplaceEncStatus=nonSysInplaceEncStatus;}staticvoidInitNonSysInplaceEncProgressBar(void){__int64totalSize=NonSysInplaceEncTotalSize;if(totalSize<=0){if(nVolumeSize<=0)return;totalSize=nVolumeSize;}InitProgressBar(totalSize,NonSysInplaceEncBytesDone,bInPlaceDecNonSys,TRUE,TRUE,TRUE);}voidDisplayRandPool(HWNDhwndDlg,HWNDhPoolDisplay,BOOLbShow){wchar_ttmp[4];unsignedchartmpByte;intcol,row;staticBOOLbRandPoolDispAscii=FALSE;DWORDmouseEventsCounter;RandpeekBytes(hwndDlg,randPool,sizeof(randPool),&mouseEventsCounter);ProcessEntropyEstimate(hEntropyBar,&mouseEventsInitialCount,mouseEventsCounter,maxEntropyLevel,&mouseEntropyGathered);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++){if(bShow){tmpByte=randPool[row*RANDPOOL_DISPLAY_COLUMNS+col];StringCbPrintfW(tmp,sizeof(tmp),bRandPoolDispAscii?((tmpByte>=32&&tmpByte<255&&tmpByte!=L'&')?L" %c ":L" . "):L"%02X ",tmpByte);}elseif(bUseMask){/* use mask to compute a randomized ASCII representation */tmpByte=(randPool[row*RANDPOOL_DISPLAY_COLUMNS+col]-lastRandPool[row*RANDPOOL_DISPLAY_COLUMNS+col])^maskRandPool[row*RANDPOOL_DISPLAY_COLUMNS+col];tmp[0]=(wchar_t)(((tmpByte>>4)%6)+L'*');tmp[1]=(wchar_t)(((tmpByte&0x0F)%6)+L'*');tmp[2]=L' ';tmp[3]=0;}else{StringCbCopyW(tmp,sizeof(tmp),L"** ");}StringCbCatW(outRandPoolDispBuffer,sizeof(outRandPoolDispBuffer),tmp);}StringCbCatW(outRandPoolDispBuffer,sizeof(outRandPoolDispBuffer),L"\n");}SetWindowText(hPoolDisplay,outRandPoolDispBuffer);memcpy(lastRandPool,randPool,sizeof(lastRandPool));}}voidDisplayPortionsOfKeys(HWNDheaderKeyHandle,HWNDmasterKeyHandle,wchar_t*headerKeyStr,wchar_t*masterKeyStr,BOOLhideKeys){constwchar_t*hiddenKey=L"******************************** ";SetWindowTextW(headerKeyHandle,hideKeys?hiddenKey:(std::wstring(headerKeyStr)+GetString("TRIPLE_DOT_GLYPH_ELLIPSIS")).c_str());SetWindowTextW(masterKeyHandle,hideKeys?hiddenKey:(std::wstring(masterKeyStr)+GetString("TRIPLE_DOT_GLYPH_ELLIPSIS")).c_str());}staticvoidWipeAbort(void){EnableWindow(GetDlgItem(hCurPage,IDC_ABORT_BUTTON),FALSE);if(bHiddenOS&&IsHiddenOSRunning()){/* Decoy system partition wipe */DecoySystemWipeStatusdecoySysPartitionWipeStatus;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{intattempts=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",MainDlg);return;}}else{/* Regular device wipe (not decoy system partition wipe) */}UpdateWipeControls();EnableWindow(GetDlgItem(hCurPage,IDC_ABORT_BUTTON),TRUE);}staticvoidWipeStart(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",MainDlg);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);}staticvoidUpdateWipeProgressBar(void){if(bHiddenOS&&IsHiddenOSRunning()){/* Decoy system partition wipe */DecoySystemWipeStatusdecoySysPartitionWipeStatus;try{decoySysPartitionWipeStatus=BootEncObj->GetDecoyOSWipeStatus();BootEncStatus=BootEncObj->GetStatus();}catch(...){return;}if(decoySysPartitionWipeStatus.WipedAreaEnd==-1)UpdateProgressBarProc(0);elseUpdateProgressBarProc(decoySysPartitionWipeStatus.WipedAreaEnd-BootEncStatus.ConfiguredEncryptedAreaStart+1);}else{/* Regular device wipe (not decoy system partition wipe) */}}staticvoidInitWipeProgressBar(void){if(bHiddenOS&&IsHiddenOSRunning()){/* Decoy system partition wipe */DecoySystemWipeStatusdecoySysPartitionWipeStatus;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) */}}staticvoidUpdateWipeControls(void){if(bHiddenOS&&IsHiddenOSRunning()){/* Decoy system partition wipe */DecoySystemWipeStatusdecoySysPartitionWipeStatus;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),L" ");}}EnableWindow(GetDlgItem(hCurPage,IDC_ABORT_BUTTON),bDeviceWipeInProgress);EnableWindow(GetDlgItem(MainDlg,IDC_PREV),!bDeviceWipeInProgress);bConfirmQuit=bDeviceWipeInProgress;}staticvoid__cdeclsysEncDriveAnalysisThread(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 completedHiddenSectorDetectionStatus=0;SaveSettings(NULL);BroadcastSysEncCfgUpdate();// This artificial delay prevents user confusion on systems where the analysis ends almost instantlySleep(3000);bSysEncDriveAnalysisInProgress=FALSE;}staticvoid__cdeclvolTransformThreadFunction(void*hwndDlgArg){intnStatus;DWORDdwWin32FormatError;BOOLbHidden;HWNDhwndDlg=(HWND)hwndDlgArg;volatileFORMAT_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));bOperationSuccess=FALSE;if(bGuiMode){bVolTransformThreadRunning=TRUE;bVolTransformThreadToRun=FALSE;}// Check administrator privilegesif(!IsAdmin()&&!IsUacSupported()){if(fileSystem==FILESYS_NTFS||fileSystem==FILESYS_EXFAT||fileSystem==FILESYS_REFS){if(Silent||(MessageBoxW(hwndDlg,GetString("ADMIN_PRIVILEGES_WARN_NTFS"),lpszTitle,MB_OKCANCEL|MB_ICONWARNING|MB_DEFBUTTON2)==IDCANCEL))gotocancel;}if(bDevice){if(Silent||(MessageBoxW(hwndDlg,GetString("ADMIN_PRIVILEGES_WARN_DEVICES"),lpszTitle,MB_OKCANCEL|MB_ICONWARNING|MB_DEFBUTTON2)==IDCANCEL))gotocancel;}}if(!bInPlaceEncNonSys){if(!bDevice){intx=_waccess(szDiskFile,06);if(x==0||errno!=ENOENT){wchar_tszTmp[512];if(!bForceOperation&&!((bHiddenVol&&!bHiddenVolHost)&&errno!=EACCES))// Only ask ask for permission to overwrite an existing volume if we're not creating a hidden volume{StringCbPrintfW(szTmp,sizeofszTmp,GetString(errno==EACCES?"READONLYPROMPT":"OVERWRITEPROMPT"),szDiskFile);x=Silent?IDNO:MessageBoxW(hwndDlg,szTmp,lpszTitle,YES_NO|MB_ICONWARNING|MB_DEFBUTTON2);if(x!=IDYES)gotocancel;}}if(_waccess(szDiskFile,06)!=0){if(errno==EACCES){if(_wchmod(szDiskFile,_S_IREAD|_S_IWRITE)!=0){if(!Silent)MessageBoxW(hwndDlg,GetString("ACCESSMODEFAIL"),lpszTitle,ICON_HAND);gotocancel;}}}}else{// Partition / device / dynamic volumeif(!FinalPreTransformPrompts())gotocancel;}}// Prevent the OS from entering Sleep mode when idleSetThreadExecutionState(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->pim=volumePim;volParams->hwndDlg=hwndDlg;volParams->bForceOperation=bForceOperation;volParams->bGuiMode=bGuiMode;if(bInPlaceDecNonSys){// In-place decryption of non-system volumeif(!bInPlaceEncNonSysResumed)DiscardUnreadableEncryptedSectors=FALSE;nStatus=DecryptPartitionInPlace(volParams,&DiscardUnreadableEncryptedSectors);}elseif(bInPlaceEncNonSys){// In-place encryption of non-system volumeHANDLEhPartition=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);}elseif(hPartition!=INVALID_HANDLE_VALUE){CloseHandle(hPartition);hPartition=INVALID_HANDLE_VALUE;}}else{nStatus=EncryptPartitionInPlaceResume(INVALID_HANDLE_VALUE,volParams,nWipeMode,&bTryToCorrectReadErrors);}}else{// Format-encryptionif(hwndDlg&&bGuiMode)InitProgressBar(GetVolumeDataAreaSize(bHidden,nVolumeSize),0,FALSE,FALSE,FALSE,TRUE);nStatus=TCFormatVolume(volParams);}// Allow the OS to enter Sleep mode when idleSetThreadExecutionState(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/decryption successfully finishednStatus=ERR_SUCCESS;}dwWin32FormatError=GetLastError();if(bHiddenVolHost&&(!bGuiMode||!bVolTransformThreadCancel)&&nStatus==0){/* Auto mount the newly created hidden volume host */switch(MountHiddenVolHost(hwndDlg,szDiskFile,&hiddenVolHostDriveNo,&volumePassword,hash_algo,volumePim,FALSE)){caseERR_NO_FREE_DRIVES:if(!Silent)MessageBoxW(hwndDlg,GetString("NO_FREE_DRIVE_FOR_OUTER_VOL"),lpszTitle,ICON_HAND);if(bGuiMode)bVolTransformThreadCancel=TRUE;break;caseERR_VOL_MOUNT_FAILED:caseERR_PASSWORD_WRONG:if(!Silent)MessageBoxW(hwndDlg,GetString("CANT_MOUNT_OUTER_VOL"),lpszTitle,ICON_HAND);if(bGuiMode)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/decryption successfully finished.{if(!bDevice&&!(bHiddenVol&&!bHiddenVolHost))// If we're not creating a hidden volume and if it's a file container{_wremove(szDiskFile);// Delete the container}gotocancel;}if(nStatus!=ERR_USER_ABORT){if(nStatus!=0){/* An error occurred */wchar_tszMsg[8192];handleError(hwndDlg,nStatus,SRC_POS);if(bInPlaceEncNonSys){if(bInPlaceEncNonSysResumed){SetNonSysInplaceEncUIStatus(NONSYS_INPLACE_ENC_STATUS_PAUSED);Error("INPLACE_ENC_GENERIC_ERR_RESUME",hwndDlg);}else{SetNonSysInplaceEncUIStatus(NONSYS_INPLACE_ENC_STATUS_ERROR);if(bInPlaceDecNonSys)Error("INPLACE_DEC_GENERIC_ERR",hwndDlg);elseShowInPlaceEncErrMsgWAltSteps(hwndDlg,"INPLACE_ENC_GENERIC_ERR_ALT_STEPS",TRUE);}}elseif(!Silent&&!(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){StringCbPrintfW(szMsg,sizeof(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{_wremove(szDiskFile);// Delete the container}gotocancel;}else{/* Volume successfully created */RestoreDefaultKeyFilesParam();PimEnable=FALSE;bOperationSuccess=TRUE;if(bDevice&&!bInPlaceEncNonSys){// Handle assigned drive letter (if any)HandleOldAssignedDriveLetter();}if(!bHiddenVolHost){if(bHiddenVol){bHiddenVolFinished=TRUE;if(!bHiddenOS)Warning("HIDVOL_FORMAT_FINISHED_HELP",hwndDlg);}elseif(bInPlaceEncNonSys){if(!bInPlaceDecNonSys){Warning("NONSYS_INPLACE_ENC_FINISHED_INFO",hwndDlg);HandleOldAssignedDriveLetter();}else{// NOP - Final steps for in-place decryption are handled with the TC_APPMSG_NONSYS_INPLACE_ENC_FINISHED message.}}else{Info("FORMAT_FINISHED_INFO",hwndDlg);if(bSparseFileSwitch&&quickFormat)Warning("SPARSE_FILE_SIZE_NOTE",hwndDlg);}}else{/* We've just created an outer volume (to host a hidden volume within) */bHiddenVolHost=FALSE;bHiddenVolFinished=FALSE;nHiddenVolHostSize=nVolumeSize;// Clear the outer volume passwordburn(&szVerify[0],sizeof(szVerify));burn(&szRawPassword[0],sizeof(szRawPassword));if(!Silent)MessageBeep(MB_OK);}if(!bInPlaceEncNonSys&&hwndDlg&&bGuiMode)SetTimer(hwndDlg,TIMER_ID_RANDVIEW,TIMER_INTERVAL_RANDVIEW,NULL);// volParams is ensured to be non NULL at this stageburn((LPVOID)volParams,sizeof(FORMAT_VOL_PARAMETERS));VirtualUnlock((LPVOID)volParams,sizeof(FORMAT_VOL_PARAMETERS));free((LPVOID)volParams);volParams=NULL;if(bGuiMode){bVolTransformThreadRunning=FALSE;bVolTransformThreadCancel=FALSE;}if(hwndDlg&&bGuiMode)PostMessage(hwndDlg,bInPlaceEncNonSys?TC_APPMSG_NONSYS_INPLACE_ENC_FINISHED:TC_APPMSG_FORMAT_FINISHED,0,0);LastDialogId="FORMAT_FINISHED";if(bGuiMode)_endthread();}}cancel:LastDialogId=(bInPlaceEncNonSys?"NONSYS_INPLACE_ENC_CANCELED":"FORMAT_CANCELED");if(!bInPlaceEncNonSys&&hwndDlg&&bGuiMode)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;}if(bGuiMode){bVolTransformThreadRunning=FALSE;bVolTransformThreadCancel=FALSE;}// Allow the OS to enter Sleep mode when idleSetThreadExecutionState(ES_CONTINUOUS);if(hwndDlg)PostMessage(hwndDlg,TC_APPMSG_VOL_TRANSFORM_THREAD_ENDED,0,0);if(bHiddenVolHost&&hiddenVolHostDriveNo<-1&&!bVolTransformThreadCancel)// If hidden volume host could not be mountedAbortProcessSilent();if(bGuiMode)_endthread();}staticvoidLoadPage(HWNDhwndDlg,intnPageNo){RECTrD,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){casePASSWORD_PAGE:{wchar_ttmp[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.wmemset(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){caseINTRO_PAGE:hCurPage=CreateDialogW(hInst,MAKEINTRESOURCEW(IDD_INTRO_PAGE_DLG),hwndDlg,(DLGPROC)PageDialogProc);break;caseSYSENC_TYPE_PAGE:hCurPage=CreateDialogW(hInst,MAKEINTRESOURCEW(IDD_SYSENC_TYPE_PAGE_DLG),hwndDlg,(DLGPROC)PageDialogProc);break;caseSYSENC_HIDDEN_OS_REQ_CHECK_PAGE:hCurPage=CreateDialogW(hInst,MAKEINTRESOURCEW(IDD_SYSENC_HIDDEN_OS_REQ_CHECK_PAGE_DLG),hwndDlg,(DLGPROC)PageDialogProc);break;caseSYSENC_SPAN_PAGE:hCurPage=CreateDialogW(hInst,MAKEINTRESOURCEW(IDD_SYSENC_SPAN_PAGE_DLG),hwndDlg,(DLGPROC)PageDialogProc);break;caseSYSENC_PRE_DRIVE_ANALYSIS_PAGE:hCurPage=CreateDialogW(hInst,MAKEINTRESOURCEW(IDD_UNIVERSAL_DUAL_CHOICE_PAGE_DLG),hwndDlg,(DLGPROC)PageDialogProc);break;caseSYSENC_DRIVE_ANALYSIS_PAGE:hCurPage=CreateDialogW(hInst,MAKEINTRESOURCEW(IDD_SYSENC_DRIVE_ANALYSIS_PAGE_DLG),hwndDlg,(DLGPROC)PageDialogProc);break;caseSYSENC_MULTI_BOOT_MODE_PAGE:hCurPage=CreateDialogW(hInst,MAKEINTRESOURCEW(IDD_SYSENC_MULTI_BOOT_MODE_PAGE_DLG),hwndDlg,(DLGPROC)PageDialogProc);break;caseSYSENC_MULTI_BOOT_SYS_EQ_BOOT_PAGE:caseSYSENC_MULTI_BOOT_NBR_SYS_DRIVES_PAGE:caseSYSENC_MULTI_BOOT_ADJACENT_SYS_PAGE:caseSYSENC_MULTI_BOOT_NONWIN_BOOT_LOADER_PAGE:hCurPage=CreateDialogW(hInst,MAKEINTRESOURCEW(IDD_UNIVERSAL_DUAL_CHOICE_PAGE_DLG),hwndDlg,(DLGPROC)PageDialogProc);break;caseSYSENC_MULTI_BOOT_OUTCOME_PAGE:hCurPage=CreateDialogW(hInst,MAKEINTRESOURCEW(IDD_INFO_PAGE_DLG),hwndDlg,(DLGPROC)PageDialogProc);break;caseVOLUME_TYPE_PAGE:hCurPage=CreateDialogW(hInst,MAKEINTRESOURCEW(IDD_VOLUME_TYPE_PAGE_DLG),hwndDlg,(DLGPROC)PageDialogProc);break;caseHIDDEN_VOL_WIZARD_MODE_PAGE:hCurPage=CreateDialogW(hInst,MAKEINTRESOURCEW(IDD_HIDDEN_VOL_WIZARD_MODE_PAGE_DLG),hwndDlg,(DLGPROC)PageDialogProc);break;caseVOLUME_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;caseDEVICE_TRANSFORM_MODE_PAGE:hCurPage=CreateDialogW(hInst,MAKEINTRESOURCEW(IDD_DEVICE_TRANSFORM_MODE_DLG),hwndDlg,(DLGPROC)PageDialogProc);break;caseHIDDEN_VOL_HOST_PRE_CIPHER_PAGE:hCurPage=CreateDialogW(hInst,MAKEINTRESOURCEW(IDD_INFO_PAGE_DLG),hwndDlg,(DLGPROC)PageDialogProc);break;caseHIDDEN_VOL_PRE_CIPHER_PAGE:hCurPage=CreateDialogW(hInst,MAKEINTRESOURCEW(IDD_INFO_PAGE_DLG),hwndDlg,(DLGPROC)PageDialogProc);break;caseCIPHER_PAGE:hCurPage=CreateDialogW(hInst,MAKEINTRESOURCEW(IDD_CIPHER_PAGE_DLG),hwndDlg,(DLGPROC)PageDialogProc);break;caseSIZE_PAGE:hCurPage=CreateDialogW(hInst,MAKEINTRESOURCEW(IDD_SIZE_PAGE_DLG),hwndDlg,(DLGPROC)PageDialogProc);break;caseHIDDEN_VOL_HOST_PASSWORD_PAGE:hCurPage=CreateDialogW(hInst,MAKEINTRESOURCEW(IDD_PASSWORD_ENTRY_PAGE_DLG),hwndDlg,(DLGPROC)PageDialogProc);break;casePASSWORD_PAGE:hCurPage=CreateDialogW(hInst,MAKEINTRESOURCEW(IDD_PASSWORD_PAGE_DLG),hwndDlg,(DLGPROC)PageDialogProc);break;casePIM_PAGE:hCurPage=CreateDialogW(hInst,MAKEINTRESOURCEW(IDD_PIM_PAGE_DLG),hwndDlg,(DLGPROC)PageDialogProc);break;caseFILESYS_PAGE:hCurPage=CreateDialogW(hInst,MAKEINTRESOURCEW(IDD_UNIVERSAL_DUAL_CHOICE_PAGE_DLG),hwndDlg,(DLGPROC)PageDialogProc);break;caseSYSENC_COLLECTING_RANDOM_DATA_PAGE:caseNONSYS_INPLACE_ENC_RAND_DATA_PAGE:hCurPage=CreateDialogW(hInst,MAKEINTRESOURCEW(IDD_SYSENC_COLLECTING_RANDOM_DATA_DLG),hwndDlg,(DLGPROC)PageDialogProc);break;caseSYSENC_KEYS_GEN_PAGE:hCurPage=CreateDialogW(hInst,MAKEINTRESOURCEW(IDD_SYSENC_KEYS_GEN_PAGE_DLG),hwndDlg,(DLGPROC)PageDialogProc);break;caseSYSENC_RESCUE_DISK_CREATION_PAGE:hCurPage=CreateDialogW(hInst,MAKEINTRESOURCEW(IDD_SYSENC_RESCUE_DISK_CREATION_DLG),hwndDlg,(DLGPROC)PageDialogProc);break;caseSYSENC_RESCUE_DISK_BURN_PAGE:hCurPage=CreateDialogW(hInst,MAKEINTRESOURCEW(IDD_SYSENC_RESCUE_DISK_BURN_PAGE_DLG),hwndDlg,(DLGPROC)PageDialogProc);break;caseSYSENC_RESCUE_DISK_VERIFIED_PAGE:hCurPage=CreateDialogW(hInst,MAKEINTRESOURCEW(IDD_INFO_PAGE_DLG),hwndDlg,(DLGPROC)PageDialogProc);break;caseSYSENC_WIPE_MODE_PAGE:caseNONSYS_INPLACE_ENC_WIPE_MODE_PAGE:hCurPage=CreateDialogW(hInst,MAKEINTRESOURCEW(IDD_SYSENC_WIPE_MODE_PAGE_DLG),hwndDlg,(DLGPROC)PageDialogProc);break;caseSYSENC_PRETEST_INFO_PAGE:hCurPage=CreateDialogW(hInst,MAKEINTRESOURCEW(IDD_INFO_PAGE_DLG),hwndDlg,(DLGPROC)PageDialogProc);break;caseSYSENC_PRETEST_RESULT_PAGE:hCurPage=CreateDialogW(hInst,MAKEINTRESOURCEW(IDD_INFO_PAGE_DLG),hwndDlg,(DLGPROC)PageDialogProc);break;caseSYSENC_ENCRYPTION_PAGE:hCurPage=CreateDialogW(hInst,MAKEINTRESOURCEW(IDD_INPLACE_ENCRYPTION_PAGE_DLG),hwndDlg,(DLGPROC)PageDialogProc);break;caseNONSYS_INPLACE_ENC_RESUME_PASSWORD_PAGE:hCurPage=CreateDialogW(hInst,MAKEINTRESOURCEW(IDD_PASSWORD_ENTRY_PAGE_DLG),hwndDlg,(DLGPROC)PageDialogProc);break;caseNONSYS_INPLACE_ENC_RESUME_PARTITION_SEL_PAGE:hCurPage=CreateDialogW(hInst,MAKEINTRESOURCEW(IDD_EXPANDED_LIST_SELECT_PAGE_DLG),hwndDlg,(DLGPROC)PageDialogProc);break;caseNONSYS_INPLACE_ENC_TRANSFORM_PAGE:hCurPage=CreateDialogW(hInst,MAKEINTRESOURCEW(IDD_INPLACE_ENCRYPTION_PAGE_DLG),hwndDlg,(DLGPROC)PageDialogProc);break;caseNONSYS_INPLACE_ENC_TRANSFORM_FINISHED_PAGE:hCurPage=CreateDialogW(hInst,MAKEINTRESOURCEW(IDD_INFO_PAGE_DLG),hwndDlg,(DLGPROC)PageDialogProc);break;caseNONSYS_INPLACE_DEC_TRANSFORM_FINISHED_DRIVE_LETTER_PAGE:hCurPage=CreateDialogW(hInst,MAKEINTRESOURCEW(IDD_DRIVE_LETTER_SELECTION_PAGE),hwndDlg,(DLGPROC)PageDialogProc);break;caseFORMAT_PAGE:hCurPage=CreateDialogW(hInst,MAKEINTRESOURCEW(IDD_FORMAT_PAGE_DLG),hwndDlg,(DLGPROC)PageDialogProc);break;caseFORMAT_FINISHED_PAGE:hCurPage=CreateDialogW(hInst,MAKEINTRESOURCEW((bHiddenVol&&!bHiddenVolHost&&!bHiddenVolFinished)?IDD_HIDVOL_HOST_FILL_PAGE_DLG:IDD_INFO_PAGE_DLG),hwndDlg,(DLGPROC)PageDialogProc);break;caseSYSENC_HIDDEN_OS_INITIAL_INFO_PAGE:hCurPage=CreateDialogW(hInst,MAKEINTRESOURCEW(IDD_INFO_PAGE_DLG),hwndDlg,(DLGPROC)PageDialogProc);break;caseSYSENC_HIDDEN_OS_WIPE_INFO_PAGE:hCurPage=CreateDialogW(hInst,MAKEINTRESOURCEW(IDD_INFO_PAGE_DLG),hwndDlg,(DLGPROC)PageDialogProc);break;caseDEVICE_WIPE_MODE_PAGE:hCurPage=CreateDialogW(hInst,MAKEINTRESOURCEW(IDD_DEVICE_WIPE_MODE_PAGE_DLG),hwndDlg,(DLGPROC)PageDialogProc);break;caseDEVICE_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){casePASSWORD_PAGE:CheckCapsLock(hwndDlg,FALSE);if(CreatingHiddenSysVol())Warning("PASSWORD_HIDDEN_OS_NOTE",MainDlg);break;caseCIPHER_PAGE:if(CreatingHiddenSysVol())Warning("HIDDEN_OS_PRE_CIPHER_WARNING",MainDlg);break;}}}__int64PrintFreeSpace(HWNDhwndTextBox,wchar_t*lpszDrive,PLARGE_INTEGERlDiskFree){char*nResourceString;__int64nMultiplier;wchar_tszTmp2[256];if(lDiskFree->QuadPart<BYTES_PER_KB)nMultiplier=1;elseif(lDiskFree->QuadPart<BYTES_PER_MB)nMultiplier=BYTES_PER_KB;elseif(lDiskFree->QuadPart<BYTES_PER_GB)nMultiplier=BYTES_PER_MB;elseif(lDiskFree->QuadPart<BYTES_PER_TB)nMultiplier=BYTES_PER_GB;elsenMultiplier=BYTES_PER_TB;if(nMultiplier==1){if(bHiddenVol&&!bHiddenVolHost)// If it's a hidden volumenResourceString="MAX_HIDVOL_SIZE_BYTES";elseif(bDevice)nResourceString="DEVICE_FREE_BYTES";elsenResourceString="DISK_FREE_BYTES";}elseif(nMultiplier==BYTES_PER_KB){if(bHiddenVol&&!bHiddenVolHost)// If it's a hidden volumenResourceString="MAX_HIDVOL_SIZE_KB";elseif(bDevice)nResourceString="DEVICE_FREE_KB";elsenResourceString="DISK_FREE_KB";}elseif(nMultiplier==BYTES_PER_MB){if(bHiddenVol&&!bHiddenVolHost)// If it's a hidden volumenResourceString="MAX_HIDVOL_SIZE_MB";elseif(bDevice)nResourceString="DEVICE_FREE_MB";elsenResourceString="DISK_FREE_MB";}elseif(nMultiplier==BYTES_PER_GB){if(bHiddenVol&&!bHiddenVolHost)// If it's a hidden volumenResourceString="MAX_HIDVOL_SIZE_GB";elseif(bDevice)nResourceString="DEVICE_FREE_GB";elsenResourceString="DISK_FREE_GB";}else{if(bHiddenVol&&!bHiddenVolHost)// If it's a hidden volumenResourceString="MAX_HIDVOL_SIZE_TB";elseif(bDevice)nResourceString="DEVICE_FREE_TB";elsenResourceString="DISK_FREE_TB";}if(bHiddenVol&&!bHiddenVolHost)// If it's a hidden volume{StringCbPrintfW(szTmp2,sizeofszTmp2,GetString(nResourceString),((double)lDiskFree->QuadPart)/nMultiplier);SetWindowTextW(GetDlgItem(hwndTextBox,IDC_SIZEBOX),szTmp2);}elseif(lpszDrive)StringCbPrintfW(szTmp2,sizeofszTmp2,GetString(nResourceString),lpszDrive,((double)lDiskFree->QuadPart)/nMultiplier);elseszTmp2[0]=0;SetWindowTextW(hwndTextBox,szTmp2);if(lDiskFree->QuadPart%(__int64)BYTES_PER_MB!=0)nMultiplier=BYTES_PER_KB;returnnMultiplier;}voidDisplaySizingErrorText(HWNDhwndTextBox){wchar_tszTmp[1024];if(translateWin32Error(szTmp,sizeof(szTmp)/sizeof(szTmp[0]))){wchar_tszTmp2[1024];StringCbPrintfW(szTmp2,sizeof(szTmp2),L"%s\n%s",GetString("CANNOT_CALC_SPACE"),szTmp);SetWindowTextW(hwndTextBox,szTmp2);}else{SetWindowText(hwndTextBox,L"");}}voidEnableDisableFileNext(HWNDhComboBox,HWNDhMainButton){intnIndex=(int)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.BOOLIsSparseFile(HWNDhwndDlg){HANDLEhFile;BY_HANDLE_FILE_INFORMATIONbhFileInfo;FILETIMEftLastAccessTime;BOOLbTimeStampValid=FALSE;BOOLretCode=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);returnFALSE;}if(bPreserveTimestamp){if(GetFileTime(hFile,NULL,&ftLastAccessTime,NULL)==0)bTimeStampValid=FALSE;elsebTimeStampValid=TRUE;}bhFileInfo.dwFileAttributes=0;GetFileInformationByHandle(hFile,&bhFileInfo);retCode=bhFileInfo.dwFileAttributes&FILE_ATTRIBUTE_SPARSE_FILE;if(bTimeStampValid)SetFileTime(hFile,NULL,&ftLastAccessTime,NULL);CloseHandle(hFile);returnretCode;}// Note: GetFileVolSize is not to be used for devices (only for file-hosted volumes)BOOLGetFileVolSize(HWNDhwndDlg,unsigned__int64*size){LARGE_INTEGERfileSize;HANDLEhFile;FILETIMEftLastAccessTime;BOOLbTimeStampValid=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);returnFALSE;}if(bPreserveTimestamp){if(GetFileTime(hFile,NULL,&ftLastAccessTime,NULL)==0)bTimeStampValid=FALSE;elsebTimeStampValid=TRUE;}if(GetFileSizeEx(hFile,&fileSize)==0){MessageBoxW(hwndDlg,GetString("CANT_GET_VOLSIZE"),lpszTitle,ICON_HAND);if(bTimeStampValid)SetFileTime(hFile,NULL,&ftLastAccessTime,NULL);CloseHandle(hFile);returnFALSE;}if(bTimeStampValid)SetFileTime(hFile,NULL,&ftLastAccessTime,NULL);CloseHandle(hFile);*size=fileSize.QuadPart;returnTRUE;}BOOLQueryFreeSpace(HWNDhwndDlg,HWNDhwndTextBox,BOOLdisplay){if(bHiddenVol&&!bHiddenVolHost)// If it's a hidden volume{LARGE_INTEGERlDiskFree;lDiskFree.QuadPart=nMaximumHiddenVolSize;if(display)PrintFreeSpace(hwndTextBox,NULL,&lDiskFree);returnTRUE;}elseif(bDevice==FALSE){wchar_troot[TC_MAX_PATH];ULARGE_INTEGERfree;if(!GetVolumePathName(szFileName,root,ARRAYSIZE(root))){handleWin32Error(hwndDlg,SRC_POS);returnFALSE;}if(!GetDiskFreeSpaceEx(root,&free,0,0)){if(display)DisplaySizingErrorText(hwndTextBox);returnFALSE;}else{LARGE_INTEGERlDiskFree;lDiskFree.QuadPart=free.QuadPart;if(display)PrintFreeSpace(hwndTextBox,root,&lDiskFree);returnTRUE;}}else{DISK_GEOMETRY_EXdriveInfo;PARTITION_INFORMATIONdiskInfo;BOOLpiValid=FALSE;BOOLgValid=FALSE;// Query partition sizepiValid=GetPartitionInfo(szDiskFile,&diskInfo);gValid=GetDriveGeometry(szDiskFile,&driveInfo);if(!piValid&&!gValid){if(display)DisplaySizingErrorText(hwndTextBox);returnFALSE;}DWORDsectorSize=GetFormatSectorSize();if(sectorSize<TC_MIN_VOLUME_SECTOR_SIZE||sectorSize>TC_MAX_VOLUME_SECTOR_SIZE||sectorSize%ENCRYPTION_DATA_UNIT_SIZE!=0){Error("SECTOR_SIZE_UNSUPPORTED",hwndDlg);returnFALSE;}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"));returnFALSE;}}else{LARGE_INTEGERlDiskFree;// Drive geometry info is used only when GetPartitionInfo() failslDiskFree.QuadPart=driveInfo.DiskSize.QuadPart;nVolumeSize=lDiskFree.QuadPart;if(display)nMultiplier=PrintFreeSpace(hwndTextBox,szDiskFile,&lDiskFree);nUIVolumeSize=lDiskFree.QuadPart/nMultiplier;}returnTRUE;}}staticBOOLFinalPreTransformPrompts(void){intx;wchar_tszTmp[4096];intdriveNo;WCHARdeviceName[MAX_PATH];StringCbCopyW(deviceName,sizeof(deviceName),szFileName);driveNo=GetDiskDeviceDriveLetter(deviceName);if(!bForceOperation&&!(bHiddenVol&&!bHiddenVolHost))// Do not ask for permission to overwrite an existing volume if we're creating a hidden volume within it{wchar_tdrive[128];wchar_tvolumeLabel[128];wchar_t*type;BOOLbTmpIsPartition=FALSE;type=GetPathType(szFileName,!bInPlaceEncNonSys,&bTmpIsPartition);if(driveNo!=-1){if(!GetDriveLabel(driveNo,volumeLabel,sizeof(volumeLabel)))volumeLabel[0]=0;StringCbPrintfW(drive,sizeof(drive),volumeLabel[0]?L" (%hc: '%s')":L" (%hc:%s)",'A'+driveNo,volumeLabel[0]?volumeLabel:L"");}else{drive[0]=0;volumeLabel[0]=0;}if(bHiddenOS&&bHiddenVolHost)StringCbPrintfW(szTmp,sizeof(szTmp),GetString("OVERWRITEPROMPT_DEVICE_HIDDEN_OS_PARTITION"),szFileName,drive);elseStringCbPrintfW(szTmp,sizeof(szTmp),GetString(bInPlaceEncNonSys?(bInPlaceDecNonSys?"NONSYS_INPLACE_DEC_CONFIRM":"NONSYS_INPLACE_ENC_CONFIRM"):"OVERWRITEPROMPT_DEVICE"),type,szFileName,drive);if(bInPlaceEncNonSys)x=AskWarnYesNoString(szTmp,MainDlg);elsex=AskWarnNoYesString(szTmp,MainDlg);if(x!=IDYES)returnFALSE;if(driveNo!=-1&&bTmpIsPartition&&!bInPlaceEncNonSys){floatpercentFreeSpace=100.0;__int64occupiedBytes=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_ttmpMcMsg[8000];wchar_ttmpMcOption1[500];wchar_ttmpMcOptionCancel[50];StringCbCopyW(tmpMcMsg,sizeof(tmpMcMsg),GetString("OVERWRITEPROMPT_DEVICE_SECOND_WARNING_LOTS_OF_DATA"));StringCbCopyW(tmpMcOption1,sizeof(tmpMcOption1),GetString("ERASE_FILES_BY_CREATING_VOLUME"));StringCbCopyW(tmpMcOptionCancel,sizeof(tmpMcOptionCancel),GetString("CANCEL"));StringCbCatW(tmpMcMsg,sizeof(tmpMcMsg),L"\n\n");StringCbCatW(tmpMcMsg,sizeof(tmpMcMsg),GetString("DRIVE_LETTER_ITEM"));StringCbPrintfW(szTmp,sizeof(szTmp),L"%hc:",'A'+driveNo);StringCbCatW(tmpMcMsg,sizeof(tmpMcMsg),szTmp);StringCbCatW(tmpMcMsg,sizeof(tmpMcMsg),L"\n");StringCbCatW(tmpMcMsg,sizeof(tmpMcMsg),GetString("LABEL_ITEM"));StringCbCatW(tmpMcMsg,sizeof(tmpMcMsg),volumeLabel[0]!=0?volumeLabel:GetString("NOT_APPLICABLE_OR_NOT_AVAILABLE"));StringCbCatW(tmpMcMsg,sizeof(tmpMcMsg),L"\n");StringCbCatW(tmpMcMsg,sizeof(tmpMcMsg),GetString("SIZE_ITEM"));GetSizeString(nVolumeSize,szTmp,sizeof(szTmp));StringCbCatW(tmpMcMsg,sizeof(tmpMcMsg),szTmp);StringCbCatW(tmpMcMsg,sizeof(tmpMcMsg),L"\n");StringCbCatW(tmpMcMsg,sizeof(tmpMcMsg),GetString("PATH_ITEM"));StringCbCatW(tmpMcMsg,sizeof(tmpMcMsg),deviceName);wchar_t*tmpStr[]={L"",tmpMcMsg,tmpMcOption1,tmpMcOptionCancel,0};switch(AskMultiChoice((void**)tmpStr,TRUE,MainDlg)){case1:// Proceed// NOPbreak;default:returnFALSE;}}}}}returnTRUE;}voidUpdateLastDialogId(void){staticcharPageDebugId[128];StringCbPrintfA(PageDebugId,sizeof(PageDebugId),"FORMAT_PAGE_%d",nCurPageNo);LastDialogId=PageDebugId;}voidHandleOldAssignedDriveLetter(void){if(bDevice){// Handle assigned drive letter (if any)WCHARdeviceName[MAX_PATH];intdriveLetter=-1;StringCbCopyW(deviceName,sizeof(deviceName),szDiskFile);driveLetter=GetDiskDeviceDriveLetter(deviceName);if(!Silent&&!bHiddenVolHost&&!bHiddenOS&&driveLetter>=0){wchar_trootPath[]={(wchar_t)driveLetter+L'A',L':',L'\\',0};wchar_tszTmp[8192];StringCbPrintfW(szTmp,sizeof(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.staticBOOLFileSize4GBLimitQuestionNeeded(void){uint64dataAreaSize=GetVolumeDataAreaSize(bHiddenVol&&!bHiddenVolHost,nVolumeSize);return(dataAreaSize>4*BYTES_PER_GB+TC_MIN_FAT_FS_SIZE&&dataAreaSize<=TC_MAX_FAT_SECTOR_COUNT*GetFormatSectorSize());}voidDisableIfGpt(HWNDcontrol){if(bSystemIsGPT){EnableWindow(control,FALSE);}}staticvoidUpdateClusterSizeList(HWNDhwndDlg,intfsType){SendMessage(GetDlgItem(hwndDlg,IDC_CLUSTERSIZE),CB_RESETCONTENT,0,0);AddComboPair(GetDlgItem(hwndDlg,IDC_CLUSTERSIZE),GetString("DEFAULT"),0);for(inti=1;i<=128;i*=2){wstringstreams;DWORDsize=GetFormatSectorSize()*i;if(size>TC_MAX_FAT_CLUSTER_SIZE)break;/* ReFS supports only 4KiB and 64KiB clusters */if((fsType==FILESYS_REFS)&&(size!=4*BYTES_PER_KB)&&(size!=64*BYTES_PER_KB))continue;if(size==512)s<<L"0.5";elses<<size/BYTES_PER_KB;s<<L" "<<GetString("KB");AddComboPair(GetDlgItem(hwndDlg,IDC_CLUSTERSIZE),s.str().c_str(),i);}SendMessage(GetDlgItem(hwndDlg,IDC_CLUSTERSIZE),CB_SETCURSEL,0,0);}/* 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 */BOOLCALLBACKPageDialogProc(HWNDhwndDlg,UINTuMsg,WPARAMwParam,LPARAMlParam){WORDlw=LOWORD(wParam);WORDhw=HIWORD(wParam);staticBOOLPimValueChangedWarning=FALSE;hCurPage=hwndDlg;switch(uMsg){caseWM_INITDIALOG:PimValueChangedWarning=FALSE;LocalizeDialog(hwndDlg,"IDD_VOL_CREATION_WIZARD_DLG");burn(randPool,sizeof(randPool));burn(lastRandPool,sizeof(lastRandPool));burn(maskRandPool,sizeof(maskRandPool));UpdateLastDialogId();switch(nCurPageNo){caseINTRO_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;caseSYSENC_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);DisableIfGpt(GetDlgItem(hwndDlg,IDC_SYSENC_HIDDEN));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;caseSYSENC_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;caseSYSENC_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));DisableIfGpt(GetDlgItem(hwndDlg,IDC_WHOLE_SYS_DRIVE));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;caseSYSENC_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;caseSYSENC_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,MainDlg)){case1:// Do not try againLoadPage(MainDlg,SYSENC_DRIVE_ANALYSIS_PAGE+1);return0;case2:// Try againbreak;default:EndMainDlg(MainDlg);return0;}}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;caseSYSENC_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);DisableIfGpt(GetDlgItem(hwndDlg,IDC_MULTI_BOOT));EnableWindow(GetDlgItem(GetParent(hwndDlg),IDC_NEXT),nMultiBoot>0);EnableWindow(GetDlgItem(GetParent(hwndDlg),IDC_PREV),TRUE);EnableWindow(GetDlgItem(GetParent(hwndDlg),IDCANCEL),TRUE);break;caseSYSENC_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;caseSYSENC_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 OSelseif(SysEncMultiBootCfg.NumberOfSysDrives==1)Update2RadButtonPage(1);// Only 1 drive contains an OSelseUpdate2RadButtonPage(-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;caseSYSENC_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;caseSYSENC_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;caseSYSENC_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;caseVOLUME_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;caseHIDDEN_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;caseVOLUME_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";elsenID=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),bHistory,FALSE,NULL);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;caseDEVICE_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(hwndDlg,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;caseHIDDEN_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;caseHIDDEN_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 partitionnVolumeSize=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;caseCIPHER_PAGE:{intea,hid;wchar_tbuf[100];// Encryption algorithmsSendMessage(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"));elseSetWindowTextW(GetDlgItem(GetParent(hwndDlg),IDC_BOX_TITLE),GetString("CIPHER_TITLE"));for(ea=EAGetFirst();ea!=0;ea=EAGetNext(ea)){if(EAIsFormatEnabled(ea)&&(!SysEncInEffect()||bSystemIsGPT||EAIsMbrSysEncEnabled(ea)))AddComboPair(GetDlgItem(hwndDlg,IDC_COMBO_BOX),EAGetName(buf,ea,1),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 algorithmsif(SysEncInEffect()){hash_algo=bSystemIsGPT?SHA512:DEFAULT_HASH_ALGORITHM_BOOT;RandSetHashFunction(hash_algo);for(hid=FIRST_PRF_ID;hid<=LAST_PRF_ID;hid++){// For now, we keep RIPEMD160 for system encryptionif(((hid==RIPEMD160)||!HashIsDeprecated(hid))&&(bSystemIsGPT||HashForSystemEncryption(hid)))AddComboPair(GetDlgItem(hwndDlg,IDC_COMBO_BOX_HASH_ALGO),HashGetName(hid),hid);}}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 buttonsSetWindowTextW(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;caseSIZE_PAGE:{wchar_tstr[1000];if(bHiddenVolHost){StringCbCopyW(str,sizeof(str),GetString("SIZE_HELP_HIDDEN_HOST_VOL"));}else{StringCbCopyW(str,sizeof(str),GetString(bHiddenVol?"SIZE_HELP_HIDDEN_VOL":"SIZE_HELP"));}if(bDevice&&!(bHiddenVol&&!bHiddenVolHost))// If raw device but not a hidden volume{StringCbPrintfW(str,sizeofstr,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);EnableWindow(GetDlgItem(hwndDlg,IDC_TB),FALSE);}elseif(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);EnableWindow(GetDlgItem(hwndDlg,IDC_TB),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);EnableWindow(GetDlgItem(hwndDlg,IDC_TB),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);SendMessage(GetDlgItem(hwndDlg,IDC_TB),BM_SETCHECK,BST_UNCHECKED,0);switch(nMultiplier){caseBYTES_PER_KB:SendMessage(GetDlgItem(hwndDlg,IDC_KB),BM_SETCHECK,BST_CHECKED,0);break;caseBYTES_PER_MB:SendMessage(GetDlgItem(hwndDlg,IDC_MB),BM_SETCHECK,BST_CHECKED,0);break;caseBYTES_PER_GB:SendMessage(GetDlgItem(hwndDlg,IDC_GB),BM_SETCHECK,BST_CHECKED,0);break;caseBYTES_PER_TB:SendMessage(GetDlgItem(hwndDlg,IDC_TB),BM_SETCHECK,BST_CHECKED,0);break;}if(nUIVolumeSize!=0){wchar_tszTmp[32];StringCbPrintfW(szTmp,sizeof(szTmp),L"%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"));elseSetWindowTextW(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;caseHIDDEN_VOL_HOST_PASSWORD_PAGE:caseNONSYS_INPLACE_ENC_RESUME_PASSWORD_PAGE:{/* Populate the PRF algorithms list */intnIndex,i;HWNDhComboBox=GetDlgItem(hwndDlg,IDC_PKCS5_PRF_ID);SendMessage(hComboBox,CB_RESETCONTENT,0,0);nIndex=(int)SendMessageW(hComboBox,CB_ADDSTRING,0,(LPARAM)GetString("AUTODETECTION"));SendMessage(hComboBox,CB_SETITEMDATA,nIndex,(LPARAM)0);for(i=FIRST_PRF_ID;i<=LAST_PRF_ID;i++){nIndex=(int)SendMessage(hComboBox,CB_ADDSTRING,0,(LPARAM)get_pkcs5_prf_name(i));SendMessage(hComboBox,CB_SETITEMDATA,nIndex,(LPARAM)i);}/* make autodetection the default */SendMessage(hComboBox,CB_SETCURSEL,0,0);SendMessage(GetDlgItem(hwndDlg,IDC_PASSWORD_DIRECT),EM_LIMITTEXT,MAX_PASSWORD,0);SetPassword(hwndDlg,IDC_PASSWORD_DIRECT,szRawPassword);SetFocus(GetDlgItem(hwndDlg,IDC_PASSWORD_DIRECT));SendMessage(GetDlgItem(hwndDlg,IDC_PIM),EM_LIMITTEXT,MAX_PIM,0);SetPim(hwndDlg,IDC_PIM,volumePim);ShowWindow(GetDlgItem(hwndDlg,IDC_PIM_ENABLE),PimEnable?SW_HIDE:SW_SHOW);ShowWindow(GetDlgItem(hwndDlg,IDT_PIM),PimEnable?SW_SHOW:SW_HIDE);ShowWindow(GetDlgItem(hwndDlg,IDC_PIM),PimEnable?SW_SHOW:SW_HIDE);ShowWindow(GetDlgItem(hwndDlg,IDC_PIM_HELP),PimEnable?SW_SHOW:SW_HIDE);SetCheckBox(hwndDlg,IDC_KEYFILES_ENABLE,KeyFilesEnable);SetWindowTextW(GetDlgItem(hwndDlg,IDC_BOX_HELP),GetString(bInPlaceEncNonSys?(bInPlaceEncNonSysResumed?"NONSYS_INPLACE_ENC_RESUME_PASSWORD_PAGE_HELP":"NONSYS_INPLACE_DEC_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;casePASSWORD_PAGE:{wchar_tstr[1000];hPasswordInputField=GetDlgItem(hwndDlg,IDC_PASSWORD);hVerifyPasswordInputField=GetDlgItem(hwndDlg,IDC_VERIFY);if(SysEncInEffect()){ToBootPwdField(hwndDlg,IDC_PASSWORD);ToBootPwdField(hwndDlg,IDC_VERIFY);StringCbPrintfW(OrigKeyboardLayout,sizeof(OrigKeyboardLayout),L"%08X",(DWORD)GetKeyboardLayout(NULL)&0xFFFF);if((DWORD)GetKeyboardLayout(NULL)!=0x00000409&&(DWORD)GetKeyboardLayout(NULL)!=0x04090409){DWORDkeybLayout=(DWORD)LoadKeyboardLayout(L"00000409",KLF_ACTIVATE);if(keybLayout!=0x00000409&&keybLayout!=0x04090409){Error("CANT_CHANGE_KEYB_LAYOUT_FOR_SYS_ENCRYPTION",MainDlg);EndMainDlg(MainDlg);return1;}bKeyboardLayoutChanged=TRUE;}if(SetTimer(MainDlg,TIMER_ID_KEYB_LAYOUT_GUARD,TIMER_INTERVAL_KEYB_LAYOUT_GUARD,NULL)==0){Error("CANNOT_SET_TIMER",MainDlg);EndMainDlg(MainDlg);return1;}}if(bHiddenVolHost){StringCbCopyW(str,sizeof(str),GetString(bHiddenOS?"PASSWORD_SYSENC_OUTERVOL_HELP":"PASSWORD_HIDDENVOL_HOST_HELP"));}elseif(bHiddenVol){StringCbPrintfW(str,sizeofstr,L"%s%s",GetString(bHiddenOS?"PASSWORD_HIDDEN_OS_HELP":"PASSWORD_HIDDENVOL_HELP"),GetString("PASSWORD_HELP"));}else{StringCbCopyW(str,sizeof(str),GetString("PASSWORD_HELP"));}SendMessage(GetDlgItem(hwndDlg,IDC_PASSWORD),EM_LIMITTEXT,MAX_PASSWORD,0);SendMessage(GetDlgItem(hwndDlg,IDC_VERIFY),EM_LIMITTEXT,MAX_PASSWORD,0);SetPassword(hwndDlg,IDC_PASSWORD,szRawPassword);SetPassword(hwndDlg,IDC_VERIFY,szVerify);SetFocus(GetDlgItem(hwndDlg,IDC_PASSWORD));SetCheckBox(hwndDlg,IDC_PIM_ENABLE,PimEnable);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"));elseif(bHiddenVol)SetWindowTextW(GetDlgItem(GetParent(hwndDlg),IDC_BOX_TITLE),GetString(bHiddenVolHost?"PASSWORD_HIDVOL_HOST_TITLE":"PASSWORD_HIDVOL_TITLE"));elseif(WizardMode==WIZARD_MODE_SYS_DEVICE)SetWindowTextW(GetDlgItem(GetParent(hwndDlg),IDC_BOX_TITLE),GetString("PASSWORD"));elseSetWindowTextW(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=(unsigned__int32)strlen((char*)volumePassword.Text);}break;casePIM_PAGE:{SendMessage(GetDlgItem(hwndDlg,IDC_PIM),EM_LIMITTEXT,SysEncInEffect()?MAX_BOOT_PIM:MAX_PIM,0);if(volumePim>0){SetPim(hwndDlg,IDC_PIM,volumePim);PimValueChangedWarning=TRUE;SetDlgItemTextW(hwndDlg,IDC_PIM_HELP,GetString(SysEncInEffect()?"PIM_SYSENC_CHANGE_WARNING":"PIM_CHANGE_WARNING"));}SetFocus(GetDlgItem(hwndDlg,IDC_PIM));SetWindowTextW(GetDlgItem(hwndDlg,IDC_BOX_HELP),GetString(SysEncInEffect()&&hash_algo!=SHA512&&hash_algo!=WHIRLPOOL?"PIM_SYSENC_HELP":"PIM_HELP"));ToHyperlink(hwndDlg,IDC_LINK_PIM_INFO);if(CreatingHiddenSysVol())SetWindowTextW(GetDlgItem(GetParent(hwndDlg),IDC_BOX_TITLE),GetString("PIM_HIDDEN_OS_TITLE"));elseif(bHiddenVol)SetWindowTextW(GetDlgItem(GetParent(hwndDlg),IDC_BOX_TITLE),GetString(bHiddenVolHost?"PIM_HIDVOL_HOST_TITLE":"PIM_HIDVOL_TITLE"));elseif(WizardMode==WIZARD_MODE_SYS_DEVICE)SetWindowTextW(GetDlgItem(GetParent(hwndDlg),IDC_BOX_TITLE),GetString("PIM"));elseSetWindowTextW(GetDlgItem(GetParent(hwndDlg),IDC_BOX_TITLE),GetString("PIM_TITLE"));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;caseFILESYS_PAGE:{wchar_tszTmp[8192];Init2RadButtonPageYesNo(nNeedToStoreFilesOver4GB);SetWindowTextW(GetDlgItem(GetParent(hwndDlg),IDC_BOX_TITLE),GetString("FILESYS_PAGE_TITLE"));StringCbCopyW(szTmp,sizeof(szTmp),GetString("FILESYS_PAGE_HELP_QUESTION"));if(bHiddenVolHost)StringCbCatW(szTmp,sizeof(szTmp),L"\n\n");else{StringCbCatW(szTmp,sizeof(szTmp),L"\n\n\n");StringCbCatW(szTmp,sizeof(szTmp),GetString("NOTE_BEGINNING"));}StringCbCatW(szTmp,sizeof(szTmp),GetString("FILESYS_PAGE_HELP_EXPLANATION"));if(bHiddenVolHost){StringCbCatW(szTmp,sizeof(szTmp),L" ");StringCbCatW(szTmp,sizeof(szTmp),GetString("FILESYS_PAGE_HELP_EXPLANATION_HIDVOL"));}SetWindowTextW(GetDlgItem(hwndDlg,IDC_BOX_HELP),szTmp);}break;caseSYSENC_COLLECTING_RANDOM_DATA_PAGE:caseNONSYS_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);mouseEntropyGathered=0xFFFFFFFF;mouseEventsInitialCount=0;bUseMask=FALSE;{HCRYPTPROVhRngProv;if(CryptAcquireContext(&hRngProv,NULL,MS_ENHANCED_PROV,PROV_RSA_FULL,CRYPT_VERIFYCONTEXT|CRYPT_SILENT)){if(CryptGenRandom(hRngProv,sizeof(maskRandPool),maskRandPool))bUseMask=TRUE;CryptReleaseContext(hRngProv,0);}}SetTimer(GetParent(hwndDlg),TIMER_ID_RANDVIEW,TIMER_INTERVAL_RANDVIEW,NULL);hRandPoolSys=GetDlgItem(hwndDlg,IDC_SYS_POOL_CONTENTS);hEntropyBar=GetDlgItem(hwndDlg,IDC_ENTROPY_BAR);SendMessage(hEntropyBar,PBM_SETRANGE32,0,maxEntropyLevel);SendMessage(hEntropyBar,PBM_SETSTEP,1,0);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(hwndDlg,hRandPoolSys,showKeys);break;caseSYSENC_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;caseSYSENC_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),bSystemIsGPT?GetString("RESCUE_DISK_EFI_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;caseSYSENC_RESCUE_DISK_BURN_PAGE:{wchar_tszTmp[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"));if(bSystemIsGPT){StringCbPrintfW(szTmp,sizeofszTmp,GetString(bDontVerifyRescueDisk?"RESCUE_DISK_EFI_EXTRACT_INFO_NO_CHECK":"RESCUE_DISK_EFI_EXTRACT_INFO"),szRescueDiskISO,GetString("RESCUE_DISK_EFI_EXTRACT_INFO_NOTE"));}else{StringCbPrintfW(szTmp,sizeofszTmp,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(bSystemIsGPT){ShowWindow(GetDlgItem(hwndDlg,IDC_DOWNLOAD_CD_BURN_SOFTWARE),SW_HIDE);}else{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;caseSYSENC_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 backEnableWindow(GetDlgItem(GetParent(hwndDlg),IDC_PREV),FALSE);// Prevent losing the burned rescue disk by inadvertent exitbConfirmQuit=TRUE;break;caseSYSENC_WIPE_MODE_PAGE:caseNONSYS_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,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_PREV),TRUE);EnableWindow(GetDlgItem(GetParent(hwndDlg),IDC_NEXT),TRUE);}break;caseSYSENC_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_tfinalMsg[8024]={0};SetWindowTextW(GetDlgItem(GetParent(hwndDlg),IDC_BOX_TITLE),GetString("SYS_ENCRYPTION_PRETEST_TITLE"));try{StringCbPrintfW(finalMsg,sizeof(finalMsg),GetString("SYS_ENCRYPTION_PRETEST_INFO"),BootEncObj->GetSystemDriveConfiguration().DriveNumber);}catch(Exception&e){e.Show(hwndDlg);EndMainDlg(MainDlg);return0;}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;caseSYSENC_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;caseSYSENC_ENCRYPTION_PAGE:if(CreateSysEncMutex()){try{BootEncStatus=BootEncObj->GetStatus();bSystemEncryptionInProgress=BootEncStatus.SetupInProgress;}catch(Exception&e){e.Show(hwndDlg);Error("ERR_GETTING_SYSTEM_ENCRYPTION_STATUS",MainDlg);EndMainDlg(MainDlg);return0;}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,FALSE);SelectAlgo(GetDlgItem(hwndDlg,IDC_WIPE_MODE),(int*)&nWipeMode);}else{EnableWindow(GetDlgItem(hwndDlg,IDC_WIPE_MODE),!bSystemEncryptionInProgress);PopulateWipeModeCombo(GetDlgItem(hwndDlg,IDC_WIPE_MODE),FALSE,TRUE,FALSE);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",MainDlg);EndMainDlg(MainDlg);return0;}return0;caseNONSYS_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(constHostDevice&device,DeferredNonSysInPlaceEncDevices){SendMessage(GetDlgItem(hwndDlg,IDC_LIST_BOX),LB_ADDSTRING,0,(LPARAM)device.Path.c_str());}// Deselect allSendMessage(GetDlgItem(hwndDlg,IDC_LIST_BOX),LB_SETCURSEL,(WPARAM)-1,0);}break;caseNONSYS_INPLACE_ENC_TRANSFORM_PAGE:if(bInPlaceEncNonSysResumed){WipeAlgorithmIdsavedWipeAlgorithm=TC_WIPE_NONE;if(LoadNonSysInPlaceEncSettings(&savedWipeAlgorithm)!=0)nWipeMode=savedWipeAlgorithm;}SetWindowTextW(GetDlgItem(GetParent(hwndDlg),IDC_BOX_TITLE),GetString(bInPlaceDecNonSys?"DECRYPTION":"ENCRYPTION"));SetWindowTextW(GetDlgItem(hwndDlg,IDC_BOX_HELP),GetString(bInPlaceDecNonSys?"NONSYS_INPLACE_DEC_DECRYPTION_PAGE_INFO":"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":(bInPlaceDecNonSys?"DECRYPT":"ENCRYPT")));SetWindowTextW(GetDlgItem(hwndDlg,IDC_PAUSE),GetString("IDC_PAUSE"));EnableWindow(GetDlgItem(GetParent(hwndDlg),IDC_PREV),!bInPlaceEncNonSysResumed&&!bInPlaceDecNonSys);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);if(bInPlaceDecNonSys){ShowWindow(GetDlgItem(hwndDlg,IDT_FORMAT_OPTIONS),SW_HIDE);ShowWindow(GetDlgItem(hwndDlg,IDT_WIPE_MODE),SW_HIDE);ShowWindow(GetDlgItem(hwndDlg,IDC_WIPE_MODE),SW_HIDE);}else{EnableWindow(GetDlgItem(hwndDlg,IDC_WIPE_MODE),TRUE);PopulateWipeModeCombo(GetDlgItem(hwndDlg,IDC_WIPE_MODE),FALSE,TRUE,FALSE);SelectAlgo(GetDlgItem(hwndDlg,IDC_WIPE_MODE),(int*)&nWipeMode);}break;caseNONSYS_INPLACE_ENC_TRANSFORM_FINISHED_PAGE:bConfirmQuit=FALSE;SetWindowTextW(GetDlgItem(GetParent(hwndDlg),IDC_BOX_TITLE),GetString(bInPlaceDecNonSys?"NONSYS_INPLACE_DEC_FINISHED_TITLE":"NONSYS_INPLACE_ENC_FINISHED_TITLE"));SetWindowTextW(GetDlgItem(hwndDlg,IDC_BOX_HELP),GetString(bInPlaceDecNonSys?"NONSYS_INPLACE_DEC_FINISHED_INFO":"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;caseNONSYS_INPLACE_DEC_TRANSFORM_FINISHED_DRIVE_LETTER_PAGE:SetWindowTextW(GetDlgItem(GetParent(hwndDlg),IDC_BOX_TITLE),GetString("NONSYS_INPLACE_DEC_FINISHED_TITLE"));SetWindowTextW(GetDlgItem(hwndDlg,IDC_BOX_HELP),GetString("NONSYS_INPLACE_DEC_FINISHED_DRIVE_LETTER_SEL_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("CANCEL"));// The Cancel button and the X button must be disabled to prevent the user from forgetting to assign a drive letter to the partition by closing// the window accidentally or clicking Cancel. The user is forced to click Finish to assign at least the pre-selected free drive letter.// This is critical because inexperienced users would not know how to access data on the decrypted volume without a drive letter.EnableWindow(GetDlgItem(GetParent(hwndDlg),IDCANCEL),FALSE);DisableCloseButton(MainDlg);bConfirmQuit=TRUE;// Alt-F4 will still work but the user will be prompted to confirm the action.// Decryption of non-system volume finished, no drive letter is assigned to the decrypted volume, and free drive letters are available.// This is critical because inexperienced users would not know how to access data on the decrypted volume. We cannot allow exit// until a drive letter is freed up and assigned to the decrypted volume.while(GetFirstAvailableDrive()==-1){Error("NONSYS_INPLACE_DEC_FINISHED_NO_DRIVE_LETTER_AVAILABLE",hwndDlg);}// Populate the combobox with free drive letters{DWORDdwUsedDrives=GetUsedLogicalDrives();wchar_tszDriveLetter[]={L' ',L':',0};inti;for(i=0;i<26;i++){if(!(dwUsedDrives&1<<i)){// AddszDriveLetter[0]=(wchar_t)(i+L'A');AddComboPair(GetDlgItem(hCurPage,IDC_DRIVE_LETTER_LIST),szDriveLetter,i);}}}SendMessage(GetDlgItem(hwndDlg,IDC_DRIVE_LETTER_LIST),CB_SETCURSEL,0,0);break;caseFORMAT_PAGE:{BOOLbNTFSallowed=FALSE;BOOLbFATallowed=FALSE;BOOLbEXFATallowed=FALSE;BOOLbReFSallowed=FALSE;BOOLbNoFSallowed=FALSE;HCRYPTPROVhRngProv;mouseEntropyGathered=0xFFFFFFFF;mouseEventsInitialCount=0;bUseMask=FALSE;if(CryptAcquireContext(&hRngProv,NULL,MS_ENHANCED_PROV,PROV_RSA_FULL,CRYPT_VERIFYCONTEXT|CRYPT_SILENT)){if(CryptGenRandom(hRngProv,sizeof(maskRandPool),maskRandPool))bUseMask=TRUE;CryptReleaseContext(hRngProv,0);}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);hEntropyBar=GetDlgItem(hwndDlg,IDC_ENTROPY_BAR);SendMessage(hEntropyBar,PBM_SETRANGE32,0,maxEntropyLevel);SendMessage(hEntropyBar,PBM_SETSTEP,1,0);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"));elseSetWindowTextW(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{wchar_troot[TC_MAX_PATH];DWORDfileSystemFlags=0;SetWindowTextW(GetDlgItem(hwndDlg,IDC_QUICKFORMAT),GetString("SPARSE_FILE"));/* Check if the host file system supports sparse files */if(GetVolumePathName(szFileName,root,array_capacity(root))){GetVolumeInformation(root,NULL,0,NULL,NULL,&fileSystemFlags,NULL,0);bSparseFileSwitch=fileSystemFlags&FILE_SUPPORTS_SPARSE_FILES;}elsebSparseFileSwitch=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?L"":L"******************************** ");SetWindowText(GetDlgItem(hwndDlg,IDC_HEADER_KEY),showKeys?L"":L"******************************** ");SetWindowText(GetDlgItem(hwndDlg,IDC_DISK_KEY),showKeys?L"":L"******************************** ");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);uint64dataAreaSize=GetVolumeDataAreaSize(bHiddenVol&&!bHiddenVolHost,nVolumeSize);if(!CreatingHiddenSysVol()){if(dataAreaSize>=TC_MIN_NTFS_FS_SIZE&&dataAreaSize<=TC_MAX_NTFS_FS_SIZE){AddComboPair(GetDlgItem(hwndDlg,IDC_FILESYS),L"NTFS",FILESYS_NTFS);bNTFSallowed=TRUE;}if(dataAreaSize>=TC_MIN_FAT_FS_SIZE&&dataAreaSize<=TC_MAX_FAT_SECTOR_COUNT*GetFormatSectorSize()){AddComboPair(GetDlgItem(hwndDlg,IDC_FILESYS),L"FAT",FILESYS_FAT);bFATallowed=TRUE;}//exFAT support added starting from Vista SP1if(IsOSVersionAtLeast(WIN_VISTA,1)&&dataAreaSize>=TC_MIN_EXFAT_FS_SIZE&&dataAreaSize<=TC_MAX_EXFAT_FS_SIZE){AddComboPair(GetDlgItem(hwndDlg,IDC_FILESYS),L"exFAT",FILESYS_EXFAT);bEXFATallowed=TRUE;}//ReFS write support activated by default starting from Windows 10//We don't support it yet for the creation of hidden volumesif((!bHiddenVolHost)&&IsOSVersionAtLeast(WIN_10,0)&&dataAreaSize>=TC_MIN_REFS_FS_SIZE&&dataAreaSize<=TC_MAX_REFS_FS_SIZE){AddComboPair(GetDlgItem(hwndDlg,IDC_FILESYS),L"ReFS",FILESYS_REFS);bReFSallowed=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){AddComboPair(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 systemif(bFATallowed&&!(nNeedToStoreFilesOver4GB==1&&(bNTFSallowed||bEXFATallowed||bReFSallowed)))fileSystem=FILESYS_FAT;elseif(bEXFATallowed)fileSystem=FILESYS_EXFAT;elseif(bNTFSallowed)fileSystem=FILESYS_NTFS;elseif(bReFSallowed)fileSystem=FILESYS_REFS;elseif(bNoFSallowed)fileSystem=FILESYS_NONE;else{AddComboPair(GetDlgItem(hwndDlg,IDC_FILESYS),L"---",0);EnableWindow(GetDlgItem(GetParent(hwndDlg),IDC_NEXT),FALSE);}}SendMessage(GetDlgItem(hwndDlg,IDC_FILESYS),CB_SETCURSEL,0,0);SelectAlgo(GetDlgItem(hwndDlg,IDC_FILESYS),(int*)&fileSystem);UpdateClusterSizeList(hwndDlg,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;caseFORMAT_FINISHED_PAGE:{if(!bHiddenVolHost&&bHiddenVol&&!bHiddenVolFinished){wchar_tmsg[4096];nNeedToStoreFilesOver4GB