📄 dlgcode.c
字号:
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 | MB_SETFOREGROUND | MB_TOPMOST))
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, "Global\\TrueCrypt System Encryption Wizard");
}
// Mutex handling to prevent multiple instances of the wizard from dealing with system encryption
void CloseSysEncMutex (void)
{
TCCloseMutex (&hSysEncMutex);
}
// 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, "Global\\TrueCrypt Driver Setup");
}
void CloseDriverSetupMutex (void)
{
TCCloseMutex (&hDriverSetupMutex);
}
// Returns TRUE if the mutex is (or had been) successfully acquired (otherwise FALSE).
BOOL TCCreateMutex (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.
handleWin32Error (NULL);
return FALSE;
}
if (GetLastError () == ERROR_ALREADY_EXISTS)
{
ReleaseMutex (*hMutex);
CloseHandle (*hMutex);
*hMutex = NULL;
return FALSE;
}
return TRUE;
}
void TCCloseMutex (HANDLE *hMutex)
{
if (*hMutex != NULL)
{
if (ReleaseMutex (*hMutex)
&& CloseHandle (*hMutex))
*hMutex = NULL;
}
}
BOOL LoadSysEncSettings (HWND hwndDlg)
{
BOOL status = TRUE;
DWORD size = 0;
char *sysEncCfgFileBuf = LoadFile (GetConfigPath (FILE_SYSTEM_ENCRYPTION_CFG), &size);
char *xml = sysEncCfgFileBuf;
char paramName[100], paramVal[MAX_PATH];
// Defaults
int newSystemEncryptionStatus = SYSENC_STATUS_NONE;
WipeAlgorithmId newnWipeMode = TC_WIPE_NONE;
if (!FileExists (GetConfigPath (FILE_SYSTEM_ENCRYPTION_CFG)))
{
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;
}
/* InitApp - initialize the application, this function is called once in the
applications WinMain function, but before the main dialog has been created */
void InitApp (HINSTANCE hInstance, char *lpszCommandLine)
{
WNDCLASS wc;
OSVERSIONINFO os;
char langId[6];
/* Save the instance handle for later */
hInst = hInstance;
/* Pull down the windows version */
os.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
if (GetVersionEx (&os) == FALSE)
AbortProcess ("NO_OS_VER");
CurrentOSMajor = os.dwMajorVersion;
CurrentOSMinor = os.dwMinorVersion;
if (os.dwPlatformId == VER_PLATFORM_WIN32_NT && CurrentOSMajor == 5 && CurrentOSMinor == 0)
nCurrentOS = WIN_2000;
else if (os.dwPlatformId == VER_PLATFORM_WIN32_NT && CurrentOSMajor == 5 && CurrentOSMinor == 1)
nCurrentOS = WIN_XP;
else if (os.dwPlatformId == VER_PLATFORM_WIN32_NT && CurrentOSMajor == 5 && CurrentOSMinor == 2)
{
OSVERSIONINFOEX osEx;
osEx.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEX);
GetVersionEx ((LPOSVERSIONINFOA) &osEx);
if (osEx.wProductType == VER_NT_SERVER || osEx.wProductType == VER_NT_DOMAIN_CONTROLLER)
nCurrentOS = WIN_SERVER_2003;
else
nCurrentOS = WIN_XP64;
}
else if (os.dwPlatformId == VER_PLATFORM_WIN32_NT && CurrentOSMajor >= 6)
nCurrentOS = WIN_VISTA_OR_LATER;
else if (os.dwPlatformId == VER_PLATFORM_WIN32_NT && CurrentOSMajor == 4)
nCurrentOS = WIN_NT4;
else if (os.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS && os.dwMajorVersion == 4 && os.dwMinorVersion == 0)
nCurrentOS = WIN_95;
else if (os.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS && os.dwMajorVersion == 4 && os.dwMinorVersion == 10)
nCurrentOS = WIN_98;
else if (os.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS && os.dwMajorVersion == 4 && os.dwMinorVersion == 90)
nCurrentOS = WIN_ME;
else if (os.dwPlatformId == VER_PLATFORM_WIN32s)
nCurrentOS = WIN_31;
else
nCurrentOS = WIN_UNKNOWN;
CoInitialize (NULL);
langId[0] = 0;
SetPreferredLangId (ConfigReadString ("Language", "", langId, sizeof (langId)));
if (langId[0] == 0)
DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_LANGUAGE), NULL,
(DLGPROC) LanguageDlgProc, (LPARAM) 1);
LoadLanguageFile ();
#ifndef SETUP
// UAC elevation moniker cannot be used in traveler mode.
// A new instance of the application must be created with elevated privileges.
if (IsNonInstallMode () && !IsAdmin () && IsUacSupported ())
{
char modPath[MAX_PATH], newCmdLine[4096];
WNDCLASSEX wcex;
HWND hWnd;
if (strstr (lpszCommandLine, "/q UAC ") == lpszCommandLine)
{
Error ("UAC_INIT_ERROR");
exit (1);
}
memset (&wcex, 0, sizeof (wcex));
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.lpfnWndProc = (WNDPROC) NonInstallUacWndProc;
wcex.hInstance = hInstance;
wcex.lpszClassName = "TrueCrypt";
RegisterClassEx (&wcex);
// A small transparent window is necessary to bring the new instance to foreground
hWnd = CreateWindowEx (WS_EX_TOOLWINDOW | WS_EX_LAYERED,
"TrueCrypt", "TrueCrypt", 0,
GetSystemMetrics (SM_CXSCREEN)/2,
GetSystemMetrics (SM_CYSCREEN)/2,
1, 1, NULL, NULL, hInstance, NULL);
SetLayeredWindowAttributes (hWnd, 0, 0, LWA_ALPHA);
ShowWindow (hWnd, SW_SHOWNORMAL);
GetModuleFileName (NULL, modPath, sizeof (modPath));
strcpy (newCmdLine, "/q UAC ");
strcat_s (newCmdLine, sizeof (newCmdLine), lpszCommandLine);
if ((int)ShellExecute (hWnd, "runas", modPath, newCmdLine, NULL, SW_SHOWNORMAL) <= 32)
exit (1);
Sleep (2000);
exit (0);
}
#endif
SetUnhandledExceptionFilter (ExceptionHandler);
RemoteSession = GetSystemMetrics (SM_REMOTESESSION) != 0;
// OS version check
if (CurrentOSMajor < 5)
{
MessageBoxW (NULL, GetString ("UNSUPPORTED_OS"), lpszTitle, MB_ICONSTOP);
exit (1);
}
else
{
OSVERSIONINFOEX osEx;
// Service pack check & warnings about critical MS issues
osEx.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEX);
if (GetVersionEx ((LPOSVERSIONINFOA) &osEx) != 0)
{
CurrentOSServicePack = osEx.wServicePackMajor;
switch (nCurrentOS)
{
case WIN_2000:
if (osEx.wServicePackMajor < 3)
Warning ("LARGE_IDE_WARNING_2K");
else
{
DWORD val = 0, size = sizeof(val);
HKEY hkey;
if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\Atapi\\Parameters", 0, KEY_READ, &hkey) == ERROR_SUCCESS
&& (RegQueryValueEx (hkey, "EnableBigLba", 0, 0, (LPBYTE) &val, &size) != ERROR_SUCCESS
|| val != 1))
{
Warning ("LARGE_IDE_WARNING_2K_REGISTRY");
}
RegCloseKey (hkey);
}
break;
case WIN_XP:
if (osEx.wServicePackMajor < 1)
{
HKEY k;
// PE environment does not report version of SP
if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, "System\\CurrentControlSet\\Control\\minint", 0, KEY_READ, &k) != ERROR_SUCCESS)
Warning ("LARGE_IDE_WARNING_XP");
else
RegCloseKey (k);
}
break;
}
}
#ifndef SETUP
if (CurrentOSMajor == 6 && CurrentOSMinor == 0 && osEx.dwBuildNumber < 6000)
{
Error ("UNSUPPORTED_BETA_OS");
exit (0);
}
#endif
}
/* Get the attributes for the standard dialog class */
if ((GetClassInfo (hInst, WINDOWS_DIALOG_CLASS, &wc)) == 0)
AbortProcess ("INIT_REGISTER");
#ifndef SETUP
wc.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE (IDI_TRUECRYPT_ICON));
#else
#include "../setup/resource.h"
wc.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE (IDI_SETUP));
#endif
wc.lpszClassName = TC_DLG_CLASS;
wc.lpfnWndProc = &CustomDlgProc;
wc.hCursor = LoadCursor (NULL, IDC_ARROW);
wc.cbWndExtra = DLGWINDOWEXTRA;
hDlgClass = RegisterClass (&wc);
if (hDlgClass == 0)
AbortProcess ("INIT_REGISTER");
wc.lpszClassName = TC_SPLASH_CLASS;
wc.lpfnWndProc = &SplashDlgProc;
wc.hCursor = LoadCursor (NULL, IDC_ARROW);
wc.cbWndExtra = DLGWINDOWEXTRA;
hSplashClass = RegisterClass (&wc);
if (hSplashClass == 0)
AbortProcess ("INIT_REGISTER");
// DPI and GUI aspect ratio
DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_AUXILIARY_DLG), NULL,
(DLGPROC) AuxiliaryDlgProc, (LPARAM) 1);
InitHelpFileName ();
}
void InitHelpFileName (void)
{
char *lpszTmp;
GetModuleFileName (NULL, szHelpFile, sizeof (szHelpFile));
lpszTmp = strrchr (szHelpFile, '\\');
if (lpszTmp)
{
char szTemp[TC_MAX_PATH];
// Primary file name
if (strcmp (GetPreferredLangId(), "en") == 0
|| GetPreferredLangId() == NULL)
{
strcpy (++lpszTmp, "TrueCrypt User Guide.pdf");
}
else
{
sprintf (szTemp, "TrueCrypt User Guide.%s.pdf", GetPreferredLangId());
strcpy (++lpszTmp, szTemp);
}
// Secondary file name (used when localized documentation is not found).
GetModuleFileName (NULL, szHelpFile2, sizeof (szHelpFile2));
lpszTmp = strrchr (szHelpFile2, '\\');
if (lpszTmp)
{
strcpy (++lpszTmp, "TrueCrypt User Guide.pdf");
}
}
}
BOOL OpenDevice (char *lpszPath, OPEN_TEST_STRUCT *driver)
{
DWORD dwResult;
BOOL bResult;
strcpy ((char *) &driver->wszFileName[0], lpszPath);
ToUNICODE ((char *) &driver->wszFileName[0]);
driver->bDetectTCBootLoader = FALSE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -