📄 tcformat.c
字号:
// Status
if (locBootEncStatus.TransformWaitingForIdle)
wcscpy (tmpStr, GetString ("PROGRESS_STATUS_WAITING"));
else
wcscpy (tmpStr, GetString (SystemEncryptionStatus == SYSENC_STATUS_DECRYPTING ? "PROGRESS_STATUS_DECRYPTING" : "PROGRESS_STATUS_ENCRYPTING"));
wcscat (tmpStr, L" ");
SetWindowTextW (GetDlgItem (hCurPage, IDC_WRITESPEED), tmpStr);
// Remainining time
if (locBootEncStatus.TransformWaitingForIdle)
{
// The estimate cannot be computed correctly when speed is zero
SetWindowTextW (GetDlgItem (hCurPage, IDC_TIMEREMAIN), GetString ("N_A_UISTR"));
}
if (locBootEncStatus.TransformWaitingForIdle != lastTransformWaitingForIdle)
{
if (lastTransformWaitingForIdle)
{
// Estimate of remaining time and other values may have been heavily distorted as the speed
// was zero. Therefore, we're going to reinitialize the progress bar and all related variables.
InitSysEncProgressBar ();
}
lastTransformWaitingForIdle = locBootEncStatus.TransformWaitingForIdle;
}
}
}
}
static void InitSysEncProgressBar (void)
{
BootEncryptionStatus locBootEncStatus;
try
{
locBootEncStatus = BootEncObj->GetStatus();
}
catch (...)
{
return;
}
if (locBootEncStatus.ConfiguredEncryptedAreaEnd == -1
|| locBootEncStatus.ConfiguredEncryptedAreaStart == -1)
return;
InitProgressBar ((locBootEncStatus.ConfiguredEncryptedAreaEnd
- locBootEncStatus.ConfiguredEncryptedAreaStart + 1) / SECTOR_SIZE,
(locBootEncStatus.EncryptedAreaEnd == locBootEncStatus.EncryptedAreaStart || locBootEncStatus.EncryptedAreaEnd == -1) ?
0 : locBootEncStatus.EncryptedAreaEnd - locBootEncStatus.EncryptedAreaStart + 1,
SystemEncryptionStatus == SYSENC_STATUS_DECRYPTING,
TRUE,
TRUE,
TRUE);
}
static void UpdateSysEncControls (void)
{
BootEncryptionStatus locBootEncStatus;
try
{
locBootEncStatus = BootEncObj->GetStatus();
}
catch (...)
{
return;
}
EnableWindow (GetDlgItem (hCurPage, IDC_WIPE_MODE),
!locBootEncStatus.SetupInProgress
&& SystemEncryptionStatus == SYSENC_STATUS_ENCRYPTING
&& !bHiddenOS);
SetWindowTextW (GetDlgItem (hCurPage, IDC_PAUSE),
GetString (locBootEncStatus.SetupInProgress ? "IDC_PAUSE" : "RESUME"));
EnableWindow (GetDlgItem (MainDlg, IDC_NEXT), !locBootEncStatus.SetupInProgress && !bFirstSysEncResumeDone);
if (!locBootEncStatus.SetupInProgress)
{
wchar_t tmpStr[100];
wcscpy (tmpStr, GetString ((SysDriveOrPartitionFullyEncrypted (TRUE) || !locBootEncStatus.DriveMounted) ?
"PROGRESS_STATUS_FINISHED" : "PROGRESS_STATUS_PAUSED"));
wcscat (tmpStr, L" ");
// Status
SetWindowTextW (GetDlgItem (hCurPage, IDC_WRITESPEED), tmpStr);
if (SysDriveOrPartitionFullyEncrypted (TRUE) || SystemEncryptionStatus == SYSENC_STATUS_NONE)
{
wcscpy (tmpStr, GetString ("PROCESSED_PORTION_100_PERCENT"));
wcscat (tmpStr, L" ");
SetWindowTextW (GetDlgItem (hCurPage, IDC_BYTESWRITTEN), tmpStr);
}
SetWindowText (GetDlgItem (hCurPage, IDC_TIMEREMAIN), " ");
}
}
static void SysEncPause (void)
{
BootEncryptionStatus locBootEncStatus;
if (CreateSysEncMutex ())
{
EnableWindow (GetDlgItem (hCurPage, IDC_PAUSE), FALSE);
try
{
locBootEncStatus = BootEncObj->GetStatus();
}
catch (Exception &e)
{
e.Show (MainDlg);
Error ("ERR_GETTING_SYSTEM_ENCRYPTION_STATUS");
EnableWindow (GetDlgItem (hCurPage, IDC_PAUSE), TRUE);
return;
}
if (!locBootEncStatus.SetupInProgress)
{
EnableWindow (GetDlgItem (hCurPage, IDC_PAUSE), TRUE);
return;
}
WaitCursor ();
try
{
int attempts = SYSENC_PAUSE_RETRIES;
BootEncObj->AbortSetup ();
locBootEncStatus = BootEncObj->GetStatus();
while (locBootEncStatus.SetupInProgress && attempts > 0)
{
Sleep (SYSENC_PAUSE_RETRY_INTERVAL);
attempts--;
locBootEncStatus = BootEncObj->GetStatus();
}
if (!locBootEncStatus.SetupInProgress)
BootEncObj->CheckEncryptionSetupResult ();
}
catch (Exception &e)
{
e.Show (MainDlg);
}
NormalCursor ();
if (locBootEncStatus.SetupInProgress)
{
SetTimer (MainDlg, TIMER_ID_SYSENC_PROGRESS, TIMER_INTERVAL_SYSENC_PROGRESS, NULL);
EnableWindow (GetDlgItem (hCurPage, IDC_PAUSE), TRUE);
Error ("FAILED_TO_INTERRUPT_SYSTEM_ENCRYPTION");
return;
}
UpdateSysEncControls ();
EnableWindow (GetDlgItem (hCurPage, IDC_PAUSE), TRUE);
}
else
Error ("SYSTEM_ENCRYPTION_IN_PROGRESS_ELSEWHERE");
}
static void SysEncResume (void)
{
BootEncryptionStatus locBootEncStatus;
if (CreateSysEncMutex ())
{
EnableWindow (GetDlgItem (hCurPage, IDC_PAUSE), FALSE);
try
{
locBootEncStatus = BootEncObj->GetStatus();
}
catch (Exception &e)
{
e.Show (MainDlg);
Error ("ERR_GETTING_SYSTEM_ENCRYPTION_STATUS");
EnableWindow (GetDlgItem (hCurPage, IDC_PAUSE), TRUE);
return;
}
if (locBootEncStatus.SetupInProgress)
{
bSystemEncryptionInProgress = TRUE;
UpdateSysEncControls ();
SetTimer (MainDlg, TIMER_ID_SYSENC_PROGRESS, TIMER_INTERVAL_SYSENC_PROGRESS, NULL);
EnableWindow (GetDlgItem (hCurPage, IDC_PAUSE), TRUE);
return;
}
bSystemEncryptionInProgress = FALSE;
WaitCursor ();
try
{
switch (SystemEncryptionStatus)
{
case SYSENC_STATUS_ENCRYPTING:
BootEncObj->StartEncryption (nWipeMode);
break;
case SYSENC_STATUS_DECRYPTING:
if (locBootEncStatus.DriveMounted) // If the drive is not encrypted we will just deinstall
BootEncObj->StartDecryption ();
break;
}
bSystemEncryptionInProgress = TRUE;
}
catch (Exception &e)
{
e.Show (MainDlg);
}
NormalCursor ();
if (!bSystemEncryptionInProgress)
{
EnableWindow (GetDlgItem (hCurPage, IDC_PAUSE), TRUE);
Error ("FAILED_TO_RESUME_SYSTEM_ENCRYPTION");
return;
}
bFirstSysEncResumeDone = TRUE;
InitSysEncProgressBar ();
UpdateSysEncProgressBar ();
UpdateSysEncControls ();
EnableWindow (GetDlgItem (hCurPage, IDC_PAUSE), TRUE);
SetTimer (MainDlg, TIMER_ID_SYSENC_PROGRESS, TIMER_INTERVAL_SYSENC_PROGRESS, NULL);
}
else
Error ("SYSTEM_ENCRYPTION_IN_PROGRESS_ELSEWHERE");
}
BOOL RegisterBootDriver (void)
{
try
{
BootEncObj->RegisterBootDriver();
}
catch (Exception &e)
{
e.Show (NULL);
return FALSE;
}
return TRUE;
}
static BOOL GetDevicePathForHiddenOS (void)
{
BOOL tmpbDevice = FALSE;
try
{
strncpy (szFileName, BootEncObj->GetPartitionForHiddenOS().DevicePath.c_str(), sizeof(szFileName));
CreateFullVolumePath (szDiskFile, szFileName, &tmpbDevice);
}
catch (Exception &e)
{
e.Show (MainDlg);
return FALSE;
}
return (szFileName[0] != 0
&& szDiskFile[0] != 0
&& tmpbDevice);
}
// Returns TRUE if there is unallocated space greater than 64 MB (max possible slack space size) between the
// boot partition and the first partition behind it. If there's none or if an error occurs, returns FALSE.
static BOOL CheckGapBetweenSysAndHiddenOS (void)
{
try
{
SystemDriveConfiguration sysDriveCfg = BootEncObj->GetSystemDriveConfiguration();
return (sysDriveCfg.SystemPartition.Info.StartingOffset.QuadPart
+ sysDriveCfg.SystemPartition.Info.PartitionLength.QuadPart
+ 64 * BYTES_PER_MB
+ 128 * BYTES_PER_KB
<= BootEncObj->GetPartitionForHiddenOS().Info.StartingOffset.QuadPart);
}
catch (Exception &e)
{
e.Show (MainDlg);
}
return FALSE;
}
void DisplayRandPool (HWND hPoolDisplay, BOOL bShow)
{
unsigned char tmp[4];
unsigned char tmpByte;
int col, row;
static BOOL bRandPoolDispAscii = FALSE;
if (!bShow)
{
SetWindowText (hPoolDisplay, "");
return;
}
RandpeekBytes (randPool, sizeof (randPool));
if (memcmp (lastRandPool, randPool, sizeof(lastRandPool)) != 0)
{
outRandPoolDispBuffer[0] = 0;
for (row = 0; row < RANDPOOL_DISPLAY_ROWS; row++)
{
for (col = 0; col < RANDPOOL_DISPLAY_COLUMNS; col++)
{
tmpByte = randPool[row * RANDPOOL_DISPLAY_COLUMNS + col];
sprintf ((char *) tmp, bRandPoolDispAscii ? ((tmpByte >= 32 && tmpByte < 255 && tmpByte != '&') ? " %c " : " . ") : "%02X ", tmpByte);
strcat ((char *) outRandPoolDispBuffer, (char *) tmp);
}
strcat ((char *) outRandPoolDispBuffer, "\n");
}
SetWindowText (hPoolDisplay, (char *) outRandPoolDispBuffer);
memcpy (lastRandPool, randPool, sizeof(lastRandPool));
}
}
static void __cdecl sysEncDriveAnalysisThread (void *hwndDlgArg)
{
// Mark the detection process as 'in progress'
HiddenSectorDetectionStatus = 1;
SaveSettings (NULL);
BroadcastSysEncCfgUpdate ();
try
{
BootEncObj->ProbeRealSystemDriveSize ();
bSysEncDriveAnalysisTimeOutOccurred = FALSE;
}
catch (TimeOut &)
{
bSysEncDriveAnalysisTimeOutOccurred = TRUE;
}
catch (Exception &e)
{
e.Show (NULL);
EndMainDlg (MainDlg);
exit(0);
}
// Mark the detection process as successful
HiddenSectorDetectionStatus = 0;
SaveSettings (NULL);
BroadcastSysEncCfgUpdate ();
// This artificial delay prevents user confusion on systems where the analysis ends almost instantly
Sleep (3000);
bSysEncDriveAnalysisInProgress = FALSE;
}
static void __cdecl formatThreadFunction (void *hwndDlgArg)
{
int nStatus;
DWORD dwWin32FormatError;
BOOL bHidden;
HWND hwndDlg = (HWND) hwndDlgArg;
// Check administrator privileges
if (!IsAdmin () && !IsUacSupported ())
{
if (fileSystem == FILESYS_NTFS)
{
if (MessageBoxW (hwndDlg, GetString ("ADMIN_PRIVILEGES_WARN_NTFS"), lpszTitle, MB_OKCANCEL|MB_ICONWARNING|MB_DEFBUTTON2) == IDCANCEL)
goto cancel;
}
if (bDevice)
{
if (MessageBoxW (hwndDlg, GetString ("ADMIN_PRIVILEGES_WARN_DEVICES"), lpszTitle, MB_OKCANCEL|MB_ICONWARNING|MB_DEFBUTTON2) == IDCANCEL)
goto cancel;
}
}
if (bDevice == FALSE)
{
int x = _access (szDiskFile, 06);
if (x == 0 || errno != ENOENT)
{
wchar_t szTmp[512];
if (! ((bHiddenVol && !bHiddenVolHost) && errno != EACCES)) // Only ask ask for permission to overwrite an existing volume if we're not creating a hidden volume
{
_snwprintf (szTmp, sizeof szTmp / 2,
GetString (errno == EACCES ? "READONLYPROMPT" : "OVERWRITEPROMPT"),
szDiskFile);
x = MessageBoxW (hwndDlg, szTmp, lpszTitle, YES_NO|MB_ICONWARNING|MB_DEFBUTTON2);
if (x != IDYES)
goto cancel;
}
}
if (_access (szDiskFile, 06) != 0)
{
if (errno == EACCES)
{
if (_chmod (szDiskFile, _S_IREAD | _S_IWRITE) != 0)
{
MessageBoxW (hwndDlg, GetString ("ACCESSMODEFAIL"), lpszTitle, ICON_HAND);
goto cancel;
}
}
}
}
else
{
int x;
wchar_t szTmp[4096];
int driveNo;
WCHAR deviceName[MAX_PATH];
strcpy ((char *)deviceName, szFileName);
ToUNICODE ((char *)deviceName);
driveNo = GetDiskDeviceDriveLetter (deviceName);
if (!(bHiddenVol && !bHiddenVolHost)) // Do not ask for permission to overwrite an existing volume if we're creating a hidden volume within it
{
wchar_t drive[128];
wchar_t *type;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -