⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 setup.c

📁 一个提供档案及Partition作加解密的程式支援以下的加密演算法AESBlowfishCAST5SerpentTriple DESTwofishAES-BlowfishAES-TwofishAES-
💻 C
📖 第 1 页 / 共 3 页
字号:
/* The source code contained in this file has been derived from the source code
   of Encryption for the Masses 2.02a by Paul Le Roux. Modifications and
   additions to that source code contained in this file are Copyright (c) 2004-2005
   TrueCrypt Foundation and Copyright (c) 2004 TrueCrypt Team. Unmodified
   parts are Copyright (c) 1998-99 Paul Le Roux. This is a TrueCrypt Foundation
   release. Please see the file license.txt for full license details. */

#include "TCdefs.h"
#include <SrRestorePtApi.h>

#define MAX_PASSWORD 

#include "apidrvr.h"
#include "dlgcode.h"
#include "../common/resource.h"

#include "resource.h"

#include "dir.h"
#include "setup.h"

#include <sys\types.h>
#include <sys\stat.h>

#pragma warning( disable : 4201 )
#pragma warning( disable : 4115 )

#include <shlobj.h>

#pragma warning( default : 4201 )
#pragma warning( default : 4115 )

char dlg_file_name[TC_MAX_PATH];
BOOL bUninstall = FALSE;
BOOL bDone = FALSE;

HMODULE SystemRestoreDll = 0;

BOOL
StatDeleteFile (char *lpszFile)
{
	struct __stat64 st;

	if (_stat64 (lpszFile, &st) == 0)
		return DeleteFile (lpszFile);
	else
		return TRUE;
}

BOOL
StatRemoveDirectory (char *lpszDir)
{
	struct __stat64 st;

	if (_stat64 (lpszDir, &st) == 0)
		return RemoveDirectory (lpszDir);
	else
		return TRUE;
}

HRESULT
CreateLink (char *lpszPathObj, char *lpszArguments,
	    char *lpszPathLink)
{
	HRESULT hres;
	IShellLink *psl;

	/* Get a pointer to the IShellLink interface.  */
	hres = CoCreateInstance (&CLSID_ShellLink, NULL,
			       CLSCTX_INPROC_SERVER, &IID_IShellLink, &psl);
	if (SUCCEEDED (hres))
	{
		IPersistFile *ppf;

		/* Set the path to the shortcut target, and add the
		   description.  */
		psl->lpVtbl->SetPath (psl, lpszPathObj);
		psl->lpVtbl->SetArguments (psl, lpszArguments);

		/* Query IShellLink for the IPersistFile interface for saving
		   the shortcut in persistent storage.  */
		hres = psl->lpVtbl->QueryInterface (psl, &IID_IPersistFile,
						    &ppf);

		if (SUCCEEDED (hres))
		{
			WORD wsz[TC_MAX_PATH];

			/* Ensure that the string is ANSI.  */
			MultiByteToWideChar (CP_ACP, 0, lpszPathLink, -1,
					     wsz, TC_MAX_PATH);

			/* Save the link by calling IPersistFile::Save.  */
			hres = ppf->lpVtbl->Save (ppf, wsz, TRUE);
			ppf->lpVtbl->Release (ppf);
		}
		psl->lpVtbl->Release (psl);
	}
	return hres;
}

void
GetProgramPath (HWND hwndDlg, char *path)
{
	ITEMIDLIST *i;
	HRESULT res;

	if (nCurrentOS == WIN_NT && IsDlgButtonChecked (hwndDlg, IDC_ALL_USERS))
        res = SHGetSpecialFolderLocation (hwndDlg, CSIDL_COMMON_PROGRAMS, &i);
	else
        res = SHGetSpecialFolderLocation (hwndDlg, CSIDL_PROGRAMS, &i);

	SHGetPathFromIDList (i, path);
}


void
StatusMessage (HWND hwndDlg, char *head, char *txt)
{
	char szTmp[TC_MAX_PATH];
	sprintf (szTmp, head, txt);
	SendMessage (GetDlgItem (hwndDlg, IDC_FILES), LB_ADDSTRING, 0, (LPARAM) szTmp);
		
	SendDlgItemMessage (hwndDlg, IDC_FILES, LB_SETTOPINDEX, 
		SendDlgItemMessage (hwndDlg, IDC_FILES, LB_GETCOUNT, 0, 0) - 1, 0);
}

void
RegMessage (HWND hwndDlg, char *txt)
{
	StatusMessage (hwndDlg, "Adding registry entry %s", txt);
}

void
CopyMessage (HWND hwndDlg, char *txt)
{
	StatusMessage (hwndDlg, "Copying %s", txt);
}

