Skip to content

Commit

Permalink
Windows: remove 32-bit logic from the code since we support only 64-b…
Browse files Browse the repository at this point in the history
…it. remove 32-bit EFI bootloader files.

We also fix intermediary files folder for Portable and Setup projects
  • Loading branch information
idrassi committed Nov 16, 2024
1 parent 489d3e3 commit c86577f
Show file tree
Hide file tree
Showing 41 changed files with 127 additions and 521 deletions.
Binary file removed src/Boot/EFI/DcsBoot32.efi
Binary file not shown.
Binary file removed src/Boot/EFI/DcsCfg32.efi
Binary file not shown.
Binary file removed src/Boot/EFI/DcsInfo32.efi
Binary file not shown.
Binary file removed src/Boot/EFI/DcsInt32.efi
Binary file not shown.
Binary file removed src/Boot/EFI/DcsRe32.efi
Binary file not shown.
Binary file removed src/Boot/EFI/LegacySpeaker32.efi
Binary file not shown.
104 changes: 10 additions & 94 deletions src/Common/BootEncryption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3332,53 +3332,29 @@ namespace VeraCrypt
}
}
DWORD sizeDcsBoot;
#ifdef _WIN64
uint8 *dcsBootImg = MapResource(L"BIN", IDR_EFI_DCSBOOT, &sizeDcsBoot);
#else
uint8 *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
uint8 *dcsIntImg = MapResource(L"BIN", IDR_EFI_DCSINT, &sizeDcsInt);
#else
uint8 *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
uint8 *dcsCfgImg = MapResource(L"BIN", IDR_EFI_DCSCFG, &sizeDcsCfg);
#else
uint8 *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
uint8 *LegacySpeakerImg = MapResource(L"BIN", IDR_EFI_LEGACYSPEAKER, &sizeLegacySpeaker);
#else
uint8 *LegacySpeakerImg = MapResource(L"BIN", Is64BitOs()? IDR_EFI_LEGACYSPEAKER: IDR_EFI_LEGACYSPEAKER32, &sizeLegacySpeaker);
#endif
if (!LegacySpeakerImg)
throw ErrorException(L"Out of resource LegacySpeaker", SRC_POS);
#ifdef VC_EFI_CUSTOM_MODE
DWORD sizeBootMenuLocker;
#ifdef _WIN64
uint8 *BootMenuLockerImg = MapResource(L"BIN", IDR_EFI_DCSBML, &sizeBootMenuLocker);
#else
uint8 *BootMenuLockerImg = MapResource(L"BIN", Is64BitOs()? IDR_EFI_DCSBML: IDR_EFI_DCSBML32, &sizeBootMenuLocker);
#endif
if (!BootMenuLockerImg)
throw ErrorException(L"Out of resource DcsBml", SRC_POS);
#endif
DWORD sizeDcsInfo;
#ifdef _WIN64
uint8 *DcsInfoImg = MapResource(L"BIN", IDR_EFI_DCSINFO, &sizeDcsInfo);
#else
uint8 *DcsInfoImg = MapResource(L"BIN", Is64BitOs()? IDR_EFI_DCSINFO: IDR_EFI_DCSINFO32, &sizeDcsInfo);
#endif
if (!DcsInfoImg)
throw ErrorException(L"Out of resource DcsInfo", SRC_POS);

Expand All @@ -3390,8 +3366,8 @@ namespace VeraCrypt
bool bAlreadyExist;
const char* g_szMsBootString = "bootmgfw.pdb";
unsigned __int64 loaderSize = 0;
const wchar_t * szStdEfiBootloader = Is64BitOs()? L"\\EFI\\Boot\\bootx64.efi": L"\\EFI\\Boot\\bootia32.efi";
const wchar_t * szBackupEfiBootloader = Is64BitOs()? L"\\EFI\\Boot\\original_bootx64.vc_backup": L"\\EFI\\Boot\\original_bootia32.vc_backup";
const wchar_t * szStdEfiBootloader = L"\\EFI\\Boot\\bootx64.efi";
const wchar_t * szBackupEfiBootloader = L"\\EFI\\Boot\\original_bootx64.vc_backup";

if (preserveUserConfig)
{
Expand Down Expand Up @@ -3547,10 +3523,7 @@ namespace VeraCrypt

// move the original bootloader backup from old location (if it exists) to new location
// we don't force the move operation if the new location already exists
if (Is64BitOs())
EfiBootInst.RenameFile (L"\\EFI\\Boot\\original_bootx64_vc_backup.efi", L"\\EFI\\Boot\\original_bootx64.vc_backup", FALSE);
else
EfiBootInst.RenameFile (L"\\EFI\\Boot\\original_bootia32_vc_backup.efi", L"\\EFI\\Boot\\original_bootia32.vc_backup", FALSE);
EfiBootInst.RenameFile (L"\\EFI\\Boot\\original_bootx64_vc_backup.efi", L"\\EFI\\Boot\\original_bootx64.vc_backup", FALSE);

// Clean beta9
EfiBootInst.DelFile(L"\\DcsBoot.efi");
Expand Down Expand Up @@ -3729,61 +3702,33 @@ namespace VeraCrypt
{
// create EFI disk structure
DWORD sizeDcsBoot;
#ifdef _WIN64
uint8 *dcsBootImg = MapResource(L"BIN", IDR_EFI_DCSBOOT, &sizeDcsBoot);
#else
uint8 *dcsBootImg = MapResource(L"BIN", Is64BitOs()? IDR_EFI_DCSBOOT : IDR_EFI_DCSBOOT32, &sizeDcsBoot);
#endif
if (!dcsBootImg)
throw ParameterIncorrect (SRC_POS);
DWORD sizeDcsInt;
#ifdef _WIN64
uint8 *dcsIntImg = MapResource(L"BIN", IDR_EFI_DCSINT, &sizeDcsInt);
#else
uint8 *dcsIntImg = MapResource(L"BIN", Is64BitOs()? IDR_EFI_DCSINT: IDR_EFI_DCSINT32, &sizeDcsInt);
#endif
if (!dcsIntImg)
throw ParameterIncorrect (SRC_POS);
DWORD sizeDcsCfg;
#ifdef _WIN64
uint8 *dcsCfgImg = MapResource(L"BIN", IDR_EFI_DCSCFG, &sizeDcsCfg);
#else
uint8 *dcsCfgImg = MapResource(L"BIN", Is64BitOs()? IDR_EFI_DCSCFG: IDR_EFI_DCSCFG32, &sizeDcsCfg);
#endif
if (!dcsCfgImg)
throw ParameterIncorrect (SRC_POS);
DWORD sizeLegacySpeaker;
#ifdef _WIN64
uint8 *LegacySpeakerImg = MapResource(L"BIN", IDR_EFI_LEGACYSPEAKER, &sizeLegacySpeaker);
#else
uint8 *LegacySpeakerImg = MapResource(L"BIN", Is64BitOs()? IDR_EFI_LEGACYSPEAKER: IDR_EFI_LEGACYSPEAKER32, &sizeLegacySpeaker);
#endif
if (!LegacySpeakerImg)
throw ParameterIncorrect (SRC_POS);
#ifdef VC_EFI_CUSTOM_MODE
DWORD sizeBootMenuLocker;
#ifdef _WIN64
uint8 *BootMenuLockerImg = MapResource(L"BIN", IDR_EFI_DCSBML, &sizeBootMenuLocker);
#else
uint8 *BootMenuLockerImg = MapResource(L"BIN", Is64BitOs()? IDR_EFI_DCSBML: IDR_EFI_DCSBML32, &sizeBootMenuLocker);
#endif
if (!BootMenuLockerImg)
throw ParameterIncorrect (SRC_POS);
#endif
DWORD sizeDcsRescue;
#ifdef _WIN64
uint8 *DcsRescueImg = MapResource(L"BIN", IDR_EFI_DCSRE, &sizeDcsRescue);
#else
uint8 *DcsRescueImg = MapResource(L"BIN", Is64BitOs()? IDR_EFI_DCSRE: IDR_EFI_DCSRE32, &sizeDcsRescue);
#endif
if (!DcsRescueImg)
throw ParameterIncorrect (SRC_POS);
DWORD sizeDcsInfo;
#ifdef _WIN64
uint8 *DcsInfoImg = MapResource(L"BIN", IDR_EFI_DCSINFO, &sizeDcsInfo);
#else
uint8 *DcsInfoImg = MapResource(L"BIN", Is64BitOs()? IDR_EFI_DCSINFO: IDR_EFI_DCSINFO32, &sizeDcsInfo);
#endif
if (!DcsInfoImg)
throw ParameterIncorrect (SRC_POS);

Expand All @@ -3809,7 +3754,7 @@ namespace VeraCrypt

finally_do_arg (zip_t**, &z, { if (*finally_arg) zip_discard (*finally_arg);});

if (!ZipAdd (z, Is64BitOs()? "EFI/Boot/bootx64.efi": "EFI/Boot/bootia32.efi", DcsRescueImg, sizeDcsRescue))
if (!ZipAdd (z, "EFI/Boot/bootx64.efi", DcsRescueImg, sizeDcsRescue))
throw ParameterIncorrect (SRC_POS);
#ifdef VC_EFI_CUSTOM_MODE
if (!ZipAdd (z, "EFI/VeraCrypt/DcsBml.dcs", BootMenuLockerImg, sizeBootMenuLocker))
Expand Down Expand Up @@ -3858,7 +3803,7 @@ namespace VeraCrypt
sysBakFile.GetFileSize(fileSize);
fileBuf.Resize ((DWORD) fileSize);
DWORD sizeLoader = sysBakFile.Read (fileBuf.Ptr (), fileSize);
bLoadAdded = ZipAdd (z, Is64BitOs()? "EFI/Boot/original_bootx64.vc_backup": "EFI/Boot/original_bootia32.vc_backup", fileBuf.Ptr (), sizeLoader);
bLoadAdded = ZipAdd (z, "EFI/Boot/original_bootx64.vc_backup", fileBuf.Ptr (), sizeLoader);
}
catch (Exception &e)
{
Expand Down Expand Up @@ -4085,19 +4030,6 @@ namespace VeraCrypt
L"EFI/VeraCrypt/svh_bak",
L"EFI/Boot/original_bootx64.vc_backup"
};

const wchar_t* efi32Files[] = {
L"EFI/Boot/bootia32.efi",
#ifdef VC_EFI_CUSTOM_MODE
L"EFI/VeraCrypt/DcsBml.dcs",
#endif
L"EFI/VeraCrypt/DcsBoot.efi",
L"EFI/VeraCrypt/DcsCfg.dcs",
L"EFI/VeraCrypt/DcsInt.dcs",
L"EFI/VeraCrypt/LegacySpeaker.dcs",
L"EFI/VeraCrypt/svh_bak",
L"EFI/Boot/original_bootia32.vc_backup"
};

zip_error_t zerr;
zip_source_t* zsrc = zip_source_buffer_create (RescueZipData, RescueZipSize, 0, &zerr);
Expand Down Expand Up @@ -4126,8 +4058,8 @@ namespace VeraCrypt
&& !wcsncmp (szNameBuffer, L"FAT", 3))
{
int i;
const wchar_t** efiFiles = Is64BitOs()? efi64Files: efi32Files;
int efiFilesSize = Is64BitOs()? ARRAYSIZE(efi64Files): ARRAYSIZE(efi32Files);
const wchar_t** efiFiles = efi64Files;
int efiFilesSize = ARRAYSIZE(efi64Files);
for (i = 0; i < efiFilesSize; i++)
{
bool bMatch = false;
Expand Down Expand Up @@ -4280,25 +4212,12 @@ namespace VeraCrypt
L"EFI/VeraCrypt/svh_bak",
L"EFI/Boot/original_bootx64.vc_backup"
};

const wchar_t* efi32Files[] = {
L"EFI/Boot/bootia32.efi",
#ifdef VC_EFI_CUSTOM_MODE
L"EFI/VeraCrypt/DcsBml.dcs",
#endif
L"EFI/VeraCrypt/DcsBoot.efi",
L"EFI/VeraCrypt/DcsCfg.dcs",
L"EFI/VeraCrypt/DcsInt.dcs",
L"EFI/VeraCrypt/LegacySpeaker.dcs",
L"EFI/VeraCrypt/svh_bak",
L"EFI/Boot/original_bootia32.vc_backup"
};

int i;
zip_stat_t statMem, statFile;
zip_int64_t indexMem, indexFile;
const wchar_t** efiFiles = Is64BitOs()? efi64Files: efi32Files;
int efiFilesSize = Is64BitOs()? ARRAYSIZE(efi64Files): ARRAYSIZE(efi32Files);
const wchar_t** efiFiles = efi64Files;
int efiFilesSize = ARRAYSIZE(efi64Files);
for (i = 0; i < efiFilesSize; i++)
{
bool bMatch = false;
Expand Down Expand Up @@ -4573,10 +4492,7 @@ namespace VeraCrypt

EfiBootInst.DeleteStartExec();
EfiBootInst.DeleteStartExec(0xDC5B, L"Driver"); // remove DcsBml boot driver it was installed
if (Is64BitOs())
EfiBootInst.RenameFile(L"\\EFI\\Boot\\original_bootx64.vc_backup", L"\\EFI\\Boot\\bootx64.efi", TRUE);
else
EfiBootInst.RenameFile(L"\\EFI\\Boot\\original_bootia32.vc_backup", L"\\EFI\\Boot\\bootia32.efi", TRUE);
EfiBootInst.RenameFile(L"\\EFI\\Boot\\original_bootx64.vc_backup", L"\\EFI\\Boot\\bootx64.efi", TRUE);

if (!EfiBootInst.RenameFile(L"\\EFI\\Microsoft\\Boot\\bootmgfw_ms.vc", L"\\EFI\\Microsoft\\Boot\\bootmgfw.efi", TRUE))
{
Expand Down
32 changes: 6 additions & 26 deletions src/Common/Cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ int CachedPim[CACHE_SIZE];
int cacheEmpty = 1;
static int nPasswordIdx = 0;

#ifdef _WIN64

uint64 VcGetPasswordEncryptionID (Password* pPassword)
{
return ((uint64) pPassword->Text) + ((uint64) pPassword);
Expand All @@ -41,8 +39,6 @@ void VcUnprotectPassword (Password* pPassword, uint64 encID)
VcProtectPassword (pPassword, encID);
}

#endif

int ReadVolumeHeaderWCache (BOOL bBoot, BOOL bCache, BOOL bCachePim, unsigned char *header, Password *password, int pkcs5_prf, int pim, PCRYPTO_INFO *retInfo)
{
int nReturnCode = ERR_PASSWORD_WRONG;
Expand All @@ -56,37 +52,29 @@ int ReadVolumeHeaderWCache (BOOL bBoot, BOOL bCache, BOOL bCachePim, unsigned ch
/* Save mount passwords back into cache if asked to do so */
if (bCache && (nReturnCode == 0 || nReturnCode == ERR_CIPHER_INIT_WEAK_KEY))
{
#ifdef _WIN64
Password tmpPass;
#endif
for (i = 0; i < CACHE_SIZE; i++)
{
Password* pCurrentPassword = &CachedPasswords[i];
#ifdef _WIN64
if (IsRamEncryptionEnabled())
{
memcpy (&tmpPass, pCurrentPassword, sizeof (Password));
VcUnprotectPassword (&tmpPass, VcGetPasswordEncryptionID (pCurrentPassword));
pCurrentPassword = &tmpPass;
}
#endif
if (memcmp (pCurrentPassword, password, sizeof (Password)) == 0)
break;
}

#ifdef _WIN64
if (IsRamEncryptionEnabled())
burn (&tmpPass, sizeof (Password));
#endif

if (i == CACHE_SIZE)
{
/* Store the password */
CachedPasswords[nPasswordIdx] = *password;
#ifdef _WIN64
if (IsRamEncryptionEnabled ())
VcProtectPassword (&CachedPasswords[nPasswordIdx], VcGetPasswordEncryptionID (&CachedPasswords[nPasswordIdx]));
#endif

/* Store also PIM if requested, otherwise set to default */
if (bCachePim && (pim > 0))
Expand All @@ -107,21 +95,18 @@ int ReadVolumeHeaderWCache (BOOL bBoot, BOOL bCache, BOOL bCachePim, unsigned ch
}
else if (!cacheEmpty)
{
#ifdef _WIN64
Password tmpPass;
#endif
/* Attempt to recognize volume using cached passwords */
for (i = 0; i < CACHE_SIZE; i++)
{
Password* pCurrentPassword = &CachedPasswords[i];
#ifdef _WIN64
if (IsRamEncryptionEnabled())
{
memcpy (&tmpPass, pCurrentPassword, sizeof (Password));
VcUnprotectPassword (&tmpPass, VcGetPasswordEncryptionID (pCurrentPassword));
pCurrentPassword = &tmpPass;
}
#endif

if ((pCurrentPassword->Length > 0) && (pCurrentPassword->Length <= (unsigned int) ((bBoot? MAX_LEGACY_PASSWORD: MAX_PASSWORD))))
{
if (pim == -1)
Expand All @@ -134,10 +119,10 @@ int ReadVolumeHeaderWCache (BOOL bBoot, BOOL bCache, BOOL bCachePim, unsigned ch
break;
}
}
#ifdef _WIN64

if (IsRamEncryptionEnabled())
burn (&tmpPass, sizeof (Password));
#endif

}

return nReturnCode;
Expand All @@ -146,32 +131,28 @@ int ReadVolumeHeaderWCache (BOOL bBoot, BOOL bCache, BOOL bCachePim, unsigned ch

void AddPasswordToCache (Password *password, int pim, BOOL bCachePim)
{
#ifdef _WIN64
Password tmpPass;
#endif
int i;
for (i = 0; i < CACHE_SIZE; i++)
{
Password* pCurrentPassword = &CachedPasswords[i];
#ifdef _WIN64
if (IsRamEncryptionEnabled())
{
memcpy (&tmpPass, pCurrentPassword, sizeof (Password));
VcUnprotectPassword (&tmpPass, VcGetPasswordEncryptionID (pCurrentPassword));
pCurrentPassword = &tmpPass;
}
#endif

if (memcmp (pCurrentPassword, password, sizeof (Password)) == 0)
break;
}

if (i == CACHE_SIZE)
{
CachedPasswords[nPasswordIdx] = *password;
#ifdef _WIN64
if (IsRamEncryptionEnabled ())
VcProtectPassword (&CachedPasswords[nPasswordIdx], VcGetPasswordEncryptionID (&CachedPasswords[nPasswordIdx]));
#endif

/* Store also PIM if requested, otherwise set to default */
if (bCachePim && (pim > 0))
CachedPim[nPasswordIdx] = pim;
Expand All @@ -184,10 +165,9 @@ void AddPasswordToCache (Password *password, int pim, BOOL bCachePim)
{
CachedPim[i] = pim > 0? pim : 0;
}
#ifdef _WIN64

if (IsRamEncryptionEnabled())
burn (&tmpPass, sizeof (Password));
#endif
}

void AddLegacyPasswordToCache (PasswordLegacy *password, int pim)
Expand Down
7 changes: 1 addition & 6 deletions src/Common/Cmdline.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,7 @@ BOOL CALLBACK CommandHelpDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM

*tmp = 0;

StringCchCopyW (tmp, 8192, L"VeraCrypt " _T(VERSION_STRING) _T(VERSION_STRING_SUFFIX));
#ifdef _WIN64
StringCchCatW (tmp, 8192, L" (64-bit)");
#else
StringCchCatW (tmp, 8192, L" (32-bit)");
#endif
StringCchCopyW (tmp, 8192, L"VeraCrypt " _T(VERSION_STRING) _T(VERSION_STRING_SUFFIX) L" (64-bit)");
#if (defined(_DEBUG) || defined(DEBUG))
StringCchCatW (tmp, 8192, L" (debug)");
#endif
Expand Down
11 changes: 0 additions & 11 deletions src/Common/Common.rc
Original file line number Diff line number Diff line change
Expand Up @@ -565,17 +565,6 @@ IDR_EFI_DCSBML BIN "..\\Boot\\EFI\\DcsBml.efi"
#endif
IDR_EFI_DCSRE BIN "..\\Boot\\EFI\\DcsRe.efi"
IDR_EFI_DCSINFO BIN "..\\Boot\\EFI\\DcsInfo.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"
IDR_EFI_LEGACYSPEAKER32 BIN "..\\Boot\\EFI\\LegacySpeaker32.efi"
#ifdef VC_EFI_CUSTOM_MODE
IDR_EFI_DCSBML32 BIN "..\\Boot\\EFI\\DcsBml32.efi"
#endif
IDR_EFI_DCSRE32 BIN "..\\Boot\\EFI\\DcsRe32.efi"
IDR_EFI_DCSINFO32 BIN "..\\Boot\\EFI\\DcsInfo32.efi"
#endif
#endif
/////////////////////////////////////////////////////////////////////////////
//
Expand Down
Loading

0 comments on commit c86577f

Please sign in to comment.