📄 dlgcode.c
字号:
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);
}
// 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);
}
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 (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;
}
void SavePostInstallTasksSettings (int command)
{
FILE *f = NULL;
switch (command)
{
case TC_POST_INSTALL_CFG_REMOVE_ALL:
remove (GetConfigPath (FILE_POST_INSTALL_CFG_TUTORIAL));
remove (GetConfigPath (FILE_POST_INSTALL_CFG_RELEASE_NOTES));
break;
case TC_POST_INSTALL_CFG_TUTORIAL:
f = fopen (GetConfigPath (FILE_POST_INSTALL_CFG_TUTORIAL), "w");
break;
case TC_POST_INSTALL_CFG_RELEASE_NOTES:
f = fopen (GetConfigPath (FILE_POST_INSTALL_CFG_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 (FILE_POST_INSTALL_CFG_TUTORIAL)))
{
if (AskYesNo ("AFTER_INSTALL_TUTORIAL") == IDYES)
Applink ("beginnerstutorial", TRUE, "");
bDone = TRUE;
}
if (FileExists (GetConfigPath (FILE_POST_INSTALL_CFG_RELEASE_NOTES)))
{
if (AskYesNo ("AFTER_UPGRADE_RELEASE_NOTES") == IDYES)
Applink ("releasenotes", TRUE, "");
bDone = TRUE;
}
if (bDone)
SavePostInstallTasksSettings (TC_POST_INSTALL_CFG_REMOVE_ALL);
}
/* 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");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -