diff options
Diffstat (limited to 'src/Setup/Setup.c')
-rw-r--r-- | src/Setup/Setup.c | 186 |
1 files changed, 109 insertions, 77 deletions
diff --git a/src/Setup/Setup.c b/src/Setup/Setup.c index fe25a412..4e1812f6 100644 --- a/src/Setup/Setup.c +++ b/src/Setup/Setup.c @@ -4,11 +4,11 @@ Copyright (c) 2003-2012 TrueCrypt Developers Association and which is governed by the TrueCrypt License 3.0, also from the source code of Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux and which is governed by the 'License Agreement for Encryption for the Masses' Modifications and additions to the original source code (contained in this file) - and all other portions of this file are Copyright (c) 2013-2017 IDRIX + and all other portions of this file are Copyright (c) 2013-2025 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ #include "Tcdefs.h" @@ -763,10 +763,13 @@ BOOL DoFilesInstall (HWND hwndDlg, wchar_t *szDestDir) wchar_t szTmp[TC_MAX_PATH]; BOOL bOK = TRUE; int i, x, fileNo; wchar_t curFileName [TC_MAX_PATH] = {0}; +#ifndef PORTABLE + PRIVILEGE_STATE originalPrivileges = { 0 }; +#endif if (!bUninstall && !bDevm) { // Self-extract all files to memory @@ -781,13 +784,17 @@ BOOL DoFilesInstall (HWND hwndDlg, wchar_t *szDestDir) return FALSE; if (szDestDir[x - 1] != L'\\') StringCbCatW (szDestDir, MAX_PATH, L"\\"); +#ifndef PORTABLE + EnableRequiredSetupPrivileges(&originalPrivileges); +#endif + for (i = 0; i < sizeof (szFiles) / sizeof (szFiles[0]); i++) { - BOOL bResult, driver64 = FALSE, zipFile = FALSE; + BOOL bResult, zipFile = FALSE; wchar_t szDir[TC_MAX_PATH]; if (wcsstr (szFiles[i], L"VeraCrypt Setup") != 0) { if (bUninstall) @@ -799,24 +806,24 @@ BOOL DoFilesInstall (HWND hwndDlg, wchar_t *szDestDir) if ((*szFiles[i] == L'A') || (*szFiles[i] == L'X')) StringCbCopyW (szDir, sizeof(szDir), szDestDir); else if (*szFiles[i] == L'D') { - if (Is64BitOs ()) - driver64 = TRUE; - if (!GetSystemDirectory (szDir, ARRAYSIZE (szDir))) StringCbCopyW(szDir, sizeof(szDir), L"C:\\Windows\\System32"); x = wcslen (szDir); if (szDir[x - 1] != L'\\') StringCbCatW (szDir, sizeof(szDir), L"\\"); StringCbCatW (szDir, sizeof(szDir), L"Drivers\\"); } else if (*szFiles[i] == L'W') - GetWindowsDirectory (szDir, ARRAYSIZE (szDir)); + { + if (!GetWindowsDirectory(szDir, ARRAYSIZE(szDir))) + StringCbCopyW(szDir, sizeof(szDir), L"C:\\Windows"); + } if (*szFiles[i] == L'I') continue; if (*szFiles[i] == L'X') @@ -852,48 +859,43 @@ BOOL DoFilesInstall (HWND hwndDlg, wchar_t *szDestDir) else { StringCchCopyNW (curFileName, ARRAYSIZE(curFileName), szFiles[i] + 1, wcslen (szFiles[i]) - 1); curFileName [wcslen (szFiles[i]) - 1] = 0; - if (Is64BitOs () - && ((wcscmp (szFiles[i], L"Dveracrypt.sys") == 0) || (wcscmp (szFiles[i], L"Averacrypt.sys") == 0))) + if ((wcscmp (szFiles[i], L"Dveracrypt.sys") == 0) || (wcscmp (szFiles[i], L"Averacrypt.sys") == 0)) { 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)); + StringCbCopyNW (curFileName, sizeof(curFileName), L"veracrypt-x64.sys", sizeof(L"veracrypt-x64.sys")); } - if (Is64BitOs () - && wcscmp (szFiles[i], L"Averacrypt.cat") == 0) + if (wcscmp (szFiles[i], L"Averacrypt.cat") == 0) { 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.exe") == 0) + if (wcscmp (szFiles[i], L"AVeraCrypt.exe") == 0) { 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) + if (wcscmp (szFiles[i], L"AVeraCryptExpander.exe") == 0) { 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) + if (wcscmp (szFiles[i], L"AVeraCrypt Format.exe") == 0) { 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")); @@ -912,11 +914,11 @@ BOOL DoFilesInstall (HWND hwndDlg, wchar_t *szDestDir) curFileName, Decompressed_Files[fileNo].fileName, min (wcslen (curFileName), (size_t) Decompressed_Files[fileNo].fileNameLength)) == 0) { // Dump filter driver cannot be installed to SysWOW64 directory - if (driver64 && !EnableWow64FsRedirection (FALSE)) + if (!EnableWow64FsRedirection (FALSE)) { handleWin32Error (hwndDlg, SRC_POS); bResult = FALSE; goto err; } @@ -937,50 +939,44 @@ BOOL DoFilesInstall (HWND hwndDlg, wchar_t *szDestDir) Decompressed_Files[fileNo].fileLength, FALSE, TRUE); } - if (driver64) - { - if (!EnableWow64FsRedirection (TRUE)) - { - handleWin32Error (hwndDlg, SRC_POS); - bResult = FALSE; - goto err; - } - - if (!bResult) - goto err; + if (!EnableWow64FsRedirection (TRUE)) + { + handleWin32Error (hwndDlg, SRC_POS); + bResult = FALSE; + goto err; } + if (!bResult) + goto err; + break; } } } else { - if (driver64) - EnableWow64FsRedirection (FALSE); + EnableWow64FsRedirection (FALSE); bResult = TCCopyFile (curFileName, szTmp); - if (driver64) - EnableWow64FsRedirection (TRUE); + EnableWow64FsRedirection (TRUE); } if (bResult && wcscmp (szFiles[i], L"AVeraCrypt.exe") == 0) { - if (Is64BitOs ()) - EnableWow64FsRedirection (FALSE); + EnableWow64FsRedirection (FALSE); wstring servicePath = GetServiceConfigPath (_T(TC_APP_NAME) L".exe", false); wstring serviceLegacyPath = GetServiceConfigPath (_T(TC_APP_NAME) L".exe", true); wstring favoritesFile = GetServiceConfigPath (TC_APPD_FILENAME_SYSTEM_FAVORITE_VOLUMES, false); wstring favoritesLegacyFile = GetServiceConfigPath (TC_APPD_FILENAME_SYSTEM_FAVORITE_VOLUMES, true); - if (bResult && Is64BitOs () + if (bResult && FileExists (favoritesLegacyFile.c_str()) && !FileExists (favoritesFile.c_str())) { // copy the favorites XML file to the native system directory bResult = CopyFile (favoritesLegacyFile.c_str(), favoritesFile.c_str(), FALSE); @@ -1025,45 +1021,39 @@ BOOL DoFilesInstall (HWND hwndDlg, wchar_t *szDestDir) } } catch (...) {} } - if (Is64BitOs ()) + // delete files from legacy path + if (FileExists (favoritesLegacyFile.c_str())) { - // delete files from legacy path - if (FileExists (favoritesLegacyFile.c_str())) - { - RemoveMessage (hwndDlg, (wchar_t *) favoritesLegacyFile.c_str()); - ForceDeleteFile (favoritesLegacyFile.c_str()); - } - - if (FileExists (serviceLegacyPath.c_str())) - { - RemoveMessage (hwndDlg, (wchar_t *) serviceLegacyPath.c_str()); - ForceDeleteFile (serviceLegacyPath.c_str()); - } + RemoveMessage (hwndDlg, (wchar_t *) favoritesLegacyFile.c_str()); + ForceDeleteFile (favoritesLegacyFile.c_str()); + } - EnableWow64FsRedirection (TRUE); + if (FileExists (serviceLegacyPath.c_str())) + { + RemoveMessage (hwndDlg, (wchar_t *) serviceLegacyPath.c_str()); + ForceDeleteFile (serviceLegacyPath.c_str()); } + + EnableWow64FsRedirection (TRUE); } } } else { - if (driver64) - EnableWow64FsRedirection (FALSE); + EnableWow64FsRedirection (FALSE); if (zipFile) bResult = StatRemoveDirectory (szTmp); else bResult = StatDeleteFile (szTmp, TRUE); - if (driver64) - EnableWow64FsRedirection (TRUE); + EnableWow64FsRedirection (TRUE); if (bResult && wcscmp (szFiles[i], L"AVeraCrypt.exe") == 0) { - if (Is64BitOs ()) - EnableWow64FsRedirection (FALSE); + EnableWow64FsRedirection (FALSE); wstring servicePath = GetServiceConfigPath (_T(TC_APP_NAME) L".exe", false); wstring serviceLegacyPath = GetServiceConfigPath (_T(TC_APP_NAME) L".exe", true); wstring favoritesFile = GetServiceConfigPath (TC_APPD_FILENAME_SYSTEM_FAVORITE_VOLUMES, false); wstring favoritesLegacyFile = GetServiceConfigPath (TC_APPD_FILENAME_SYSTEM_FAVORITE_VOLUMES, true); @@ -1079,26 +1069,23 @@ BOOL DoFilesInstall (HWND hwndDlg, wchar_t *szDestDir) { RemoveMessage (hwndDlg, (wchar_t *) servicePath.c_str()); ForceDeleteFile (servicePath.c_str()); } - if (Is64BitOs ()) + if (FileExists (favoritesLegacyFile.c_str())) { - if (FileExists (favoritesLegacyFile.c_str())) - { - RemoveMessage (hwndDlg, (wchar_t *) favoritesLegacyFile.c_str()); - ForceDeleteFile (favoritesLegacyFile.c_str()); - } - - if (FileExists (serviceLegacyPath.c_str())) - { - RemoveMessage (hwndDlg, (wchar_t *) serviceLegacyPath.c_str()); - ForceDeleteFile (serviceLegacyPath.c_str()); - } + RemoveMessage (hwndDlg, (wchar_t *) favoritesLegacyFile.c_str()); + ForceDeleteFile (favoritesLegacyFile.c_str()); + } - EnableWow64FsRedirection (TRUE); + if (FileExists (serviceLegacyPath.c_str())) + { + RemoveMessage (hwndDlg, (wchar_t *) serviceLegacyPath.c_str()); + ForceDeleteFile (serviceLegacyPath.c_str()); } + + EnableWow64FsRedirection (TRUE); } } err: if (bResult == FALSE) @@ -1132,14 +1119,23 @@ err: else StringCbPrintfW (szTmp2, sizeof(szTmp2), GetString ("UNINSTALL_OF_FAILED"), szTmp, pszDesc); if (lpMsgBuf) LocalFree (lpMsgBuf); - if (!Silent && MessageBoxW (hwndDlg, szTmp2, lpszTitle, MB_YESNO | MB_ICONHAND) != IDYES) + if (!Silent && MessageBoxW(hwndDlg, szTmp2, lpszTitle, MB_YESNO | MB_ICONHAND) != IDYES) + { +#ifndef PORTABLE + RestorePrivilegeState(&originalPrivileges); +#endif return FALSE; + } } } + +#ifndef PORTABLE + RestorePrivilegeState(&originalPrivileges); +#endif if (bUninstall == FALSE) { WIN32_FIND_DATA f; HANDLE h; @@ -1644,11 +1640,10 @@ BOOL DoDriverUnload (HWND hwndDlg) } } if (hDriver != INVALID_HANDLE_VALUE) { - MOUNT_LIST_STRUCT driver; LONG driverVersion = VERSION_NUM; int refCount; DWORD dwResult; BOOL bResult; @@ -1723,11 +1718,11 @@ BOOL DoDriverUnload (HWND hwndDlg) if (bResult) { if (volumesMounted != 0) { bOK = FALSE; - MessageBoxW (hwndDlg, GetString ("DISMOUNT_ALL_FIRST"), lpszTitle, MB_ICONHAND); + MessageBoxW (hwndDlg, GetString ("UNMOUNT_ALL_FIRST"), lpszTitle, MB_ICONHAND); } } else { bOK = FALSE; @@ -1893,19 +1888,19 @@ error: OleUninitialize (); return bOK; } -BOOL DoShortcutsInstall (HWND hwndDlg, wchar_t *szDestDir, BOOL bProgGroup, BOOL bDesktopIcon) +BOOL DoShortcutsInstall (HWND hwndDlg, wchar_t *szDestDir, BOOL bProgGroup, BOOL bUseDesktopIcon) { wchar_t szLinkDir[TC_MAX_PATH], szDir[TC_MAX_PATH]; wchar_t szTmp[TC_MAX_PATH], szTmp2[TC_MAX_PATH]; BOOL bSlash, bOK = FALSE; HRESULT hOle; int x; - if (bProgGroup == FALSE && bDesktopIcon == FALSE) + if (bProgGroup == FALSE && bUseDesktopIcon == FALSE) return TRUE; hOle = OleInitialize (NULL); GetProgramPath (hwndDlg, szLinkDir); @@ -1980,11 +1975,11 @@ BOOL DoShortcutsInstall (HWND hwndDlg, wchar_t *szDestDir, BOOL bProgGroup, BOOL StringCbPrintfW (szTmp2, sizeof(szTmp2), L"%s%s", szLinkDir, L"\\VeraCrypt User's Guide.lnk"); StatDeleteFile (szTmp2, FALSE); } - if (bDesktopIcon) + if (bUseDesktopIcon) { StringCbCopyW (szDir, sizeof(szDir), szDestDir); x = wcslen (szDestDir); if (szDestDir[x - 1] == L'\\') bSlash = TRUE; @@ -2014,10 +2009,41 @@ error: OleUninitialize (); return bOK; } +void RemoveLegacyFiles (wchar_t *szDestDir) +{ + const wchar_t* oldFileNames[] = { + L"docs\\html\\en\\BCH_Logo_48x30.png", + L"docs\\html\\en\\LinuxPrepAndBuild.sh", + L"docs\\html\\en\\LinuxPrepAndBuild.zip", + L"docs\\html\\en\\RIPEMD-160.html", + L"docs\\html\\en\\ru\\BCH_Logo_48x30.png", + L"Languages\\Language.ru - Copy.xml", + }; + wchar_t szDir[TC_MAX_PATH]; + wchar_t oldPath[TC_MAX_PATH]; + BOOL bSlash; + size_t x, i; + + StringCbCopyW (szDir, sizeof(szDir), szDestDir); + x = wcslen (szDestDir); + if (szDestDir[x - 1] == L'\\') + bSlash = TRUE; + else + bSlash = FALSE; + + if (bSlash == FALSE) + StringCbCatW (szDir, sizeof(szDir), L"\\"); + + for (i = 0; i < ARRAYSIZE(oldFileNames); i++) + { + StringCbPrintfW (oldPath, sizeof(oldPath), L"%s%s", szDestDir, oldFileNames[i]); + StatDeleteFile (oldPath, FALSE); + } +} void OutcomePrompt (HWND hwndDlg, BOOL bOK) { if (bOK) { @@ -2197,11 +2223,10 @@ void DoUninstall (void *arg) void DoInstall (void *arg) { HWND hwndDlg = (HWND) arg; BOOL bOK = TRUE; wchar_t path[MAX_PATH]; - BootEncryption bootEnc (hwndDlg); // Refresh the main GUI (wizard thread) InvalidateRect (MainDlg, NULL, TRUE); @@ -2341,10 +2366,16 @@ void DoInstall (void *arg) { WriteMemoryProtectionConfig(bDisableMemoryProtection? FALSE : TRUE); bRestartRequired = TRUE; // Restart is required to apply the new memory protection settings } + if (bOK && bUpgrade) + { + // delete legacy files + RemoveLegacyFiles (InstallationPath); + } + if (bOK) { UpdateProgressBarProc(100); UninstallBatch[0] = 0; StatusMessage (hwndDlg, "INSTALL_COMPLETED"); @@ -2576,10 +2607,11 @@ static tLanguageEntry g_languagesEntries[] = { {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"Norsk Bokmål", IDR_LANG_NB, LANG_NORWEGIAN, "nb", 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}, @@ -2591,11 +2623,11 @@ static tLanguageEntry g_languagesEntries[] = { {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_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, |