📄 dlgcode.c
字号:
{
case TC_WIPE_NONE:
return GetString ("WIPE_MODE_NONE");
case TC_WIPE_1_RAND:
return GetString ("WIPE_MODE_1_RAND");
case TC_WIPE_3_DOD_5220:
return GetString ("WIPE_MODE_3_DOD_5220");
case TC_WIPE_7_DOD_5220:
return GetString ("WIPE_MODE_7_DOD_5220");
case TC_WIPE_35_GUTMANN:
return GetString ("WIPE_MODE_35_GUTMANN");
default:
return GetString ("NOT_APPLICABLE_OR_NOT_AVAILABLE");
}
}
wchar_t *GetPathType (const char *path, BOOL bUpperCase, BOOL *bIsPartition)
{
if (strstr (path, "Partition")
&& strstr (path, "Partition0") == NULL)
{
*bIsPartition = TRUE;
return GetString (bUpperCase ? "PARTITION_UPPER_CASE" : "PARTITION_LOWER_CASE");
}
else if (strstr (path, "HarddiskVolume"))
{
*bIsPartition = TRUE;
return GetString (bUpperCase ? "VOLUME_UPPER_CASE" : "VOLUME_LOWER_CASE");
}
*bIsPartition = FALSE;
return GetString (bUpperCase ? "DEVICE_UPPER_CASE" : "DEVICE_LOWER_CASE");
}
LRESULT CALLBACK CustomDlgProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if (uMsg == WM_SETCURSOR && hCursor != NULL)
{
SetCursor (hCursor);
return TRUE;
}
return DefDlgProc (hwnd, uMsg, wParam, lParam);
}
void ExceptionHandlerThread (void *ept)
{
#define MAX_RET_ADDR_COUNT 8
EXCEPTION_POINTERS *ep = (EXCEPTION_POINTERS *) ept;
DWORD addr, retAddr[MAX_RET_ADDR_COUNT];
DWORD exCode = ep->ExceptionRecord->ExceptionCode;
SYSTEM_INFO si;
wchar_t msg[8192];
char modPath[MAX_PATH];
int crc = 0;
char url[MAX_URL_LENGTH];
char lpack[128];
int i;
addr = (DWORD) ep->ExceptionRecord->ExceptionAddress;
ZeroMemory (retAddr, sizeof (retAddr));
switch (exCode)
{
case 0x80000003:
case 0x80000004:
case 0xc0000006:
case 0xc000001d:
case 0xc000001e:
case 0xc0000096:
case 0xeedfade:
// Exception not caused by TrueCrypt
MessageBoxW (0, GetString ("EXCEPTION_REPORT_EXT"),
GetString ("EXCEPTION_REPORT_TITLE"),
MB_ICONERROR | MB_OK | MB_SETFOREGROUND | MB_TOPMOST);
return;
default:
{
// Call stack
PDWORD sp = (PDWORD) ep->ContextRecord->Esp, stackTop;
int i = 0, e = 0;
MEMORY_BASIC_INFORMATION mi;
VirtualQuery (sp, &mi, sizeof (mi));
stackTop = (PDWORD)((char *)mi.BaseAddress + mi.RegionSize);
while (&sp[i] < stackTop && e < MAX_RET_ADDR_COUNT)
{
if (sp[i] > 0x400000 && sp[i] < 0x500000)
{
int ee = 0;
// Skip duplicates
while (ee < MAX_RET_ADDR_COUNT && retAddr[ee] != sp[i])
ee++;
if (ee != MAX_RET_ADDR_COUNT)
{
i++;
continue;
}
retAddr[e++] = sp[i];
}
i++;
}
}
}
// Checksum of the module
if (GetModuleFileName (NULL, modPath, sizeof (modPath)))
{
HANDLE h = CreateFile (modPath, FILE_READ_DATA | FILE_READ_ATTRIBUTES, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
if (h != INVALID_HANDLE_VALUE)
{
BY_HANDLE_FILE_INFORMATION fi;
if (GetFileInformationByHandle (h, &fi))
{
char *buf = (char *) malloc (fi.nFileSizeLow);
if (buf)
{
DWORD bytesRead;
if (ReadFile (h, buf, fi.nFileSizeLow, &bytesRead, NULL) && bytesRead == fi.nFileSizeLow)
crc = GetCrc32 ((unsigned char *) buf, fi.nFileSizeLow);
free (buf);
}
}
CloseHandle (h);
}
}
GetSystemInfo (&si);
if (LocalizationActive)
sprintf_s (lpack, sizeof (lpack), "&langpack=%s_%s", GetPreferredLangId (), GetActiveLangPackVersion ());
else
lpack[0] = 0;
sprintf (url, TC_APPLINK_SECURE "&dest=err-report%s&os=Windows&osver=%d.%d.%d&arch=%s&cpus=%d&app=%s&cksum=%x&dlg=%s&err=%x&addr=%x"
, lpack
, CurrentOSMajor
, CurrentOSMinor
, CurrentOSServicePack
, Is64BitOs () ? "x64" : "x86"
, si.dwNumberOfProcessors
#ifdef TCMOUNT
,"main"
#endif
#ifdef VOLFORMAT
,"format"
#endif
#ifdef SETUP
,"setup"
#endif
, crc
, LastDialogId ? LastDialogId : "-"
, exCode
, addr);
for (i = 0; i < MAX_RET_ADDR_COUNT && retAddr[i]; i++)
sprintf (url + strlen(url), "&st%d=%x", i, retAddr[i]);
swprintf (msg, GetString ("EXCEPTION_REPORT"), url);
if (IDYES == MessageBoxW (0, msg, GetString ("EXCEPTION_REPORT_TITLE"), MB_ICONERROR | MB_YESNO | MB_DEFBUTTON1))
ShellExecute (NULL, "open", (LPCTSTR) url, NULL, NULL, SW_SHOWNORMAL);
else
UnhandledExceptionFilter (ep);
}
LONG __stdcall ExceptionHandler (EXCEPTION_POINTERS *ep)
{
SetUnhandledExceptionFilter (NULL);
WaitForSingleObject ((HANDLE) _beginthread (ExceptionHandlerThread, 0, (void *)ep), INFINITE);
return EXCEPTION_EXECUTE_HANDLER;
}
static LRESULT CALLBACK NonInstallUacWndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
return DefWindowProc (hWnd, message, wParam, lParam);
}
// Mutex handling to prevent multiple instances of the wizard or main app from dealing with system encryption.
// Returns TRUE if the mutex is (or had been) successfully acquired (otherwise FALSE).
BOOL CreateSysEncMutex (void)
{
return TCCreateMutex (&hSysEncMutex, TC_MUTEX_NAME_SYSENC);
}
BOOL InstanceHasSysEncMutex (void)
{
return (hSysEncMutex != NULL);
}
// Mutex handling to prevent multiple instances of the wizard from dealing with system encryption
void CloseSysEncMutex (void)
{
TCCloseMutex (&hSysEncMutex);
}
// Returns TRUE if the mutex is (or had been) successfully acquired (otherwise FALSE).
BOOL CreateNonSysInplaceEncMutex (void)
{
return TCCreateMutex (&hNonSysInplaceEncMutex, TC_MUTEX_NAME_NONSYS_INPLACE_ENC);
}
BOOL InstanceHasNonSysInplaceEncMutex (void)
{
return (hNonSysInplaceEncMutex != NULL);
}
void CloseNonSysInplaceEncMutex (void)
{
TCCloseMutex (&hNonSysInplaceEncMutex);
}
// Returns TRUE if another instance of the wizard is preparing, resuming or performing non-system in-place encryption
BOOL NonSysInplaceEncInProgressElsewhere (void)
{
return (!InstanceHasNonSysInplaceEncMutex ()
&& MutexExistsOnSystem (TC_MUTEX_NAME_NONSYS_INPLACE_ENC));
}
// Mutex handling to prevent multiple instances of the wizard or main app from trying to install
// or register the driver or from trying to launch it in traveler mode at the same time.
// Returns TRUE if the mutex is (or had been) successfully acquired (otherwise FALSE).
BOOL CreateDriverSetupMutex (void)
{
return TCCreateMutex (&hDriverSetupMutex, TC_MUTEX_NAME_DRIVER_SETUP);
}
void CloseDriverSetupMutex (void)
{
TCCloseMutex (&hDriverSetupMutex);
}
BOOL CreateAppSetupMutex (void)
{
return TCCreateMutex (&hAppSetupMutex, TC_MUTEX_NAME_APP_SETUP);
}
void CloseAppSetupMutex (void)
{
TCCloseMutex (&hAppSetupMutex);
}
BOOL IsTrueCryptInstallerRunning (void)
{
return (MutexExistsOnSystem (TC_MUTEX_NAME_APP_SETUP));
}
// Returns TRUE if the mutex is (or had been) successfully acquired (otherwise FALSE).
BOOL TCCreateMutex (volatile HANDLE *hMutex, char *name)
{
if (*hMutex != NULL)
return TRUE; // This instance already has the mutex
*hMutex = CreateMutex (NULL, TRUE, name);
if (*hMutex == NULL)
{
// In multi-user configurations, the OS returns "Access is denied" here when a user attempts
// to acquire the mutex if another user already has. However, on Vista, "Access is denied" is
// returned also if the mutex is owned by a process with admin rights while we have none.
return FALSE;
}
if (GetLastError () == ERROR_ALREADY_EXISTS)
{
ReleaseMutex (*hMutex);
CloseHandle (*hMutex);
*hMutex = NULL;
return FALSE;
}
return TRUE;
}
void TCCloseMutex (volatile HANDLE *hMutex)
{
if (*hMutex != NULL)
{
if (ReleaseMutex (*hMutex)
&& CloseHandle (*hMutex))
*hMutex = NULL;
}
}
// Returns TRUE if a process running on the system has the specified mutex (otherwise FALSE).
BOOL MutexExistsOnSystem (char *name)
{
if (name[0] == 0)
return FALSE;
HANDLE hMutex = OpenMutex (MUTEX_ALL_ACCESS, FALSE, name);
if (hMutex == NULL)
{
if (GetLastError () == ERROR_FILE_NOT_FOUND)
return FALSE;
if (GetLastError () == ERROR_ACCESS_DENIED) // On Vista, this is returned if the owner of the mutex is elevated while we are not
return TRUE;
// The call failed and it is not certain whether the mutex exists or not
return FALSE;
}
CloseHandle (hMutex);
return TRUE;
}
BOOL LoadSysEncSettings (HWND hwndDlg)
{
BOOL status = TRUE;
DWORD size = 0;
char *sysEncCfgFileBuf = LoadFile (GetConfigPath (TC_APPD_FILENAME_SYSTEM_ENCRYPTION), &size);
char *xml = sysEncCfgFileBuf;
char paramName[100], paramVal[MAX_PATH];
// Defaults
int newSystemEncryptionStatus = SYSENC_STATUS_NONE;
WipeAlgorithmId newnWipeMode = TC_WIPE_NONE;
if (!FileExists (GetConfigPath (TC_APPD_FILENAME_SYSTEM_ENCRYPTION)))
{
SystemEncryptionStatus = newSystemEncryptionStatus;
nWipeMode = newnWipeMode;
}
if (xml == NULL)
{
return FALSE;
}
while (xml = XmlFindElement (xml, "config"))
{
XmlGetAttributeText (xml, "key", paramName, sizeof (paramName));
XmlGetNodeText (xml, paramVal, sizeof (paramVal));
if (strcmp (paramName, "SystemEncryptionStatus") == 0)
{
newSystemEncryptionStatus = atoi (paramVal);
}
else if (strcmp (paramName, "WipeMode") == 0)
{
newnWipeMode = (WipeAlgorithmId) atoi (paramVal);
}
xml++;
}
SystemEncryptionStatus = newSystemEncryptionStatus;
nWipeMode = newnWipeMode;
free (sysEncCfgFileBuf);
return status;
}
// Returns the number of partitions where non-system in-place encryption is progress or had been in progress
// but was interrupted. In addition, via the passed pointer, returns the last selected wipe algorithm ID.
int LoadNonSysInPlaceEncSettings (WipeAlgorithmId *wipeAlgorithm)
{
char *fileBuf = NULL;
char *fileBuf2 = NULL;
DWORD size, size2;
int count;
*wipeAlgorithm = TC_WIPE_NONE;
if (!FileExists (GetConfigPath (TC_APPD_FILENAME_NONSYS_INPLACE_ENC)))
return 0;
if ((fileBuf = LoadFile (GetConfigPath (TC_APPD_FILENAME_NONSYS_INPLACE_ENC), &size)) == NULL)
return 0;
if (FileExists (GetConfigPath (TC_APPD_FILENAME_NONSYS_INPLACE_ENC_WIPE)))
{
if ((fileBuf2 = LoadFile (GetConfigPath (TC_APPD_FILENAME_NONSYS_INPLACE_ENC_WIPE), &size2)) != NULL)
*wipeAlgorithm = (WipeAlgorithmId) atoi (fileBuf2);
}
count = atoi (fileBuf);
if (fileBuf != NULL)
TCfree (fileBuf);
if (fileBuf2 != NULL)
TCfree (fileBuf2);
return (count);
}
void SavePostInstallTasksSettings (int command)
{
FILE *f = NULL;
switch (command)
{
case TC_POST_INSTALL_CFG_REMOVE_ALL:
remove (GetConfigPath (TC_APPD_FILENAME_POST_INSTALL_TASK_TUTORIAL));
remove (GetConfigPath (TC_APPD_FILENAME_POST_INSTALL_TASK_RELEASE_NOTES));
break;
case TC_POST_INSTALL_CFG_TUTORIAL:
f = fopen (GetConfigPath (TC_APPD_FILENAME_POST_INSTALL_TASK_TUTORIAL), "w");
break;
case TC_POST_INSTALL_CFG_RELEASE_NOTES:
f = fopen (GetConfigPath (TC_APPD_FILENAME_POST_INSTALL_TASK_RELEASE_NOTES), "w");
break;
default:
return;
}
if (f == NULL)
return;
if (fputs ("1", f) < 0)
{
// Error
fclose (f);
return;
}
TCFlushFile (f);
fclose (f);
}
void DoPostInstallTasks (void)
{
BOOL bDone = FALSE;
if (FileExists (GetConfigPath (TC_APPD_FILENAME_POST_INSTALL_TASK_TUTORIAL)))
{
if (AskYesNo ("AFTER_INSTALL_TUTORIAL") == IDYES)
Applink ("beginnerstutorial", TRUE, "");
bDone = TRUE;
}
if (FileExists (GetConfigPath (TC_APPD_FILENAME_POST_INSTALL_TASK_RELEASE_NOTES)))
{
if (AskYesNo ("AFTER_UPGRADE_RELEASE_NOTES") == IDYES)
Applink ("releasenotes", TRUE, "");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -