/* 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"cpu.h"#include<time.h>#include<math.h>#include<dbt.h>#include<fcntl.h>#include<io.h>#include<shlobj.h>#include<sys/stat.h>#include<windowsx.h>#include"Apidrvr.h"#include"BootEncryption.h"#include"Cmdline.h"#include"Crypto.h"#include"Dlgcode.h"#include"Combo.h"#include"Favorites.h"#include"Hotkeys.h"#include"Keyfiles.h"#include"Language.h"#include"MainCom.h"#include"Mount.h"#include"Pkcs5.h"#include"Random.h"#include"Registry.h"#include"Resource.h"#include"Password.h"#include"Xml.h"#include"../Boot/Windows/BootCommon.h"#include"../Common/Dictionary.h"#include"../Common/Common.h"#include"../Common/Resource.h"#include"../Common/SecurityToken.h"#include"../Platform/Finally.h"#include"../Platform/ForEach.h"#include<Strsafe.h>#import <msxml6.dll>#include<wtsapi32.h>typedefBOOL(WINAPI*WTSREGISTERSESSIONNOTIFICATION)(HWND,DWORD);typedefBOOL(WINAPI*WTSUNREGISTERSESSIONNOTIFICATION)(HWND);usingnamespaceVeraCrypt;enumtimer_ids{TIMER_ID_MAIN=0xff,TIMER_ID_KEYB_LAYOUT_GUARD,TIMER_ID_UPDATE_DEVICE_LIST};enumhidden_os_read_only_notif_mode{TC_HIDDEN_OS_READ_ONLY_NOTIF_MODE_NONE=0,TC_HIDDEN_OS_READ_ONLY_NOTIF_MODE_COMPACT,TC_HIDDEN_OS_READ_ONLY_NOTIF_MODE_DISABLED};#define TIMER_INTERVAL_MAIN 500#define TIMER_INTERVAL_KEYB_LAYOUT_GUARD 10#define TIMER_INTERVAL_UPDATE_DEVICE_LIST 1000BootEncryption*BootEncObj=NULL;BootEncryptionStatusBootEncStatus;BootEncryptionStatusRecentBootEncStatus;BOOLbExplore=FALSE;/* Display explorer window after mount */BOOLbBeep=FALSE;/* Donot beep after mount */wchar_tszFileName[TC_MAX_PATH+1];/* Volume to mount */wchar_tszDriveLetter[3];/* Drive Letter to mount */wchar_tcommandLineDrive=0;BOOLbCacheInDriver=FALSE;/* Cache any passwords we see */BOOLbCacheInDriverDefault=FALSE;BOOLbCacheDuringMultipleMount=FALSE;BOOLbCmdCacheDuringMultipleMount=FALSE;BOOLbIncludePimInCache=FALSE;BOOLbTryEmptyPasswordWhenKeyfileUsed=FALSE;BOOLbCmdTryEmptyPasswordWhenKeyfileUsed=FALSE;BOOLbCmdTryEmptyPasswordWhenKeyfileUsedValid=FALSE;BOOLbHistoryCmdLine=FALSE;/* History control is always disabled */BOOLbUseDifferentTrayIconIfVolMounted=TRUE;BOOLbCloseDismountedWindows=TRUE;/* Close all open explorer windows of dismounted volume */BOOLbWipeCacheOnExit=FALSE;/* Wipe password from chace on exit */BOOLbWipeCacheOnAutoDismount=TRUE;BOOLbEnableBkgTask=FALSE;BOOLbCloseBkgTaskWhenNoVolumes=FALSE;BOOLbDismountOnLogOff=TRUE;BOOLbDismountOnSessionLocked=TRUE;BOOLbDismountOnScreenSaver=TRUE;BOOLbDismountOnPowerSaving=FALSE;BOOLbForceAutoDismount=TRUE;BOOLbForceMount=FALSE;/* Mount volume even if host file/device already in use */BOOLbForceUnmount=FALSE;/* Unmount volume even if it cannot be locked */BOOLbWipe=FALSE;/* Wipe driver passwords */BOOLbAuto=FALSE;/* Do everything without user input */BOOLLogOn=FALSE;BOOLbAutoMountDevices=FALSE;/* Auto-mount devices */BOOLbAutoMountFavorites=FALSE;BOOLbPlaySoundOnSuccessfulHkDismount=TRUE;BOOLbDisplayBalloonOnSuccessfulHkDismount=TRUE;BOOLbHibernationPreventionNotified=FALSE;/* TRUE if the user has been notified that hibernation was prevented (system encryption) during the session. */BOOLbHiddenSysLeakProtNotifiedDuringSession=FALSE;/* TRUE if the user has been notified during the session that unencrypted filesystems and non-hidden TrueCrypt volumes are mounted as read-only under hidden OS. */BOOLCloseSecurityTokenSessionsAfterMount=FALSE;BOOLQuit=FALSE;/* Exit after processing command line */BOOLComServerMode=FALSE;BOOLServiceMode=FALSE;BOOLUsePreferences=TRUE;BOOLbSystemIsGPT=FALSE;wchar_tszDefaultRescueDiskName[TC_MAX_PATH+1];wchar_tszRescueDiskExtension[4];intHiddenSysLeakProtectionNotificationStatus=TC_HIDDEN_OS_READ_ONLY_NOTIF_MODE_NONE;intMaxVolumeIdleTime=-120;intnCurrentShowType=0;/* current display mode, mount, unmount etc */intnSelectedDriveIndex=-1;/* Item number of selected drive */intcmdUnmountDrive=-2;/* Volume drive letter to unmount (-1 = all) */PasswordVolumePassword;/* Password used for mounting volumes */PasswordCmdVolumePassword;/* Password passed from command line */intVolumePkcs5=0;intCmdVolumePkcs5=0;intVolumePim=-1;intCmdVolumePim=-1;intDefaultVolumePkcs5=0;BOOLVolumeTrueCryptMode=FALSE;BOOLCmdVolumeTrueCryptMode=FALSE;BOOLDefaultVolumeTrueCryptMode=FALSE;BOOLCmdVolumePasswordValid=FALSE;MountOptionsCmdMountOptions;BOOLCmdMountOptionsValid=FALSE;MountOptionsmountOptions;MountOptionsdefaultMountOptions;KeyFile*FirstCmdKeyFile;HBITMAPhbmLogoBitmapRescaled=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. */staticKeyFilesDlgParamhidVolProtKeyFilesParam;staticMOUNT_LIST_STRUCTLastKnownMountList={0};VOLUME_NOTIFICATIONS_LISTVolumeNotificationsList;staticDWORDLastKnownLogicalDrives;staticHANDLETaskBarIconMutex=NULL;staticBOOLMainWindowHidden=FALSE;staticintpwdChangeDlgMode=PCDM_CHANGE_PASSWORD;staticintbSysEncPwdChangeDlgMode=FALSE;staticintbPrebootPasswordDlgMode=FALSE;staticintNoCmdLineArgs;staticBOOLCmdLineVolumeSpecified;staticintLastDriveListVolumeColumnWidth;// WTS handlingstaticHMODULEhWtsLib=NULL;staticWTSREGISTERSESSIONNOTIFICATIONfnWtsRegisterSessionNotification=NULL;staticWTSUNREGISTERSESSIONNOTIFICATIONfnWtsUnRegisterSessionNotification=NULL;staticvoidRegisterWtsNotification(HWNDhWnd){if(!hWtsLib){wchar_tdllPath[MAX_PATH];if(GetSystemDirectory(dllPath,MAX_PATH))StringCbCatW(dllPath,sizeof(dllPath),L"\\wtsapi32.dll");elseStringCbCopyW(dllPath,sizeof(dllPath),L"c:\\Windows\\System32\\wtsapi32.dll");hWtsLib=LoadLibrary(dllPath);if(hWtsLib){fnWtsRegisterSessionNotification=(WTSREGISTERSESSIONNOTIFICATION)GetProcAddress(hWtsLib,"WTSRegisterSessionNotification");fnWtsUnRegisterSessionNotification=(WTSUNREGISTERSESSIONNOTIFICATION)GetProcAddress(hWtsLib,"WTSUnRegisterSessionNotification");if(!fnWtsRegisterSessionNotification||!fnWtsUnRegisterSessionNotification||!fnWtsRegisterSessionNotification(hWnd,NOTIFY_FOR_THIS_SESSION)){fnWtsRegisterSessionNotification=NULL;fnWtsUnRegisterSessionNotification=NULL;FreeLibrary(hWtsLib);hWtsLib=NULL;}}}}staticvoidUnregisterWtsNotification(HWNDhWnd){if(hWtsLib&&fnWtsUnRegisterSessionNotification){fnWtsUnRegisterSessionNotification(hWnd);FreeLibrary(hWtsLib);hWtsLib=NULL;fnWtsRegisterSessionNotification=NULL;fnWtsUnRegisterSessionNotification=NULL;}}staticstd::vector<MSXML2::IXMLDOMNodePtr>GetReadChildNodes(MSXML2::IXMLDOMNodeListPtrchilds){std::vector<MSXML2::IXMLDOMNodePtr>list;if(childs&&childs->Getlength()){for(longi=0;i<childs->Getlength();i++){MSXML2::IXMLDOMNodePtrnode=childs->Getitem(i);if(node){//skip commentsif(node->GetnodeType()==NODE_COMMENT)continue;// skip root xml nodeif(node->GetbaseName().GetBSTR()&&(0==strcmp("xml",(constchar*)node->GetbaseName())))continue;list.push_back(node);}}}returnlist;}staticboolvalidateDcsPropXml(constchar*xmlData){boolbValid=false;HRESULThr=CoInitialize(NULL);if(FAILED(hr))returnfalse;else{MSXML2::IXMLDOMDocumentPtrpXMLDom;hr=pXMLDom.CreateInstance(__uuidof(MSXML2::DOMDocument60),NULL,CLSCTX_INPROC_SERVER);if(SUCCEEDED(hr)){try{pXMLDom->async=VARIANT_FALSE;pXMLDom->validateOnParse=VARIANT_FALSE;pXMLDom->resolveExternals=VARIANT_FALSE;if(pXMLDom->loadXML(xmlData)==VARIANT_TRUE&&pXMLDom->hasChildNodes()){MSXML2::IXMLDOMNodePtrveracryptNode,configurationNode,configNode;std::vector<MSXML2::IXMLDOMNodePtr>nodes=GetReadChildNodes(pXMLDom->GetchildNodes());size_tnodesCount=nodes.size();if(nodesCount==1&&((veracryptNode=nodes[0])->GetnodeType()==NODE_ELEMENT)&&veracryptNode->GetnodeName().GetBSTR()&&(0==strcmp((constchar*)veracryptNode->GetnodeName(),"VeraCrypt"))&&veracryptNode->hasChildNodes()){nodes=GetReadChildNodes(veracryptNode->GetchildNodes());nodesCount=nodes.size();if((nodesCount==1)&&((configurationNode=nodes[0])->GetnodeType()==NODE_ELEMENT)&&configurationNode->GetnodeName().GetBSTR()&&(0==strcmp((constchar*)configurationNode->GetnodeName(),"configuration"))&&(configurationNode->hasChildNodes())){nodes=GetReadChildNodes(configurationNode->GetchildNodes());nodesCount=nodes.size();if(nodesCount>1){bValid=true;for(size_ti=0;bValid&&(i<nodesCount);i++){configNode=nodes[i];if(configNode->GetnodeType()==NODE_COMMENT)continue;elseif((configNode->GetnodeType()==NODE_ELEMENT)&&(configNode->GetnodeName().GetBSTR())&&(0==strcmp((constchar*)configNode->GetnodeName(),"config"))){nodes=GetReadChildNodes(configNode->GetchildNodes());nodesCount=nodes.size();if((nodesCount==0||(nodesCount==1&&nodes[0]->GetnodeType()==NODE_TEXT))&&configNode->Getattributes()&&(configNode->Getattributes()->Getlength()==1)&&(configNode->Getattributes()->Getitem(0))){std::stringval;bstr_tbstr=configNode->Getattributes()->Getitem(0)->GetnodeName();if(bstr.GetBSTR())val=(constchar*)bstr;if(val!="key")bValid=false;}elsebValid=false;}elsebValid=false;}}}}}}catch(_com_errorerrorObject){bValid=false;}}}CoUninitialize();returnbValid;}staticvoidlocalcleanup(void){// Wipe command linechar*c=GetCommandLineA();wchar_t*wc=GetCommandLineW();burn(c,strlen(c));burn(wc,wcslen(wc)*sizeof(wchar_t));/* Delete buffered bitmaps (if any) */if(hbmLogoBitmapRescaled!=NULL){DeleteObject((HGDIOBJ)hbmLogoBitmapRescaled);hbmLogoBitmapRescaled=NULL;}/* These items should have already been cleared by the functions that used them, but we're going to clear them for extra security. */burn(&VolumePassword,sizeof(VolumePassword));burn(&CmdVolumePassword,sizeof(CmdVolumePassword));burn(&VolumePkcs5,sizeof(VolumePkcs5));burn(&CmdVolumePkcs5,sizeof(CmdVolumePkcs5));burn(&VolumePim,sizeof(VolumePim));burn(&CmdVolumePim,sizeof(CmdVolumePim));burn(&VolumeTrueCryptMode,sizeof(VolumeTrueCryptMode));burn(&CmdVolumeTrueCryptMode,sizeof(CmdVolumeTrueCryptMode));burn(&mountOptions,sizeof(mountOptions));burn(&defaultMountOptions,sizeof(defaultMountOptions));burn(szFileName,sizeof(szFileName));/* Cleanup common code resources */cleanup();if(BootEncObj!=NULL){deleteBootEncObj;BootEncObj=NULL;}RandStop(TRUE);}voidRefreshMainDlg(HWNDhwndDlg){intdrive=(wchar_t)(HIWORD(GetSelectedLong(GetDlgItem(hwndDlg,IDC_DRIVELIST))));MoveEditToCombo(GetDlgItem(hwndDlg,IDC_VOLUME),bHistory);LoadDriveLetters(hwndDlg,GetDlgItem(hwndDlg,IDC_DRIVELIST),drive);EnableDisableButtons(hwndDlg);}voidEndMainDlg(HWNDhwndDlg){MoveEditToCombo(GetDlgItem(hwndDlg,IDC_VOLUME),bHistory);if(UsePreferences)SaveSettings(hwndDlg);if(bWipeCacheOnExit){DWORDdwResult;DeviceIoControl(hDriver,TC_IOCTL_WIPE_PASSWORD_CACHE,NULL,0,NULL,0,&dwResult,NULL);}if(!bHistory){SetWindowText(GetDlgItem(hwndDlg,IDC_VOLUME),L"");ClearHistory(GetDlgItem(hwndDlg,IDC_VOLUME));}if(TaskBarIconMutex!=NULL){MainWindowHidden=TRUE;ShowWindow(hwndDlg,SW_HIDE);}else{KillTimer(hwndDlg,TIMER_ID_MAIN);KillTimer(hwndDlg,TIMER_ID_UPDATE_DEVICE_LIST);TaskBarIconRemove(hwndDlg);UnregisterWtsNotification(hwndDlg);EndDialog(hwndDlg,0);}}staticvoidInitMainDialog(HWNDhwndDlg){MENUITEMINFOWinfo;char*popupTexts[]={"MENU_VOLUMES","MENU_SYSTEM_ENCRYPTION","MENU_FAVORITES","MENU_TOOLS","MENU_SETTINGS","MENU_HELP","MENU_WEBSITE",0};wchar_t*str;inti;/* Call the common dialog init code */InitDialog(hwndDlg);LocalizeDialog(hwndDlg,NULL);SetWindowLongPtrW(hwndDlg,DWLP_USER,(LONG_PTR)(IsAdmin()?TC_MAIN_WINDOW_FLAG_ADMIN_PRIVILEGES:0));DragAcceptFiles(hwndDlg,TRUE);SendMessageW(GetDlgItem(hwndDlg,IDC_VOLUME),CB_LIMITTEXT,TC_MAX_PATH,0);SetWindowTextW(hwndDlg,(IsAdmin()&&!IsBuiltInAdmin()&&IsUacSupported()&&!IsNonInstallMode())?(wstring(lpszTitle)+L" ["+GetString("ADMINISTRATOR")+L"]").c_str():lpszTitle);// Help file nameInitHelpFileName();// Localize menu stringsfor(i=40001;str=(wchar_t*)GetDictionaryValueByInt(i);i++){info.cbSize=sizeof(info);info.fMask=MIIM_TYPE;info.fType=MFT_STRING;info.dwTypeData=str;info.cch=(UINT)wcslen(str);SetMenuItemInfoW(GetMenu(hwndDlg),i,FALSE,&info);}for(i=0;popupTexts[i]!=0;i++){str=GetString(popupTexts[i]);info.cbSize=sizeof(info);info.fMask=MIIM_TYPE;if(strcmp(popupTexts[i],"MENU_WEBSITE")==0)info.fType=MFT_STRING|MFT_RIGHTJUSTIFY;elseinfo.fType=MFT_STRING;if(strcmp(popupTexts[i],"MENU_FAVORITES")==0)FavoriteVolumesMenu=GetSubMenu(GetMenu(hwndDlg),i);info.dwTypeData=str;info.cch=(UINT)wcslen(str);SetMenuItemInfoW(GetMenu(hwndDlg),i,TRUE,&info);}{// disable hidden OS creation for GPT system encryptionif(bSystemIsGPT){EnableMenuItem(GetMenu(hwndDlg),IDM_CREATE_HIDDEN_OS,MF_GRAYED);}}// Disable menu item for changing system header key derivation algorithm until it's implementedEnableMenuItem(GetMenu(hwndDlg),IDM_CHANGE_SYS_HEADER_KEY_DERIV_ALGO,MF_GRAYED);try{LoadFavoriteVolumes();}catch(Exception&e){e.Show(NULL);}// initialize the list of devices available for mounting as early as possibleUpdateMountableHostDeviceList();// Resize the logo bitmap if the user has a non-default DPIif(ScreenDPI!=USER_DEFAULT_SCREEN_DPI&&hbmLogoBitmapRescaled==NULL)// If not re-called (e.g. after language pack change){hbmLogoBitmapRescaled=RenderBitmap(MAKEINTRESOURCE(IDB_LOGO_288DPI),GetDlgItem(hwndDlg,IDC_LOGO),0,0,0,0,FALSE,TRUE);}BuildTree(hwndDlg,GetDlgItem(hwndDlg,IDC_DRIVELIST));if(*szDriveLetter!=0){SelectItem(GetDlgItem(hwndDlg,IDC_DRIVELIST),*szDriveLetter);if(nSelectedDriveIndex>SendMessage(GetDlgItem(hwndDlg,IDC_DRIVELIST),LVM_GETITEMCOUNT,0,0)/2)SendMessage(GetDlgItem(hwndDlg,IDC_DRIVELIST),LVM_SCROLL,0,10000);}else{SendMessage(hwndDlg,WM_NEXTDLGCTL,(WPARAM)GetDlgItem(hwndDlg,IDC_DRIVELIST),1L);}SendMessage(GetDlgItem(hwndDlg,IDC_NO_HISTORY),BM_SETCHECK,bHistory?BST_UNCHECKED:BST_CHECKED,0);EnableDisableButtons(hwndDlg);}voidEnableDisableButtons(HWNDhwndDlg){HWNDhOKButton=GetDlgItem(hwndDlg,IDOK);WORDx;x=LOWORD(GetSelectedLong(GetDlgItem(hwndDlg,IDC_DRIVELIST)));EnableMenuItem(GetMenu(hwndDlg),IDM_MOUNT_VOLUME,MF_ENABLED);EnableMenuItem(GetMenu(hwndDlg),IDM_MOUNT_VOLUME_OPTIONS,MF_ENABLED);EnableMenuItem(GetMenu(hwndDlg),IDM_BACKUP_VOL_HEADER,MF_ENABLED);EnableMenuItem(GetMenu(hwndDlg),IDM_RESTORE_VOL_HEADER,MF_ENABLED);EnableMenuItem(GetMenu(hwndDlg),IDM_CHANGE_PASSWORD,MF_ENABLED);EnableWindow(hOKButton,TRUE);switch(x){caseTC_MLIST_ITEM_NONSYS_VOL:{SetWindowTextW(hOKButton,GetString("UNMOUNT_BUTTON"));EnableWindow(hOKButton,TRUE);EnableMenuItem(GetMenu(hwndDlg),IDM_UNMOUNT_VOLUME,MF_ENABLED);EnableWindow(GetDlgItem(hwndDlg,IDC_VOLUME_PROPERTIES),TRUE);EnableMenuItem(GetMenu(hwndDlg),IDM_VOLUME_PROPERTIES,MF_ENABLED);}break;caseTC_MLIST_ITEM_SYS_PARTITION:caseTC_MLIST_ITEM_SYS_DRIVE:EnableWindow(hOKButton,FALSE);SetWindowTextW(hOKButton,GetString("MOUNT_BUTTON"));EnableWindow(GetDlgItem(hwndDlg,IDC_VOLUME_PROPERTIES),TRUE);EnableMenuItem(GetMenu(hwndDlg),IDM_UNMOUNT_VOLUME,MF_GRAYED);break;caseTC_MLIST_ITEM_FREE:default:SetWindowTextW(hOKButton,GetString("MOUNT_BUTTON"));EnableWindow(GetDlgItem(hwndDlg,IDC_VOLUME_PROPERTIES),FALSE);EnableMenuItem(GetMenu(hwndDlg),IDM_VOLUME_PROPERTIES,MF_GRAYED);EnableMenuItem(GetMenu(hwndDlg),IDM_UNMOUNT_VOLUME,MF_GRAYED);}EnableWindow(GetDlgItem(hwndDlg,IDC_WIPE_CACHE),!IsPasswordCacheEmpty());EnableMenuItem(GetMenu(hwndDlg),IDM_WIPE_CACHE,IsPasswordCacheEmpty()?MF_GRAYED:MF_ENABLED);EnableMenuItem(GetMenu(hwndDlg),IDM_CLEAR_HISTORY,IsComboEmpty(GetDlgItem(hwndDlg,IDC_VOLUME))?MF_GRAYED:MF_ENABLED);}BOOLVolumeSelected(HWNDhwndDlg){return(GetWindowTextLength(GetDlgItem(hwndDlg,IDC_VOLUME))>0);}voidGetVolumePath(HWNDhwndDlg,LPWSTRszPath,intnMaxCount){GetWindowText(GetDlgItem(hwndDlg,IDC_VOLUME),szPath,nMaxCount);CorrectFileName(szPath);}/* Returns TRUE if the last partition/drive selected via the Select Device dialog box was the systempartition/drive and if it is encrypted. WARNING: This function is very fast but not always reliable (for example, if the user manually types a device path before Select Device is invoked during the session; after the Select Device dialog has been invoked at least once, the correct system device paths are cached). Therefore, it must NOT be used before performing any dangerous operations (such as header backup restore or formatting a supposedly non-system device) -- instead use IsSystemDevicePath(path, hwndDlg, TRUE) for such purposes. This function can be used only for preliminary GUI checks requiring very fast responses. */BOOLActiveSysEncDeviceSelected(void){try{BootEncStatus=BootEncObj->GetStatus();if(BootEncStatus.DriveEncrypted){intretCode=0;GetVolumePath(MainDlg,szFileName,ARRAYSIZE(szFileName));retCode=IsSystemDevicePath(szFileName,MainDlg,FALSE);return(WholeSysDriveEncryption(FALSE)?(retCode==2||retCode==1):(retCode==1));}}catch(Exception&e){e.Show(MainDlg);}returnFALSE;}// When a function does not require the affected volume to be dismounted, there may be cases where we have two valid// paths selected in the main window and we cannot be sure which of them the user really intends to apply the function to.// This function asks the user to explicitly select either the volume path specified in the input field below the main// drive list (whether mounted or not), or the path to the volume selected in the main drive list. If, however, both// of the GUI elements contain the same volume (or one of them does not contain any path), this function does not// ask the user and returns the volume path directly (no selection ambiguity).// If driveNoPtr is not NULL, and the volume is mounted, its drive letter is returned in *driveNoPtr (if no valid drive// letter is resolved, -1 is stored instead).staticwstringResolveAmbiguousSelection(HWNDhwndDlg,int*driveNoPtr){LPARAMselectedDrive=GetSelectedLong(GetDlgItem(MainDlg,IDC_DRIVELIST));wchar_tvolPathInputField[TC_MAX_PATH];wchar_tvolPathDriveListW[TC_MAX_PATH];wstringvolPathDriveListStr;wstringretPath;VOLUME_PROPERTIES_STRUCTprop;DWORDdwResult;BOOLuseInputField=TRUE;memset(&prop,0,sizeof(prop));BOOLambig=(LOWORD(selectedDrive)!=TC_MLIST_ITEM_FREE&&LOWORD(selectedDrive)!=0xffff&&HIWORD(selectedDrive)!=0xffff&&VolumeSelected(MainDlg));if(VolumeSelected(MainDlg)){// volPathInputField will contain the volume path (if any) from the input field below the drive listGetVolumePath(MainDlg,volPathInputField,ARRAYSIZE(volPathInputField));if(!ambig)retPath=(wstring)volPathInputField;}if(LOWORD(selectedDrive)!=TC_MLIST_ITEM_FREE&&LOWORD(selectedDrive)!=0xffff&&HIWORD(selectedDrive)!=0xffff){// A volume is selected in the main drive list.switch(LOWORD(selectedDrive)){caseTC_MLIST_ITEM_NONSYS_VOL:prop.driveNo=HIWORD(selectedDrive)-L'A';if(!DeviceIoControl(hDriver,TC_IOCTL_GET_VOLUME_PROPERTIES,&prop,sizeof(prop),&prop,sizeof(prop),&dwResult,NULL)||dwResult==0){// The driver did not return any path for this drive letter (the volume may have been dismounted).// Return whatever is in the input field below the drive list (even if empty)return((wstring)volPathInputField);}// volPathDriveListWStr will contain the volume path selected in the main drive listvolPathDriveListStr=(wstring)prop.wszVolume;break;caseTC_MLIST_ITEM_SYS_PARTITION:GetSysDevicePaths(MainDlg);if(bCachedSysDevicePathsValid){volPathDriveListStr=(wstring)SysPartitionDevicePath;}break;caseTC_MLIST_ITEM_SYS_DRIVE:GetSysDevicePaths(MainDlg);if(bCachedSysDevicePathsValid){volPathDriveListStr=(wstring)SysDriveDevicePath;}break;}if(!ambig){useInputField=FALSE;retPath=volPathDriveListStr;}}if(ambig){/* We have two paths. Compare them and if they don't match, ask the user to select one of them. Otherwise, return the path without asking. */if(wmemcmp(volPathDriveListStr.c_str(),L"\\??\\",4)==0){// The volume path starts with "\\??\\" which is used for file-hosted containers. We're going to strip this prefix.volPathDriveListStr=(wstring)(volPathDriveListStr.c_str()+4);}StringCbCopyW(volPathDriveListW,sizeof(volPathDriveListW),volPathDriveListStr.c_str());if(wcscmp(((wmemcmp(volPathDriveListW,L"\\??\\",4)==0)?volPathDriveListW+4:volPathDriveListW),volPathInputField)!=0){// The path selected in the input field is different from the path to the volume selected// in the drive lettter list. We have to resolve possible ambiguity.wchar_t*tmp[]={L"",L"",L"",L"",L"",0};constintmaxVolPathLen=80;if(volPathDriveListStr.length()>maxVolPathLen){// Ellipsis (path too long)volPathDriveListStr=wstring(L"...")+volPathDriveListStr.substr(volPathDriveListStr.length()-maxVolPathLen,maxVolPathLen);}wstringvolPathInputFieldWStr(volPathInputField);if(volPathInputFieldWStr.length()>maxVolPathLen){// Ellipsis (path too long)volPathInputFieldWStr=wstring(L"...")+volPathInputFieldWStr.substr(volPathInputFieldWStr.length()-maxVolPathLen,maxVolPathLen);}tmp[1]=GetString("AMBIGUOUS_VOL_SELECTION");tmp[2]=(wchar_t*)volPathDriveListStr.c_str();tmp[3]=(wchar_t*)volPathInputFieldWStr.c_str();tmp[4]=GetString("IDCANCEL");switch(AskMultiChoice((void**)tmp,FALSE,hwndDlg)){case1:retPath=volPathDriveListStr;break;case2:retPath=(wstring)volPathInputField;break;default:if(driveNoPtr!=NULL)*driveNoPtr=-1;returnwstring(L"");}}else{// Both selected paths are the sameretPath=(wstring)volPathInputField;}}if(driveNoPtr!=NULL)*driveNoPtr=GetMountedVolumeDriveNo((wchar_t*)retPath.c_str());if(wmemcmp(retPath.c_str(),L"\\??\\",4)==0){// The selected volume path starts with "\\??\\" which is used for file-hosted containers. We're going to strip this prefix.retPath=(wstring)(retPath.c_str()+4);}returnretPath;}voidLoadSettingsAndCheckModified(HWNDhwndDlg,BOOLbOnlyCheckModified,BOOL*pbSettingsModified,BOOL*pbHistoryModified){charlangid[6]={0};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 the config file has already been loaded during this sessionif(ConfigBuffer!=NULL){free(ConfigBuffer);ConfigBuffer=NULL;}// OptionsConfigReadCompareInt("OpenExplorerWindowAfterMount",FALSE,&bExplore,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("UseDifferentTrayIconIfVolumesMounted",TRUE,&bUseDifferentTrayIconIfVolMounted,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("SaveVolumeHistory",FALSE,&bHistory,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("CachePasswords",FALSE,&bCacheInDriverDefault,bOnlyCheckModified,pbSettingsModified);if(!bOnlyCheckModified)bCacheInDriver=bCacheInDriverDefault;ConfigReadCompareInt("CachePasswordDuringMultipleMount",FALSE,&bCacheDuringMultipleMount,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("WipePasswordCacheOnExit",FALSE,&bWipeCacheOnExit,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("WipeCacheOnAutoDismount",TRUE,&bWipeCacheOnAutoDismount,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("IncludePimInCache",FALSE,&bIncludePimInCache,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("TryEmptyPasswordWhenKeyfileUsed",FALSE,&bTryEmptyPasswordWhenKeyfileUsed,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("StartOnLogon",FALSE,&bStartOnLogon,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("MountDevicesOnLogon",FALSE,&bMountDevicesOnLogon,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("MountFavoritesOnLogon",FALSE,&bMountFavoritesOnLogon,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("EnableBackgroundTask",TRUE,&bEnableBkgTask,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("CloseBackgroundTaskOnNoVolumes",FALSE,&bCloseBkgTaskWhenNoVolumes,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("DismountOnLogOff",!(IsServerOS()&&IsAdmin()),&bDismountOnLogOff,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("DismountOnSessionLocked",FALSE,&bDismountOnSessionLocked,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("DismountOnPowerSaving",FALSE,&bDismountOnPowerSaving,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("DismountOnScreenSaver",FALSE,&bDismountOnScreenSaver,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("ForceAutoDismount",TRUE,&bForceAutoDismount,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("MaxVolumeIdleTime",-60,&MaxVolumeIdleTime,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("HiddenSectorDetectionStatus",0,&HiddenSectorDetectionStatus,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("UseKeyfiles",FALSE,&defaultKeyFilesParam.EnableKeyFiles,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("PreserveTimestamps",TRUE,&defaultMountOptions.PreserveTimestamp,bOnlyCheckModified,pbSettingsModified);if(!bOnlyCheckModified)bPreserveTimestamp=defaultMountOptions.PreserveTimestamp;ConfigReadCompareInt("ShowDisconnectedNetworkDrives",FALSE,&bShowDisconnectedNetworkDrives,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("HideWaitingDialog",FALSE,&bHideWaitingDialog,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("UseSecureDesktop",FALSE,&bUseSecureDesktop,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("MountVolumesRemovable",FALSE,&defaultMountOptions.Removable,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("MountVolumesReadOnly",FALSE,&defaultMountOptions.ReadOnly,bOnlyCheckModified,pbSettingsModified);if(!bOnlyCheckModified){defaultMountOptions.ProtectHiddenVolume=FALSE;defaultMountOptions.ProtectedHidVolPkcs5Prf=0;defaultMountOptions.ProtectedHidVolPim=0;defaultMountOptions.PartitionInInactiveSysEncScope=FALSE;defaultMountOptions.RecoveryMode=FALSE;defaultMountOptions.UseBackupHeader=FALSE;mountOptions=defaultMountOptions;}ConfigReadCompareInt("CloseSecurityTokenSessionsAfterMount",0,&CloseSecurityTokenSessionsAfterMount,bOnlyCheckModified,pbSettingsModified);if(IsHiddenOSRunning())ConfigReadCompareInt("HiddenSystemLeakProtNotifStatus",TC_HIDDEN_OS_READ_ONLY_NOTIF_MODE_NONE,&HiddenSysLeakProtectionNotificationStatus,bOnlyCheckModified,pbSettingsModified);// Drive letter - command line arg overrides registryif(!bOnlyCheckModified&&bHistory&&szDriveLetter[0]==0){charszTmp[3]={0};ConfigReadString("LastSelectedDrive","",szTmp,sizeof(szTmp));MultiByteToWideChar(CP_UTF8,0,szTmp,-1,szDriveLetter,ARRAYSIZE(szDriveLetter));}if(bHistory&&pbSettingsModified){// only check for last drive modification if history enabledcharszTmp[32]={0};LPARAMlLetter;lLetter=GetSelectedLong(GetDlgItem(MainDlg,IDC_DRIVELIST));if(LOWORD(lLetter)!=0xffff)StringCbPrintfA(szTmp,sizeof(szTmp),"%lc:",(wchar_t)HIWORD(lLetter));ConfigReadCompareString("LastSelectedDrive","",szTmp,sizeof(szTmp),bOnlyCheckModified,pbSettingsModified);}{charszTmp[MAX_PATH];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);}}// HotkeysConfigReadCompareInt("PlaySoundOnHotkeyMountDismount",TRUE,&bPlaySoundOnSuccessfulHkDismount,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("DisplayMsgBoxOnHotkeyDismount",TRUE,&bDisplayBalloonOnSuccessfulHkDismount,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("HotkeyModAutoMountDevices",0,(int*)&Hotkeys[HK_AUTOMOUNT_DEVICES].vKeyModifiers,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("HotkeyCodeAutoMountDevices",0,(int*)&Hotkeys[HK_AUTOMOUNT_DEVICES].vKeyCode,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("HotkeyModDismountAll",0,(int*)&Hotkeys[HK_DISMOUNT_ALL].vKeyModifiers,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("HotkeyCodeDismountAll",0,(int*)&Hotkeys[HK_DISMOUNT_ALL].vKeyCode,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("HotkeyModWipeCache",0,(int*)&Hotkeys[HK_WIPE_CACHE].vKeyModifiers,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("HotkeyCodeWipeCache",0,(int*)&Hotkeys[HK_WIPE_CACHE].vKeyCode,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("HotkeyModDismountAllWipe",0,(int*)&Hotkeys[HK_DISMOUNT_ALL_AND_WIPE].vKeyModifiers,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("HotkeyCodeDismountAllWipe",0,(int*)&Hotkeys[HK_DISMOUNT_ALL_AND_WIPE].vKeyCode,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("HotkeyModForceDismountAllWipe",0,(int*)&Hotkeys[HK_FORCE_DISMOUNT_ALL_AND_WIPE].vKeyModifiers,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("HotkeyCodeForceDismountAllWipe",0,(int*)&Hotkeys[HK_FORCE_DISMOUNT_ALL_AND_WIPE].vKeyCode,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("HotkeyModForceDismountAllWipeExit",0,(int*)&Hotkeys[HK_FORCE_DISMOUNT_ALL_AND_WIPE_AND_EXIT].vKeyModifiers,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("HotkeyCodeForceDismountAllWipeExit",0,(int*)&Hotkeys[HK_FORCE_DISMOUNT_ALL_AND_WIPE_AND_EXIT].vKeyCode,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("HotkeyModMountFavoriteVolumes",0,(int*)&Hotkeys[HK_MOUNT_FAVORITE_VOLUMES].vKeyModifiers,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("HotkeyCodeMountFavoriteVolumes",0,(int*)&Hotkeys[HK_MOUNT_FAVORITE_VOLUMES].vKeyCode,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("HotkeyModShowHideMainWindow",0,(int*)&Hotkeys[HK_SHOW_HIDE_MAIN_WINDOW].vKeyModifiers,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("HotkeyCodeShowHideMainWindow",0,(int*)&Hotkeys[HK_SHOW_HIDE_MAIN_WINDOW].vKeyCode,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("HotkeyModCloseSecurityTokenSessions",0,(int*)&Hotkeys[HK_CLOSE_SECURITY_TOKEN_SESSIONS].vKeyModifiers,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("HotkeyCodeCloseSecurityTokenSessions",0,(int*)&Hotkeys[HK_CLOSE_SECURITY_TOKEN_SESSIONS].vKeyCode,bOnlyCheckModified,pbSettingsModified);// Historyif(bHistoryCmdLine!=TRUE){LoadCombo(GetDlgItem(MainDlg,IDC_VOLUME),bHistory,bOnlyCheckModified,pbHistoryModified);if(!bOnlyCheckModified&&CmdLineVolumeSpecified)SetWindowText(GetDlgItem(MainDlg,IDC_VOLUME),szFileName);}// Mount OptionsConfigReadCompareInt("DefaultPRF",0,&DefaultVolumePkcs5,bOnlyCheckModified,pbSettingsModified);ConfigReadCompareInt("DefaultTrueCryptMode",FALSE,&DefaultVolumeTrueCryptMode,bOnlyCheckModified,pbSettingsModified);if(bOnlyCheckModified){if(!IsNonInstallMode()){ConfigReadString("Language","",langid,sizeof(langid));// when installed, if no preferred language set by user, English is set default//if(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(DefaultVolumePkcs5<0||DefaultVolumePkcs5>LAST_PRF_ID)DefaultVolumePkcs5=0;if(DefaultVolumeTrueCryptMode!=TRUE&&DefaultVolumeTrueCryptMode!=FALSE)DefaultVolumeTrueCryptMode=FALSE;}voidLoadSettings(HWNDhwndDlg){LoadSettingsAndCheckModified(hwndDlg,FALSE,NULL,NULL);}voidSaveSettings(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(bSettingsChanged){charszTmp[32]={0};LPARAMlLetter;// OptionsConfigWriteBegin();ConfigWriteInt("OpenExplorerWindowAfterMount",bExplore);ConfigWriteInt("UseDifferentTrayIconIfVolumesMounted",bUseDifferentTrayIconIfVolMounted);ConfigWriteInt("SaveVolumeHistory",bHistory);ConfigWriteInt("CachePasswords",bCacheInDriverDefault);ConfigWriteInt("CachePasswordDuringMultipleMount",bCacheDuringMultipleMount);ConfigWriteInt("WipePasswordCacheOnExit",bWipeCacheOnExit);ConfigWriteInt("WipeCacheOnAutoDismount",bWipeCacheOnAutoDismount);ConfigWriteInt("IncludePimInCache",bIncludePimInCache);ConfigWriteInt("TryEmptyPasswordWhenKeyfileUsed",bTryEmptyPasswordWhenKeyfileUsed);ConfigWriteInt("StartOnLogon",bStartOnLogon);ConfigWriteInt("MountDevicesOnLogon",bMountDevicesOnLogon);ConfigWriteInt("MountFavoritesOnLogon",bMountFavoritesOnLogon);ConfigWriteInt("MountVolumesReadOnly",defaultMountOptions.ReadOnly);ConfigWriteInt("MountVolumesRemovable",defaultMountOptions.Removable);ConfigWriteInt("PreserveTimestamps",defaultMountOptions.PreserveTimestamp);ConfigWriteInt("ShowDisconnectedNetworkDrives",bShowDisconnectedNetworkDrives);ConfigWriteInt("HideWaitingDialog",bHideWaitingDialog);ConfigWriteInt("UseSecureDesktop",bUseSecureDesktop);ConfigWriteInt("EnableBackgroundTask",bEnableBkgTask);ConfigWriteInt("CloseBackgroundTaskOnNoVolumes",bCloseBkgTaskWhenNoVolumes);ConfigWriteInt("DismountOnLogOff",bDismountOnLogOff);ConfigWriteInt("DismountOnSessionLocked",bDismountOnSessionLocked);ConfigWriteInt("DismountOnPowerSaving",bDismountOnPowerSaving);ConfigWriteInt("DismountOnScreenSaver",bDismountOnScreenSaver);ConfigWriteInt("ForceAutoDismount",bForceAutoDismount);ConfigWriteInt("MaxVolumeIdleTime",MaxVolumeIdleTime);ConfigWriteInt("HiddenSectorDetectionStatus",HiddenSectorDetectionStatus);ConfigWriteInt("UseKeyfiles",defaultKeyFilesParam.EnableKeyFiles);if(IsHiddenOSRunning())ConfigWriteInt("HiddenSystemLeakProtNotifStatus",HiddenSysLeakProtectionNotificationStatus);// save last selected drive only when history enabledif(bHistory){// Drive LetterlLetter=GetSelectedLong(GetDlgItem(MainDlg,IDC_DRIVELIST));if(LOWORD(lLetter)!=0xffff)StringCbPrintfA(szTmp,sizeof(szTmp),"%lc:",(wchar_t)HIWORD(lLetter));ConfigWriteString("LastSelectedDrive",szTmp);}ConfigWriteInt("CloseSecurityTokenSessionsAfterMount",CloseSecurityTokenSessionsAfterMount);// HotkeysConfigWriteInt("HotkeyModAutoMountDevices",Hotkeys[HK_AUTOMOUNT_DEVICES].vKeyModifiers);ConfigWriteInt("HotkeyCodeAutoMountDevices",Hotkeys[HK_AUTOMOUNT_DEVICES].vKeyCode);ConfigWriteInt("HotkeyModDismountAll",Hotkeys[HK_DISMOUNT_ALL].vKeyModifiers);ConfigWriteInt("HotkeyCodeDismountAll",Hotkeys[HK_DISMOUNT_ALL].vKeyCode);ConfigWriteInt("HotkeyModWipeCache",Hotkeys[HK_WIPE_CACHE].vKeyModifiers);ConfigWriteInt("HotkeyCodeWipeCache",Hotkeys[HK_WIPE_CACHE].vKeyCode);ConfigWriteInt("HotkeyModDismountAllWipe",Hotkeys[HK_DISMOUNT_ALL_AND_WIPE].vKeyModifiers);ConfigWriteInt("HotkeyCodeDismountAllWipe",Hotkeys[HK_DISMOUNT_ALL_AND_WIPE].vKeyCode);ConfigWriteInt("HotkeyModForceDismountAllWipe",Hotkeys[HK_FORCE_DISMOUNT_ALL_AND_WIPE].vKeyModifiers);ConfigWriteInt("HotkeyCodeForceDismountAllWipe",Hotkeys[HK_FORCE_DISMOUNT_ALL_AND_WIPE].vKeyCode);ConfigWriteInt("HotkeyModForceDismountAllWipeExit",Hotkeys[HK_FORCE_DISMOUNT_ALL_AND_WIPE_AND_EXIT].vKeyModifiers);ConfigWriteInt("HotkeyCodeForceDismountAllWipeExit",Hotkeys[HK_FORCE_DISMOUNT_ALL_AND_WIPE_AND_EXIT].vKeyCode);ConfigWriteInt("HotkeyModMountFavoriteVolumes",Hotkeys[HK_MOUNT_FAVORITE_VOLUMES].vKeyModifiers);ConfigWriteInt("HotkeyCodeMountFavoriteVolumes",Hotkeys[HK_MOUNT_FAVORITE_VOLUMES].vKeyCode);ConfigWriteInt("HotkeyModShowHideMainWindow",Hotkeys[HK_SHOW_HIDE_MAIN_WINDOW].vKeyModifiers);ConfigWriteInt("HotkeyCodeShowHideMainWindow",Hotkeys[HK_SHOW_HIDE_MAIN_WINDOW].vKeyCode);ConfigWriteInt("HotkeyModCloseSecurityTokenSessions",Hotkeys[HK_CLOSE_SECURITY_TOKEN_SESSIONS].vKeyModifiers);ConfigWriteInt("HotkeyCodeCloseSecurityTokenSessions",Hotkeys[HK_CLOSE_SECURITY_TOKEN_SESSIONS].vKeyCode);ConfigWriteInt("PlaySoundOnHotkeyMountDismount",bPlaySoundOnSuccessfulHkDismount);ConfigWriteInt("DisplayMsgBoxOnHotkeyDismount",bDisplayBalloonOnSuccessfulHkDismount);// LanguageConfigWriteString("Language",GetPreferredLangId());// PKCS#11 Library PathConfigWriteStringW("SecurityTokenLibrary",SecurityTokenLibraryPath[0]?SecurityTokenLibraryPath:L"");// Mount OptionsConfigWriteInt("DefaultPRF",DefaultVolumePkcs5);ConfigWriteInt("DefaultTrueCryptMode",DefaultVolumeTrueCryptMode);ConfigWriteEnd(hwndDlg);}if(bHistoryChanged){// HistoryDumpCombo(GetDlgItem(MainDlg,IDC_VOLUME),IsButtonChecked(GetDlgItem(MainDlg,IDC_NO_HISTORY)));}NormalCursor();}// 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 Tcformat.c as well. */try{BootEncStatus=BootEncObj->GetStatus();}catch(Exception&e){e.Show(MainDlg);}return(SystemEncryptionStatus==SYSENC_STATUS_ENCRYPTING||SystemEncryptionStatus==SYSENC_STATUS_DECRYPTING||(BootEncStatus.DriveMounted&&(BootEncStatus.ConfiguredEncryptedAreaStart!=BootEncStatus.EncryptedAreaStart||BootEncStatus.ConfiguredEncryptedAreaEnd!=BootEncStatus.EncryptedAreaEnd)));}// Returns TRUE if the system partition/drive is completely encryptedstaticBOOLSysDriveOrPartitionFullyEncrypted(BOOLbSilent){/* If you update this function, revise SysDriveOrPartitionFullyEncrypted() in Tcformat.c as well. */try{BootEncStatus=BootEncObj->GetStatus();}catch(Exception&e){if(!bSilent)e.Show(MainDlg);}return(!BootEncStatus.SetupInProgress&&BootEncStatus.ConfiguredEncryptedAreaEnd!=0&&BootEncStatus.ConfiguredEncryptedAreaEnd!=-1&&BootEncStatus.ConfiguredEncryptedAreaStart==BootEncStatus.EncryptedAreaStart&&BootEncStatus.ConfiguredEncryptedAreaEnd==BootEncStatus.EncryptedAreaEnd);}// Returns TRUE if the system partition/drive is being filtered by the TrueCrypt driver and the key data// was successfully decrypted (the device is fully ready to be encrypted or decrypted). Note that this// function does not examine whether the system device is encrypted or not (or to what extent).staticBOOLSysEncDeviceActive(BOOLbSilent){try{BootEncStatus=BootEncObj->GetStatus();}catch(Exception&e){if(!bSilent)e.Show(MainDlg);returnFALSE;}return(BootEncStatus.DriveMounted);}// Returns TRUE if the entire system drive (as opposed to the system partition only) of the currently running OS is (or is to be) encryptedBOOLWholeSysDriveEncryption(BOOLbSilent){try{BootEncStatus=BootEncObj->GetStatus();if(BootEncStatus.BootDriveLength.QuadPart<1)// paranoid checkreturnFALSE;elsereturn(BootEncStatus.ConfiguredEncryptedAreaStart==TC_BOOT_LOADER_AREA_SIZE&&BootEncStatus.ConfiguredEncryptedAreaEnd>=BootEncStatus.BootDriveLength.QuadPart-1);}catch(Exception&e){if(!bSilent)e.Show(MainDlg);returnFALSE;}}// Returns the size of the system drive/partition (if encrypted) in bytesunsigned__int64GetSysEncDeviceSize(BOOLbSilent){try{BootEncStatus=BootEncObj->GetStatus();}catch(Exception&e){if(!bSilent)e.Show(MainDlg);return1;}if(BootEncStatus.ConfiguredEncryptedAreaEnd<0||BootEncStatus.ConfiguredEncryptedAreaStart<0||BootEncStatus.ConfiguredEncryptedAreaEnd<BootEncStatus.ConfiguredEncryptedAreaStart)return1;// we return 1 to avoid devision by zeroelsereturn((unsigned__int64)(BootEncStatus.ConfiguredEncryptedAreaEnd-BootEncStatus.ConfiguredEncryptedAreaStart))+1;}// Returns the current size of the encrypted area of the system drive/partition in bytesunsigned__int64GetSysEncDeviceEncryptedPartSize(BOOLbSilent){try{BootEncStatus=BootEncObj->GetStatus();}catch(Exception&e){if(!bSilent)e.Show(MainDlg);return0;}if(BootEncStatus.EncryptedAreaEnd<0||BootEncStatus.EncryptedAreaStart<0||BootEncStatus.EncryptedAreaEnd<BootEncStatus.EncryptedAreaStart)return0;elsereturn((unsigned__int64)(BootEncStatus.EncryptedAreaEnd-BootEncStatus.EncryptedAreaStart))+1;}staticvoidPopulateSysEncContextMenu(HMENUpopup,BOOLbToolsOnly){SystemDriveConfigurationconfig;try{BootEncStatus=BootEncObj->GetStatus();config=BootEncObj->GetSystemDriveConfiguration();}catch(Exception&e){e.Show(MainDlg);}if(!bToolsOnly&&!IsHiddenOSRunning()){if(SysEncryptionOrDecryptionRequired()){if(!BootEncStatus.SetupInProgress)AppendMenuW(popup,MF_STRING,IDM_SYSENC_RESUME,GetString("IDM_SYSENC_RESUME"));if(SystemEncryptionStatus!=SYSENC_STATUS_DECRYPTING)AppendMenuW(popup,MF_STRING,IDM_PERMANENTLY_DECRYPT_SYS,GetString("PERMANENTLY_DECRYPT"));AppendMenuW(popup,MF_STRING,IDM_ENCRYPT_SYSTEM_DEVICE,GetString("ENCRYPT"));AppendMenu(popup,MF_SEPARATOR,0,L"");}}AppendMenuW(popup,MF_STRING,IDM_CHANGE_SYS_PASSWORD,GetString("IDM_CHANGE_SYS_PASSWORD"));// AppendMenuW (popup, MF_STRING, IDM_CHANGE_SYS_HEADER_KEY_DERIV_ALGO, GetString ("IDM_CHANGE_SYS_HEADER_KEY_DERIV_ALGO"));AppendMenu(popup,MF_SEPARATOR,0,L"");AppendMenuW(popup,MF_STRING,IDM_SYS_ENC_SETTINGS,GetString("IDM_SYS_ENC_SETTINGS"));if(!IsHiddenOSRunning()){AppendMenu(popup,MF_SEPARATOR,0,L"");AppendMenuW(popup,MF_STRING,IDM_CREATE_RESCUE_DISK,GetString("IDM_CREATE_RESCUE_DISK"));AppendMenuW(popup,MF_STRING,IDM_VERIFY_RESCUE_DISK,GetString("IDM_VERIFY_RESCUE_DISK"));AppendMenuW(popup,MF_STRING,IDM_VERIFY_RESCUE_DISK_ISO,GetString("IDM_VERIFY_RESCUE_DISK_ISO"));}if(!bToolsOnly){if(SysDriveOrPartitionFullyEncrypted(FALSE)&&!IsHiddenOSRunning()){AppendMenu(popup,MF_SEPARATOR,0,L"");AppendMenuW(popup,MF_STRING,IDM_PERMANENTLY_DECRYPT_SYS,GetString("PERMANENTLY_DECRYPT"));}AppendMenu(popup,MF_SEPARATOR,0,L"");AppendMenuW(popup,MF_STRING,IDM_VOLUME_PROPERTIES,GetString("IDPM_PROPERTIES"));}}// WARNING: This function may take a long time to complete. To prevent data corruption, it MUST be called before// mounting a partition (as a regular volume) that is within key scope of system encryption.// Returns TRUE if the partition can be mounted as a partition within key scope of inactive system encryption.// If devicePath is empty, the currently selected partition in the GUI is checked.BOOLCheckSysEncMountWithoutPBA(HWNDhwndDlg,constwchar_t*devicePath,BOOLquiet){BOOLtmpbDevice;wchar_tszDevicePath[TC_MAX_PATH+1];wchar_tszDiskFile[TC_MAX_PATH+1];if(wcslen(devicePath)<2){GetVolumePath(MainDlg,szDevicePath,ARRAYSIZE(szDevicePath));CreateFullVolumePath(szDiskFile,sizeof(szDiskFile),szDevicePath,&tmpbDevice);if(!tmpbDevice){if(!quiet)Warning("NO_SYSENC_PARTITION_SELECTED",hwndDlg);returnFALSE;}if(LOWORD(GetSelectedLong(GetDlgItem(MainDlg,IDC_DRIVELIST)))!=TC_MLIST_ITEM_FREE){if(!quiet)Warning("SELECT_FREE_DRIVE",hwndDlg);returnFALSE;}}elseStringCbCopyW(szDevicePath,sizeof(szDevicePath),devicePath);wchar_t*partionPortion=wcsrchr(szDevicePath,L'\\');if(!partionPortion||!_wcsicmp(partionPortion,L"\\Partition0")){// Only partitions are supported (not whole drives)if(!quiet)Warning("NO_SYSENC_PARTITION_SELECTED",hwndDlg);returnFALSE;}try{BootEncStatus=BootEncObj->GetStatus();if(BootEncStatus.DriveMounted){intretCode=0;intdriveNo;wchar_tparentDrivePath[TC_MAX_PATH+1];if(swscanf(szDevicePath,L"\\Device\\Harddisk%d\\Partition",&driveNo)!=1){if(!quiet)Error("INVALID_PATH",hwndDlg);returnFALSE;}StringCbPrintfW(parentDrivePath,sizeof(parentDrivePath),L"\\Device\\Harddisk%d\\Partition0",driveNo);WaitCursor();// This is critical (re-mounting a mounted system volume as a normal volume could cause data corruption)// so we force the slower but reliable methodretCode=IsSystemDevicePath(parentDrivePath,MainDlg,TRUE);NormalCursor();if(retCode!=2)returnTRUE;else{// The partition is located on active system driveif(!quiet)Warning("MOUNT_WITHOUT_PBA_VOL_ON_ACTIVE_SYSENC_DRIVE",hwndDlg);returnFALSE;}}elsereturnTRUE;}catch(Exception&e){NormalCursor();e.Show(hwndDlg);}returnFALSE;}// Returns TRUE if the host drive of the specified partition contains a portion of the TrueCrypt Boot Loader// and if the drive is not within key scope of active system encryption (e.g. the system drive of the running OS).// If bPrebootPasswordDlgMode is TRUE, this function returns FALSE (because the check would be redundant).BOOLTCBootLoaderOnInactiveSysEncDrive(wchar_t*szDevicePath){try{intdriveNo;wchar_tparentDrivePath[TC_MAX_PATH+1];if(bPrebootPasswordDlgMode)returnFALSE;if(swscanf(szDevicePath,L"\\Device\\Harddisk%d\\Partition",&driveNo)!=1)returnFALSE;StringCbPrintfW(parentDrivePath,sizeof(parentDrivePath),L"\\Device\\Harddisk%d\\Partition0",driveNo);BootEncStatus=BootEncObj->GetStatus();if(BootEncStatus.DriveMounted&&IsSystemDevicePath(parentDrivePath,MainDlg,FALSE)==2){// The partition is within key scope of active system encryptionreturnFALSE;}return((BOOL)BootEncObj->IsBootLoaderOnDrive(parentDrivePath));}catch(...){returnFALSE;}}BOOLSelectItem(HWNDhTree,wchar_tnLetter){if(nLetter==0){// The caller specified an invalid drive letter (typically because it is unknown).// Find out which drive letter is currently selected in the list and use it.nLetter=(wchar_t)(HIWORD(GetSelectedLong(hTree)));}inti;LVITEMitem;for(i=0;i<ListView_GetItemCount(hTree);i++){memset(&item,0,sizeof(LVITEM));item.mask=LVIF_PARAM;item.iItem=i;if(ListView_GetItem(hTree,&item)==FALSE)returnFALSE;else{if(HIWORD(item.lParam)==nLetter){memset(&item,0,sizeof(LVITEM));item.state=LVIS_FOCUSED|LVIS_SELECTED;item.stateMask=LVIS_FOCUSED|LVIS_SELECTED;item.mask=LVIF_STATE;item.iItem=i;SendMessage(hTree,LVM_SETITEMSTATE,i,(LPARAM)&item);returnTRUE;}}}returnTRUE;}staticvoidLaunchVolCreationWizard(HWNDhwndDlg,constwchar_t*arg,BOOLbElevation){wchar_tt[TC_MAX_PATH+1024]={L'"',0};wchar_t*tmp;GetModuleFileName(NULL,t+1,ARRAYSIZE(t)-1);tmp=wcsrchr(t,L'\\');if(tmp){STARTUPINFOsi;PROCESS_INFORMATIONpi;wchar_tformatExeName[64];wchar_t*suffix=NULL;ZeroMemory(&si,sizeof(si));StringCbCopyW(formatExeName,sizeof(formatExeName),L"\\VeraCrypt Format");// check if there is a suffix in VeraCrypt file name// in order to use the same for "VeraCrypt Format"suffix=wcsrchr(tmp+1,L'-');if(suffix){StringCbCatW(formatExeName,sizeof(formatExeName),suffix);StringCbCatW(formatExeName,sizeof(formatExeName),L"\"");}elseStringCbCatW(formatExeName,sizeof(formatExeName),L".exe\"");*tmp=0;StringCbCatW(t,sizeof(t),formatExeName);if(!FileExists(t))Error("VOL_CREATION_WIZARD_NOT_FOUND",hwndDlg);// Display a user-friendly error message and advise what to doelse{if(bElevation&&!IsAdmin()&&IsUacSupported()){LaunchElevatedProcess(hwndDlg,t,arg);}else{if(wcslen(arg)>0){StringCbCatW(t,sizeof(t),L" ");StringCbCatW(t,sizeof(t),arg);}if(!CreateProcess(NULL,(LPWSTR)t,NULL,NULL,FALSE,NORMAL_PRIORITY_CLASS,NULL,NULL,&si,&pi)){handleWin32Error(hwndDlg,SRC_POS);}else{CloseHandle(pi.hProcess);CloseHandle(pi.hThread);}}}}}staticvoidLaunchVolExpander(HWNDhwndDlg){wchar_tt[TC_MAX_PATH+TC_MAX_PATH]={L'"',0};wchar_t*tmp;GetModuleFileName(NULL,t+1,ARRAYSIZE(t)-1);tmp=wcsrchr(t,L'\\');if(tmp){wchar_texpanderExeName[64];wchar_t*suffix=NULL;StringCbCopyW(expanderExeName,sizeof(expanderExeName),L"\\VeraCryptExpander");// check if there is a suffix in VeraCrypt file name// in order to use the same for "VeraCrypt Format"suffix=wcsrchr(tmp+1,L'-');if(suffix){StringCbCatW(expanderExeName,sizeof(expanderExeName),suffix);StringCbCatW(expanderExeName,sizeof(expanderExeName),L"\"");}elseStringCbCatW(expanderExeName,sizeof(expanderExeName),L".exe\"");*tmp=0;StringCbCatW(t,sizeof(t),expanderExeName);if(!FileExists(t))Error("VOL_EXPANDER_NOT_FOUND",hwndDlg);// Display a user-friendly error message and advise what to doelseif(((int)ShellExecuteW(NULL,(!IsAdmin()&&IsUacSupported())?L"runas":L"open",t,NULL,NULL,SW_SHOW))<=32){handleWin32Error(hwndDlg,SRC_POS);}}}// Fills drive list// drive>0 = update only the corresponding drive subitemsvoidLoadDriveLetters(HWNDhwndDlg,HWNDhTree,intdrive){// Remember the top-most visible itemintlastTopMostVisibleItem=ListView_GetTopIndex(hTree);wchar_t*szDriveLetters[]={L"A:",L"B:",L"C:",L"D:",L"E:",L"F:",L"G:",L"H:",L"I:",L"J:",L"K:",L"L:",L"M:",L"N:",L"O:",L"P:",L"Q:",L"R:",L"S:",L"T:",L"U:",L"V:",L"W:",L"X:",L"Y:",L"Z:"};DWORDdwResult;BOOLbResult;DWORDdwUsedDrives;MOUNT_LIST_STRUCTdriver;VOLUME_PROPERTIES_STRUCTpropSysEnc;wchar_tsysDriveLetter=0;BOOLbSysEnc=FALSE;BOOLbWholeSysDriveEncryption=FALSE;LVITEMlistItem;intitem=0;chari;try{BootEncStatus=BootEncObj->GetStatus();if(bSysEnc=BootEncStatus.DriveMounted){BootEncObj->GetVolumeProperties(&propSysEnc);}}catch(...){bSysEnc=FALSE;}ZeroMemory(&driver,sizeof(driver));bResult=DeviceIoControl(hDriver,TC_IOCTL_GET_MOUNTED_VOLUMES,&driver,sizeof(driver),&driver,sizeof(driver),&dwResult,NULL);memcpy(&LastKnownMountList,&driver,sizeof(driver));if((bResult==FALSE)||(driver.ulMountedDrives>=(1<<26))){KillTimer(MainDlg,TIMER_ID_MAIN);KillTimer(hwndDlg,TIMER_ID_UPDATE_DEVICE_LIST);handleWin32Error(hTree,SRC_POS);AbortProcessSilent();}LastKnownLogicalDrives=dwUsedDrives=GetUsedLogicalDrives();if(dwUsedDrives==0)Warning("DRIVELETTERS",hwndDlg);if(drive==0)ListView_DeleteAllItems(hTree);if(bSysEnc){bWholeSysDriveEncryption=WholeSysDriveEncryption(TRUE);sysDriveLetter=GetSystemDriveLetter();}/* System drive */if(bWholeSysDriveEncryption){intcurDrive=0;if(drive>0){LVITEMtmp;memset(&tmp,0,sizeof(LVITEM));tmp.mask=LVIF_PARAM;tmp.iItem=item;if(ListView_GetItem(hTree,&tmp))curDrive=HIWORD(tmp.lParam);}{wchar_tszTmp[1024];wchar_tszTmpW[1024];memset(&listItem,0,sizeof(listItem));listItem.mask=LVIF_TEXT|LVIF_IMAGE|LVIF_PARAM;listItem.iImage=2;listItem.iItem=item++;listItem.pszText=szTmp;szTmp[0]=L' ';szTmp[1]=0;listItem.lParam=MAKELONG(TC_MLIST_ITEM_SYS_DRIVE,ENC_SYSDRIVE_PSEUDO_DRIVE_LETTER);if(drive==0)ListView_InsertItem(hTree,&listItem);elseListView_SetItem(hTree,&listItem);listItem.mask=LVIF_TEXT;// Fully encryptedif(SysDriveOrPartitionFullyEncrypted(TRUE)){StringCbCopyW(szTmpW,sizeof(szTmpW),GetString("SYSTEM_DRIVE"));}else{// Partially encryptedif(BootEncStatus.SetupInProgress){// Currently encrypting/decryptingif(BootEncStatus.SetupMode!=SetupDecryption){StringCbPrintfW(szTmpW,sizeofszTmpW,GetString("SYSTEM_DRIVE_ENCRYPTING"),(double)GetSysEncDeviceEncryptedPartSize(TRUE)/(double)GetSysEncDeviceSize(TRUE)*100.0);}else{StringCbPrintfW(szTmpW,sizeofszTmpW,GetString("SYSTEM_DRIVE_DECRYPTING"),100.0-((double)GetSysEncDeviceEncryptedPartSize(TRUE)/(double)GetSysEncDeviceSize(TRUE)*100.0));}}else{StringCbPrintfW(szTmpW,sizeofszTmpW,GetString("SYSTEM_DRIVE_PARTIALLY_ENCRYPTED"),(double)GetSysEncDeviceEncryptedPartSize(TRUE)/(double)GetSysEncDeviceSize(TRUE)*100.0);}}ListSubItemSet(hTree,listItem.iItem,1,szTmpW);GetSizeString(GetSysEncDeviceSize(TRUE),szTmpW,sizeof(szTmpW));ListSubItemSet(hTree,listItem.iItem,2,szTmpW);if(propSysEnc.ea>=EAGetFirst()&&propSysEnc.ea<=EAGetCount()){EAGetName(szTmp,propSysEnc.ea,1);}else{szTmp[0]=L'?';szTmp[1]=0;}listItem.iSubItem=3;ListView_SetItem(hTree,&listItem);ListSubItemSet(hTree,listItem.iItem,4,GetString(IsHiddenOSRunning()?"HIDDEN":"SYSTEM_VOLUME_TYPE_ADJECTIVE"));}}/* Drive letters */for(i=0;i<26;i++){intcurDrive=0;BOOLbSysEncPartition=(bSysEnc&&!bWholeSysDriveEncryption&&sysDriveLetter==*((wchar_t*)szDriveLetters[i]));if(drive>0){LVITEMtmp;memset(&tmp,0,sizeof(LVITEM));tmp.mask=LVIF_PARAM;tmp.iItem=item;if(ListView_GetItem(hTree,&tmp))curDrive=HIWORD(tmp.lParam);}if(((driver.ulMountedDrives&(1<<i))&&(IsNullTerminateString(driver.wszVolume[i],TC_MAX_PATH)))||bSysEncPartition){wchar_tszTmp[1024];wchar_tszTmpW[1024];wchar_t*ws;memset(&listItem,0,sizeof(listItem));listItem.mask=LVIF_TEXT|LVIF_IMAGE|LVIF_PARAM;listItem.iImage=bSysEncPartition?2:1;listItem.iItem=item++;if(drive>0&&drive!=curDrive)continue;listItem.lParam=MAKELONG(bSysEncPartition?TC_MLIST_ITEM_SYS_PARTITION:TC_MLIST_ITEM_NONSYS_VOL,i+L'A');listItem.pszText=szDriveLetters[i];if(drive==0)ListView_InsertItem(hTree,&listItem);elseListView_SetItem(hTree,&listItem);listItem.mask=LVIF_TEXT;listItem.pszText=szTmp;if(bSysEncPartition){// Fully encryptedif(SysDriveOrPartitionFullyEncrypted(TRUE)){StringCbCopyW(szTmpW,sizeof(szTmpW),GetString(IsHiddenOSRunning()?"HIDDEN_SYSTEM_PARTITION":"SYSTEM_PARTITION"));}else{// Partially encryptedif(BootEncStatus.SetupInProgress){// Currently encrypting/decryptingif(BootEncStatus.SetupMode!=SetupDecryption){StringCbPrintfW(szTmpW,sizeofszTmpW,GetString("SYSTEM_PARTITION_ENCRYPTING"),(double)GetSysEncDeviceEncryptedPartSize(TRUE)/(double)GetSysEncDeviceSize(TRUE)*100.0);}else{StringCbPrintfW(szTmpW,sizeofszTmpW,GetString("SYSTEM_PARTITION_DECRYPTING"),100.0-((double)GetSysEncDeviceEncryptedPartSize(TRUE)/(double)GetSysEncDeviceSize(TRUE)*100.0));}}else{StringCbPrintfW(szTmpW,sizeofszTmpW,GetString("SYSTEM_PARTITION_PARTIALLY_ENCRYPTED"),(double)GetSysEncDeviceEncryptedPartSize(TRUE)/(double)GetSysEncDeviceSize(TRUE)*100.0);}}ListSubItemSet(hTree,listItem.iItem,1,szTmpW);}else{wchar_t*path=driver.wszVolume[i];if(wmemcmp(path,L"\\??\\",4)==0)path+=4;listItem.iSubItem=1;// first check label used for mounting. If empty, look for it in favorites.booluseInExplorer=false;wstringlabel=(wchar_t*)driver.wszLabel[i];if(label.empty())label=GetFavoriteVolumeLabel(path,useInExplorer);if(!label.empty())ListSubItemSet(hTree,listItem.iItem,1,(wchar_t*)label.c_str());elseListSubItemSet(hTree,listItem.iItem,1,(wchar_t*)FitPathInGfxWidth(hTree,hUserFont,ListView_GetColumnWidth(hTree,1)-GetTextGfxWidth(hTree,L"___",hUserFont),path).c_str());}GetSizeString(bSysEncPartition?GetSysEncDeviceSize(TRUE):driver.diskLength[i],szTmpW,sizeof(szTmpW));ListSubItemSet(hTree,listItem.iItem,2,szTmpW);EAGetName(szTmp,bSysEncPartition?propSysEnc.ea:driver.ea[i],1);listItem.iSubItem=3;ListView_SetItem(hTree,&listItem);if(bSysEncPartition){ws=GetString(IsHiddenOSRunning()?"HIDDEN":"SYSTEM_VOLUME_TYPE_ADJECTIVE");VolumeNotificationsList.bHidVolDamagePrevReported[i]=FALSE;ListSubItemSet(hTree,listItem.iItem,4,ws);}else{switch(driver.volumeType[i]){casePROP_VOL_TYPE_NORMAL:ws=GetString("NORMAL");break;casePROP_VOL_TYPE_HIDDEN:ws=GetString("HIDDEN");break;casePROP_VOL_TYPE_OUTER:ws=GetString("OUTER");// Normal/outer volume (hidden volume protected)break;casePROP_VOL_TYPE_OUTER_VOL_WRITE_PREVENTED:ws=GetString("OUTER_VOL_WRITE_PREVENTED");// Normal/outer volume (hidden volume protected AND write denied)break;default:ws=L"?";}if(driver.truecryptMode[i]){StringCbPrintfW(szTmpW,sizeof(szTmpW),L"TrueCrypt-%s",ws);ListSubItemSet(hTree,listItem.iItem,4,szTmpW);}elseListSubItemSet(hTree,listItem.iItem,4,ws);if(driver.volumeType[i]==PROP_VOL_TYPE_OUTER_VOL_WRITE_PREVENTED)// Normal/outer volume (hidden volume protected AND write denied){if(!VolumeNotificationsList.bHidVolDamagePrevReported[i]){wchar_tszTmp[4096];VolumeNotificationsList.bHidVolDamagePrevReported[i]=TRUE;StringCbPrintfW(szTmp,sizeof(szTmp),GetString("DAMAGE_TO_HIDDEN_VOLUME_PREVENTED"),i+L'A');SetForegroundWindow(GetParent(hTree));MessageBoxW(GetParent(hTree),szTmp,lpszTitle,MB_ICONWARNING|MB_SETFOREGROUND|MB_TOPMOST);}}else{VolumeNotificationsList.bHidVolDamagePrevReported[i]=FALSE;}}}else{VolumeNotificationsList.bHidVolDamagePrevReported[i]=FALSE;if(!(dwUsedDrives&1<<i)){if(drive>0&&drive!=HIWORD(GetSelectedLong(hTree))){item++;continue;}memset(&listItem,0,sizeof(listItem));listItem.mask=LVIF_TEXT|LVIF_IMAGE|LVIF_PARAM;listItem.iImage=0;listItem.iItem=item++;listItem.pszText=szDriveLetters[i];listItem.lParam=MAKELONG(TC_MLIST_ITEM_FREE,i+'A');if(drive==0)ListView_InsertItem(hTree,&listItem);elseListView_SetItem(hTree,&listItem);listItem.mask=LVIF_TEXT;listItem.pszText=L"";listItem.iSubItem=1;ListView_SetItem(hTree,&listItem);listItem.iSubItem=2;ListView_SetItem(hTree,&listItem);listItem.iSubItem=3;ListView_SetItem(hTree,&listItem);listItem.iSubItem=4;ListView_SetItem(hTree,&listItem);}}}// Restore the original scroll position (the topmost item that was visible when we were called) and the// last selected item.SetListScrollHPos(hTree,lastTopMostVisibleItem);SelectItem(hTree,0);}staticvoidPasswordChangeEnable(HWNDhwndDlg,intbutton,intpasswordId,BOOLkeyFilesEnabled,intnewPasswordId,intnewVerifyId,BOOLnewKeyFilesEnabled){charpassword[MAX_PASSWORD+1];charnewPassword[MAX_PASSWORD+1];charnewVerify[MAX_PASSWORD+1];wchar_ttmp[MAX_PASSWORD+1];BOOLbEnable=TRUE;intpasswordUtf8Len,newPasswordUtf8Len,newVerifyUtf8Len;GetWindowText(GetDlgItem(hwndDlg,passwordId),tmp,ARRAYSIZE(tmp));passwordUtf8Len=WideCharToMultiByte(CP_UTF8,0,tmp,-1,password,sizeof(password),NULL,NULL);if(pwdChangeDlgMode==PCDM_CHANGE_PKCS5_PRF)newKeyFilesEnabled=keyFilesEnabled;switch(pwdChangeDlgMode){casePCDM_REMOVE_ALL_KEYFILES_FROM_VOL:casePCDM_ADD_REMOVE_VOL_KEYFILES:casePCDM_CHANGE_PKCS5_PRF:memcpy(newPassword,password,sizeof(newPassword));memcpy(newVerify,password,sizeof(newVerify));newPasswordUtf8Len=passwordUtf8Len;newVerifyUtf8Len=passwordUtf8Len;break;default:GetWindowText(GetDlgItem(hwndDlg,newPasswordId),tmp,ARRAYSIZE(tmp));newPasswordUtf8Len=WideCharToMultiByte(CP_UTF8,0,tmp,-1,newPassword,sizeof(newPassword),NULL,NULL);GetWindowText(GetDlgItem(hwndDlg,newVerifyId),tmp,ARRAYSIZE(tmp));newVerifyUtf8Len=WideCharToMultiByte(CP_UTF8,0,tmp,-1,newVerify,sizeof(newVerify),NULL,NULL);}if(passwordUtf8Len<=0||(!keyFilesEnabled&&((passwordUtf8Len-1)<MIN_PASSWORD)))bEnable=FALSE;elseif(strcmp(newPassword,newVerify)!=0)bEnable=FALSE;elseif((newPasswordUtf8Len<=0)||(!newKeyFilesEnabled&&((newPasswordUtf8Len-1)<MIN_PASSWORD)))bEnable=FALSE;burn(password,sizeof(password));burn(newPassword,sizeof(newPassword));burn(newVerify,sizeof(newVerify));burn(tmp,sizeof(tmp));EnableWindow(GetDlgItem(hwndDlg,button),bEnable);}// implementation for support of change password operation in wait dialog mechanismtypedefstruct{Password*oldPassword;intold_pkcs5;intold_pim;Password*newPassword;intpkcs5;intpim;intwipePassCount;BOOLtruecryptMode;int*pnStatus;}ChangePwdThreadParam;voidCALLBACKChangePwdWaitThreadProc(void*pArg,HWNDhwndDlg){ChangePwdThreadParam*pThreadParam=(ChangePwdThreadParam*)pArg;if(bSysEncPwdChangeDlgMode){// Systemtry{VOLUME_PROPERTIES_STRUCTproperties;BootEncObj->GetVolumeProperties(&properties);pThreadParam->old_pkcs5=properties.pkcs5;}catch(...){}pThreadParam->pkcs5=0;// PKCS-5 PRF unchanged (currently we can't change PRF of system encryption)try{*pThreadParam->pnStatus=BootEncObj->ChangePassword(pThreadParam->oldPassword,pThreadParam->old_pkcs5,pThreadParam->old_pim,pThreadParam->newPassword,pThreadParam->pkcs5,pThreadParam->pim,pThreadParam->wipePassCount,hwndDlg);}catch(Exception&e){e.Show(hwndDlg);*(pThreadParam->pnStatus)=ERR_OS_ERROR;}}else{// Non-system*pThreadParam->pnStatus=ChangePwd(szFileName,pThreadParam->oldPassword,pThreadParam->old_pkcs5,pThreadParam->old_pim,pThreadParam->truecryptMode,pThreadParam->newPassword,pThreadParam->pkcs5,pThreadParam->pim,pThreadParam->wipePassCount,hwndDlg);if(*pThreadParam->pnStatus==ERR_OS_ERROR&&GetLastError()==ERROR_ACCESS_DENIED&&IsUacSupported()&&IsVolumeDeviceHosted(szFileName)){*pThreadParam->pnStatus=UacChangePwd(szFileName,pThreadParam->oldPassword,pThreadParam->old_pkcs5,pThreadParam->old_pim,pThreadParam->truecryptMode,pThreadParam->newPassword,pThreadParam->pkcs5,pThreadParam->pim,pThreadParam->wipePassCount,hwndDlg);}}}// implementation for support of backup header operation in wait dialog mechanismtypedefstruct{BOOLbRequireConfirmation;wchar_t*lpszVolume;size_tcchVolume;int*iResult;}BackupHeaderThreadParam;voidCALLBACKBackupHeaderWaitThreadProc(void*pArg,HWNDhwndDlg){BackupHeaderThreadParam*pThreadParam=(BackupHeaderThreadParam*)pArg;if(TranslateVolumeID(hwndDlg,pThreadParam->lpszVolume,pThreadParam->cchVolume)){if(!IsAdmin()&&IsUacSupported()&&IsVolumeDeviceHosted(pThreadParam->lpszVolume))*(pThreadParam->iResult)=UacBackupVolumeHeader(hwndDlg,pThreadParam->bRequireConfirmation,pThreadParam->lpszVolume);else*(pThreadParam->iResult)=BackupVolumeHeader(hwndDlg,pThreadParam->bRequireConfirmation,pThreadParam->lpszVolume);}else*(pThreadParam->iResult)=ERR_OS_ERROR;}// implementation for support of restoring header operation in wait dialog mechanismtypedefstruct{wchar_t*lpszVolume;size_tcchVolume;int*iResult;}RestoreHeaderThreadParam;voidCALLBACKRestoreHeaderWaitThreadProc(void*pArg,HWNDhwndDlg){RestoreHeaderThreadParam*pThreadParam=(RestoreHeaderThreadParam*)pArg;if(TranslateVolumeID(hwndDlg,pThreadParam->lpszVolume,pThreadParam->cchVolume)){if(!IsAdmin()&&IsUacSupported()&&IsVolumeDeviceHosted(pThreadParam->lpszVolume))*(pThreadParam->iResult)=UacRestoreVolumeHeader(hwndDlg,pThreadParam->lpszVolume);else*(pThreadParam->iResult)=RestoreVolumeHeader(hwndDlg,pThreadParam->lpszVolume);}else*(pThreadParam->iResult)=ERR_OS_ERROR;}/* 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 */BOOLCALLBACKPasswordChangeDlgProc(HWNDhwndDlg,UINTmsg,WPARAMwParam,LPARAMlParam){staticKeyFilesDlgParamnewKeyFilesParam;staticBOOLPimValueChangedWarning=FALSE;staticint*NewPimValuePtr=NULL;WORDlw=LOWORD(wParam);WORDhw=HIWORD(wParam);switch(msg){caseWM_INITDIALOG:{LPARAMnIndex,nSelectedIndex=0;HWNDhComboBox=GetDlgItem(hwndDlg,IDC_PKCS5_OLD_PRF_ID);inti;WipeAlgorithmIdheaderWipeMode=TC_WIPE_3_DOD_5220;intEffectiveVolumePkcs5=CmdVolumePkcs5;BOOLEffectiveVolumeTrueCryptMode=CmdVolumeTrueCryptMode;intEffectiveVolumePim=CmdVolumePim;/* Priority is given to command line parameters * Default values used only when nothing specified in command line */if(EffectiveVolumePkcs5==0)EffectiveVolumePkcs5=DefaultVolumePkcs5;if(!EffectiveVolumeTrueCryptMode)EffectiveVolumeTrueCryptMode=DefaultVolumeTrueCryptMode;NewPimValuePtr=(int*)lParam;PimValueChangedWarning=FALSE;ZeroMemory(&newKeyFilesParam,sizeof(newKeyFilesParam));if(NewPimValuePtr){/* we are in the case of a volume. Store its name to use it in the key file dialog * this will help avoid using the current container file as a key file */StringCbCopyW(newKeyFilesParam.VolumeFileName,sizeof(newKeyFilesParam.VolumeFileName),szFileName);}SetWindowTextW(hwndDlg,GetString("IDD_PASSWORDCHANGE_DLG"));LocalizeDialog(hwndDlg,"IDD_PASSWORDCHANGE_DLG");SendMessage(GetDlgItem(hwndDlg,IDC_OLD_PASSWORD),EM_LIMITTEXT,MAX_PASSWORD,0);SendMessage(GetDlgItem(hwndDlg,IDC_PASSWORD),EM_LIMITTEXT,MAX_PASSWORD,0);SendMessage(GetDlgItem(hwndDlg,IDC_VERIFY),EM_LIMITTEXT,MAX_PASSWORD,0);SendMessage(GetDlgItem(hwndDlg,IDC_OLD_PIM),EM_LIMITTEXT,MAX_PIM,0);SendMessage(GetDlgItem(hwndDlg,IDC_PIM),EM_LIMITTEXT,MAX_PIM,0);EnableWindow(GetDlgItem(hwndDlg,IDOK),FALSE);SetCheckBox(hwndDlg,IDC_ENABLE_KEYFILES,KeyFilesEnable);EnableWindow(GetDlgItem(hwndDlg,IDC_KEYFILES),TRUE);EnableWindow(GetDlgItem(hwndDlg,IDC_NEW_KEYFILES),TRUE);/* Add PRF algorithm list for current password */SendMessage(hComboBox,CB_RESETCONTENT,0,0);nIndex=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=SendMessage(hComboBox,CB_ADDSTRING,0,(LPARAM)get_pkcs5_prf_name(i));SendMessage(hComboBox,CB_SETITEMDATA,nIndex,(LPARAM)i);if(i==EffectiveVolumePkcs5){nSelectedIndex=nIndex;}}SendMessage(hComboBox,CB_SETCURSEL,nSelectedIndex,0);/* check TrueCrypt Mode if it was set as default*/SetCheckBox(hwndDlg,IDC_TRUECRYPT_MODE,EffectiveVolumeTrueCryptMode);/* set default PIM if set in the command line*/if(EffectiveVolumePim>0){SetCheckBox(hwndDlg,IDC_PIM_ENABLE,TRUE);ShowWindow(GetDlgItem(hwndDlg,IDC_PIM_ENABLE),SW_HIDE);ShowWindow(GetDlgItem(hwndDlg,IDT_OLD_PIM),SW_SHOW);ShowWindow(GetDlgItem(hwndDlg,IDC_OLD_PIM),SW_SHOW);ShowWindow(GetDlgItem(hwndDlg,IDC_OLD_PIM_HELP),SW_SHOW);SetPim(hwndDlg,IDC_OLD_PIM,EffectiveVolumePim);}/* Add PRF algorithm list for new password */hComboBox=GetDlgItem(hwndDlg,IDC_PKCS5_PRF_ID);SendMessage(hComboBox,CB_RESETCONTENT,0,0);nIndex=SendMessageW(hComboBox,CB_ADDSTRING,0,(LPARAM)GetString("UNCHANGED"));SendMessage(hComboBox,CB_SETITEMDATA,nIndex,(LPARAM)0);for(i=FIRST_PRF_ID;i<=LAST_PRF_ID;i++){if(!HashIsDeprecated(i)){nIndex=SendMessage(hComboBox,CB_ADDSTRING,0,(LPARAM)get_pkcs5_prf_name(i));SendMessage(hComboBox,CB_SETITEMDATA,nIndex,(LPARAM)i);}}SendMessage(hComboBox,CB_SETCURSEL,0,0);PopulateWipeModeCombo(GetDlgItem(hwndDlg,IDC_WIPE_MODE),FALSE,FALSE,TRUE);SelectAlgo(GetDlgItem(hwndDlg,IDC_WIPE_MODE),(int*)&headerWipeMode);switch(pwdChangeDlgMode){casePCDM_CHANGE_PKCS5_PRF:SetWindowTextW(hwndDlg,GetString("IDD_PCDM_CHANGE_PKCS5_PRF"));LocalizeDialog(hwndDlg,"IDD_PCDM_CHANGE_PKCS5_PRF");EnableWindow(GetDlgItem(hwndDlg,IDC_PASSWORD),FALSE);EnableWindow(GetDlgItem(hwndDlg,IDC_VERIFY),FALSE);EnableWindow(GetDlgItem(hwndDlg,IDT_PIM),FALSE);EnableWindow(GetDlgItem(hwndDlg,IDC_PIM),FALSE);EnableWindow(GetDlgItem(hwndDlg,IDC_PIM_HELP),FALSE);EnableWindow(GetDlgItem(hwndDlg,IDC_NEW_PIM_ENABLE),FALSE);EnableWindow(GetDlgItem(hwndDlg,IDC_ENABLE_NEW_KEYFILES),FALSE);EnableWindow(GetDlgItem(hwndDlg,IDC_SHOW_PASSWORD_CHPWD_NEW),FALSE);EnableWindow(GetDlgItem(hwndDlg,IDC_NEW_KEYFILES),FALSE);EnableWindow(GetDlgItem(hwndDlg,IDT_NEW_PASSWORD),FALSE);EnableWindow(GetDlgItem(hwndDlg,IDT_CONFIRM_PASSWORD),FALSE);break;casePCDM_ADD_REMOVE_VOL_KEYFILES:SetWindowTextW(hwndDlg,GetString("IDD_PCDM_ADD_REMOVE_VOL_KEYFILES"));LocalizeDialog(hwndDlg,"IDD_PCDM_ADD_REMOVE_VOL_KEYFILES");newKeyFilesParam.EnableKeyFiles=TRUE;EnableWindow(GetDlgItem(hwndDlg,IDC_PASSWORD),FALSE);EnableWindow(GetDlgItem(hwndDlg,IDC_VERIFY),FALSE);EnableWindow(GetDlgItem(hwndDlg,IDT_PIM),FALSE);EnableWindow(GetDlgItem(hwndDlg,IDC_PIM),FALSE);EnableWindow(GetDlgItem(hwndDlg,IDC_PIM_HELP),FALSE);EnableWindow(GetDlgItem(hwndDlg,IDC_NEW_PIM_ENABLE),FALSE);EnableWindow(GetDlgItem(hwndDlg,IDC_SHOW_PASSWORD_CHPWD_NEW),FALSE);EnableWindow(GetDlgItem(hwndDlg,IDT_NEW_PASSWORD),FALSE);EnableWindow(GetDlgItem(hwndDlg,IDT_CONFIRM_PASSWORD),FALSE);EnableWindow(GetDlgItem(hwndDlg,IDT_NEW_PKCS5_PRF),FALSE);EnableWindow(GetDlgItem(hwndDlg,IDC_PKCS5_PRF_ID),FALSE);break;casePCDM_REMOVE_ALL_KEYFILES_FROM_VOL:newKeyFilesParam.EnableKeyFiles=FALSE;SetWindowTextW(hwndDlg,GetString("IDD_PCDM_REMOVE_ALL_KEYFILES_FROM_VOL"));LocalizeDialog(hwndDlg,"IDD_PCDM_REMOVE_ALL_KEYFILES_FROM_VOL");KeyFilesEnable=TRUE;SetCheckBox(hwndDlg,IDC_ENABLE_KEYFILES,TRUE);EnableWindow(GetDlgItem(hwndDlg,IDC_KEYFILES),TRUE);EnableWindow(GetDlgItem(hwndDlg,IDC_ENABLE_KEYFILES),TRUE);EnableWindow(GetDlgItem(hwndDlg,IDC_PASSWORD),FALSE);EnableWindow(GetDlgItem(hwndDlg,IDC_VERIFY),FALSE);EnableWindow(GetDlgItem(hwndDlg,IDT_PIM),FALSE);EnableWindow(GetDlgItem(hwndDlg,IDC_PIM),FALSE);EnableWindow(GetDlgItem(hwndDlg,IDC_PIM_HELP),FALSE);EnableWindow(GetDlgItem(hwndDlg,IDC_NEW_PIM_ENABLE),FALSE);EnableWindow(GetDlgItem(hwndDlg,IDC_ENABLE_NEW_KEYFILES),FALSE);EnableWindow(GetDlgItem(hwndDlg,IDC_SHOW_PASSWORD_CHPWD_NEW),FALSE);EnableWindow(GetDlgItem(hwndDlg,IDC_NEW_KEYFILES),FALSE);EnableWindow(GetDlgItem(hwndDlg,IDT_NEW_PASSWORD),FALSE);EnableWindow(GetDlgItem(hwndDlg,IDT_CONFIRM_PASSWORD),FALSE);EnableWindow(GetDlgItem(hwndDlg,IDT_NEW_PKCS5_PRF),FALSE);EnableWindow(GetDlgItem(hwndDlg,IDC_PKCS5_PRF_ID),FALSE);break;casePCDM_CHANGE_PASSWORD:default:// NOPbreak;};if(bSysEncPwdChangeDlgMode){/* No support for changing the password of TrueCrypt system partition */SetCheckBox(hwndDlg,IDC_TRUECRYPT_MODE,FALSE);EnableWindow(GetDlgItem(hwndDlg,IDC_TRUECRYPT_MODE),FALSE);ToBootPwdField(hwndDlg,IDC_PASSWORD);ToBootPwdField(hwndDlg,IDC_VERIFY);ToBootPwdField(hwndDlg,IDC_OLD_PASSWORD);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",hwndDlg);EndDialog(hwndDlg,IDCANCEL);return0;}bKeyboardLayoutChanged=TRUE;}/* for system encryption, we can't change the PRF */EnableWindow(GetDlgItem(hwndDlg,IDT_PKCS5_PRF),FALSE);EnableWindow(GetDlgItem(hwndDlg,IDT_NEW_PKCS5_PRF),FALSE);EnableWindow(GetDlgItem(hwndDlg,IDC_PKCS5_PRF_ID),FALSE);EnableWindow(GetDlgItem(hwndDlg,IDC_PKCS5_OLD_PRF_ID),FALSE);if(SetTimer(hwndDlg,TIMER_ID_KEYB_LAYOUT_GUARD,TIMER_INTERVAL_KEYB_LAYOUT_GUARD,NULL)==0){Error("CANNOT_SET_TIMER",hwndDlg);EndDialog(hwndDlg,IDCANCEL);return0;}newKeyFilesParam.EnableKeyFiles=FALSE;KeyFilesEnable=FALSE;SetCheckBox(hwndDlg,IDC_ENABLE_KEYFILES,FALSE);EnableWindow(GetDlgItem(hwndDlg,IDC_ENABLE_KEYFILES),FALSE);EnableWindow(GetDlgItem(hwndDlg,IDC_ENABLE_NEW_KEYFILES),FALSE);}CheckCapsLock(hwndDlg,FALSE);return0;}caseWM_TIMER:switch(wParam){caseTIMER_ID_KEYB_LAYOUT_GUARD:if(bSysEncPwdChangeDlgMode){DWORDkeybLayout=(DWORD)GetKeyboardLayout(NULL);/* Watch the keyboard layout */if(keybLayout!=0x00000409&&keybLayout!=0x04090409){// Keyboard layout is not standard US// Attempt to wipe passwords stored in the input field bufferswchar_ttmp[MAX_PASSWORD+1];wmemset(tmp,L'X',MAX_PASSWORD);tmp[MAX_PASSWORD]=0;SetWindowText(GetDlgItem(hwndDlg,IDC_OLD_PASSWORD),tmp);SetWindowText(GetDlgItem(hwndDlg,IDC_PASSWORD),tmp);SetWindowText(GetDlgItem(hwndDlg,IDC_VERIFY),tmp);SetWindowText(GetDlgItem(hwndDlg,IDC_OLD_PASSWORD),L"");SetWindowText(GetDlgItem(hwndDlg,IDC_PASSWORD),L"");SetWindowText(GetDlgItem(hwndDlg,IDC_VERIFY),L"");keybLayout=(DWORD)LoadKeyboardLayout(L"00000409",KLF_ACTIVATE);if(keybLayout!=0x00000409&&keybLayout!=0x04090409){KillTimer(hwndDlg,TIMER_ID_KEYB_LAYOUT_GUARD);Error("CANT_CHANGE_KEYB_LAYOUT_FOR_SYS_ENCRYPTION",hwndDlg);EndDialog(hwndDlg,IDCANCEL);return1;}bKeyboardLayoutChanged=TRUE;wchar_tszTmp[4096];StringCbCopyW(szTmp,sizeof(szTmp),GetString("KEYB_LAYOUT_CHANGE_PREVENTED"));StringCbCatW(szTmp,sizeof(szTmp),L"\n\n");StringCbCatW(szTmp,sizeof(szTmp),GetString("KEYB_LAYOUT_SYS_ENC_EXPLANATION"));MessageBoxW(MainDlg,szTmp,lpszTitle,MB_ICONWARNING|MB_SETFOREGROUND|MB_TOPMOST);}/* Watch the right Alt key (which is used to enter various characters on non-US keyboards) */if(bKeyboardLayoutChanged&&!bKeybLayoutAltKeyWarningShown){if(GetAsyncKeyState(VK_RMENU)<0){bKeybLayoutAltKeyWarningShown=TRUE;wchar_tszTmp[4096];StringCbCopyW(szTmp,sizeof(szTmp),GetString("ALT_KEY_CHARS_NOT_FOR_SYS_ENCRYPTION"));StringCbCatW(szTmp,sizeof(szTmp),L"\n\n");StringCbCatW(szTmp,sizeof(szTmp),GetString("KEYB_LAYOUT_SYS_ENC_EXPLANATION"));MessageBoxW(MainDlg,szTmp,lpszTitle,MB_ICONINFORMATION|MB_SETFOREGROUND|MB_TOPMOST);}}}return1;}return0;caseWM_CTLCOLORSTATIC:{if(PimValueChangedWarning&&((HWND)lParam==GetDlgItem(hwndDlg,IDC_PIM_HELP))){// we're about to draw the static// set the text colour in (HDC)lParamSetBkMode((HDC)wParam,TRANSPARENT);SetTextColor((HDC)wParam,RGB(255,0,0));// NOTE: per documentation as pointed out by selbie, GetSolidBrush would leak a GDI handle.return(BOOL)GetSysColorBrush(COLOR_MENU);}}return0;caseWM_COMMAND:if(lw==IDCANCEL){// Attempt to wipe passwords stored in the input field bufferswchar_ttmp[MAX_PASSWORD+1];wmemset(tmp,L'X',MAX_PASSWORD);tmp[MAX_PASSWORD]=0;SetWindowText(GetDlgItem(hwndDlg,IDC_PASSWORD),tmp);SetWindowText(GetDlgItem(hwndDlg,IDC_OLD_PASSWORD),tmp);SetWindowText(GetDlgItem(hwndDlg,IDC_VERIFY),tmp);RestoreDefaultKeyFilesParam();EndDialog(hwndDlg,IDCANCEL);return1;}if(hw==EN_CHANGE){PasswordChangeEnable(hwndDlg,IDOK,IDC_OLD_PASSWORD,KeyFilesEnable&&FirstKeyFile!=NULL,IDC_PASSWORD,IDC_VERIFY,newKeyFilesParam.EnableKeyFiles&&newKeyFilesParam.FirstKeyFile!=NULL);if((lw==IDC_OLD_PIM)&&IsWindowEnabled(GetDlgItem(hwndDlg,IDC_PIM))){wchar_ttmp[MAX_PIM+1]={0};GetDlgItemText(hwndDlg,IDC_OLD_PIM,tmp,MAX_PIM+1);SetDlgItemText(hwndDlg,IDC_PIM,tmp);}if(lw==IDC_PIM){if(GetPim(hwndDlg,IDC_OLD_PIM,0)!=GetPim(hwndDlg,IDC_PIM,0)){PimValueChangedWarning=TRUE;SetDlgItemTextW(hwndDlg,IDC_PIM_HELP,GetString(bSysEncPwdChangeDlgMode?"PIM_SYSENC_CHANGE_WARNING":"PIM_CHANGE_WARNING"));}else{PimValueChangedWarning=FALSE;SetDlgItemTextW(hwndDlg,IDC_PIM_HELP,(wchar_t*)GetDictionaryValueByInt(IDC_PIM_HELP));}}return1;}if(lw==IDC_PIM_ENABLE){ShowWindow(GetDlgItem(hwndDlg,IDC_PIM_ENABLE),SW_HIDE);ShowWindow(GetDlgItem(hwndDlg,IDT_OLD_PIM),SW_SHOW);ShowWindow(GetDlgItem(hwndDlg,IDC_OLD_PIM),SW_SHOW);ShowWindow(GetDlgItem(hwndDlg,IDC_OLD_PIM_HELP),SW_SHOW);// check also the "Use PIM" for the new password if it is enabledif(IsWindowEnabled(GetDlgItem(hwndDlg,IDC_NEW_PIM_ENABLE))){SetCheckBox(hwndDlg,IDC_NEW_PIM_ENABLE,TRUE);ShowWindow(GetDlgItem(hwndDlg,IDC_NEW_PIM_ENABLE),SW_HIDE);ShowWindow(GetDlgItem(hwndDlg,IDT_PIM),SW_SHOW);ShowWindow(GetDlgItem(hwndDlg,IDC_PIM),SW_SHOW);ShowWindow(GetDlgItem(hwndDlg,IDC_PIM_HELP),SW_SHOW);}SetFocus(GetDlgItem(hwndDlg,IDC_OLD_PIM));return1;}if(lw==IDC_NEW_PIM_ENABLE){ShowWindow(GetDlgItem(hwndDlg,IDC_NEW_PIM_ENABLE),SW_HIDE);ShowWindow(GetDlgItem(hwndDlg,IDT_PIM),SW_SHOW);ShowWindow(GetDlgItem(hwndDlg,IDC_PIM),SW_SHOW);ShowWindow(GetDlgItem(hwndDlg,IDC_PIM_HELP),SW_SHOW);SetFocus(GetDlgItem(hwndDlg,IDC_PIM));return1;}if(lw==IDC_KEYFILES){if(bSysEncPwdChangeDlgMode){Warning("KEYFILES_NOT_SUPPORTED_FOR_SYS_ENCRYPTION",hwndDlg);return1;}KeyFilesDlgParamparam;param.EnableKeyFiles=KeyFilesEnable;param.FirstKeyFile=FirstKeyFile;if(IDOK==DialogBoxParamW(hInst,MAKEINTRESOURCEW(IDD_KEYFILES),hwndDlg,(DLGPROC)KeyFilesDlgProc,(LPARAM)&param)){KeyFilesEnable=param.EnableKeyFiles;FirstKeyFile=param.FirstKeyFile;SetCheckBox(hwndDlg,IDC_ENABLE_KEYFILES,KeyFilesEnable);}PasswordChangeEnable(hwndDlg,IDOK,IDC_OLD_PASSWORD,KeyFilesEnable&&FirstKeyFile!=NULL,IDC_PASSWORD,IDC_VERIFY,newKeyFilesParam.EnableKeyFiles&&newKeyFilesParam.FirstKeyFile!=NULL);return1;}if(lw==IDC_NEW_KEYFILES){if(bSysEncPwdChangeDlgMode){Warning("KEYFILES_NOT_SUPPORTED_FOR_SYS_ENCRYPTION",hwndDlg);return1;}if(IDOK==DialogBoxParamW(hInst,MAKEINTRESOURCEW(IDD_KEYFILES),hwndDlg,(DLGPROC)KeyFilesDlgProc,(LPARAM)&newKeyFilesParam)){SetCheckBox(hwndDlg,IDC_ENABLE_NEW_KEYFILES,newKeyFilesParam.EnableKeyFiles);VerifyPasswordAndUpdate(hwndDlg,GetDlgItem(hwndDlg,IDOK),GetDlgItem(hwndDlg,IDC_PASSWORD),GetDlgItem(hwndDlg,IDC_VERIFY),NULL,NULL,newKeyFilesParam.EnableKeyFiles&&newKeyFilesParam.FirstKeyFile!=NULL);}PasswordChangeEnable(hwndDlg,IDOK,IDC_OLD_PASSWORD,KeyFilesEnable&&FirstKeyFile!=NULL,IDC_PASSWORD,IDC_VERIFY,newKeyFilesParam.EnableKeyFiles&&newKeyFilesParam.FirstKeyFile!=NULL);return1;}if(lw==IDC_ENABLE_KEYFILES){KeyFilesEnable=GetCheckBox(hwndDlg,IDC_ENABLE_KEYFILES);PasswordChangeEnable(hwndDlg,IDOK,IDC_OLD_PASSWORD,KeyFilesEnable&&FirstKeyFile!=NULL,IDC_PASSWORD,IDC_VERIFY,newKeyFilesParam.EnableKeyFiles&&newKeyFilesParam.FirstKeyFile!=NULL);return1;}if(lw==IDC_ENABLE_NEW_KEYFILES){newKeyFilesParam.EnableKeyFiles=GetCheckBox(hwndDlg,IDC_ENABLE_NEW_KEYFILES);PasswordChangeEnable(hwndDlg,IDOK,IDC_OLD_PASSWORD,KeyFilesEnable&&FirstKeyFile!=NULL,IDC_PASSWORD,IDC_VERIFY,newKeyFilesParam.EnableKeyFiles&&newKeyFilesParam.FirstKeyFile!=NULL);return1;}if(hw==CBN_SELCHANGE){switch(lw){caseIDC_PKCS5_PRF_ID:if(bSysEncPwdChangeDlgMode){intnew_hash_algo_id=(int)SendMessage(GetDlgItem(hwndDlg,IDC_PKCS5_PRF_ID),CB_GETITEMDATA,SendMessage(GetDlgItem(hwndDlg,IDC_PKCS5_PRF_ID),CB_GETCURSEL,0,0),0);if(new_hash_algo_id!=0&&!bSystemIsGPT&&!HashForSystemEncryption(new_hash_algo_id)){intnew_hash_algo_id=DEFAULT_HASH_ALGORITHM_BOOT;Info("ALGO_NOT_SUPPORTED_FOR_SYS_ENCRYPTION",hwndDlg);SelectAlgo(GetDlgItem(hwndDlg,IDC_PKCS5_PRF_ID),&new_hash_algo_id);}}break;}return1;}if(lw==IDC_TRUECRYPT_MODE){BOOLbEnablePim=GetCheckBox(hwndDlg,IDC_TRUECRYPT_MODE)?FALSE:TRUE;EnableWindow(GetDlgItem(hwndDlg,IDT_OLD_PIM),bEnablePim);EnableWindow(GetDlgItem(hwndDlg,IDC_OLD_PIM),bEnablePim);EnableWindow(GetDlgItem(hwndDlg,IDC_OLD_PIM_HELP),bEnablePim);}if(lw==IDC_SHOW_PASSWORD_CHPWD_ORI){HandleShowPasswordFieldAction(hwndDlg,IDC_SHOW_PASSWORD_CHPWD_ORI,IDC_OLD_PASSWORD,IDC_OLD_PIM);return1;}if(lw==IDC_SHOW_PASSWORD_CHPWD_NEW){HandleShowPasswordFieldAction(hwndDlg,IDC_SHOW_PASSWORD_CHPWD_NEW,IDC_PASSWORD,IDC_VERIFY);HandleShowPasswordFieldAction(hwndDlg,IDC_SHOW_PASSWORD_CHPWD_NEW,IDC_PIM,0);return1;}if(lw==IDOK){HWNDhParent=GetParent(hwndDlg);PasswordoldPassword;PasswordnewPassword;WipeAlgorithmIdheaderWiperMode=(WipeAlgorithmId)SendMessage(GetDlgItem(hwndDlg,IDC_WIPE_MODE),CB_GETITEMDATA,SendMessage(GetDlgItem(hwndDlg,IDC_WIPE_MODE),CB_GETCURSEL,0,0),0);intnStatus;intold_pkcs5=(int)SendMessage(GetDlgItem(hwndDlg,IDC_PKCS5_OLD_PRF_ID),CB_GETITEMDATA,SendMessage(GetDlgItem(hwndDlg,IDC_PKCS5_OLD_PRF_ID),CB_GETCURSEL,0,0),0);intpkcs5=(int)SendMessage(GetDlgItem(hwndDlg,IDC_PKCS5_PRF_ID),CB_GETITEMDATA,SendMessage(GetDlgItem(hwndDlg,IDC_PKCS5_PRF_ID),CB_GETCURSEL,0,0),0);BOOLtruecryptMode=GetCheckBox(hwndDlg,IDC_TRUECRYPT_MODE);intold_pim=GetPim(hwndDlg,IDC_OLD_PIM,0);intpim=GetPim(hwndDlg,IDC_PIM,0);if(truecryptMode&&!is_pkcs5_prf_supported(old_pkcs5,TRUE,PRF_BOOT_NO)){Error("ALGO_NOT_SUPPORTED_FOR_TRUECRYPT_MODE",hwndDlg);return1;}elseif(truecryptMode&&(old_pim!=0)){Error("PIM_NOT_SUPPORTED_FOR_TRUECRYPT_MODE",hwndDlg);return1;}if(bSysEncPwdChangeDlgMode&&!CheckPasswordCharEncoding(GetDlgItem(hwndDlg,IDC_PASSWORD),NULL)){Error("UNSUPPORTED_CHARS_IN_PWD",hwndDlg);return1;}if(bSysEncPwdChangeDlgMode&&(pim>MAX_BOOT_PIM_VALUE)){SetFocus(GetDlgItem(hwndDlg,IDC_PIM));Error("PIM_SYSENC_TOO_BIG",hwndDlg);return1;}if(!bSysEncPwdChangeDlgMode&&(pim>MAX_PIM_VALUE)){SetFocus(GetDlgItem(hwndDlg,IDC_PIM));Error("PIM_TOO_BIG",hwndDlg);return1;}if(pwdChangeDlgMode==PCDM_CHANGE_PKCS5_PRF){newKeyFilesParam.EnableKeyFiles=KeyFilesEnable;}elseif(!(newKeyFilesParam.EnableKeyFiles&&newKeyFilesParam.FirstKeyFile!=NULL)&&pwdChangeDlgMode==PCDM_CHANGE_PASSWORD){intbootPRF=0;if(bSysEncPwdChangeDlgMode){try{VOLUME_PROPERTIES_STRUCTproperties;BootEncObj->GetVolumeProperties(&properties);bootPRF=properties.pkcs5;}catch(...){}}if(!CheckPasswordLength(hwndDlg,GetWindowTextLength(GetDlgItem(hwndDlg,IDC_PASSWORD)),pim,bSysEncPwdChangeDlgMode,bootPRF,FALSE,FALSE))return1;}GetVolumePath(hParent,szFileName,ARRAYSIZE(szFileName));if(GetPassword(hwndDlg,IDC_OLD_PASSWORD,(LPSTR)oldPassword.Text,sizeof(oldPassword.Text),TRUE))oldPassword.Length=(unsigned__int32)strlen((char*)oldPassword.Text);else{return1;}switch(pwdChangeDlgMode){casePCDM_REMOVE_ALL_KEYFILES_FROM_VOL:casePCDM_ADD_REMOVE_VOL_KEYFILES:casePCDM_CHANGE_PKCS5_PRF:memcpy(newPassword.Text,oldPassword.Text,sizeof(newPassword.Text));newPassword.Length=(unsigned__int32)strlen((char*)oldPassword.Text);pim=old_pim;break;default:if(GetPassword(hwndDlg,IDC_PASSWORD,(LPSTR)newPassword.Text,sizeof(newPassword.Text),TRUE))newPassword.Length=(unsigned__int32)strlen((char*)newPassword.Text);elsereturn1;}WaitCursor();if(KeyFilesEnable)KeyFilesApply(hwndDlg,&oldPassword,FirstKeyFile,szFileName);if(newKeyFilesParam.EnableKeyFiles){if(!KeyFilesApply(hwndDlg,&newPassword,pwdChangeDlgMode==PCDM_CHANGE_PKCS5_PRF?FirstKeyFile:newKeyFilesParam.FirstKeyFile,szFileName)){nStatus=ERR_DONT_REPORT;gotoerr;}}ChangePwdThreadParamchangePwdParam;changePwdParam.oldPassword=&oldPassword;changePwdParam.old_pkcs5=old_pkcs5;changePwdParam.old_pim=old_pim;changePwdParam.newPassword=&newPassword;changePwdParam.pkcs5=pkcs5;changePwdParam.pim=pim;changePwdParam.wipePassCount=GetWipePassCount(headerWiperMode);changePwdParam.pnStatus=&nStatus;changePwdParam.truecryptMode=truecryptMode;ShowWaitDialog(hwndDlg,TRUE,ChangePwdWaitThreadProc,&changePwdParam);err:// notify the caller in case the PIM has changedif(NewPimValuePtr){if(pim!=old_pim)*NewPimValuePtr=pim;else*NewPimValuePtr=-1;}burn(&oldPassword,sizeof(oldPassword));burn(&newPassword,sizeof(newPassword));burn(&old_pim,sizeof(old_pim));burn(&pim,sizeof(pim));NormalCursor();if(nStatus==0){// Attempt to wipe passwords stored in the input field bufferswchar_ttmp[MAX_PASSWORD+1];wmemset(tmp,L'X',MAX_PASSWORD);tmp[MAX_PASSWORD]=0;SetWindowText(GetDlgItem(hwndDlg,IDC_PASSWORD),tmp);SetWindowText(GetDlgItem(hwndDlg,IDC_OLD_PASSWORD),tmp);SetWindowText(GetDlgItem(hwndDlg,IDC_VERIFY),tmp);KeyFileRemoveAll(&newKeyFilesParam.FirstKeyFile);RestoreDefaultKeyFilesParam();if(bSysEncPwdChangeDlgMode){KillTimer(hwndDlg,TIMER_ID_KEYB_LAYOUT_GUARD);}EndDialog(hwndDlg,IDOK);}return1;}return0;}return0;}staticwchar_tPasswordDlgVolume[MAX_PATH+1];staticBOOLPasswordDialogDisableMountOptions;staticchar*PasswordDialogTitleStringId;/* 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 */BOOLCALLBACKPasswordDlgProc(HWNDhwndDlg,UINTmsg,WPARAMwParam,LPARAMlParam){WORDlw=LOWORD(wParam);staticPassword*szXPwd;staticint*pkcs5;staticint*pim;staticBOOL*truecryptMode;switch(msg){caseWM_INITDIALOG:{inti,nIndex,defaultPrfIndex=0;szXPwd=((PasswordDlgParam*)lParam)->password;pkcs5=((PasswordDlgParam*)lParam)->pkcs5;pim=((PasswordDlgParam*)lParam)->pim;truecryptMode=((PasswordDlgParam*)lParam)->truecryptMode;LocalizeDialog(hwndDlg,"IDD_PASSWORD_DLG");DragAcceptFiles(hwndDlg,TRUE);if(PasswordDialogTitleStringId){SetWindowTextW(hwndDlg,GetString(PasswordDialogTitleStringId));}elseif(wcslen(PasswordDlgVolume)>0){wchar_ts[1024];RECTrect;GetWindowRect(hwndDlg,&rect);booluseInExplorer=false;wstringlabel=GetFavoriteVolumeLabel(PasswordDlgVolume,useInExplorer);if(!label.empty()){StringCbPrintfW(s,sizeof(s),GetString("ENTER_PASSWORD_FOR_LABEL"),label.c_str());if(useInExplorer)StringCbCopyW(mountOptions.Label,sizeof(mountOptions.Label),label.c_str());}else{StringCbPrintfW(s,sizeof(s),GetString("ENTER_PASSWORD_FOR"),L"___");StringCbPrintfW(s,sizeof(s),GetString("ENTER_PASSWORD_FOR"),FitPathInGfxWidth(hwndDlg,WindowTitleBarFont,rect.right-rect.left-GetTextGfxWidth(hwndDlg,s,WindowTitleBarFont),PasswordDlgVolume).c_str());}SetWindowTextW(hwndDlg,s);}/* Populate the PRF algorithms list */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);if(*pkcs5&&(*pkcs5==i))defaultPrfIndex=nIndex;}/* make autodetection the default unless a specific PRF was specified in the command line */SendMessage(hComboBox,CB_SETCURSEL,defaultPrfIndex,0);SendMessage(GetDlgItem(hwndDlg,IDC_PASSWORD),EM_LIMITTEXT,MAX_PASSWORD,0);SendMessage(GetDlgItem(hwndDlg,IDC_CACHE),BM_SETCHECK,bCacheInDriver?BST_CHECKED:BST_UNCHECKED,0);SendMessage(GetDlgItem(hwndDlg,IDC_PIM),EM_LIMITTEXT,MAX_PIM,0);SetPim(hwndDlg,IDC_PIM,*pim);/* make PIM field visible if a PIM value has been explicitely specified */if(*pim>0){SetCheckBox(hwndDlg,IDC_PIM_ENABLE,TRUE);ShowWindow(GetDlgItem(hwndDlg,IDC_PIM_ENABLE),SW_HIDE);ShowWindow(GetDlgItem(hwndDlg,IDT_PIM),SW_SHOW);ShowWindow(GetDlgItem(hwndDlg,IDC_PIM),SW_SHOW);ShowWindow(GetDlgItem(hwndDlg,IDC_PIM_HELP),SW_SHOW);}SetCheckBox(hwndDlg,IDC_KEYFILES_ENABLE,KeyFilesEnable);mountOptions.PartitionInInactiveSysEncScope=bPrebootPasswordDlgMode;if(bPrebootPasswordDlgMode){SendMessage(hwndDlg,TC_APPMSG_PREBOOT_PASSWORD_MODE,0,0);}if(PasswordDialogDisableMountOptions){EnableWindow(GetDlgItem(hwndDlg,IDC_CACHE),FALSE);EnableWindow(GetDlgItem(hwndDlg,IDC_MOUNT_OPTIONS),FALSE);/* Disable TrueCrypt mode option in case of backup/restore header operation */SetCheckBox(hwndDlg,IDC_TRUECRYPT_MODE,FALSE);EnableWindow(GetDlgItem(hwndDlg,IDC_TRUECRYPT_MODE),FALSE);}elseif(*truecryptMode){/* Check TrueCryptMode if it is enabled on the command line */SetCheckBox(hwndDlg,IDC_TRUECRYPT_MODE,TRUE);}if(!SetForegroundWindow(hwndDlg)&&(FavoriteMountOnArrivalInProgress||LogOn)){SetWindowPos(hwndDlg,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);FLASHWINFOflash;flash.cbSize=sizeof(flash);flash.dwFlags=FLASHW_ALL|FLASHW_TIMERNOFG;flash.dwTimeout=0;flash.hwnd=hwndDlg;flash.uCount=0;FlashWindowEx(&flash);SetWindowPos(hwndDlg,HWND_NOTOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);}}return0;caseTC_APPMSG_PREBOOT_PASSWORD_MODE:{/* Repopulate the PRF algorithms list with algorithms that support system encryption */HWNDhComboBox=GetDlgItem(hwndDlg,IDC_PKCS5_PRF_ID);SendMessage(hComboBox,CB_RESETCONTENT,0,0);inti,defaultPrfIndex=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++){if(bSystemIsGPT||HashForSystemEncryption(i)){nIndex=(int)SendMessage(hComboBox,CB_ADDSTRING,0,(LPARAM)get_pkcs5_prf_name(i));SendMessage(hComboBox,CB_SETITEMDATA,nIndex,(LPARAM)i);if(*pkcs5&&(*pkcs5==i))defaultPrfIndex=nIndex;}}/* make autodetection the default unless a specific PRF was specified in the command line */SendMessage(hComboBox,CB_SETCURSEL,defaultPrfIndex,0);ToBootPwdField(hwndDlg,IDC_PASSWORD);// Attempt to wipe the password stored in the input field bufferwchar_ttmp[MAX_PASSWORD+1];wmemset(tmp,L'X',MAX_PASSWORD);tmp[MAX_PASSWORD]=0;SetWindowText(GetDlgItem(hwndDlg,IDC_PASSWORD),tmp);SetWindowText(GetDlgItem(hwndDlg,IDC_PASSWORD),L"");StringCbPrintfW(OrigKeyboardLayout,sizeof(OrigKeyboardLayout),L"%08X",(DWORD)GetKeyboardLayout(NULL)&0xFFFF);DWORDkeybLayout=(DWORD)LoadKeyboardLayout(L"00000409",KLF_ACTIVATE);if(keybLayout!=0x00000409&&keybLayout!=0x04090409){Error("CANT_CHANGE_KEYB_LAYOUT_FOR_SYS_ENCRYPTION",hwndDlg);EndDialog(hwndDlg,IDCANCEL);return1;}if(SetTimer(hwndDlg,TIMER_ID_KEYB_LAYOUT_GUARD,TIMER_INTERVAL_KEYB_LAYOUT_GUARD,NULL)==0){Error("CANNOT_SET_TIMER",hwndDlg);EndDialog(hwndDlg,IDCANCEL);return1;}if(GetCheckBox(hwndDlg,IDC_SHOW_PASSWORD)){// simulate hiding passwordSetCheckBox(hwndDlg,IDC_SHOW_PASSWORD,FALSE);HandleShowPasswordFieldAction(hwndDlg,IDC_SHOW_PASSWORD,IDC_PASSWORD,IDC_PIM);}SetCheckBox(hwndDlg,IDC_KEYFILES_ENABLE,FALSE);EnableWindow(GetDlgItem(hwndDlg,IDC_KEYFILES_ENABLE),FALSE);EnableWindow(GetDlgItem(hwndDlg,IDC_KEY_FILES),FALSE);SetPim(hwndDlg,IDC_PIM,*pim);bPrebootPasswordDlgMode=TRUE;}return1;caseWM_TIMER:switch(wParam){caseTIMER_ID_KEYB_LAYOUT_GUARD:if(bPrebootPasswordDlgMode){DWORDkeybLayout=(DWORD)GetKeyboardLayout(NULL);if(keybLayout!=0x00000409&&keybLayout!=0x04090409){// Keyboard layout is not standard US// Attempt to wipe the password stored in the input field bufferwchar_ttmp[MAX_PASSWORD+1];wmemset(tmp,L'X',MAX_PASSWORD);tmp[MAX_PASSWORD]=0;SetWindowText(GetDlgItem(hwndDlg,IDC_PASSWORD),tmp);SetWindowText(GetDlgItem(hwndDlg,IDC_PASSWORD),L"");keybLayout=(DWORD)LoadKeyboardLayout(L"00000409",KLF_ACTIVATE);if(keybLayout!=0x00000409&&keybLayout!=0x04090409){KillTimer(hwndDlg,TIMER_ID_KEYB_LAYOUT_GUARD);Error("CANT_CHANGE_KEYB_LAYOUT_FOR_SYS_ENCRYPTION",hwndDlg);EndDialog(hwndDlg,IDCANCEL);return1;}wchar_tszTmp[4096];StringCbCopyW(szTmp,sizeof(szTmp),GetString("KEYB_LAYOUT_CHANGE_PREVENTED"));StringCbCatW(szTmp,sizeof(szTmp),L"\n\n");StringCbCatW(szTmp,sizeof(szTmp),GetString("KEYB_LAYOUT_SYS_ENC_EXPLANATION"));MessageBoxW(MainDlg,szTmp,lpszTitle,MB_ICONWARNING|MB_SETFOREGROUND|MB_TOPMOST);}}return1;}return0;caseWM_COMMAND:if(lw==IDC_MOUNT_OPTIONS){/* Use default PRF specified by the user if any */if(mountOptions.ProtectedHidVolPkcs5Prf==0)mountOptions.ProtectedHidVolPkcs5Prf=*pkcs5;if(mountOptions.ProtectedHidVolPim==0)mountOptions.ProtectedHidVolPim=*pim;DialogBoxParamW(hInst,MAKEINTRESOURCEW(IDD_MOUNT_OPTIONS),hwndDlg,(DLGPROC)MountOptionsDlgProc,(LPARAM)&mountOptions);if(!bPrebootPasswordDlgMode&&mountOptions.PartitionInInactiveSysEncScope)SendMessage(hwndDlg,TC_APPMSG_PREBOOT_PASSWORD_MODE,0,0);return1;}if(lw==IDC_PIM_ENABLE){ShowWindow(GetDlgItem(hwndDlg,IDC_PIM_ENABLE),SW_HIDE);ShowWindow(GetDlgItem(hwndDlg,IDT_PIM),SW_SHOW);ShowWindow(GetDlgItem(hwndDlg,IDC_PIM),SW_SHOW);ShowWindow(GetDlgItem(hwndDlg,IDC_PIM_HELP),SW_SHOW);SetFocus(GetDlgItem(hwndDlg,IDC_PIM));return1;}if(lw==IDC_SHOW_PASSWORD){HandleShowPasswordFieldAction(hwndDlg,IDC_SHOW_PASSWORD,IDC_PASSWORD,IDC_PIM);return1;}if(lw==IDC_TRUECRYPT_MODE){BOOLbEnablePim=GetCheckBox(hwndDlg,IDC_TRUECRYPT_MODE)?FALSE:TRUE;EnableWindow(GetDlgItem(hwndDlg,IDT_PIM),bEnablePim);EnableWindow(GetDlgItem(hwndDlg,IDC_PIM),bEnablePim);EnableWindow(GetDlgItem(hwndDlg,IDC_PIM_HELP),bEnablePim);}if(lw==IDC_KEY_FILES){KeyFilesDlgParamparam;param.EnableKeyFiles=KeyFilesEnable;param.FirstKeyFile=FirstKeyFile;if(IDOK==DialogBoxParamW(hInst,MAKEINTRESOURCEW(IDD_KEYFILES),hwndDlg,(DLGPROC)KeyFilesDlgProc,(LPARAM)&param)){KeyFilesEnable=param.EnableKeyFiles;FirstKeyFile=param.FirstKeyFile;SetCheckBox(hwndDlg,IDC_KEYFILES_ENABLE,KeyFilesEnable);}return1;}if(lw==IDC_KEYFILES_ENABLE){KeyFilesEnable=GetCheckBox(hwndDlg,IDC_KEYFILES_ENABLE);return1;}if(lw==IDCANCEL||lw==IDOK){wchar_ttmp[MAX_PASSWORD+1];if(lw==IDOK){if(mountOptions.ProtectHiddenVolume&&hidVolProtKeyFilesParam.EnableKeyFiles)KeyFilesApply(hwndDlg,&mountOptions.ProtectedHidVolPassword,hidVolProtKeyFilesParam.FirstKeyFile,wcslen(PasswordDlgVolume)>0?PasswordDlgVolume:NULL);if(GetPassword(hwndDlg,IDC_PASSWORD,(LPSTR)szXPwd->Text,MAX_PASSWORD+1,TRUE))szXPwd->Length=(unsigned__int32)strlen((char*)szXPwd->Text);elsereturn1;bCacheInDriver=IsButtonChecked(GetDlgItem(hwndDlg,IDC_CACHE));*pkcs5=(int)SendMessage(GetDlgItem(hwndDlg,IDC_PKCS5_PRF_ID),CB_GETITEMDATA,SendMessage(GetDlgItem(hwndDlg,IDC_PKCS5_PRF_ID),CB_GETCURSEL,0,0),0);*truecryptMode=GetCheckBox(hwndDlg,IDC_TRUECRYPT_MODE);*pim=GetPim(hwndDlg,IDC_PIM,0);/* check that PRF is supported in TrueCrypt Mode */if((*truecryptMode)&&((!is_pkcs5_prf_supported(*pkcs5,TRUE,PRF_BOOT_NO))||(mountOptions.ProtectHiddenVolume&&!is_pkcs5_prf_supported(mountOptions.ProtectedHidVolPkcs5Prf,TRUE,PRF_BOOT_NO)))){Error("ALGO_NOT_SUPPORTED_FOR_TRUECRYPT_MODE",hwndDlg);return1;}if((*truecryptMode)&&(*pim!=0)){Error("PIM_NOT_SUPPORTED_FOR_TRUECRYPT_MODE",hwndDlg);return1;}}// Attempt to wipe password stored in the input field bufferwmemset(tmp,L'X',MAX_PASSWORD);tmp[MAX_PASSWORD]=0;SetWindowText(GetDlgItem(hwndDlg,IDC_PASSWORD),tmp);SetWindowText(GetDlgItem(hwndDlg,IDC_PASSWORD_PROT_HIDVOL),tmp);if(hidVolProtKeyFilesParam.FirstKeyFile!=NULL){KeyFileRemoveAll(&hidVolProtKeyFilesParam.FirstKeyFile);hidVolProtKeyFilesParam.EnableKeyFiles=FALSE;}if(bPrebootPasswordDlgMode){KillTimer(hwndDlg,TIMER_ID_KEYB_LAYOUT_GUARD);// Restore the original keyboard layoutif(LoadKeyboardLayout(OrigKeyboardLayout,KLF_ACTIVATE|KLF_SUBSTITUTE_OK)==NULL)Warning("CANNOT_RESTORE_KEYBOARD_LAYOUT",hwndDlg);}EndDialog(hwndDlg,lw);return1;}return0;caseWM_CONTEXTMENU:{RECTbuttonRect;GetWindowRect(GetDlgItem(hwndDlg,IDC_KEY_FILES),&buttonRect);if(LOWORD(lParam)>=buttonRect.left&&LOWORD(lParam)<=buttonRect.right&&HIWORD(lParam)>=buttonRect.top&&HIWORD(lParam)<=buttonRect.bottom){// The "Keyfiles" button has been right-clickedKeyFilesDlgParamparam;param.EnableKeyFiles=KeyFilesEnable;param.FirstKeyFile=FirstKeyFile;POINTpopupPos;popupPos.x=buttonRect.left+2;popupPos.y=buttonRect.top+2;if(KeyfilesPopupMenu(hwndDlg,popupPos,&param)){KeyFilesEnable=param.EnableKeyFiles;FirstKeyFile=param.FirstKeyFile;SetCheckBox(hwndDlg,IDC_KEYFILES_ENABLE,KeyFilesEnable);}}}break;caseWM_DROPFILES:{HDROPhdrop=(HDROP)wParam;inti=0,count=DragQueryFile(hdrop,0xFFFFFFFF,NULL,0);while(count-->0){KeyFile*kf=(KeyFile*)malloc(sizeof(KeyFile));if(kf){DragQueryFile(hdrop,i++,kf->FileName,ARRAYSIZE(kf->FileName));FirstKeyFile=KeyFileAdd(FirstKeyFile,kf);KeyFilesEnable=TRUE;}}SetCheckBox(hwndDlg,IDC_KEYFILES_ENABLE,KeyFilesEnable);DragFinish(hdrop);}return1;}return0;}staticvoidPreferencesDlgEnableButtons(HWNDhwndDlg){BOOLback=IsButtonChecked(GetDlgItem(hwndDlg,IDC_PREF_BKG_TASK_ENABLE));BOOLidle=IsButtonChecked(GetDlgItem(hwndDlg,IDC_PREF_DISMOUNT_INACTIVE));BOOLinstalled=!IsNonInstallMode();BOOLwtsEnabled=(hWtsLib!=NULL)?TRUE:FALSE;EnableWindow(GetDlgItem(hwndDlg,IDC_CLOSE_BKG_TASK_WHEN_NOVOL),back&&installed);EnableWindow(GetDlgItem(hwndDlg,IDT_LOGON),installed);EnableWindow(GetDlgItem(hwndDlg,IDC_PREF_LOGON_START),back&&installed);EnableWindow(GetDlgItem(hwndDlg,IDC_PREF_LOGON_MOUNT_DEVICES),installed);EnableWindow(GetDlgItem(hwndDlg,IDT_AUTO_DISMOUNT),back);EnableWindow(GetDlgItem(hwndDlg,IDT_AUTO_DISMOUNT_ON),back);EnableWindow(GetDlgItem(hwndDlg,IDT_MINUTES),back);EnableWindow(GetDlgItem(hwndDlg,IDC_PREF_DISMOUNT_LOGOFF),back);EnableWindow(GetDlgItem(hwndDlg,IDC_PREF_DISMOUNT_SESSION_LOCKED),back&&wtsEnabled);EnableWindow(GetDlgItem(hwndDlg,IDC_PREF_DISMOUNT_POWERSAVING),back);EnableWindow(GetDlgItem(hwndDlg,IDC_PREF_DISMOUNT_SCREENSAVER),back);EnableWindow(GetDlgItem(hwndDlg,IDC_PREF_DISMOUNT_INACTIVE),back);EnableWindow(GetDlgItem(hwndDlg,IDC_PREF_DISMOUNT_INACTIVE_TIME),back&&idle);EnableWindow(GetDlgItem(hwndDlg,IDC_PREF_FORCE_AUTO_DISMOUNT),back);}BOOLCALLBACKPreferencesDlgProc(HWNDhwndDlg,UINTmsg,WPARAMwParam,LPARAMlParam){staticBOOLPreferencesDialogActive=FALSE;staticHWNDActivePreferencesDialogWindow;WORDlw=LOWORD(wParam);switch(msg){caseWM_INITDIALOG:{if(PreferencesDialogActive){ShowWindow(ActivePreferencesDialogWindow,SW_SHOW);SetForegroundWindow(ActivePreferencesDialogWindow);EndDialog(hwndDlg,IDCANCEL);return1;}ActivePreferencesDialogWindow=hwndDlg;PreferencesDialogActive=TRUE;LocalizeDialog(hwndDlg,"IDD_PREFERENCES_DLG");SendMessage(GetDlgItem(hwndDlg,IDC_PREF_OPEN_EXPLORER),BM_SETCHECK,bExplore?BST_CHECKED:BST_UNCHECKED,0);SendMessage(GetDlgItem(hwndDlg,IDC_PREF_USE_DIFF_TRAY_ICON_IF_VOL_MOUNTED),BM_SETCHECK,bUseDifferentTrayIconIfVolMounted?BST_CHECKED:BST_UNCHECKED,0);SendMessage(GetDlgItem(hwndDlg,IDC_PRESERVE_TIMESTAMPS),BM_SETCHECK,defaultMountOptions.PreserveTimestamp?BST_CHECKED:BST_UNCHECKED,0);SendMessage(GetDlgItem(hwndDlg,IDC_SHOW_DISCONNECTED_NETWORK_DRIVES),BM_SETCHECK,bShowDisconnectedNetworkDrives?BST_CHECKED:BST_UNCHECKED,0);SendMessage(GetDlgItem(hwndDlg,IDC_HIDE_WAITING_DIALOG),BM_SETCHECK,bHideWaitingDialog?BST_CHECKED:BST_UNCHECKED,0);SendMessage(GetDlgItem(hwndDlg,IDC_SECURE_DESKTOP_PASSWORD_ENTRY),BM_SETCHECK,bUseSecureDesktop?BST_CHECKED:BST_UNCHECKED,0);SendMessage(GetDlgItem(hwndDlg,IDC_PREF_TEMP_CACHE_ON_MULTIPLE_MOUNT),BM_SETCHECK,bCacheDuringMultipleMount?BST_CHECKED:BST_UNCHECKED,0);SendMessage(GetDlgItem(hwndDlg,IDC_PREF_WIPE_CACHE_ON_EXIT),BM_SETCHECK,bWipeCacheOnExit?BST_CHECKED:BST_UNCHECKED,0);SendMessage(GetDlgItem(hwndDlg,IDC_PREF_WIPE_CACHE_ON_AUTODISMOUNT),BM_SETCHECK,bWipeCacheOnAutoDismount?BST_CHECKED:BST_UNCHECKED,0);SendMessage(GetDlgItem(hwndDlg,IDC_PREF_CACHE_PASSWORDS),BM_SETCHECK,bCacheInDriver?BST_CHECKED:BST_UNCHECKED,0);SendMessage(GetDlgItem(hwndDlg,IDC_PREF_CACHE_PIM),BM_SETCHECK,bIncludePimInCache?BST_CHECKED:BST_UNCHECKED,0);SendMessage(GetDlgItem(hwndDlg,IDC_PREF_MOUNT_READONLY),BM_SETCHECK,defaultMountOptions.ReadOnly?BST_CHECKED:BST_UNCHECKED,0);SendMessage(GetDlgItem(hwndDlg,IDC_PREF_MOUNT_REMOVABLE),BM_SETCHECK,defaultMountOptions.Removable?BST_CHECKED:BST_UNCHECKED,0);SendMessage(GetDlgItem(hwndDlg,IDC_PREF_LOGON_START),BM_SETCHECK,bStartOnLogon?BST_CHECKED:BST_UNCHECKED,0);SendMessage(GetDlgItem(hwndDlg,IDC_PREF_LOGON_MOUNT_DEVICES),BM_SETCHECK,bMountDevicesOnLogon?BST_CHECKED:BST_UNCHECKED,0);SendMessage(GetDlgItem(hwndDlg,IDC_PREF_BKG_TASK_ENABLE),BM_SETCHECK,bEnableBkgTask?BST_CHECKED:BST_UNCHECKED,0);SendMessage(GetDlgItem(hwndDlg,IDC_CLOSE_BKG_TASK_WHEN_NOVOL),BM_SETCHECK,bCloseBkgTaskWhenNoVolumes||IsNonInstallMode()?BST_CHECKED:BST_UNCHECKED,0);SendMessage(GetDlgItem(hwndDlg,IDC_PREF_DISMOUNT_LOGOFF),BM_SETCHECK,bDismountOnLogOff?BST_CHECKED:BST_UNCHECKED,0);SendMessage(GetDlgItem(hwndDlg,IDC_PREF_DISMOUNT_SESSION_LOCKED),BM_SETCHECK,bDismountOnSessionLocked?BST_CHECKED:BST_UNCHECKED,0);SendMessage(GetDlgItem(hwndDlg,IDC_PREF_DISMOUNT_POWERSAVING),BM_SETCHECK,bDismountOnPowerSaving?BST_CHECKED:BST_UNCHECKED,0);SendMessage(GetDlgItem(hwndDlg,IDC_PREF_DISMOUNT_SCREENSAVER),BM_SETCHECK,bDismountOnScreenSaver?BST_CHECKED:BST_UNCHECKED,0);SendMessage(GetDlgItem(hwndDlg,IDC_PREF_FORCE_AUTO_DISMOUNT),BM_SETCHECK,bForceAutoDismount?BST_CHECKED:BST_UNCHECKED,0);SendMessage(GetDlgItem(hwndDlg,IDC_PREF_DISMOUNT_INACTIVE),BM_SETCHECK,MaxVolumeIdleTime>0?BST_CHECKED:BST_UNCHECKED,0);SetDlgItemInt(hwndDlg,IDC_PREF_DISMOUNT_INACTIVE_TIME,abs(MaxVolumeIdleTime),FALSE);PreferencesDlgEnableButtons(hwndDlg);}return0;caseWM_COMMAND:if(lw==IDC_PREF_BKG_TASK_ENABLE&&!IsButtonChecked(GetDlgItem(hwndDlg,IDC_PREF_BKG_TASK_ENABLE))){if(AskWarnNoYes("CONFIRM_BACKGROUND_TASK_DISABLED",hwndDlg)==IDNO)SetCheckBox(hwndDlg,IDC_PREF_BKG_TASK_ENABLE,TRUE);}// Forced dismount disabled warningif(lw==IDC_PREF_DISMOUNT_INACTIVE||lw==IDC_PREF_DISMOUNT_LOGOFF||lw==IDC_PREF_DISMOUNT_SESSION_LOCKED||lw==IDC_PREF_DISMOUNT_POWERSAVING||lw==IDC_PREF_DISMOUNT_SCREENSAVER||lw==IDC_PREF_FORCE_AUTO_DISMOUNT){BOOLi=IsButtonChecked(GetDlgItem(hwndDlg,IDC_PREF_DISMOUNT_INACTIVE));BOOLl=IsButtonChecked(GetDlgItem(hwndDlg,IDC_PREF_DISMOUNT_LOGOFF));BOOLsl=IsButtonChecked(GetDlgItem(hwndDlg,IDC_PREF_DISMOUNT_SESSION_LOCKED));BOOLp=IsButtonChecked(GetDlgItem(hwndDlg,IDC_PREF_DISMOUNT_POWERSAVING));BOOLs=IsButtonChecked(GetDlgItem(hwndDlg,IDC_PREF_DISMOUNT_SCREENSAVER));BOOLq=IsButtonChecked(GetDlgItem(hwndDlg,IDC_PREF_FORCE_AUTO_DISMOUNT));if(!q){if(lw==IDC_PREF_FORCE_AUTO_DISMOUNT&&(i||l||sl||p||s)){if(AskWarnNoYes("CONFIRM_NO_FORCED_AUTODISMOUNT",hwndDlg)==IDNO)SetCheckBox(hwndDlg,IDC_PREF_FORCE_AUTO_DISMOUNT,TRUE);}elseif((lw==IDC_PREF_DISMOUNT_INACTIVE&&i||lw==IDC_PREF_DISMOUNT_LOGOFF&&l||lw==IDC_PREF_DISMOUNT_SESSION_LOCKED&&sl||lw==IDC_PREF_DISMOUNT_POWERSAVING&&p||lw==IDC_PREF_DISMOUNT_SCREENSAVER&&s))Warning("WARN_PREF_AUTO_DISMOUNT",hwndDlg);}if(p&&lw==IDC_PREF_DISMOUNT_POWERSAVING)Warning("WARN_PREF_AUTO_DISMOUNT_ON_POWER",hwndDlg);}if(lw==IDCANCEL){PreferencesDialogActive=FALSE;EndDialog(hwndDlg,lw);return1;}if(lw==IDOK){WaitCursor();bExplore=IsButtonChecked(GetDlgItem(hwndDlg,IDC_PREF_OPEN_EXPLORER));bUseDifferentTrayIconIfVolMounted=IsButtonChecked(GetDlgItem(hwndDlg,IDC_PREF_USE_DIFF_TRAY_ICON_IF_VOL_MOUNTED));bPreserveTimestamp=defaultMountOptions.PreserveTimestamp=IsButtonChecked(GetDlgItem(hwndDlg,IDC_PRESERVE_TIMESTAMPS));bShowDisconnectedNetworkDrives=IsButtonChecked(GetDlgItem(hwndDlg,IDC_SHOW_DISCONNECTED_NETWORK_DRIVES));bHideWaitingDialog=IsButtonChecked(GetDlgItem(hwndDlg,IDC_HIDE_WAITING_DIALOG));bUseSecureDesktop=IsButtonChecked(GetDlgItem(hwndDlg,IDC_SECURE_DESKTOP_PASSWORD_ENTRY));bCacheDuringMultipleMount=IsButtonChecked(GetDlgItem(hwndDlg,IDC_PREF_TEMP_CACHE_ON_MULTIPLE_MOUNT));bWipeCacheOnExit=IsButtonChecked(GetDlgItem(hwndDlg,IDC_PREF_WIPE_CACHE_ON_EXIT));bWipeCacheOnAutoDismount=IsButtonChecked(GetDlgItem(hwndDlg,IDC_PREF_WIPE_CACHE_ON_AUTODISMOUNT));bCacheInDriverDefault=bCacheInDriver=IsButtonChecked(GetDlgItem(hwndDlg,IDC_PREF_CACHE_PASSWORDS));bIncludePimInCache=IsButtonChecked(GetDlgItem(hwndDlg,IDC_PREF_CACHE_PIM));defaultMountOptions.ReadOnly=IsButtonChecked(GetDlgItem(hwndDlg,IDC_PREF_MOUNT_READONLY));defaultMountOptions.Removable=IsButtonChecked(GetDlgItem(hwndDlg,IDC_PREF_MOUNT_REMOVABLE));bEnableBkgTask=IsButtonChecked(GetDlgItem(hwndDlg,IDC_PREF_BKG_TASK_ENABLE));bCloseBkgTaskWhenNoVolumes=IsNonInstallMode()?bCloseBkgTaskWhenNoVolumes:IsButtonChecked(GetDlgItem(hwndDlg,IDC_CLOSE_BKG_TASK_WHEN_NOVOL));bDismountOnLogOff=IsButtonChecked(GetDlgItem(hwndDlg,IDC_PREF_DISMOUNT_LOGOFF));bDismountOnSessionLocked=IsButtonChecked(GetDlgItem(hwndDlg,IDC_PREF_DISMOUNT_SESSION_LOCKED));bDismountOnPowerSaving=IsButtonChecked(GetDlgItem(hwndDlg,IDC_PREF_DISMOUNT_POWERSAVING));bDismountOnScreenSaver=IsButtonChecked(GetDlgItem(hwndDlg,IDC_PREF_DISMOUNT_SCREENSAVER));bForceAutoDismount=IsButtonChecked(GetDlgItem(hwndDlg,IDC_PREF_FORCE_AUTO_DISMOUNT));MaxVolumeIdleTime=GetDlgItemInt(hwndDlg,IDC_PREF_DISMOUNT_INACTIVE_TIME,NULL,FALSE)*(IsButtonChecked(GetDlgItem(hwndDlg,IDC_PREF_DISMOUNT_INACTIVE))?1:-1);bStartOnLogon=IsButtonChecked(GetDlgItem(hwndDlg,IDC_PREF_LOGON_START));bMountDevicesOnLogon=IsButtonChecked(GetDlgItem(hwndDlg,IDC_PREF_LOGON_MOUNT_DEVICES));ManageStartupSeq();SaveSettings(hwndDlg);NormalCursor();PreferencesDialogActive=FALSE;EndDialog(hwndDlg,lw);return1;}if(lw==IDC_MORE_SETTINGS){HMENUpopup=CreatePopupMenu();if(popup){AppendMenuW(popup,MF_STRING,IDM_LANGUAGE,GetString("IDM_LANGUAGE"));AppendMenuW(popup,MF_STRING,IDM_HOTKEY_SETTINGS,GetString("IDM_HOTKEY_SETTINGS"));AppendMenuW(popup,MF_STRING,IDM_PERFORMANCE_SETTINGS,GetString("IDM_PERFORMANCE_SETTINGS"));AppendMenuW(popup,MF_STRING,IDM_SYSENC_SETTINGS,GetString("IDM_SYSENC_SETTINGS"));AppendMenuW(popup,MF_STRING,IDM_SYS_FAVORITES_SETTINGS,GetString("IDM_SYS_FAVORITES_SETTINGS"));AppendMenuW(popup,MF_STRING,IDM_DEFAULT_KEYFILES,GetString("IDM_DEFAULT_KEYFILES"));AppendMenuW(popup,MF_STRING,IDM_DEFAULT_MOUNT_PARAMETERS,GetString("IDM_DEFAULT_MOUNT_PARAMETERS"));AppendMenuW(popup,MF_STRING,IDM_TOKEN_PREFERENCES,GetString("IDM_TOKEN_PREFERENCES"));RECTrect;GetWindowRect(GetDlgItem(hwndDlg,IDC_MORE_SETTINGS),&rect);intmenuItem=TrackPopupMenu(popup,TPM_RETURNCMD|TPM_LEFTBUTTON,rect.left+2,rect.top+2,0,hwndDlg,NULL);DestroyMenu(popup);SendMessage(MainDlg,WM_COMMAND,menuItem,(LPARAM)hwndDlg);return1;}elsereturn0;}if(HIWORD(wParam)==BN_CLICKED){PreferencesDlgEnableButtons(hwndDlg);return1;}return0;}return0;}BOOLCALLBACKMountOptionsDlgProc(HWNDhwndDlg,UINTmsg,WPARAMwParam,LPARAMlParam){staticMountOptions*mountOptions;WORDlw=LOWORD(wParam);switch(msg){caseWM_INITDIALOG:{BOOLprotect;mountOptions=(MountOptions*)lParam;LocalizeDialog(hwndDlg,"IDD_MOUNT_OPTIONS");SendDlgItemMessage(hwndDlg,IDC_MOUNT_READONLY,BM_SETCHECK,mountOptions->ReadOnly?BST_CHECKED:BST_UNCHECKED,0);SendDlgItemMessage(hwndDlg,IDC_MOUNT_REMOVABLE,BM_SETCHECK,mountOptions->Removable?BST_CHECKED:BST_UNCHECKED,0);SendDlgItemMessage(hwndDlg,IDC_PROTECT_HIDDEN_VOL,BM_SETCHECK,mountOptions->ProtectHiddenVolume?BST_CHECKED:BST_UNCHECKED,0);SendDlgItemMessage(hwndDlg,IDC_PROTECT_HIDDEN_VOL,BM_SETCHECK,mountOptions->ProtectHiddenVolume?BST_CHECKED:BST_UNCHECKED,0);mountOptions->PartitionInInactiveSysEncScope=bPrebootPasswordDlgMode;SendDlgItemMessage(hwndDlg,IDC_MOUNT_SYSENC_PART_WITHOUT_PBA,BM_SETCHECK,bPrebootPasswordDlgMode?BST_CHECKED:BST_UNCHECKED,0);SendDlgItemMessage(hwndDlg,IDC_USE_EMBEDDED_HEADER_BAK,BM_SETCHECK,mountOptions->UseBackupHeader?BST_CHECKED:BST_UNCHECKED,0);EnableWindow(GetDlgItem(hwndDlg,IDC_MOUNT_SYSENC_PART_WITHOUT_PBA),!bPrebootPasswordDlgMode);SetDlgItemTextW(hwndDlg,IDC_VOLUME_LABEL,mountOptions->Label);SendDlgItemMessage(hwndDlg,IDC_VOLUME_LABEL,EM_LIMITTEXT,32,0);// 32 is the maximum possible length for a drive label in Windows/* Add PRF algorithm list for hidden volume password */HWNDhComboBox=GetDlgItem(hwndDlg,IDC_PKCS5_PRF_ID);SendMessage(hComboBox,CB_RESETCONTENT,0,0);inti,nSelectedIndex=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);/* if a PRF was selected previously, select it */if(i==mountOptions->ProtectedHidVolPkcs5Prf)nSelectedIndex=nIndex;}SendMessage(hComboBox,CB_SETCURSEL,nSelectedIndex,0);protect=IsButtonChecked(GetDlgItem(hwndDlg,IDC_PROTECT_HIDDEN_VOL));EnableWindow(GetDlgItem(hwndDlg,IDC_PROTECT_HIDDEN_VOL),!IsButtonChecked(GetDlgItem(hwndDlg,IDC_MOUNT_READONLY)));EnableWindow(GetDlgItem(hwndDlg,IDT_HIDDEN_VOL_PROTECTION),!IsButtonChecked(GetDlgItem(hwndDlg,IDC_MOUNT_READONLY)));EnableWindow(GetDlgItem(hwndDlg,IDC_PASSWORD_PROT_HIDVOL),protect);EnableWindow(GetDlgItem(hwndDlg,IDC_SHOW_PASSWORD_MO),protect);EnableWindow(GetDlgItem(hwndDlg,IDT_HIDDEN_PROT_PASSWD),protect);EnableWindow(GetDlgItem(hwndDlg,IDC_KEYFILES_HIDVOL_PROT),protect);EnableWindow(GetDlgItem(hwndDlg,IDC_KEYFILES_ENABLE_HIDVOL_PROT),protect);EnableWindow(GetDlgItem(hwndDlg,IDT_PKCS5_PRF),protect);EnableWindow(GetDlgItem(hwndDlg,IDC_PKCS5_PRF_ID),protect);EnableWindow(GetDlgItem(hwndDlg,IDT_PIM),protect);EnableWindow(GetDlgItem(hwndDlg,IDC_PIM),protect);EnableWindow(GetDlgItem(hwndDlg,IDC_PIM_HELP),protect);EnableWindow(GetDlgItem(hwndDlg,IDC_PIM_ENABLE),protect);SetCheckBox(hwndDlg,IDC_KEYFILES_ENABLE_HIDVOL_PROT,hidVolProtKeyFilesParam.EnableKeyFiles);SendDlgItemMessage(hwndDlg,IDC_PASSWORD_PROT_HIDVOL,EM_LIMITTEXT,MAX_PASSWORD,0);SendDlgItemMessage(hwndDlg,IDC_PIM,EM_LIMITTEXT,MAX_PIM,0);if(mountOptions->ProtectedHidVolPassword.Length>0){wchar_tszTmp[MAX_PASSWORD+1];if(0==MultiByteToWideChar(CP_UTF8,0,(LPSTR)mountOptions->ProtectedHidVolPassword.Text,-1,szTmp,MAX_PASSWORD+1))szTmp[0]=0;SetWindowText(GetDlgItem(hwndDlg,IDC_PASSWORD_PROT_HIDVOL),szTmp);burn(szTmp,sizeof(szTmp));}SetPim(hwndDlg,IDC_PIM,mountOptions->ProtectedHidVolPim);/* make PIM field visible if a PIM value has been explicitely specified */if(mountOptions->ProtectedHidVolPim>0){SetCheckBox(hwndDlg,IDC_PIM_ENABLE,TRUE);ShowWindow(GetDlgItem(hwndDlg,IDC_PIM_ENABLE),SW_HIDE);ShowWindow(GetDlgItem(hwndDlg,IDT_PIM),SW_SHOW);ShowWindow(GetDlgItem(hwndDlg,IDC_PIM),SW_SHOW);ShowWindow(GetDlgItem(hwndDlg,IDC_PIM_HELP),SW_SHOW);}ToHyperlink(hwndDlg,IDC_LINK_HIDVOL_PROTECTION_INFO);}return0;caseWM_CONTEXTMENU:{RECTbuttonRect;GetWindowRect(GetDlgItem(hwndDlg,IDC_KEYFILES_HIDVOL_PROT),&buttonRect);if(IsButtonChecked(GetDlgItem(hwndDlg,IDC_PROTECT_HIDDEN_VOL))&&LOWORD(lParam)>=buttonRect.left&&LOWORD(lParam)<=buttonRect.right&&HIWORD(lParam)>=buttonRect.top&&HIWORD(lParam)<=buttonRect.bottom){// The "Keyfiles" button has been right-clickedPOINTpopupPos;popupPos.x=buttonRect.left+2;popupPos.y=buttonRect.top+2;if(KeyfilesPopupMenu(hwndDlg,popupPos,&hidVolProtKeyFilesParam))SetCheckBox(hwndDlg,IDC_KEYFILES_ENABLE_HIDVOL_PROT,hidVolProtKeyFilesParam.EnableKeyFiles);}}break;caseWM_COMMAND:if(lw==IDC_KEYFILES_HIDVOL_PROT){if(IDOK==DialogBoxParamW(hInst,MAKEINTRESOURCEW(IDD_KEYFILES),hwndDlg,(DLGPROC)KeyFilesDlgProc,(LPARAM)&hidVolProtKeyFilesParam)){SetCheckBox(hwndDlg,IDC_KEYFILES_ENABLE_HIDVOL_PROT,hidVolProtKeyFilesParam.EnableKeyFiles);}}if(lw==IDC_KEYFILES_ENABLE_HIDVOL_PROT){hidVolProtKeyFilesParam.EnableKeyFiles=GetCheckBox(hwndDlg,IDC_KEYFILES_ENABLE_HIDVOL_PROT);return0;}if(lw==IDC_SHOW_PASSWORD_MO){HandleShowPasswordFieldAction(hwndDlg,IDC_SHOW_PASSWORD_MO,IDC_PASSWORD_PROT_HIDVOL,IDC_PIM);return1;}if(lw==IDC_PIM_ENABLE){ShowWindow(GetDlgItem(hwndDlg,IDC_PIM_ENABLE),SW_HIDE);ShowWindow(GetDlgItem(hwndDlg,IDT_PIM),SW_SHOW);ShowWindow(GetDlgItem(hwndDlg,IDC_PIM),SW_SHOW);ShowWindow(GetDlgItem(hwndDlg,IDC_PIM_HELP),SW_SHOW);SetFocus(GetDlgItem(hwndDlg,IDC_PIM));return1;}if(lw==IDC_LINK_HIDVOL_PROTECTION_INFO){Applink("hiddenvolprotection");}if(lw==IDCANCEL){wchar_ttmp[MAX_PASSWORD+1];// Cleanupwmemset(tmp,L'X',MAX_PASSWORD);tmp[MAX_PASSWORD]=0;SetWindowText(GetDlgItem(hwndDlg,IDC_PASSWORD_PROT_HIDVOL),tmp);EndDialog(hwndDlg,lw);return1;}if(lw==IDOK){wchar_ttmp[MAX_PASSWORD+1];mountOptions->ReadOnly=IsButtonChecked(GetDlgItem(hwndDlg,IDC_MOUNT_READONLY));mountOptions->Removable=IsButtonChecked(GetDlgItem(hwndDlg,IDC_MOUNT_REMOVABLE));mountOptions->ProtectHiddenVolume=IsButtonChecked(GetDlgItem(hwndDlg,IDC_PROTECT_HIDDEN_VOL));mountOptions->PartitionInInactiveSysEncScope=IsButtonChecked(GetDlgItem(hwndDlg,IDC_MOUNT_SYSENC_PART_WITHOUT_PBA));mountOptions->UseBackupHeader=IsButtonChecked(GetDlgItem(hwndDlg,IDC_USE_EMBEDDED_HEADER_BAK));GetDlgItemTextW(hwndDlg,IDC_VOLUME_LABEL,mountOptions->Label,sizeof(mountOptions->Label)/sizeof(wchar_t));if(mountOptions->ProtectHiddenVolume){GetPassword(hwndDlg,IDC_PASSWORD_PROT_HIDVOL,(LPSTR)mountOptions->ProtectedHidVolPassword.Text,MAX_PASSWORD+1,FALSE);mountOptions->ProtectedHidVolPassword.Length=(unsigned__int32)strlen((char*)mountOptions->ProtectedHidVolPassword.Text);mountOptions->ProtectedHidVolPkcs5Prf=(int)SendMessage(GetDlgItem(hwndDlg,IDC_PKCS5_PRF_ID),CB_GETITEMDATA,SendMessage(GetDlgItem(hwndDlg,IDC_PKCS5_PRF_ID),CB_GETCURSEL,0,0),0);mountOptions->ProtectedHidVolPim=GetPim(hwndDlg,IDC_PIM,0);}// Cleanupwmemset(tmp,L'X',MAX_PASSWORD);tmp[MAX_PASSWORD]=0;SetWindowText(GetDlgItem(hwndDlg,IDC_PASSWORD_PROT_HIDVOL),tmp);if((mountOptions->ProtectHiddenVolume&&!bEnableBkgTask)&&(AskWarnYesNo("HIDVOL_PROT_BKG_TASK_WARNING",hwndDlg)==IDYES)){bEnableBkgTask=TRUE;TaskBarIconAdd(MainDlg);}EndDialog(hwndDlg,lw);return1;}if(lw==IDC_MOUNT_READONLY||lw==IDC_PROTECT_HIDDEN_VOL){BOOLprotect;if(lw==IDC_MOUNT_READONLY){SendDlgItemMessage(hwndDlg,IDC_PROTECT_HIDDEN_VOL,BM_SETCHECK,BST_UNCHECKED,0);EnableWindow(GetDlgItem(hwndDlg,IDC_PROTECT_HIDDEN_VOL),!IsButtonChecked(GetDlgItem(hwndDlg,IDC_MOUNT_READONLY)));EnableWindow(GetDlgItem(hwndDlg,IDT_HIDDEN_VOL_PROTECTION),!IsButtonChecked(GetDlgItem(hwndDlg,IDC_MOUNT_READONLY)));}protect=IsButtonChecked(GetDlgItem(hwndDlg,IDC_PROTECT_HIDDEN_VOL));EnableWindow(GetDlgItem(hwndDlg,IDC_PASSWORD_PROT_HIDVOL),protect);EnableWindow(GetDlgItem(hwndDlg,IDT_HIDDEN_PROT_PASSWD),protect);EnableWindow(GetDlgItem(hwndDlg,IDC_SHOW_PASSWORD_MO),protect);EnableWindow(GetDlgItem(hwndDlg,IDC_KEYFILES_HIDVOL_PROT),protect);EnableWindow(GetDlgItem(hwndDlg,IDC_KEYFILES_ENABLE_HIDVOL_PROT),protect);EnableWindow(GetDlgItem(hwndDlg,IDT_PKCS5_PRF),protect);EnableWindow(GetDlgItem(hwndDlg,IDC_PKCS5_PRF_ID),protect);EnableWindow(GetDlgItem(hwndDlg,IDT_PIM),protect);EnableWindow(GetDlgItem(hwndDlg,IDC_PIM),protect);EnableWindow(GetDlgItem(hwndDlg,IDC_PIM_HELP),protect);EnableWindow(GetDlgItem(hwndDlg,IDC_PIM_ENABLE),protect);return1;}return0;}return0;}// Returns the block size (in bits) of the cipher with which the volume mounted as the// specified drive letter is encrypted. In case of a cascade of ciphers with different// block sizes the function returns the smallest block size.intGetCipherBlockSizeByDriveNo(intnDosDriveNo){VOLUME_PROPERTIES_STRUCTprop;DWORDdwResult;intblockSize=0,cipherID;memset(&prop,0,sizeof(prop));prop.driveNo=nDosDriveNo;if(DeviceIoControl(hDriver,TC_IOCTL_GET_VOLUME_PROPERTIES,&prop,sizeof(prop),&prop,sizeof(prop),&dwResult,NULL)){if((prop.driveNo==nDosDriveNo)&&(prop.ea>=EAGetFirst()&&prop.ea<=EAGetCount())){for(cipherID=EAGetLastCipher(prop.ea);cipherID!=0;cipherID=EAGetPreviousCipher(prop.ea,cipherID)){if(blockSize>0)blockSize=min(blockSize,CipherGetBlockSize(cipherID)*8);elseblockSize=CipherGetBlockSize(cipherID)*8;}}}returnblockSize;}// Returns the mode of operation in which the volume mounted as the specified drive letter is encrypted.intGetModeOfOperationByDriveNo(intnDosDriveNo){VOLUME_PROPERTIES_STRUCTprop;DWORDdwResult;memset(&prop,0,sizeof(prop));prop.driveNo=nDosDriveNo;if(DeviceIoControl(hDriver,TC_IOCTL_GET_VOLUME_PROPERTIES,&prop,sizeof(prop),&prop,sizeof(prop),&dwResult,NULL)){if((prop.driveNo==nDosDriveNo)&&(prop.ea>=EAGetFirst()&&prop.ea<=EAGetCount())&&(prop.mode>=FIRST_MODE_OF_OPERATION_ID&&prop.mode<MODE_ENUM_END_ID)){returnprop.mode;}}return0;}voidDisplayVolumePropertiesListContextMenu(HWNDhwndDlg,LPARAMlParam){/* Volume Properties list context menu */DWORDmPos;intmenuItem;HWNDhList=GetDlgItem(hwndDlg,IDC_VOLUME_PROPERTIES_LIST);inthItem=ListView_GetSelectionMark(hList);SetFocus(hList);if(hItem>=0){HMENUpopup=CreatePopupMenu();AppendMenuW(popup,MF_STRING,IDPM_COPY_VALUE_TO_CLIPBOARD,GetString("IDPM_COPY_VALUE_TO_CLIPBOARD"));if(lParam){mPos=GetMessagePos();}else{POINTpt={0};if(ListView_GetItemPosition(hList,hItem,&pt)){pt.x+=2+::GetSystemMetrics(SM_CXICON);pt.y+=2;}ClientToScreen(hList,&pt);mPos=MAKELONG(pt.x,pt.y);}menuItem=TrackPopupMenu(popup,TPM_RETURNCMD|TPM_LEFTBUTTON,GET_X_LPARAM(mPos),GET_Y_LPARAM(mPos),0,hwndDlg,NULL);DestroyMenu(popup);switch(menuItem){caseIDPM_COPY_VALUE_TO_CLIPBOARD:{wchar_tvalueText[256]={0};ListView_GetItemText(hList,hItem,1,valueText,ARRAYSIZE(valueText));CopyTextToClipboard(valueText);}break;}}}BOOLCALLBACKVolumePropertiesDlgProc(HWNDhwndDlg,UINTmsg,WPARAMwParam,LPARAMlParam){BOOLbSysEnc=(BOOL)lParam;BOOLbSysEncWholeDrive=FALSE;WORDlw=LOWORD(wParam);inti=0;switch(msg){caseWM_INITDIALOG:{VOLUME_PROPERTIES_STRUCTprop;DWORDdwResult;LVCOLUMNWlvCol;HWNDlist=GetDlgItem(hwndDlg,IDC_VOLUME_PROPERTIES_LIST);wchar_tszTmp[1024];wchar_tsw[1024];wchar_t*s;if(bSysEnc){try{BootEncStatus=BootEncObj->GetStatus();bSysEncWholeDrive=WholeSysDriveEncryption(FALSE);}catch(Exception&e){e.Show(MainDlg);return0;}if(!BootEncStatus.DriveEncrypted&&!BootEncStatus.DriveMounted)return0;}else{switch(LOWORD(GetSelectedLong(GetDlgItem(GetParent(hwndDlg),IDC_DRIVELIST)))){caseTC_MLIST_ITEM_FREE:// No mounted volumeEndDialog(hwndDlg,IDOK);return0;caseTC_MLIST_ITEM_NONSYS_VOL:// NOPbreak;caseTC_MLIST_ITEM_SYS_DRIVE:// Encrypted system drivebSysEnc=TRUE;bSysEncWholeDrive=TRUE;break;caseTC_MLIST_ITEM_SYS_PARTITION:// Encrypted system partitionbSysEnc=TRUE;bSysEncWholeDrive=FALSE;break;}}LocalizeDialog(hwndDlg,"IDD_VOLUME_PROPERTIES");SendMessage(list,LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_FULLROWSELECT|LVS_EX_HEADERDRAGDROP|LVS_EX_LABELTIP);memset(&lvCol,0,sizeof(lvCol));lvCol.mask=LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM|LVCF_FMT;lvCol.pszText=GetString("VALUE");lvCol.cx=CompensateXDPI(208);lvCol.fmt=LVCFMT_LEFT;SendMessage(list,LVM_INSERTCOLUMNW,0,(LPARAM)&lvCol);lvCol.pszText=GetString("PROPERTY");lvCol.cx=CompensateXDPI(192);lvCol.fmt=LVCFMT_LEFT;SendMessage(list,LVM_INSERTCOLUMNW,0,(LPARAM)&lvCol);memset(&prop,0,sizeof(prop));prop.driveNo=HIWORD(GetSelectedLong(GetDlgItem(GetParent(hwndDlg),IDC_DRIVELIST)))-L'A';if(bSysEnc){try{BootEncStatus=BootEncObj->GetStatus();if(!BootEncStatus.DriveEncrypted&&!BootEncStatus.DriveMounted)return0;BootEncObj->GetVolumeProperties(&prop);}catch(Exception&e){e.Show(MainDlg);return0;}}else{if(!DeviceIoControl(hDriver,TC_IOCTL_GET_VOLUME_PROPERTIES,&prop,sizeof(prop),&prop,sizeof(prop),&dwResult,NULL)||dwResult==0)return0;}// LocationListItemAdd(list,i,GetString("LOCATION"));if(bSysEnc)ListSubItemSet(list,i++,1,GetString(bSysEncWholeDrive?"SYSTEM_DRIVE":IsHiddenOSRunning()?"HIDDEN_SYSTEM_PARTITION":"SYSTEM_PARTITION"));elseListSubItemSet(list,i++,1,(wchar_t*)(prop.wszVolume[1]!=L'?'?prop.wszVolume:prop.wszVolume+4));if(!bSysEnc&&IsVolumeDeviceHosted((wchar_t*)(prop.wszVolume[1]!=L'?'?prop.wszVolume:prop.wszVolume+4))){// Volume IDstd::wstringhexID=ArrayToHexWideString(prop.volumeID,sizeof(prop.volumeID));ListItemAdd(list,i,GetString("VOLUME_ID"));ListSubItemSet(list,i++,1,hexID.c_str());}// SizeListItemAdd(list,i,GetString("SIZE"));StringCbPrintfW(sw,sizeof(sw),L"%I64u %s",prop.diskLength,GetString("BYTES"));ListSubItemSet(list,i++,1,sw);// TypeListItemAdd(list,i,GetString("TYPE"));if(bSysEnc)ListSubItemSet(list,i++,1,GetString(IsHiddenOSRunning()?"TYPE_HIDDEN_SYSTEM_ADJECTIVE":"SYSTEM_VOLUME_TYPE_ADJECTIVE"));else{booltruecryptMode=prop.pkcs5Iterations==get_pkcs5_iteration_count(prop.pkcs5,0,TRUE,prop.partitionInInactiveSysEncScope);s=prop.hiddenVolume?GetString("HIDDEN"):(prop.hiddenVolProtection!=HIDVOL_PROT_STATUS_NONE?GetString("OUTER"):GetString("NORMAL"));if(truecryptMode){StringCbPrintfW(sw,sizeof(sw),L"TrueCrypt - %s",s);ListSubItemSet(list,i++,1,sw);}elseListSubItemSet(list,i++,1,s);}if(!bSysEnc){// Write protectionListItemAdd(list,i,GetString("READ_ONLY"));if(prop.readOnly||prop.hiddenVolProtection==HIDVOL_PROT_STATUS_ACTION_TAKEN)s=GetString("UISTR_YES");elses=GetString("UISTR_NO");ListSubItemSet(list,i++,1,s);// Hidden Volume ProtectionListItemAdd(list,i,GetString("HIDDEN_VOL_PROTECTION"));if(prop.hiddenVolume)s=GetString("NOT_APPLICABLE_OR_NOT_AVAILABLE");elseif(prop.hiddenVolProtection==HIDVOL_PROT_STATUS_NONE)s=GetString("UISTR_NO");elseif(prop.hiddenVolProtection==HIDVOL_PROT_STATUS_ACTIVE)s=GetString("UISTR_YES");elseif(prop.hiddenVolProtection==HIDVOL_PROT_STATUS_ACTION_TAKEN)s=GetString("HID_VOL_DAMAGE_PREVENTED");ListSubItemSet(list,i++,1,s);}// Encryption algorithmListItemAdd(list,i,GetString("ENCRYPTION_ALGORITHM"));if(prop.ea<EAGetFirst()||prop.ea>EAGetCount()){ListSubItemSet(list,i,1,L"?");return1;}EAGetName(szTmp,prop.ea,1);ListSubItemSet(list,i++,1,szTmp);// Key size(s){wchar_tname[128];intsize=EAGetKeySize(prop.ea);EAGetName(name,prop.ea,1);// Primary keyListItemAdd(list,i,GetString("KEY_SIZE"));StringCbPrintfW(sw,sizeof(sw),L"%d %s",size*8,GetString("BITS"));ListSubItemSet(list,i++,1,sw);if(wcscmp(EAGetModeName(prop.ea,prop.mode,TRUE),L"XTS")==0){// Secondary key (XTS)ListItemAdd(list,i,GetString("SECONDARY_KEY_SIZE_XTS"));ListSubItemSet(list,i++,1,sw);}}// Block sizeListItemAdd(list,i,GetString("BLOCK_SIZE"));StringCbPrintfW(sw,sizeof(sw),L"%d ",CipherGetBlockSize(EAGetFirstCipher(prop.ea))*8);StringCbCatW(sw,sizeof(sw),GetString("BITS"));ListSubItemSet(list,i++,1,sw);// ModeListItemAdd(list,i,GetString("MODE_OF_OPERATION"));ListSubItemSet(list,i++,1,EAGetModeName(prop.ea,prop.mode,TRUE));// PKCS 5 PRFListItemAdd(list,i,GetString("PKCS5_PRF"));if(prop.volumePim==0)ListSubItemSet(list,i++,1,get_pkcs5_prf_name(prop.pkcs5));else{StringCbPrintfW(szTmp,sizeof(szTmp),L"%s (Dynamic)",get_pkcs5_prf_name(prop.pkcs5));ListSubItemSet(list,i++,1,szTmp);}#if 0 // PCKS 5 iterations ListItemAdd (list, i, GetString ("PKCS5_ITERATIONS")); sprintf (szTmp, "%d", prop.pkcs5Iterations); ListSubItemSet (list, i++, 1, szTmp);#endif#if 0 { // Legacy FILETIME ft, curFt; LARGE_INTEGER ft64, curFt64; SYSTEMTIME st; wchar_t date[128]; memset (date, 0, sizeof (date)); // Volume date ListItemAdd (list, i, GetString ("VOLUME_CREATE_DATE")); *(unsigned __int64 *)(&ft) = prop.volumeCreationTime; FileTimeToSystemTime (&ft, &st); GetDateFormatW (LOCALE_USER_DEFAULT, 0, &st, 0, sw, sizeof (sw)/2); swprintf (date, L"%s ", sw); GetTimeFormatW (LOCALE_USER_DEFAULT, 0, &st, 0, sw, sizeof (sw)/2); wcscat (date, sw); ListSubItemSet (list, i++, 1, date); // Header date ListItemAdd (list, i, GetString ("VOLUME_HEADER_DATE")); *(unsigned __int64 *)(&ft) = prop.headerCreationTime; FileTimeToSystemTime (&ft, &st); GetDateFormatW (LOCALE_USER_DEFAULT, 0, &st, 0, sw, sizeof (sw)/2); swprintf (date, L"%s ", sw); GetTimeFormatW (LOCALE_USER_DEFAULT, 0, &st, 0, sw, sizeof (sw)/2); wcscat (date, sw); GetLocalTime (&st); SystemTimeToFileTime (&st, &curFt); curFt64.HighPart = curFt.dwHighDateTime; curFt64.LowPart = curFt.dwLowDateTime; ft64.HighPart = ft.dwHighDateTime; ft64.LowPart = ft.dwLowDateTime; swprintf (date + wcslen (date), GetString ("VOLUME_HEADER_DAYS") , (curFt64.QuadPart - ft64.QuadPart)/(24LL*3600*10000000)); ListSubItemSet (list, i++, 1, date); }#endif // 0if(!bSysEnc||IsHiddenOSRunning()){// Volume format versionListItemAdd(list,i,GetString("VOLUME_FORMAT_VERSION"));StringCbPrintfW(szTmp,sizeof(szTmp),L"%d",prop.volFormatVersion);ListSubItemSet(list,i++,1,szTmp);// Backup headerListItemAdd(list,i,GetString("BACKUP_HEADER"));ListSubItemSet(list,i++,1,GetString(prop.volFormatVersion>1?"UISTR_YES":"UISTR_NO"));}// Total data readListItemAdd(list,i,GetString("TOTAL_DATA_READ"));GetSizeString(prop.totalBytesRead,sw,sizeof(sw));ListSubItemSet(list,i++,1,sw);// Total data writtenListItemAdd(list,i,GetString("TOTAL_DATA_WRITTEN"));GetSizeString(prop.totalBytesWritten,sw,sizeof(sw));ListSubItemSet(list,i++,1,sw);if(bSysEnc){// TrueCrypt Boot Loader versionListItemAdd(list,i,GetString("VC_BOOT_LOADER_VERSION"));ListSubItemSet(list,i++,1,GetUserFriendlyVersionString(BootEncStatus.BootLoaderVersion).c_str());// Encrypted portionListItemAdd(list,i,GetString("ENCRYPTED_PORTION"));if(GetSysEncDeviceEncryptedPartSize(FALSE)==GetSysEncDeviceSize(FALSE))ListSubItemSet(list,i++,1,GetString("ENCRYPTED_PORTION_FULLY_ENCRYPTED"));elseif(GetSysEncDeviceEncryptedPartSize(FALSE)<=1)ListSubItemSet(list,i++,1,GetString("ENCRYPTED_PORTION_NOT_ENCRYPTED"));else{StringCbPrintfW(sw,sizeofsw,GetString("PROCESSED_PORTION_X_PERCENT"),(double)GetSysEncDeviceEncryptedPartSize(FALSE)/(double)GetSysEncDeviceSize(FALSE)*100.0);ListSubItemSet(list,i++,1,sw);}}return0;}caseWM_NOTIFY:if(wParam==IDC_VOLUME_PROPERTIES_LIST){/* Right click */switch(((NM_LISTVIEW*)lParam)->hdr.code){caseNM_RCLICK:caseLVN_BEGINRDRAG:/* If the mouse was moving while the right mouse button is pressed, popup menu would not open, because drag&drop operation would be initiated. Therefore, we're handling RMB drag-and-drop operations as well. */{DisplayVolumePropertiesListContextMenu(hwndDlg,lParam);return1;}}}return0;caseWM_CONTEXTMENU:{HWNDhList=GetDlgItem(hwndDlg,IDC_VOLUME_PROPERTIES_LIST);// only handle if it is coming from keyboard and if the drive// list has focus. The other cases are handled elsewhereif((-1==GET_X_LPARAM(lParam))&&(-1==GET_Y_LPARAM(lParam))&&(GetFocus()==hList)){