void
RemoveMessage (HWND hwndDlg, char *txt)
{
	StatusMessage (hwndDlg, "Removing %s", txt);
}

void
ServiceMessage (HWND hwndDlg, char *txt)
{
	StatusMessage (hwndDlg, "Service %s", txt);
}

void
IconMessage (HWND hwndDlg, char *txt)
{
	StatusMessage (hwndDlg, "Adding icon %s", txt);
}


void
LoadLicense (HWND hwndDlg)
{
	FILE *fp;

	fp = fopen ("Setup Files\\License.txt", "rb");

	if (fp == NULL)
		return;
	else
	{
		long x;

		fseek (fp, 0, SEEK_END);
		x = ftell (fp);
		rewind (fp);

		if (x > 0)
		{
			char *tmp = malloc (x + 1);
			long z;

			if (tmp == NULL)
				goto exit;
			z = (long) fread (tmp, 1, x, fp);
			if (z != x)
			{
				free (tmp);
				goto exit;
			}
			else
			{
//				int i;
				tmp[x] = 0;

				//// Remove single CRLFs
				//for (i = 0; i < x - 3; i++)
				//{
				//	if (tmp[i] == 0xd && tmp[i+2] == 0xd)
				//		i += 4;

				//	if (tmp[i] == 0xd && tmp[i+2] != 0xd)
				//	{
				//		tmp[i] = tmp[i+1] = ' ';
				//	}
				//}

				SendMessage (GetDlgItem (hwndDlg, IDC_LICENSE), WM_SETFONT, (WPARAM) hFixedFont, (LPARAM) 0);
				SetWindowText (GetDlgItem (hwndDlg, IDC_LICENSE), tmp);

				free (tmp);
			}
		}
	}

      exit:
	fclose (fp);
}

BOOL
DoFilesInstall (HWND hwndDlg, char *szDestDir, BOOL bUninstallSupport)
{
	char *szFiles[]=
	{
		"ATrueCrypt.exe", "ATrueCrypt Format.exe",
		"ALicense.txt", "ATrueCrypt User Guide.pdf",
		"WTrueCrypt Setup.exe", "Dtruecrypt.sys"
	};

	char szTmp[TC_MAX_PATH];
	BOOL bOK = TRUE;
	int i;

	if (bUninstall == TRUE)
		bUninstallSupport = FALSE;

	for (i = 0; i < sizeof (szFiles) / sizeof (szFiles[0]); i++)
	{
		BOOL bResult, bSlash;
		char szDir[TC_MAX_PATH];
		int x;

		if (bUninstallSupport == FALSE && strstr (szFiles[i], "TrueCrypt Setup") != 0)
			continue;

		if (*szFiles[i] == 'A')
			strcpy (szDir, szDestDir);
		else if (*szFiles[i] == 'S')
			GetSystemDirectory (szDir, sizeof (szDir));
		else if (*szFiles[i] == 'I')
		{
			GetSystemDirectory (szDir, sizeof (szDir));

			x = strlen (szDestDir);
			if (szDestDir[x - 1] == '\\')
				bSlash = TRUE;
			else
				bSlash = FALSE;

			if (bSlash == FALSE)
				strcat (szDir, "\\");

			strcat (szDir, "IOSUBSYS");
		}
		else if (*szFiles[i] == 'D')
		{
			GetSystemDirectory (szDir, sizeof (szDir));

			x = strlen (szDestDir);
			if (szDestDir[x - 1] == '\\')
				bSlash = TRUE;
			else
				bSlash = FALSE;

			if (bSlash == FALSE)
				strcat (szDir, "\\");

			strcat (szDir, "Drivers");
		}
		else if (*szFiles[i] == 'W')
			GetWindowsDirectory (szDir, sizeof (szDir));

		x = strlen (szDestDir);
		if (szDestDir[x - 1] == '\\')
			bSlash = TRUE;
		else
			bSlash = FALSE;

		if (bSlash == FALSE)
			strcat (szDir, "\\");

		if ((*szFiles[i] == 'D' || *szFiles[i] == 'S') && nCurrentOS != WIN_NT)
			continue;

		if (*szFiles[i] == 'I' && nCurrentOS == WIN_NT)
			continue;

		sprintf (szTmp, "%s%s", szDir, szFiles[i] + 1);

		if (bUninstall == FALSE)
			CopyMessage (hwndDlg, szTmp);
		else
			RemoveMessage (hwndDlg, szTmp);

		if (bUninstall == FALSE)
		{
			bResult = TCCopyFile (szFiles[i] + 1, szTmp);
			if (!bResult)
			{
				char s[256];
				sprintf (s, "Setup Files\\%s", szFiles[i] + 1);
				bResult = TCCopyFile (s, szTmp);
			}
		}
		else
		{
			bResult = StatDeleteFile (szTmp);
		}

		if (bResult == FALSE)
		{
			LPVOID lpMsgBuf;
			DWORD dwError = GetLastError ();
			char szTmp2[700];

			FormatMessage (
					      FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
					      NULL,
					      dwError,
				 MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),	/* Default language */
					      (char *) &lpMsgBuf,
					      0,
					      NULL
				);


			if (bUninstall == FALSE)
				sprintf (szTmp2, "Installation of '%s' has failed.\n%s\nDo you want to continue installing?",
					 szTmp, lpMsgBuf);
			else
				sprintf (szTmp2, "Uninstallation of '%s' has failed.\n%s\nDo you want to continue uninstalling?",
					 szTmp, lpMsgBuf);

			LocalFree (lpMsgBuf);

			if (MessageBox (hwndDlg, szTmp2, lpszTitle, MB_YESNO | MB_ICONHAND) != IDYES)
				return FALSE;
		}

	}

	return bOK;
}

