From 2dc39a7c7e085d77a5b3505b15fd00111a6fff5e Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Mon, 16 Apr 2018 00:32:27 +0200 Subject: Windows: simplify installer logic by copying only binaries for the current architecture. --- src/Setup/Portable.vcxproj | 4 ++-- src/Setup/SelfExtract.c | 25 +++++++++++++++---------- src/Setup/SelfExtract.h | 6 ++++-- src/Setup/Setup.c | 38 +++++++------------------------------- src/Setup/Setup.h | 19 ++++++++++++------- src/Setup/Setup.vcxproj | 4 ++-- 6 files changed, 42 insertions(+), 54 deletions(-) diff --git a/src/Setup/Portable.vcxproj b/src/Setup/Portable.vcxproj index 78f48197..06c2e45a 100644 --- a/src/Setup/Portable.vcxproj +++ b/src/Setup/Portable.vcxproj @@ -69,7 +69,7 @@ /NODEFAULTLIB:LIBCMTD %(AdditionalOptions) - libcmtd.lib;atlsd.lib;mpr.lib;..\Common\Debug\Zip.lib;%(AdditionalDependencies) + libcmtd.lib;atlsd.lib;mpr.lib;..\Common\Debug\Zip.lib;..\Crypto\Debug\crypto.lib;%(AdditionalDependencies) $(OutDir)VeraCryptPortable.exe AsInvoker user32.dll;gdi32.dll;advapi32.dll;shell32.dll;ole32.dll;mpr.dll;%(DelayLoadDLLs) @@ -107,7 +107,7 @@ copy PortableDebug\VeraCryptPortable.exe "..\Debug\Setup Files\VeraCrypt Portabl /IGNORE:4089 %(AdditionalOptions) - mpr.lib;..\Common\Release\Zip.lib;%(AdditionalDependencies) + mpr.lib;..\Common\Release\Zip.lib;..\Crypto\Release\crypto.lib;%(AdditionalDependencies) $(OutDir)VeraCryptPortable.exe AsInvoker user32.dll;gdi32.dll;advapi32.dll;shell32.dll;ole32.dll;mpr.dll;%(DelayLoadDLLs) diff --git a/src/Setup/SelfExtract.c b/src/Setup/SelfExtract.c index 7b3fb4fe..2a3a8b29 100644 --- a/src/Setup/SelfExtract.c +++ b/src/Setup/SelfExtract.c @@ -34,8 +34,8 @@ #else #define OutputPackageFile L"VeraCrypt Setup " _T(VERSION_STRING) L".exe" #endif -#define MAG_START_MARKER "TCINSTRT" -#define MAG_END_MARKER_OBFUSCATED "T/C/I/N/S/C/R/C" +#define MAG_START_MARKER "VCINSTRT" +#define MAG_END_MARKER_OBFUSCATED "V/C/I/N/S/C/R/C" #define PIPE_BUFFER_LEN (4 * BYTES_PER_KB) unsigned char MagEndMarker [sizeof (MAG_END_MARKER_OBFUSCATED)]; @@ -57,7 +57,7 @@ void SelfExtractStartupInit (void) // The end marker must be included in the self-extracting exe only once, not twice (used e.g. // by IsSelfExtractingPackage()) and that's why MAG_END_MARKER_OBFUSCATED is obfuscated and // needs to be deobfuscated using this function at startup. -static void DeobfuscateMagEndMarker (void) +void DeobfuscateMagEndMarker (void) { int i; @@ -385,16 +385,21 @@ err: // Verifies the CRC-32 of the whole self-extracting package (except the digital signature areas, if present) -BOOL VerifyPackageIntegrity (void) +BOOL VerifySelfPackageIntegrity () +{ + wchar_t path [TC_MAX_PATH]; + + GetModuleFileName (NULL, path, ARRAYSIZE (path)); + return VerifyPackageIntegrity (path); +} + +BOOL VerifyPackageIntegrity (const wchar_t *path) { int fileDataEndPos = 0; int fileDataStartPos = 0; unsigned __int32 crc = 0; unsigned char *tmpBuffer; int tmpFileSize; - wchar_t path [TC_MAX_PATH]; - - GetModuleFileName (NULL, path, ARRAYSIZE (path)); #ifdef NDEBUG // verify Authenticode digital signature of the exe file @@ -464,7 +469,7 @@ BOOL IsSelfExtractingPackage (void) } -static void FreeAllFileBuffers (void) +void FreeAllFileBuffers (void) { int fileNo; @@ -619,7 +624,7 @@ sem_end: return FALSE; } - +#ifdef SETUP void __cdecl ExtractAllFilesThread (void *hwndDlg) { int fileNo; @@ -704,4 +709,4 @@ eaf_end: else PostMessage (MainDlg, TC_APPMSG_EXTRACTION_FAILURE, 0, 0); } - +#endif diff --git a/src/Setup/SelfExtract.h b/src/Setup/SelfExtract.h index 020b1441..ed4b6655 100644 --- a/src/Setup/SelfExtract.h +++ b/src/Setup/SelfExtract.h @@ -32,9 +32,11 @@ void SelfExtractStartupInit (void); BOOL SelfExtractInMemory (wchar_t *path); void __cdecl ExtractAllFilesThread (void *hwndDlg); BOOL MakeSelfExtractingPackage (HWND hwndDlg, wchar_t *szDestDir); -BOOL VerifyPackageIntegrity (void); +BOOL VerifyPackageIntegrity (const wchar_t *path); +BOOL VerifySelfPackageIntegrity (void); BOOL IsSelfExtractingPackage (void); -static void DeobfuscateMagEndMarker (void); +void FreeAllFileBuffers (void); +void DeobfuscateMagEndMarker (void); extern wchar_t DestExtractPath [TC_MAX_PATH]; diff --git a/src/Setup/Setup.c b/src/Setup/Setup.c index cedd9f61..5f2cea19 100644 --- a/src/Setup/Setup.c +++ b/src/Setup/Setup.c @@ -685,18 +685,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') @@ -765,36 +753,18 @@ BOOL DoFilesInstall (HWND hwndDlg, wchar_t *szDestDir) StringCbCopyNW (curFileName, sizeof(curFileName), L"VeraCrypt-x64.exe", sizeof (L"VeraCrypt-x64.exe")); } - if (Is64BitOs () - && wcscmp (szFiles[i], L"AVeraCrypt-x86.exe") == 0) - { - StringCbCopyNW (curFileName, sizeof(curFileName), L"VeraCrypt.exe", sizeof (L"VeraCrypt.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 (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 (!bDevm) { bResult = FALSE; @@ -1052,6 +1022,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); } @@ -2586,7 +2562,7 @@ int WINAPI wWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, wchar_t *lpsz { if (IsSelfExtractingPackage()) { - if (!VerifyPackageIntegrity()) + if (!VerifySelfPackageIntegrity()) { // Package corrupted exit (1); diff --git a/src/Setup/Setup.h b/src/Setup/Setup.h index b29ad14a..12b4159f 100644 --- a/src/Setup/Setup.h +++ b/src/Setup/Setup.h @@ -27,14 +27,7 @@ static wchar_t *szFiles[]= L"AVeraCrypt.exe", L"AVeraCryptExpander.exe", L"AVeraCrypt Format.exe", - L"AVeraCrypt-x86.exe", - L"AVeraCryptExpander-x86.exe", - L"AVeraCrypt Format-x86.exe", - L"AVeraCrypt-x64.exe", - L"AVeraCryptExpander-x64.exe", - L"AVeraCrypt Format-x64.exe", L"Averacrypt.sys", - L"Averacrypt-x64.sys", L"Dveracrypt.sys", L"AVeraCrypt Setup.exe", L"XLanguages.zip", @@ -59,6 +52,18 @@ static wchar_t *szCompressedFiles[]= L"docs.zip" }; +// Specifies what legacy files to remove during install +static wchar_t *szLegacyFiles[]= +{ + L"VeraCrypt-x86.exe", + L"VeraCryptExpander-x86.exe", + L"VeraCrypt Format-x86.exe", + L"VeraCrypt-x64.exe", + L"VeraCryptExpander-x64.exe", + L"VeraCrypt Format-x64.exe", + L"veracrypt-x64.sys", +}; + #define FILENAME_64BIT_DRIVER L"veracrypt-x64.sys" #define NBR_COMPRESSED_FILES (sizeof(szCompressedFiles) / sizeof(szCompressedFiles[0])) diff --git a/src/Setup/Setup.vcxproj b/src/Setup/Setup.vcxproj index c4c1aad0..932cb051 100644 --- a/src/Setup/Setup.vcxproj +++ b/src/Setup/Setup.vcxproj @@ -69,7 +69,7 @@ /NODEFAULTLIB:LIBCMTD %(AdditionalOptions) - libcmtd.lib;atlsd.lib;mpr.lib;..\Common\Debug\Zip.lib;%(AdditionalDependencies) + libcmtd.lib;atlsd.lib;mpr.lib;..\Common\Debug\Zip.lib;..\Crypto\Debug\crypto.lib;%(AdditionalDependencies) $(OutDir)VeraCryptSetup.exe RequireAdministrator user32.dll;gdi32.dll;advapi32.dll;shell32.dll;ole32.dll;oleaut32.dll;mpr.dll;%(DelayLoadDLLs) @@ -107,7 +107,7 @@ copy Debug\VeraCryptSetup.exe "..\Debug\Setup Files\VeraCrypt Setup.exe" >NUL /IGNORE:4089 %(AdditionalOptions) - mpr.lib;..\Common\Release\Zip.lib;%(AdditionalDependencies) + mpr.lib;..\Common\Release\Zip.lib;..\Crypto\Release\crypto.lib;%(AdditionalDependencies) $(OutDir)VeraCryptSetup.exe RequireAdministrator user32.dll;gdi32.dll;advapi32.dll;shell32.dll;ole32.dll;oleaut32.dll;mpr.dll;%(DelayLoadDLLs) -- cgit v1.2.3