From 0b1b8b479f7c37812c9189cf9c843b58ad3304a3 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Tue, 27 Jun 2017 15:52:23 +0200 Subject: Windows: reduce size of 64-bit binaries by not embedding 32-bit EFI bootloader files in their resources. --- src/Common/BootEncryption.cpp | 56 +++++++++++++++++++++++++++++++++-- src/Common/Common.rc | 3 +- src/ExpandVolume/ExpandVolume.vcxproj | 6 ++++ src/Format/Format.vcxproj | 6 ++++ src/Mount/Mount.vcxproj | 6 ++++ 5 files changed, 74 insertions(+), 3 deletions(-) diff --git a/src/Common/BootEncryption.cpp b/src/Common/BootEncryption.cpp index c6fccb3b..757c14a4 100644 --- a/src/Common/BootEncryption.cpp +++ b/src/Common/BootEncryption.cpp @@ -2611,27 +2611,51 @@ namespace VeraCrypt } } DWORD sizeDcsBoot; +#ifdef _WIN64 + byte *dcsBootImg = MapResource(L"BIN", IDR_EFI_DCSBOOT, &sizeDcsBoot); +#else byte *dcsBootImg = MapResource(L"BIN", Is64BitOs()? IDR_EFI_DCSBOOT : IDR_EFI_DCSBOOT32, &sizeDcsBoot); +#endif if (!dcsBootImg) throw ErrorException(L"Out of resource DcsBoot", SRC_POS); DWORD sizeDcsInt; +#ifdef _WIN64 + byte *dcsIntImg = MapResource(L"BIN", IDR_EFI_DCSINT, &sizeDcsInt); +#else byte *dcsIntImg = MapResource(L"BIN", Is64BitOs()? IDR_EFI_DCSINT: IDR_EFI_DCSINT32, &sizeDcsInt); +#endif if (!dcsIntImg) throw ErrorException(L"Out of resource DcsInt", SRC_POS); DWORD sizeDcsCfg; +#ifdef _WIN64 + byte *dcsCfgImg = MapResource(L"BIN", IDR_EFI_DCSCFG, &sizeDcsCfg); +#else byte *dcsCfgImg = MapResource(L"BIN", Is64BitOs()? IDR_EFI_DCSCFG: IDR_EFI_DCSCFG32, &sizeDcsCfg); +#endif if (!dcsCfgImg) throw ErrorException(L"Out of resource DcsCfg", SRC_POS); DWORD sizeLegacySpeaker; +#ifdef _WIN64 + byte *LegacySpeakerImg = MapResource(L"BIN", IDR_EFI_LEGACYSPEAKER, &sizeLegacySpeaker); +#else byte *LegacySpeakerImg = MapResource(L"BIN", Is64BitOs()? IDR_EFI_LEGACYSPEAKER: IDR_EFI_LEGACYSPEAKER32, &sizeLegacySpeaker); +#endif if (!LegacySpeakerImg) throw ErrorException(L"Out of resource LegacySpeaker", SRC_POS); DWORD sizeBootMenuLocker; +#ifdef _WIN64 + byte *BootMenuLockerImg = MapResource(L"BIN", IDR_EFI_DCSBML, &sizeBootMenuLocker); +#else byte *BootMenuLockerImg = MapResource(L"BIN", Is64BitOs()? IDR_EFI_DCSBML: IDR_EFI_DCSBML32, &sizeBootMenuLocker); +#endif if (!BootMenuLockerImg) throw ErrorException(L"Out of resource DcsBml", SRC_POS); DWORD sizeDcsInfo; +#ifdef _WIN64 + byte *DcsInfoImg = MapResource(L"BIN", IDR_EFI_DCSINFO, &sizeDcsInfo); +#else byte *DcsInfoImg = MapResource(L"BIN", Is64BitOs()? IDR_EFI_DCSINFO: IDR_EFI_DCSINFO32, &sizeDcsInfo); +#endif if (!DcsInfoImg) throw ErrorException(L"Out of resource DcsInfo", SRC_POS); @@ -2813,33 +2837,61 @@ namespace VeraCrypt { // create EFI disk structure DWORD sizeDcsBoot; - byte *dcsBootImg = MapResource(L"BIN", Is64BitOs()? IDR_EFI_DCSBOOT: IDR_EFI_DCSBOOT32, &sizeDcsBoot); +#ifdef _WIN64 + byte *dcsBootImg = MapResource(L"BIN", IDR_EFI_DCSBOOT, &sizeDcsBoot); +#else + byte *dcsBootImg = MapResource(L"BIN", Is64BitOs()? IDR_EFI_DCSBOOT : IDR_EFI_DCSBOOT32, &sizeDcsBoot); +#endif if (!dcsBootImg) throw ParameterIncorrect (SRC_POS); DWORD sizeDcsInt; +#ifdef _WIN64 + byte *dcsIntImg = MapResource(L"BIN", IDR_EFI_DCSINT, &sizeDcsInt); +#else byte *dcsIntImg = MapResource(L"BIN", Is64BitOs()? IDR_EFI_DCSINT: IDR_EFI_DCSINT32, &sizeDcsInt); +#endif if (!dcsIntImg) throw ParameterIncorrect (SRC_POS); DWORD sizeDcsCfg; +#ifdef _WIN64 + byte *dcsCfgImg = MapResource(L"BIN", IDR_EFI_DCSCFG, &sizeDcsCfg); +#else byte *dcsCfgImg = MapResource(L"BIN", Is64BitOs()? IDR_EFI_DCSCFG: IDR_EFI_DCSCFG32, &sizeDcsCfg); +#endif if (!dcsCfgImg) throw ParameterIncorrect (SRC_POS); DWORD sizeLegacySpeaker; +#ifdef _WIN64 + byte *LegacySpeakerImg = MapResource(L"BIN", IDR_EFI_LEGACYSPEAKER, &sizeLegacySpeaker); +#else byte *LegacySpeakerImg = MapResource(L"BIN", Is64BitOs()? IDR_EFI_LEGACYSPEAKER: IDR_EFI_LEGACYSPEAKER32, &sizeLegacySpeaker); +#endif if (!LegacySpeakerImg) throw ParameterIncorrect (SRC_POS); DWORD sizeBootMenuLocker; +#ifdef _WIN64 + byte *BootMenuLockerImg = MapResource(L"BIN", IDR_EFI_DCSBML, &sizeBootMenuLocker); +#else byte *BootMenuLockerImg = MapResource(L"BIN", Is64BitOs()? IDR_EFI_DCSBML: IDR_EFI_DCSBML32, &sizeBootMenuLocker); +#endif if (!BootMenuLockerImg) throw ParameterIncorrect (SRC_POS); DWORD sizeDcsRescue; +#ifdef _WIN64 + byte *DcsRescueImg = MapResource(L"BIN", IDR_EFI_DCSRE, &sizeDcsRescue); +#else byte *DcsRescueImg = MapResource(L"BIN", Is64BitOs()? IDR_EFI_DCSRE: IDR_EFI_DCSRE32, &sizeDcsRescue); +#endif if (!DcsRescueImg) throw ParameterIncorrect (SRC_POS); DWORD sizeDcsInfo; +#ifdef _WIN64 + byte *DcsInfoImg = MapResource(L"BIN", IDR_EFI_DCSINFO, &sizeDcsInfo); +#else byte *DcsInfoImg = MapResource(L"BIN", Is64BitOs()? IDR_EFI_DCSINFO: IDR_EFI_DCSINFO32, &sizeDcsInfo); +#endif if (!DcsInfoImg) - throw ErrorException(L"Out of resource DcsInfo", SRC_POS); + throw ParameterIncorrect (SRC_POS); char szTmpPath[MAX_PATH + 1], szTmpFilePath[MAX_PATH + 1]; if (!GetTempPathA (MAX_PATH, szTmpPath)) diff --git a/src/Common/Common.rc b/src/Common/Common.rc index a9313f1a..e66122ff 100644 --- a/src/Common/Common.rc +++ b/src/Common/Common.rc @@ -555,6 +555,7 @@ IDR_EFI_DCSCFG BIN "..\\Boot\\EFI\\DcsCfg.efi" IDR_EFI_LEGACYSPEAKER BIN "..\\Boot\\EFI\\LegacySpeaker.efi" IDR_EFI_DCSBML BIN "..\\Boot\\EFI\\DcsBml.efi" IDR_EFI_DCSRE BIN "..\\Boot\\EFI\\DcsRe.efi" +#ifndef WIN64 IDR_EFI_DCSBOOT32 BIN "..\\Boot\\EFI\\DcsBoot32.efi" IDR_EFI_DCSINT32 BIN "..\\Boot\\EFI\\DcsInt32.efi" IDR_EFI_DCSCFG32 BIN "..\\Boot\\EFI\\DcsCfg32.efi" @@ -563,7 +564,7 @@ IDR_EFI_DCSBML32 BIN "..\\Boot\\EFI\\DcsBml32.efi" IDR_EFI_DCSRE32 BIN "..\\Boot\\EFI\\DcsRe32.efi" IDR_EFI_DCSINFO BIN "..\\Boot\\EFI\\DcsInfo.efi" IDR_EFI_DCSINFO32 BIN "..\\Boot\\EFI\\DcsInfo32.efi" - +#endif ///////////////////////////////////////////////////////////////////////////// // // XML diff --git a/src/ExpandVolume/ExpandVolume.vcxproj b/src/ExpandVolume/ExpandVolume.vcxproj index 3c2d2474..47db3a53 100644 --- a/src/ExpandVolume/ExpandVolume.vcxproj +++ b/src/ExpandVolume/ExpandVolume.vcxproj @@ -193,6 +193,9 @@ copy Debug\VeraCryptExpander.exe "..\Debug\Setup Files" >NUL: copy $(TargetPath) "..\Debug\Setup Files\VeraCryptExpander-x64.exe" >NUL: + + WIN64;%(PreprocessorDefinitions) + @@ -284,6 +287,9 @@ copy $(TargetPath) "..\Debug\Setup Files\VeraCryptExpander-x64.exe" >NUL: copy $(TargetPath) "..\Release\Setup Files\VeraCryptExpander-x64.exe" + + WIN64;%(PreprocessorDefinitions) + diff --git a/src/Format/Format.vcxproj b/src/Format/Format.vcxproj index 7d206bf2..c5d73070 100644 --- a/src/Format/Format.vcxproj +++ b/src/Format/Format.vcxproj @@ -165,6 +165,9 @@ copy Debug\VeraCryptFormat.exe "..\Debug\Setup Files\VeraCrypt Format.exe" >N copy $(TargetPath) "..\Debug\Setup Files\VeraCrypt Format-x64.exe" >NUL: + + WIN64;%(PreprocessorDefinitions) + @@ -247,6 +250,9 @@ copy $(TargetPath) "..\Debug\Setup Files\VeraCrypt Format-x64.exe" >NUL: copy $(TargetPath) "..\Release\Setup Files\VeraCrypt Format-x64.exe" + + WIN64;%(PreprocessorDefinitions) + diff --git a/src/Mount/Mount.vcxproj b/src/Mount/Mount.vcxproj index 51cc316b..82cae7dd 100644 --- a/src/Mount/Mount.vcxproj +++ b/src/Mount/Mount.vcxproj @@ -183,6 +183,9 @@ copy Debug\VeraCrypt.exe "..\Debug\Setup Files" >NUL: copy $(TargetPath) "..\Debug\Setup Files\VeraCrypt-x64.exe" >NUL: + + WIN64;%(PreprocessorDefinitions) + @@ -272,6 +275,9 @@ copy $(TargetPath) "..\Debug\Setup Files\VeraCrypt-x64.exe" >NUL: copy $(TargetPath) "..\Release\Setup Files\VeraCrypt-x64.exe" + + WIN64;%(PreprocessorDefinitions) + -- cgit v1.2.3