BOOL
DoRegInstall (HWND hwndDlg, char *szDestDir, BOOL bInstallType, BOOL bUninstallSupport)
{
	char szDir[TC_MAX_PATH], *key;
	HKEY hkey = 0;
	BOOL bSlash, bOK = FALSE;
	DWORD dw;
	int x;

	strcpy (szDir, szDestDir);
	x = strlen (szDestDir);
	if (szDestDir[x - 1] == '\\')
		bSlash = TRUE;
	else
		bSlash = FALSE;

	if (bSlash == FALSE)
		strcat (szDir, "\\");

	if (nCurrentOS == WIN_NT)
	{
		/* 9/9/99 FIX This code should no longer be needed as we use
		   the "services" api to install the driver now, rather than
		   setting the registry by hand */

		/* Install device driver */
		key = "SYSTEM\\CurrentControlSet\\Services\\truecrypt";
		RegMessage (hwndDlg, key);
		if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
				    key,
				    0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
			goto error;

		dw = 1;
		if (RegSetValueEx (hkey, "Type", 0, REG_DWORD, (BYTE *) & dw, 4) != ERROR_SUCCESS)
			goto error;

		dw = 1;
		if (RegSetValueEx (hkey, "Start", 0, REG_DWORD, (BYTE *) & dw, 4) != ERROR_SUCCESS)
			goto error;

		dw = 1;
		if (RegSetValueEx (hkey, "ErrorControl", 0, REG_DWORD, (BYTE *) & dw, 4) != ERROR_SUCCESS)
			goto error;

		if (RegSetValueEx (hkey, "Group", 0, REG_SZ, (BYTE *) "Primary disk", 13) != ERROR_SUCCESS)
			goto error;

		RegCloseKey (hkey);
		hkey = 0;
	}

	if (bInstallType == TRUE)
	{
		char szTmp[TC_MAX_PATH];

		key = "SOFTWARE\\Classes\\TrueCryptVolume";
		RegMessage (hwndDlg, key);
		if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
				    key,
				    0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
			goto error;

		sprintf (szTmp, "TrueCrypt Volume", szDir);
		if (RegSetValueEx (hkey, "", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
			goto error;

		RegCloseKey (hkey);
		hkey = 0;

		key = "SOFTWARE\\Classes\\TrueCryptVolume\\DefaultIcon";
		RegMessage (hwndDlg, key);
		if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
				    key,
				    0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
			goto error;

		sprintf (szTmp, "%sTrueCrypt.exe,1", szDir);
		if (RegSetValueEx (hkey, "", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
			goto error;

		RegCloseKey (hkey);
		hkey = 0;

		key = "SOFTWARE\\Classes\\TrueCryptVolume\\Shell\\open\\command";
		RegMessage (hwndDlg, key);
		if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
				    key,
				    0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
			goto error;

		sprintf (szTmp, "\"%sTrueCrypt.exe\" /v \"%%1\"", szDir );
		if (RegSetValueEx (hkey, "", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
			goto error;

		RegCloseKey (hkey);
		hkey = 0;

		key = "SOFTWARE\\Classes\\.tc";
		RegMessage (hwndDlg, key);
		if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
				    key,
				    0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
			goto error;

		strcpy (szTmp, "TrueCryptVolume");
		if (RegSetValueEx (hkey, "", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
			goto error;
	}


	if (bUninstallSupport == TRUE)
	{
		char szTmp[TC_MAX_PATH];

		key = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\TrueCrypt";
		RegMessage (hwndDlg, key);
		if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
				    key,
				    0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -