📄 tcformat.c
字号:
{
LoadSysEncSettings (hwndDlg);
defaultKeyFilesParam.EnableKeyFiles = FALSE;
bStartOnLogon = ConfigReadInt ("StartOnLogon", FALSE);
bHistory = ConfigReadInt ("SaveVolumeHistory", FALSE);
if (hwndDlg != NULL)
{
LoadCombo (GetDlgItem (hwndDlg, IDC_COMBO_BOX));
return;
}
if (bHistoryCmdLine)
return;
}
static void SaveSettings (HWND hwndDlg)
{
WaitCursor ();
if (hwndDlg != NULL)
DumpCombo (GetDlgItem (hwndDlg, IDC_COMBO_BOX), !bHistory);
ConfigWriteBegin ();
ConfigWriteInt ("StartOnLogon", bStartOnLogon);
ConfigWriteInt ("SaveVolumeHistory", bHistory);
if (GetPreferredLangId () != NULL)
ConfigWriteString ("Language", GetPreferredLangId ());
ConfigWriteEnd ();
NormalCursor ();
}
// WARNING: This function does NOT cause immediate application exit (use e,g. return 1 after calling it
// from a DialogProc function).
static void EndMainDlg (HWND hwndDlg)
{
if (nCurPageNo == FILE_PAGE)
{
if (IsWindow(GetDlgItem(hCurPage, IDC_NO_HISTORY)))
bHistory = !IsButtonChecked (GetDlgItem (hCurPage, IDC_NO_HISTORY));
MoveEditToCombo (GetDlgItem (hCurPage, IDC_COMBO_BOX), bHistory);
SaveSettings (hCurPage);
}
else
{
SaveSettings (NULL);
}
SaveSysEncSettings (hwndDlg);
if (!bHistory)
CleanLastVisitedMRU ();
EndDialog (hwndDlg, 0);
}
// Returns TRUE if system encryption or decryption had been or is in progress and has not been completed
static BOOL SysEncryptionOrDecryptionRequired (void)
{
/* If you update this function, revise SysEncryptionOrDecryptionRequired() in Mount.c as well. */
static BootEncryptionStatus locBootEncStatus;
try
{
locBootEncStatus = BootEncObj->GetStatus();
}
catch (Exception &e)
{
e.Show (MainDlg);
}
return (SystemEncryptionStatus == SYSENC_STATUS_ENCRYPTING
|| SystemEncryptionStatus == SYSENC_STATUS_DECRYPTING
||
(
locBootEncStatus.DriveMounted
&&
(
locBootEncStatus.ConfiguredEncryptedAreaStart != locBootEncStatus.EncryptedAreaStart
|| locBootEncStatus.ConfiguredEncryptedAreaEnd != locBootEncStatus.EncryptedAreaEnd
)
)
);
}
// Returns TRUE if the system partition/drive is completely encrypted
static BOOL SysDriveOrPartitionFullyEncrypted (BOOL bSilent)
{
/* If you update this function, revise SysDriveOrPartitionFullyEncrypted() in Mount.c as well. */
static BootEncryptionStatus locBootEncStatus;
try
{
locBootEncStatus = BootEncObj->GetStatus();
}
catch (Exception &e)
{
if (!bSilent)
e.Show (MainDlg);
}
return (!locBootEncStatus.SetupInProgress
&& locBootEncStatus.ConfiguredEncryptedAreaEnd != 0
&& locBootEncStatus.ConfiguredEncryptedAreaEnd != -1
&& locBootEncStatus.ConfiguredEncryptedAreaStart == locBootEncStatus.EncryptedAreaStart
&& locBootEncStatus.ConfiguredEncryptedAreaEnd == locBootEncStatus.EncryptedAreaEnd);
}
// Adds or removes the wizard to/from the system startup sequence
static void ManageStartupSeqWiz (BOOL bRemove, const char *arg)
{
char regk [64];
// Split the string in order to prevent some antivirus packages from falsely reporting
// TrueCrypt Format.exe to contain a possible Trojan horse because of this string (heuristic scan).
sprintf (regk, "%s%s", "Software\\Microsoft\\Windows\\Curren", "tVersion\\Run");
if (!bRemove)
{
char exe[MAX_PATH * 2] = { '"' };
GetModuleFileName (NULL, exe + 1, sizeof (exe) - 1);
if (strlen (arg) > 0)
{
strcat (exe, "\" ");
strcat (exe, arg);
}
WriteRegistryString (regk, "TrueCrypt Format", exe);
}
else
DeleteRegistryValue (regk, "TrueCrypt Format");
}
// This functions is to be used when the wizard mode needs to be changed to WIZARD_MODE_SYS_DEVICE.
// If the function fails to switch the mode, it returns FALSE (otherwise TRUE).
BOOL SwitchWizardToSysEncMode (void)
{
WaitCursor ();
try
{
BootEncStatus = BootEncObj->GetStatus();
bWholeSysDrive = BootEncObj->SystemPartitionCoversWholeDrive();
}
catch (Exception &e)
{
e.Show (MainDlg);
Error ("ERR_GETTING_SYSTEM_ENCRYPTION_STATUS");
NormalCursor ();
return FALSE;
}
// From now on, we should be the only instance of the TC wizard allowed to deal with system encryption
if (!CreateSysEncMutex ())
{
Warning ("SYSTEM_ENCRYPTION_IN_PROGRESS_ELSEWHERE");
NormalCursor ();
return FALSE;
}
// User-mode app may have crashed and its mutex may have gotten lost, so we need to check the driver status too
if (BootEncStatus.SetupInProgress)
{
if (AskWarnYesNo ("SYSTEM_ENCRYPTION_RESUME_PROMPT") == IDYES)
{
if (SystemEncryptionStatus != SYSENC_STATUS_ENCRYPTING
&& SystemEncryptionStatus != SYSENC_STATUS_DECRYPTING)
{
// The config file with status was lost or not written correctly
if (!ResolveUnknownSysEncDirection ())
{
CloseSysEncMutex ();
NormalCursor ();
return FALSE;
}
}
bDirectSysEncMode = TRUE;
ChangeWizardMode (WIZARD_MODE_SYS_DEVICE);
LoadPage (MainDlg, SYSENC_ENCRYPTION_PAGE);
NormalCursor ();
return TRUE;
}
else
{
CloseSysEncMutex ();
Error ("SYS_ENCRYPTION_OR_DECRYPTION_IN_PROGRESS");
NormalCursor ();
return FALSE;
}
}
if (BootEncStatus.DriveMounted
|| BootEncStatus.DriveEncrypted
|| SysEncryptionOrDecryptionRequired ())
{
if (!SysDriveOrPartitionFullyEncrypted (FALSE)
&& AskWarnYesNo ("SYSTEM_ENCRYPTION_RESUME_PROMPT") == IDYES)
{
if (SystemEncryptionStatus == SYSENC_STATUS_NONE)
{
// If the config file with status was lost or not written correctly, we
// don't know whether to encrypt or decrypt (but we know that encryption or
// decryption is required). Ask the user to select encryption, decryption,
// or cancel
if (!ResolveUnknownSysEncDirection ())
{
CloseSysEncMutex ();
NormalCursor ();
return FALSE;
}
}
bDirectSysEncMode = TRUE;
ChangeWizardMode (WIZARD_MODE_SYS_DEVICE);
LoadPage (MainDlg, SYSENC_ENCRYPTION_PAGE);
NormalCursor ();
return TRUE;
}
else
{
CloseSysEncMutex ();
Error ("SETUP_FAILED_BOOT_DRIVE_ENCRYPTED");
NormalCursor ();
return FALSE;
}
}
else
{
// Check compliance with requirements for boot encryption
if (!IsAdmin())
{
if (!IsUacSupported())
{
Warning ("ADMIN_PRIVILEGES_WARN_DEVICES");
}
}
try
{
BootEncObj->CheckRequirements ();
}
catch (Exception &e)
{
CloseSysEncMutex ();
e.Show (MainDlg);
NormalCursor ();
return FALSE;
}
if (!ChangeWizardMode (WIZARD_MODE_SYS_DEVICE))
{
NormalCursor ();
return FALSE;
}
if (bSysDriveSelected || bSysPartitionSelected)
{
// The user selected the non-sys-device wizard mode but then selected a system device
bWholeSysDrive = (bSysDriveSelected && !bSysPartitionSelected);
bSysDriveSelected = FALSE;
bSysPartitionSelected = FALSE;
try
{
if (BootEncObj->SystemDriveIsDynamic())
{
Warning ("SYSENC_UNSUPPORTED_FOR_DYNAMIC_DISK");
ChangeWizardMode (WIZARD_MODE_NONSYS_DEVICE);
return FALSE;
}
if (bWholeSysDrive && !BootEncObj->SystemPartitionCoversWholeDrive())
{
if (BootEncObj->SystemDriveContainsExtendedPartition())
{
bWholeSysDrive = FALSE;
Warning ("WDE_UNSUPPORTED_FOR_EXTENDED_PARTITIONS");
if (AskYesNo ("ASK_ENCRYPT_PARTITION_INSTEAD_OF_DRIVE") == IDNO)
{
ChangeWizardMode (WIZARD_MODE_NONSYS_DEVICE);
return FALSE;
}
}
else
Warning ("WDE_EXTENDED_PARTITIONS_WARNING");
}
else if (BootEncObj->SystemPartitionCoversWholeDrive()
&& !bWholeSysDrive)
bWholeSysDrive = (AskYesNo ("WHOLE_SYC_DEVICE_RECOM") == IDYES);
}
catch (Exception &e)
{
e.Show (MainDlg);
return FALSE;
}
// Skip SYSENC_SPAN_PAGE as the user already made the choice
LoadPage (MainDlg, bWholeSysDrive ? SYSENC_DRIVE_ANALYSIS_PAGE : SYSENC_MULTI_BOOT_MODE_PAGE);
}
else
LoadPage (MainDlg, SYSENC_SPAN_PAGE);
NormalCursor ();
return TRUE;
}
CloseSysEncMutex ();
NormalCursor ();
return FALSE;
}
void SwitchWizardToFileContainerMode (void)
{
ChangeWizardMode (WIZARD_MODE_FILE_CONTAINER);
LoadPage (MainDlg, FILE_PAGE);
NormalCursor ();
}
void SwitchWizardToNonSysDeviceMode (void)
{
ChangeWizardMode (WIZARD_MODE_NONSYS_DEVICE);
LoadPage (MainDlg, VOLUME_TYPE_PAGE);
NormalCursor ();
}
// Use this function e.g. if the config file with the system encryption settings was lost or not written
// correctly, and we don't know whether to encrypt or decrypt (but we know that encryption or decryption
// is required). Returns FALSE if failed or cancelled.
static BOOL ResolveUnknownSysEncDirection (void)
{
if (CreateSysEncMutex ())
{
if (SystemEncryptionStatus != SYSENC_STATUS_ENCRYPTING
&& SystemEncryptionStatus != SYSENC_STATUS_DECRYPTING)
{
try
{
BootEncStatus = BootEncObj->GetStatus();
}
catch (Exception &e)
{
e.Show (MainDlg);
Error ("ERR_GETTING_SYSTEM_ENCRYPTION_STATUS");
return FALSE;
}
if (BootEncStatus.SetupInProgress)
{
return ChangeSystemEncryptionStatus (
(BootEncStatus.SetupMode != SetupDecryption) ? SYSENC_STATUS_ENCRYPTING : SYSENC_STATUS_DECRYPTING);
}
else
{
// Ask the user to select encryption, decryption, or cancel
char *tmpStr[] = {0,
!BootEncStatus.DriveEncrypted ? "CHOOSE_ENCRYPT_OR_DECRYPT_FINALIZE_DECRYPT_NOTE" : "CHOOSE_ENCRYPT_OR_DECRYPT",
"ENCRYPT",
"DECRYPT",
"IDCANCEL",
0};
switch (AskMultiChoice ((void **) tmpStr))
{
case 1:
return ChangeSystemEncryptionStatus (SYSENC_STATUS_ENCRYPTING);
case 2:
return ChangeSystemEncryptionStatus (SYSENC_STATUS_DECRYPTING);
default:
return FALSE;
}
}
}
else
return TRUE;
}
else
{
Error ("SYSTEM_ENCRYPTION_IN_PROGRESS_ELSEWHERE");
return FALSE;
}
}
void ComboSelChangeEA (HWND hwndDlg)
{
LPARAM nIndex = SendMessage (GetDlgItem (hwndDlg, IDC_COMBO_BOX), CB_GETCURSEL, 0, 0);
if (nIndex == CB_ERR)
{
SetWindowText (GetDlgItem (hwndDlg, IDC_BOX_HELP), "");
}
else
{
char name[100];
wchar_t auxLine[4096];
wchar_t hyperLink[256] = { 0 };
char cipherIDs[5];
int i, cnt = 0;
nIndex = SendMessage (GetDlgItem (hwndDlg, IDC_COMBO_BOX), CB_GETITEMDATA, nIndex, 0);
EAGetName (name, nIndex);
if (strcmp (name, "AES") == 0)
{
swprintf_s (hyperLink, sizeof(hyperLink) / 2, GetString ("MORE_INFO_ABOUT"), name);
SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString ("AES_HELP"));
}
else if (strcmp (name, "Serpent") == 0)
{
swprintf_s (hyperLink, sizeof(hyperLink) / 2, GetString ("MORE_INFO_ABOUT"), name);
SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString ("SERPENT_HELP"));
}
else if (strcmp (name, "Twofish") == 0)
{
swprintf_s (hyperLink, sizeof(hyperLink) / 2, GetString ("MORE_INFO_ABOUT"), name);
SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString ("TWOFISH_HELP"));
}
else if (EAGetCipherCount (nIndex) > 1)
{
// Cascade
cipherIDs[cnt++] = i = EAGetLastCipher(nIndex);
while (i = EAGetPreviousCipher(nIndex, i))
{
cipherIDs[cnt] = i;
cnt++;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -