diff options
Diffstat (limited to 'src/Setup/Setup.c')
-rw-r--r-- | src/Setup/Setup.c | 738 |
1 files changed, 483 insertions, 255 deletions
diff --git a/src/Setup/Setup.c b/src/Setup/Setup.c index a1f27f41..6edc0ea9 100644 --- a/src/Setup/Setup.c +++ b/src/Setup/Setup.c @@ -1,4 +1,4 @@ -/* +/* Legal Notice: Some portions of the source code contained in this file were derived from the source code of TrueCrypt 7.1a, which is Copyright (c) 2003-2012 TrueCrypt Developers Association and which is @@ -74,14 +74,20 @@ BOOL UnloadDriver = TRUE; BOOL bSystemRestore = TRUE; BOOL bDisableSwapFiles = FALSE; BOOL bForAllUsers = TRUE; +BOOL bDisableMemoryProtection = FALSE; +BOOL bOriginalDisableMemoryProtection = FALSE; BOOL bRegisterFileExt = TRUE; BOOL bAddToStartMenu = TRUE; BOOL bDesktopIcon = TRUE; +BOOL bUserSetLanguage = FALSE; + BOOL bDesktopIconStatusDetermined = FALSE; HMODULE volatile SystemRestoreDll = 0; +extern HMODULE hcrypt32dll; + void localcleanup (void) { localcleanupwiz (); @@ -90,6 +96,102 @@ void localcleanup (void) CloseAppSetupMutex (); } +#define WAIT_PERIOD 3 + +BOOL StartStopService (HWND hwndDlg, wchar_t *lpszService, BOOL bStart, DWORD argc, LPCWSTR* argv) +{ + SC_HANDLE hManager, hService = NULL; + BOOL bOK = FALSE, bRet; + SERVICE_STATUS status = {0}; + int x; + DWORD dwExpectedState = bStart? SERVICE_RUNNING : SERVICE_STOPPED; + + hManager = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS); + if (hManager == NULL) + goto error; + + hService = OpenService (hManager, lpszService, SERVICE_ALL_ACCESS); + if (hService == NULL) + goto error; + + if (bStart) + StatusMessageParam (hwndDlg, "STARTING", lpszService); + else + StatusMessageParam (hwndDlg, "STOPPING", lpszService); + + if (bStart) + { + if (!StartService (hService, argc, argv) && (GetLastError () != ERROR_SERVICE_ALREADY_RUNNING)) + goto error; + } + else + ControlService (hService, SERVICE_CONTROL_STOP, &status); + + for (x = 0; x < WAIT_PERIOD; x++) + { + bRet = QueryServiceStatus (hService, &status); + if (bRet != TRUE) + goto error; + + if (status.dwCurrentState == dwExpectedState) + break; + + Sleep (1000); + } + + bRet = QueryServiceStatus (hService, &status); + if (bRet != TRUE) + goto error; + + if (status.dwCurrentState != dwExpectedState) + goto error; + + bOK = TRUE; + +error: + + if (bOK == FALSE && GetLastError () == ERROR_SERVICE_DOES_NOT_EXIST) + { + bOK = TRUE; + } + + if (hService != NULL) + CloseServiceHandle (hService); + + if (hManager != NULL) + CloseServiceHandle (hManager); + + return bOK; +} + +BOOL ForceCopyFile (LPCWSTR szSrcFile, LPCWSTR szDestFile) +{ + BOOL bRet = CopyFileW (szSrcFile, szDestFile, FALSE); + if (!bRet) + { + wstring renamedPath = szDestFile; + renamedPath += VC_FILENAME_RENAMED_SUFFIX; + + /* rename the locked file in order to be able to create a new one */ + if (MoveFileExW (szDestFile, renamedPath.c_str(), MOVEFILE_REPLACE_EXISTING)) + { + bRet = CopyFileW (szSrcFile, szDestFile, FALSE); + if (bRet) + { + /* delete the renamed file when the machine reboots */ + MoveFileEx (renamedPath.c_str(), NULL, MOVEFILE_DELAY_UNTIL_REBOOT); + } + else + { + /* restore the original file name */ + MoveFileEx (renamedPath.c_str(), szDestFile, MOVEFILE_REPLACE_EXISTING); + } + } + } + + return bRet; +} + BOOL ForceDeleteFile (LPCWSTR szFileName) { if (!DeleteFile (szFileName)) @@ -387,44 +489,6 @@ void SearchAndDeleteRegistrySubString (HKEY hKey, const wchar_t *subKey, const w } } -/* Set the given privilege of the current process */ -BOOL SetPrivilege(LPTSTR szPrivilegeName, BOOL bEnable) -{ - TOKEN_PRIVILEGES tp; - LUID luid; - HANDLE hProcessToken; - BOOL bStatus = FALSE; - - if ( OpenProcessToken(GetCurrentProcess(), - TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, - &hProcessToken) ) - { - if ( LookupPrivilegeValue( - NULL, - szPrivilegeName, - &luid ) ) - { - - tp.PrivilegeCount = 1; - tp.Privileges[0].Luid = luid; - tp.Privileges[0].Attributes = bEnable? SE_PRIVILEGE_ENABLED : SE_PRIVILEGE_REMOVED; - - // Enable the privilege - bStatus = AdjustTokenPrivileges( - hProcessToken, - FALSE, - &tp, - sizeof(TOKEN_PRIVILEGES), - (PTOKEN_PRIVILEGES) NULL, - (PDWORD) NULL); - } - - CloseHandle(hProcessToken); - } - - return bStatus; -} - /* * Creates a VT_LPWSTR propvariant. * we use our own implementation to use SHStrDupW function pointer @@ -508,26 +572,13 @@ BOOL IsSystemRestoreEnabled () GetRestorePointRegKeyName (szRegPath, sizeof (szRegPath)); if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, szRegPath, 0, KEY_READ | KEY_WOW64_64KEY, &hKey) == ERROR_SUCCESS) { - if (IsOSAtLeast (WIN_VISTA)) - { - if ( (ERROR_SUCCESS == RegQueryValueEx (hKey, L"RPSessionInterval", NULL, NULL, (LPBYTE) &dwValue, &cbValue)) - && (dwValue == 1) - ) - { - bEnabled = TRUE; - } - } - else + if ( (ERROR_SUCCESS == RegQueryValueEx (hKey, L"RPSessionInterval", NULL, NULL, (LPBYTE) &dwValue, &cbValue)) + && (dwValue == 1) + ) { - if ( (ERROR_SUCCESS == RegQueryValueEx (hKey, L"DisableSR", NULL, NULL, (LPBYTE) &dwValue, &cbValue)) - && (dwValue == 0) - ) - { - bEnabled = TRUE; - } + bEnabled = TRUE; } - RegCloseKey (hKey); } @@ -598,6 +649,53 @@ void IconMessage (HWND hwndDlg, const wchar_t *txt) StatusMessageParam (hwndDlg, "ADDING_ICON", txt); } +#ifdef VC_EFI_CUSTOM_MODE +BOOL CheckSecureBootCompatibility (HWND hWnd) +{ + BOOL bRet = FALSE; + BOOL bDriverAttached = FALSE; + if (hDriver == INVALID_HANDLE_VALUE) + { + int status = DriverAttach(); + if (status || (hDriver == INVALID_HANDLE_VALUE)) + return FALSE; + bDriverAttached = TRUE; + } + + try + { + BootEncryption bootEnc (hWnd); + if (bootEnc.GetDriverServiceStartType() == SERVICE_BOOT_START) + { + SystemDriveConfiguration config = bootEnc.GetSystemDriveConfiguration (); + if (config.SystemPartition.IsGPT) + { + BOOL bSecureBootEnabled = FALSE, bVeraCryptKeysLoaded = FALSE; + bootEnc.GetSecureBootConfig (&bSecureBootEnabled, &bVeraCryptKeysLoaded); + if (!bSecureBootEnabled || bVeraCryptKeysLoaded) + { + bRet = TRUE; + } + } + else + bRet = TRUE; + } + else + bRet = TRUE; + } + catch (...) + { + } + + if (bDriverAttached) + { + CloseHandle (hDriver); + hDriver = INVALID_HANDLE_VALUE; + } + return bRet; +} +#endif + void DetermineUpgradeDowngradeStatus (BOOL bCloseDriverHandle, LONG *driverVersionPtr) { LONG driverVersion = VERSION_NUM; @@ -611,10 +709,6 @@ void DetermineUpgradeDowngradeStatus (BOOL bCloseDriverHandle, LONG *driverVersi DWORD dwResult; BOOL bResult = DeviceIoControl (hDriver, TC_IOCTL_GET_DRIVER_VERSION, NULL, 0, &driverVersion, sizeof (driverVersion), &dwResult, NULL); - if (!bResult) - bResult = DeviceIoControl (hDriver, TC_IOCTL_LEGACY_GET_DRIVER_VERSION, NULL, 0, &driverVersion, sizeof (driverVersion), &dwResult, NULL); - - bUpgrade = (bResult && driverVersion <= VERSION_NUM); bDowngrade = (bResult && driverVersion > VERSION_NUM); bReinstallMode = (bResult && driverVersion == VERSION_NUM); @@ -631,6 +725,24 @@ void DetermineUpgradeDowngradeStatus (BOOL bCloseDriverHandle, LONG *driverVersi *driverVersionPtr = driverVersion; } +BOOL isMsiInstalled () +{ + BOOL bRet = FALSE; + HKEY hKey; + if (ERROR_SUCCESS == RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\VeraCrypt_MSI", 0, KEY_READ | KEY_WOW64_64KEY, &hKey)) + { + DWORD dwType = 0; + if ( (ERROR_SUCCESS == RegQueryValueExW(hKey, L"ProductGuid", NULL, &dwType, NULL, NULL)) + && (REG_SZ == dwType)) + { + bRet = TRUE; + } + RegCloseKey(hKey); + } + + return bRet; +} + static BOOL IsFileInUse (const wstring &filePath) { @@ -660,7 +772,7 @@ BOOL DoFilesInstall (HWND hwndDlg, wchar_t *szDestDir) GetModuleFileName (NULL, szTmp, ARRAYSIZE (szTmp)); - if (!SelfExtractInMemory (szTmp)) + if (!SelfExtractInMemory (szTmp, FALSE)) return FALSE; } @@ -685,18 +797,6 @@ BOOL DoFilesInstall (HWND hwndDlg, wchar_t *szDestDir) continue; // Destination = target } - // skip files that don't apply to the current architecture - if ( (Is64BitOs () && (wcscmp (szFiles[i], L"AVeraCrypt-x64.exe") == 0)) - || (Is64BitOs () && (wcscmp (szFiles[i], L"AVeraCryptExpander-x64.exe") == 0)) - || (Is64BitOs () && (wcscmp (szFiles[i], L"AVeraCrypt Format-x64.exe") == 0)) - || (!Is64BitOs () && (wcscmp (szFiles[i], L"AVeraCrypt-x86.exe") == 0)) - || (!Is64BitOs () && (wcscmp (szFiles[i], L"AVeraCryptExpander-x86.exe") == 0)) - || (!Is64BitOs () && (wcscmp (szFiles[i], L"AVeraCrypt Format-x86.exe") == 0)) - ) - { - continue; - } - if ((*szFiles[i] == L'A') || (*szFiles[i] == L'X')) StringCbCopyW (szDir, sizeof(szDir), szDestDir); else if (*szFiles[i] == L'D') @@ -704,7 +804,8 @@ BOOL DoFilesInstall (HWND hwndDlg, wchar_t *szDestDir) if (Is64BitOs ()) driver64 = TRUE; - GetSystemDirectory (szDir, ARRAYSIZE (szDir)); + if (!GetSystemDirectory (szDir, ARRAYSIZE (szDir))) + StringCbCopyW(szDir, sizeof(szDir), L"C:\\Windows\\System32"); x = wcslen (szDir); if (szDir[x - 1] != L'\\') @@ -754,45 +855,48 @@ BOOL DoFilesInstall (HWND hwndDlg, wchar_t *szDestDir) curFileName [wcslen (szFiles[i]) - 1] = 0; if (Is64BitOs () - && wcscmp (szFiles[i], L"Dveracrypt.sys") == 0) + && ((wcscmp (szFiles[i], L"Dveracrypt.sys") == 0) || (wcscmp (szFiles[i], L"Averacrypt.sys") == 0))) { - StringCbCopyNW (curFileName, sizeof(curFileName), FILENAME_64BIT_DRIVER, sizeof (FILENAME_64BIT_DRIVER)); + if (IsARM()) + StringCbCopyNW (curFileName, sizeof(curFileName), L"veracrypt-arm64.sys", sizeof(L"veracrypt-arm64.sys")); + else + StringCbCopyNW (curFileName, sizeof(curFileName), FILENAME_64BIT_DRIVER, sizeof (FILENAME_64BIT_DRIVER)); } if (Is64BitOs () - && wcscmp (szFiles[i], L"AVeraCrypt.exe") == 0) + && wcscmp (szFiles[i], L"Averacrypt.cat") == 0) { - StringCbCopyNW (curFileName, sizeof(curFileName), L"VeraCrypt-x64.exe", sizeof (L"VeraCrypt-x64.exe")); + if (IsARM()) + StringCbCopyNW (curFileName, sizeof(curFileName), L"veracrypt-arm64.cat", sizeof(L"veracrypt-arm64.cat")); + else + StringCbCopyNW (curFileName, sizeof(curFileName), L"veracrypt-x64.cat", sizeof (L"veracrypt-x64.cat")); } if (Is64BitOs () - && wcscmp (szFiles[i], L"AVeraCrypt-x86.exe") == 0) + && wcscmp (szFiles[i], L"AVeraCrypt.exe") == 0) { - StringCbCopyNW (curFileName, sizeof(curFileName), L"VeraCrypt.exe", sizeof (L"VeraCrypt.exe")); + if (IsARM()) + StringCbCopyNW (curFileName, sizeof(curFileName), L"VeraCrypt-arm64.exe", sizeof(L"VeraCrypt-arm64.exe")); + else + StringCbCopyNW (curFileName, sizeof(curFileName), L"VeraCrypt-x64.exe", sizeof (L"VeraCrypt-x64.exe")); } if (Is64BitOs () && wcscmp (szFiles[i], L"AVeraCryptExpander.exe") == 0) { - StringCbCopyNW (curFileName, sizeof(curFileName), L"VeraCryptExpander-x64.exe", sizeof (L"VeraCryptExpander-x64.exe")); - } - - if (Is64BitOs () - && wcscmp (szFiles[i], L"AVeraCryptExpander-x86.exe") == 0) - { - StringCbCopyNW (curFileName, sizeof(curFileName), L"VeraCryptExpander.exe", sizeof (L"VeraCryptExpander.exe")); + if (IsARM()) + StringCbCopyNW (curFileName, sizeof(curFileName), L"VeraCryptExpander-arm64.exe", sizeof(L"VeraCryptExpander-arm64.exe")); + else + StringCbCopyNW (curFileName, sizeof(curFileName), L"VeraCryptExpander-x64.exe", sizeof (L"VeraCryptExpander-x64.exe")); } if (Is64BitOs () && wcscmp (szFiles[i], L"AVeraCrypt Format.exe") == 0) { - StringCbCopyNW (curFileName, sizeof(curFileName), L"VeraCrypt Format-x64.exe", sizeof (L"VeraCrypt Format-x64.exe")); - } - - if (Is64BitOs () - && wcscmp (szFiles[i], L"AVeraCrypt Format-x86.exe") == 0) - { - StringCbCopyNW (curFileName, sizeof(curFileName), L"VeraCrypt Format.exe", sizeof (L"VeraCrypt Format.exe")); + if (IsARM()) + StringCbCopyNW (curFileName, sizeof(curFileName), L"VeraCrypt Format-arm64.exe", sizeof(L"VeraCrypt Format-arm64.exe")); + else + StringCbCopyNW (curFileName, sizeof(curFileName), L"VeraCrypt Format-x64.exe", sizeof (L"VeraCrypt Format-x64.exe")); } if (!bDevm) @@ -874,14 +978,6 @@ BOOL DoFilesInstall (HWND hwndDlg, wchar_t *szDestDir) wstring favoritesFile = GetServiceConfigPath (TC_APPD_FILENAME_SYSTEM_FAVORITE_VOLUMES, false); wstring favoritesLegacyFile = GetServiceConfigPath (TC_APPD_FILENAME_SYSTEM_FAVORITE_VOLUMES, true); - if ( FileExists (servicePath.c_str()) - || (Is64BitOs () && FileExists (serviceLegacyPath.c_str())) - ) - { - CopyMessage (hwndDlg, (wchar_t *) servicePath.c_str()); - bResult = CopyFile (szTmp, servicePath.c_str(), FALSE); - } - if (bResult && Is64BitOs () && FileExists (favoritesLegacyFile.c_str()) && !FileExists (favoritesFile.c_str())) @@ -890,7 +986,7 @@ BOOL DoFilesInstall (HWND hwndDlg, wchar_t *szDestDir) bResult = CopyFile (favoritesLegacyFile.c_str(), favoritesFile.c_str(), FALSE); } - if (bResult && Is64BitOs () && FileExists (favoritesFile.c_str()) && FileExists (servicePath.c_str())) + if (bResult) { // Update the path of the service BootEncryption BootEncObj (hwndDlg); @@ -899,7 +995,33 @@ BOOL DoFilesInstall (HWND hwndDlg, wchar_t *szDestDir) { if (BootEncObj.GetDriverServiceStartType() == SERVICE_BOOT_START) { + uint32 driverFlags = ReadDriverConfigurationFlags (); + uint32 serviceFlags = BootEncObj.ReadServiceConfigurationFlags (); + BootEncObj.UpdateSystemFavoritesService (); + + CopyMessage (hwndDlg, (wchar_t *) servicePath.c_str()); + + // Tell the service not to update loader on stop + BootEncObj.SetServiceConfigurationFlag (VC_SYSTEM_FAVORITES_SERVICE_CONFIG_DONT_UPDATE_LOADER, true); + + if (StartStopService (hwndDlg, TC_SYSTEM_FAVORITES_SERVICE_NAME, FALSE, 0, NULL)) + { + // we tell the service not to load system favorites on startup + LPCWSTR szArgs[2] = { TC_SYSTEM_FAVORITES_SERVICE_NAME, VC_SYSTEM_FAVORITES_SERVICE_ARG_SKIP_MOUNT}; + if (!CopyFile (szTmp, servicePath.c_str(), FALSE)) + ForceCopyFile (szTmp, servicePath.c_str()); + + StartStopService (hwndDlg, TC_SYSTEM_FAVORITES_SERVICE_NAME, TRUE, 2, szArgs); + } + else + ForceCopyFile (szTmp, servicePath.c_str()); + + BootEncObj.SetDriverConfigurationFlag (driverFlags, true); + + // remove the service flag if it was set originally + if (!(serviceFlags & VC_SYSTEM_FAVORITES_SERVICE_CONFIG_DONT_UPDATE_LOADER)) + BootEncObj.SetServiceConfigurationFlag (VC_SYSTEM_FAVORITES_SERVICE_CONFIG_DONT_UPDATE_LOADER, false); } } catch (...) {} @@ -1051,6 +1173,12 @@ err: FindClose (h); } + + // remvove legacy files that are not needed anymore + for (i = 0; i < sizeof (szLegacyFiles) / sizeof (szLegacyFiles[0]); i++) + { + StatDeleteFile (szLegacyFiles [i], TRUE); + } SetCurrentDirectory (SetupFilesDir); } @@ -1073,7 +1201,7 @@ BOOL DoRegInstall (HWND hwndDlg, wchar_t *szDestDir, BOOL bInstallType) if (RegCreateKeyEx (HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\VeraCrypt", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE | KEY_WOW64_32KEY, NULL, &hkey, &dw) == ERROR_SUCCESS) { - StringCbCopyW (szTmp, sizeof(szTmp), _T(VERSION_STRING)); + StringCbCopyW (szTmp, sizeof(szTmp), _T(VERSION_STRING) _T(VERSION_STRING_SUFFIX)); RegSetValueEx (hkey, L"DisplayVersion", 0, REG_SZ, (BYTE *) szTmp, (wcslen (szTmp) + 1) * sizeof (wchar_t)); StringCbCopyW (szTmp, sizeof(szTmp), TC_HOMEPAGE); @@ -1189,7 +1317,7 @@ BOOL DoRegInstall (HWND hwndDlg, wchar_t *szDestDir, BOOL bInstallType) if (RegSetValueEx (hkey, L"DisplayIcon", 0, REG_SZ, (BYTE *) szTmp, (wcslen (szTmp) + 1) * sizeof (wchar_t)) != ERROR_SUCCESS) goto error; - StringCbCopyW (szTmp, sizeof(szTmp), _T(VERSION_STRING)); + StringCbCopyW (szTmp, sizeof(szTmp), _T(VERSION_STRING) _T(VERSION_STRING_SUFFIX)); if (RegSetValueEx (hkey, L"DisplayVersion", 0, REG_SZ, (BYTE *) szTmp, (wcslen (szTmp) + 1) * sizeof (wchar_t)) != ERROR_SUCCESS) goto error; @@ -1218,13 +1346,10 @@ error: } // Register COM servers for UAC - if (IsOSAtLeast (WIN_VISTA)) + if (!RegisterComServers (szDir)) { - if (!RegisterComServers (szDir)) - { - Error ("COM_REG_FAILED", hwndDlg); - return FALSE; - } + Error ("COM_REG_FAILED", hwndDlg); + return FALSE; } return bOK; @@ -1297,16 +1422,9 @@ BOOL DoApplicationDataUninstall (HWND hwndDlg) BOOL DoRegUninstall (HWND hwndDlg, BOOL bRemoveDeprecated) { wchar_t regk [64]; - typedef LSTATUS (WINAPI *RegDeleteKeyExWFn) (HKEY hKey,LPCWSTR lpSubKey,REGSAM samDesired,WORD Reserved); - RegDeleteKeyExWFn RegDeleteKeyExWPtr = NULL; - HMODULE hAdvapiDll = LoadLibrary (L"Advapi32.dll"); - if (hAdvapiDll) - { - RegDeleteKeyExWPtr = (RegDeleteKeyExWFn) GetProcAddress(hAdvapiDll, "RegDeleteKeyExW"); - } // Unregister COM servers - if (!bRemoveDeprecated && IsOSAtLeast (WIN_VISTA)) + if (!bRemoveDeprecated) { if (!UnregisterComServers (InstallationPath)) StatusMessage (hwndDlg, "COM_DEREG_FAILED"); @@ -1315,16 +1433,9 @@ BOOL DoRegUninstall (HWND hwndDlg, BOOL bRemoveDeprecated) if (!bRemoveDeprecated) StatusMessage (hwndDlg, "REMOVING_REG"); - if (RegDeleteKeyExWPtr) - { - RegDeleteKeyExWPtr (HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\VeraCrypt", KEY_WOW64_32KEY, 0); - RegDeleteKeyExWPtr (HKEY_CURRENT_USER, L"Software\\VeraCrypt", KEY_WOW64_32KEY, 0); - } - else - { - RegDeleteKey (HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\VeraCrypt"); - RegDeleteKey (HKEY_LOCAL_MACHINE, L"Software\\VeraCrypt"); - } + RegDeleteKeyExW (HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\VeraCrypt", KEY_WOW64_32KEY, 0); + RegDeleteKeyExW (HKEY_CURRENT_USER, L"Software\\VeraCrypt", KEY_WOW64_32KEY, 0); + RegDeleteKey (HKEY_LOCAL_MACHINE, L"Software\\Classes\\VeraCryptVolume\\Shell\\open\\command"); RegDeleteKey (HKEY_LOCAL_MACHINE, L"Software\\Classes\\VeraCryptVolume\\Shell\\open"); RegDeleteKey (HKEY_LOCAL_MACHINE, L"Software\\Classes\\VeraCryptVolume\\Shell"); @@ -1363,9 +1474,6 @@ BOOL DoRegUninstall (HWND hwndDlg, BOOL bRemoveDeprecated) SHChangeNotify (SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL); } - if (hAdvapiDll) - FreeLibrary (hAdvapiDll); - return TRUE; } @@ -1409,8 +1517,6 @@ retry: else StatusMessageParam (hwndDlg, "STOPPING", lpszService); -#define WAIT_PERIOD 3 - for (x = 0; x < WAIT_PERIOD; x++) { bRet = QueryServiceStatus (hService, &status); @@ -1586,6 +1692,10 @@ BOOL DoDriverUnload (HWND hwndDlg) if (CurrentOSMajor == 6 && CurrentOSMinor == 0 && CurrentOSServicePack < 1) AbortProcess ("SYS_ENCRYPTION_UPGRADE_UNSUPPORTED_ON_VISTA_SP0"); + // check if we are upgrading a system encrypted with unsupported algorithms + if (bootEnc.IsUsingUnsupportedAlgorithm(driverVersion)) + AbortProcess ("SYS_ENCRYPTION_UPGRADE_UNSUPPORTED_ALGORITHM"); + SystemEncryptionUpdate = TRUE; PortableMode = FALSE; } @@ -1610,13 +1720,6 @@ BOOL DoDriverUnload (HWND hwndDlg) // Check mounted volumes bResult = DeviceIoControl (hDriver, TC_IOCTL_IS_ANY_VOLUME_MOUNTED, NULL, 0, &volumesMounted, sizeof (volumesMounted), &dwResult, NULL); - if (!bResult) - { - bResult = DeviceIoControl (hDriver, TC_IOCTL_LEGACY_GET_MOUNTED_VOLUMES, NULL, 0, &driver, sizeof (driver), &dwResult, NULL); - if (bResult) - volumesMounted = driver.ulMountedDrives; - } - if (bResult) { if (volumesMounted != 0) @@ -1763,11 +1866,6 @@ BOOL DoShortcutsUninstall (HWND hwndDlg, wchar_t *szDestDir) if (StatDeleteFile (szTmp2, FALSE) == FALSE) goto error; - StringCbPrintfW (szTmp2, sizeof(szTmp2), L"%s%s", szLinkDir, L"\\Uninstall VeraCrypt.lnk"); - RemoveMessage (hwndDlg, szTmp2); - if (StatDeleteFile (szTmp2, FALSE) == FALSE) - goto error; - StringCbPrintfW (szTmp2, sizeof(szTmp2), L"%s%s", szLinkDir, L"\\VeraCrypt User's Guide.lnk"); StatDeleteFile (szTmp2, FALSE); @@ -1800,7 +1898,7 @@ error: BOOL DoShortcutsInstall (HWND hwndDlg, wchar_t *szDestDir, BOOL bProgGroup, BOOL bDesktopIcon) { wchar_t szLinkDir[TC_MAX_PATH], szDir[TC_MAX_PATH]; - wchar_t szTmp[TC_MAX_PATH], szTmp2[TC_MAX_PATH], szTmp3[TC_MAX_PATH]; + wchar_t szTmp[TC_MAX_PATH], szTmp2[TC_MAX_PATH]; BOOL bSlash, bOK = FALSE; HRESULT hOle; int x; @@ -1877,18 +1975,8 @@ BOOL DoShortcutsInstall (HWND hwndDlg, wchar_t *szDestDir, BOOL bProgGroup, BOOL else goto error; - StringCbPrintfW (szTmp, sizeof(szTmp), L"%s%s", szDir, L"VeraCrypt Setup.exe"); StringCbPrintfW (szTmp2, sizeof(szTmp2), L"%s%s", szLinkDir, L"\\Uninstall VeraCrypt.lnk"); - if (GetSystemDirectory (szTmp3, ARRAYSIZE(szTmp3))) - { - StringCbCatW (szTmp3, sizeof(szTmp3), L"\\control.exe"); - } - else - StringCbCopyW(szTmp3, sizeof(szTmp3), L"C:\\Windows\\System32\\control.exe"); - - IconMessage (hwndDlg, szTmp2); - if (CreateLink (szTmp3, L"appwiz.cpl", szTmp2, szTmp, 0) != S_OK) - goto error; + StatDeleteFile (szTmp2, FALSE); StringCbPrintfW (szTmp2, sizeof(szTmp2), L"%s%s", szLinkDir, L"\\VeraCrypt User's Guide.lnk"); StatDeleteFile (szTmp2, FALSE); @@ -2119,6 +2207,14 @@ void DoInstall (void *arg) ClearLogWindow (hwndDlg); + if (isMsiInstalled()) + { + MessageBoxW (hwndDlg, GetString ("CANT_INSTALL_WITH_EXE_OVER_MSI"), lpszTitle, MB_ICONHAND); + Error ("INSTALL_FAILED", hwndDlg); + PostMessage (MainDlg, TC_APPMSG_INSTALL_FAILURE, 0, 0); + return; + } + if (mkfulldir (InstallationPath, TRUE) != 0) { if (mkfulldir (InstallationPath, FALSE) != 0) @@ -2147,12 +2243,15 @@ void DoInstall (void *arg) && (IsFileInUse (wstring (InstallationPath) + L'\\' + _T(TC_APP_NAME) L".exe") || IsFileInUse (wstring (InstallationPath) + L'\\' + _T(TC_APP_NAME) L"-x86.exe") || IsFileInUse (wstring (InstallationPath) + L'\\' + _T(TC_APP_NAME) L"-x64.exe") + || IsFileInUse (wstring (InstallationPath) + L'\\' + _T(TC_APP_NAME) L"-arm64.exe") || IsFileInUse (wstring (InstallationPath) + L'\\' + _T(TC_APP_NAME) L" Format.exe") || IsFileInUse (wstring (InstallationPath) + L'\\' + _T(TC_APP_NAME) L" Format-x86.exe") || IsFileInUse (wstring (InstallationPath) + L'\\' + _T(TC_APP_NAME) L" Format-x64.exe") + || IsFileInUse (wstring (InstallationPath) + L'\\' + _T(TC_APP_NAME) L" Format-arm64.exe") || IsFileInUse (wstring (InstallationPath) + L'\\' + _T(TC_APP_NAME) L"Expander.exe") || IsFileInUse (wstring (InstallationPath) + L'\\' + _T(TC_APP_NAME) L"Expander-x86.exe") || IsFileInUse (wstring (InstallationPath) + L'\\' + _T(TC_APP_NAME) L"Expander-x64.exe") + || IsFileInUse (wstring (InstallationPath) + L'\\' + _T(TC_APP_NAME) L"Expander-arm64.exe") || IsFileInUse (wstring (InstallationPath) + L'\\' + _T(TC_APP_NAME) L" Setup.exe") ) ) @@ -2238,6 +2337,12 @@ void DoInstall (void *arg) if (bSystemRestore) SetSystemRestorePoint (hwndDlg, TRUE); + if (bOK && (bDisableMemoryProtection != bOriginalDisableMemoryProtection)) + { + WriteMemoryProtectionConfig(bDisableMemoryProtection? FALSE : TRUE); + bRestartRequired = TRUE; // Restart is required to apply the new memory protection settings + } + if (bOK) { UpdateProgressBarProc(100); @@ -2272,6 +2377,15 @@ void DoInstall (void *arg) if (bOK && !bUninstall && !bDowngrade && !bRepairMode && !bDevm) { + BOOL bHibernateEnabled = FALSE, bHiberbootEnabled = FALSE; + if (GetHibernateStatus (bHibernateEnabled, bHiberbootEnabled)) + { + if (bHiberbootEnabled) + { + bPromptFastStartup = TRUE; + } + } + if (!IsHiddenOSRunning()) // A hidden OS user should not see the post-install notes twice (on decoy OS and then on hidden OS). { if (bRestartRequired || SystemEncryptionUpdate) @@ -2313,45 +2427,9 @@ void DoInstall (void *arg) void SetInstallationPath (HWND hwndDlg) { - HKEY hkey; BOOL bInstallPathDetermined = FALSE; - wchar_t path[MAX_PATH+20]; - ITEMIDLIST *itemList; - - memset (InstallationPath, 0, sizeof (InstallationPath)); - - // Determine if VeraCrypt is already installed and try to determine its "Program Files" location - if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\VeraCrypt", 0, KEY_READ | KEY_WOW64_32KEY, &hkey) == ERROR_SUCCESS) - { - /* Default 'UninstallString' registry strings written by VeraCrypt: - ------------------------------------------------------------------------------------ - 5.0+ "C:\Program Files\VeraCrypt\VeraCrypt Setup.exe" /u - */ - - wchar_t rv[MAX_PATH*4]; - DWORD size = sizeof (rv); - if (RegQueryValueEx (hkey, L"UninstallString", 0, 0, (LPBYTE) &rv, &size) == ERROR_SUCCESS && wcsrchr (rv, L'/')) - { - size_t len = 0; - - // Cut and paste the location (path) where VeraCrypt is installed to InstallationPath - if (rv[0] == L'"') - { - len = wcsrchr (rv, L'/') - rv - 2; - StringCchCopyNW (InstallationPath, ARRAYSIZE(InstallationPath), rv + 1, len); - InstallationPath [len] = 0; - bInstallPathDetermined = TRUE; - - if (InstallationPath [wcslen (InstallationPath) - 1] != L'\\') - { - len = wcsrchr (InstallationPath, L'\\') - InstallationPath; - InstallationPath [len] = 0; - } - } - - } - RegCloseKey (hkey); - } + + GetInstallationPath (hwndDlg, InstallationPath, ARRAYSIZE (InstallationPath), &bInstallPathDetermined); if (bInstallPathDetermined) { @@ -2367,36 +2445,6 @@ void SetInstallationPath (HWND hwndDlg) bChangeMode = TRUE; } } - else - { - /* VeraCrypt is not installed or it wasn't possible to determine where it is installed. */ - - // Default "Program Files" path. - SHGetSpecialFolderLocation (hwndDlg, CSIDL_PROGRAM_FILES, &itemList); - SHGetPathFromIDList (itemList, path); - - if (Is64BitOs()) - { - // Use a unified default installation path (registry redirection of %ProgramFiles% does not work if the installation path is user-selectable) - wstring s = path; - size_t p = s.find (L" (x86)"); - if (p != wstring::npos) - { - s = s.substr (0, p); - if (_waccess (s.c_str(), 0) != -1) - StringCbCopyW (path, sizeof (path), s.c_str()); - } - } - - StringCbCatW (path, sizeof(path), L"\\VeraCrypt\\"); - StringCbCopyW (InstallationPath, sizeof(InstallationPath), path); - } - - // Make sure the path ends with a backslash - if (InstallationPath [wcslen (InstallationPath) - 1] != L'\\') - { - StringCbCatW (InstallationPath, sizeof(InstallationPath), L"\\"); - } } @@ -2496,38 +2544,175 @@ BOOL CALLBACK UninstallDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP } #endif +typedef struct +{ + LPCWSTR name; + int resourceid; + WORD langid; + LPCSTR internalId; + LPCWSTR langtag; +} tLanguageEntry; + +static tLanguageEntry g_languagesEntries[] = { + {L"العربية", IDR_LANG_AR, LANG_ARABIC, "ar", NULL}, + {L"Беларуская", IDR_LANG_BE, LANG_BELARUSIAN, "be", NULL}, + {L"Български", IDR_LANG_BG, LANG_BULGARIAN, "bg", NULL}, + {L"Català", IDR_LANG_CA, LANG_CATALAN, "ca", NULL}, + {L"Corsu", IDR_LANG_CO, LANG_CORSICAN, "co", NULL}, + {L"Čeština", IDR_LANG_CS, LANG_CZECH, "cs", NULL}, + {L"Dansk", IDR_LANG_DA, LANG_DANISH, "da", NULL}, + {L"Deutsch", IDR_LANG_DE, LANG_GERMAN, "de", NULL}, + {L"Ελληνικά", IDR_LANG_EL, LANG_GREEK, "el", NULL}, + {L"English", IDR_LANGUAGE, LANG_ENGLISH, "en", NULL}, + {L"Español", IDR_LANG_ES, LANG_SPANISH, "es", NULL}, + {L"Eesti", IDR_LANG_ET, LANG_ESTONIAN, "et", NULL}, + {L"Euskara", IDR_LANG_EU, LANG_BASQUE, "eu", NULL}, + {L"فارسي", IDR_LANG_FA, LANG_PERSIAN, "fa", NULL}, + {L"Suomi", IDR_LANG_FI, LANG_FINNISH, "fi", NULL}, + {L"Français", IDR_LANG_FR, LANG_FRENCH, "fr", NULL}, + {L"עברית", IDR_LANG_HE, LANG_HEBREW, "he", NULL}, + {L"Magyar", IDR_LANG_HU, LANG_HUNGARIAN, "hu", NULL}, + {L"Bahasa Indonesia", IDR_LANG_ID, LANG_INDONESIAN, "id", NULL}, + {L"Italiano", IDR_LANG_IT, LANG_ITALIAN, "it", NULL}, + {L"日本語", IDR_LANG_JA, LANG_JAPANESE, "ja", NULL}, + {L"ქართული", IDR_LANG_KA, LANG_GEORGIAN, "ka", NULL}, + {L"한국어", IDR_LANG_KO, LANG_KOREAN, "ko", NULL}, + {L"Latviešu", IDR_LANG_LV, LANG_LATVIAN, "lv", NULL}, + {L"Nederlands", IDR_LANG_NL, LANG_DUTCH, "nl", NULL}, + {L"Norsk Nynorsk", IDR_LANG_NN, LANG_NORWEGIAN, "nn", NULL}, + {L"Polski", IDR_LANG_PL, LANG_POLISH, "pl", NULL}, + {L"Română", IDR_LANG_RO, LANG_ROMANIAN, "ro", NULL}, + {L"Русский", IDR_LANG_RU, LANG_RUSSIAN, "ru", NULL}, + {L"Português-Brasil", IDR_LANG_PTBR, LANG_PORTUGUESE, "pt-br", L"pt-BR"}, + {L"Slovenčina", IDR_LANG_SK, LANG_SLOVAK, "sk", NULL}, + {L"Slovenščina", IDR_LANG_SL, LANG_SLOVENIAN, "sl", NULL}, + {L"Svenska", IDR_LANG_SV, LANG_SWEDISH, "sv", NULL}, + {L"ภาษาไทย", IDR_LANG_TH, LANG_THAI, "th", NULL}, + {L"Türkçe", IDR_LANG_TR, LANG_TURKISH, "tr", NULL}, + {L"Українська", IDR_LANG_UK, LANG_UKRAINIAN, "uk", NULL}, + {L"Ўзбекча", IDR_LANG_UZ, LANG_UZBEK, "uz", NULL}, + {L"Tiếng Việt", IDR_LANG_VI, LANG_VIETNAMESE, "vi", NULL}, + {L"简体中文", IDR_LANG_ZHCN, LANG_CHINESE, "zh-cn", L"zh-CN"}, + {L"繁體中文(香港)", IDR_LANG_ZHHK, LANG_CHINESE, "zh-hk", L"zh-HK"}, + {L"繁體中文", IDR_LANG_ZHTW, LANG_CHINESE, "zh-tw", L"zh-TW"}, +}; + +typedef int (WINAPI *LCIDToLocaleNameFn)( + LCID Locale, + LPWSTR lpName, + int cchName, + DWORD dwFlags); + +static void UpdateSelectLanguageDialog (HWND hwndDlg) +{ + HWND hLangList = GetDlgItem (hwndDlg, IDC_LANGUAGES_LIST); + LPARAM nIndex = SendMessage (hLangList, CB_GETCURSEL, 0, 0); + int resourceid = (int) SendMessage (hLangList, CB_GETITEMDATA, nIndex, 0); + BOOL bVal; + + LoadLanguageFromResource (resourceid, TRUE, TRUE); + + bVal = LocalizationActive; + LocalizationActive = TRUE; + LocalizeDialog (hwndDlg, "IDD_INSTL_DLG"); + InvalidateRect (hwndDlg, NULL, FALSE); + LocalizationActive = bVal; +} -int WINAPI wWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, wchar_t *lpszCommandLine, int nCmdShow) +BOOL CALLBACK SelectLanguageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { - atexit (localcleanup); + WORD lw = LOWORD (wParam); - SelfExtractStartupInit(); + switch (uMsg) + { + case WM_INITDIALOG: + { + char* preferredLanguage = GetPreferredLangId (); + if (strlen (preferredLanguage)) + { + // language already selected by user in current install + // use it for the setup + for (size_t i = 0; i < ARRAYSIZE (g_languagesEntries); i++) + { + if (0 == strcmp (preferredLanguage, g_languagesEntries[i].internalId)) + { + LoadLanguageFromResource (g_languagesEntries[i].resourceid, FALSE, TRUE); + break; + } + } + EndDialog (hwndDlg, IDCANCEL); + return FALSE; + } + else + { + // Get the default UI language + LCIDToLocaleNameFn LCIDToLocaleNamePtr = (LCIDToLocaleNameFn) GetProcAddress (GetModuleHandle (L"kernel32.dll"), "LCIDToLocaleName"); + WCHAR langtag[256]; + LANGID defaultLanguage = GetUserDefaultUILanguage (); + WORD langid = (WORD) (defaultLanguage & 0x03FF); // primary language ID -#ifdef PORTABLE - lpszTitle = L"VeraCrypt Portable"; -#else - lpszTitle = L"VeraCrypt Setup"; -#endif - /* Call InitApp to initialize the common code */ - InitApp (hInstance, NULL); + InitDialog (hwndDlg); -#ifndef PORTABLE - if (IsAdmin () != TRUE) - if (MessageBoxW (NULL, GetString ("SETUP_ADMIN"), lpszTitle, MB_YESNO | MB_ICONQUESTION) != IDYES) + LCIDToLocaleNamePtr (MAKELCID (defaultLanguage, 0), langtag, ARRAYSIZE (langtag), 0); // language tag (e.g. "en-US") + int resourceid = IDR_LANGUAGE; + for (size_t i = 0; i < ARRAYSIZE (g_languagesEntries); i++) + { + if (g_languagesEntries[i].langid == langid) + { + if (!g_languagesEntries[i].langtag || (0 == _wcsicmp (g_languagesEntries[i].langtag, langtag))) + { + resourceid = g_languagesEntries[i].resourceid; + break; + } + } + } + + for (size_t i = 0; i < ARRAYSIZE (g_languagesEntries); i++) + { + AddComboPair (GetDlgItem (hwndDlg, IDC_LANGUAGES_LIST), g_languagesEntries[i].name, g_languagesEntries[i].resourceid); + } + + SelectAlgo (GetDlgItem (hwndDlg, IDC_LANGUAGES_LIST), &resourceid); + + UpdateSelectLanguageDialog (hwndDlg); + } + + } + return TRUE; + + case WM_COMMAND: + if (CBN_SELCHANGE == HIWORD (wParam)) { - FinalizeApp (); - exit (1); + UpdateSelectLanguageDialog (hwndDlg); + return 1; } -#endif - /* Setup directory */ - { - wchar_t *s; - GetModuleFileName (NULL, SetupFilesDir, ARRAYSIZE (SetupFilesDir)); - s = wcsrchr (SetupFilesDir, L'\\'); - if (s) - s[1] = 0; + + if (lw == IDOK) + { + bUserSetLanguage = TRUE; + EndDialog (hwndDlg, IDOK); + return 1; + } + + if (lw == IDCANCEL) + { + SetPreferredLangId (""); + EndDialog (hwndDlg, IDCANCEL); + return 1; + } + return 0; } + return 0; +} + + +int WINAPI wWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, wchar_t *lpszCommandLine, int nCmdShow) +{ + atexit (localcleanup); + + SelfExtractStartupInit(); + /* Parse command line arguments */ if (lpszCommandLine[0] == L'/') @@ -2560,22 +2745,57 @@ int WINAPI wWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, wchar_t *lpsz } } +#ifdef PORTABLE + lpszTitle = L"VeraCrypt Portable"; +#else + lpszTitle = L"VeraCrypt Setup"; +#endif + /* Call InitApp to initialize the common code */ + InitApp (hInstance, NULL); + +#ifndef PORTABLE + if (IsAdmin () != TRUE) + if (MessageBoxW (NULL, GetString ("SETUP_ADMIN"), lpszTitle, MB_YESNO | MB_ICONQUESTION) != IDYES) + { + exit (1); + } +#endif + /* Setup directory */ + { + wchar_t *s; + GetModuleFileName (NULL, SetupFilesDir, ARRAYSIZE (SetupFilesDir)); + s = wcsrchr (SetupFilesDir, L'\\'); + if (s) + s[1] = 0; + } + if (bMakePackage) { /* Create self-extracting package */ - MakeSelfExtractingPackage (NULL, SetupFilesDir); + MakeSelfExtractingPackage (NULL, SetupFilesDir, FALSE); } else { #ifndef PORTABLE SetInstallationPath (NULL); #endif - if (!bUninstall) + if (bUninstall) + { + wchar_t path [TC_MAX_PATH]; + + GetModuleFileName (NULL, path, ARRAYSIZE (path)); + if (!VerifyModuleSignature (path)) + { + Error ("DIST_PACKAGE_CORRUPTED", NULL); + exit (1); + } + } + else { if (IsSelfExtractingPackage()) { - if (!VerifyPackageIntegrity()) + if (!VerifySelfPackageIntegrity()) { // Package corrupted exit (1); @@ -2589,7 +2809,6 @@ int WINAPI wWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, wchar_t *lpsz #else MessageBox (NULL, L"Error: This portable installer file does not contain any compressed files.\n\nTo create a self-extracting portable installation package (with embedded compressed files), run:\n\"VeraCrypt Portable.exe\" /p", L"VeraCrypt", MB_ICONERROR | MB_SETFOREGROUND | MB_TOPMOST); #endif - FinalizeApp (); exit (1); } @@ -2610,7 +2829,6 @@ int WINAPI wWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, wchar_t *lpsz bUninstall = TRUE; break; default: - FinalizeApp (); exit (1); } } @@ -2636,6 +2854,17 @@ int WINAPI wWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, wchar_t *lpsz if (!bUninstall) { + if (!bDevm && !LocalizationActive) + { + BOOL bHasPreferredLanguage = (strlen (GetPreferredLangId ()) > 0)? TRUE : FALSE; + if ((IDCANCEL == DialogBoxParamW (hInstance, MAKEINTRESOURCEW (IDD_INSTALL_LANGUAGE), NULL, (DLGPROC) SelectLanguageDialogProc, (LPARAM) 0 )) + && !bHasPreferredLanguage + ) + { + // Language dialog cancelled by user: exit the installer + exit (1); + } + } /* Create the main dialog for install */ DialogBoxParamW (hInstance, MAKEINTRESOURCEW (IDD_INSTL_DLG), NULL, (DLGPROC) MainDialogProc, @@ -2669,6 +2898,5 @@ int WINAPI wWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, wchar_t *lpsz } #endif } - FinalizeApp (); return 0; } |