Windows: only update MBR first 512 bytes if they have changed and don't update full MBR bootload in case of PostOOBE

This commit is contained in:
Mounir IDRASSI 2019-10-25 13:08:53 +02:00
parent faa541f613
commit 343d1a95dc
No known key found for this signature in database
GPG Key ID: 02C30AE90FAE4A6F

View File

@ -3489,6 +3489,8 @@ namespace VeraCrypt
EfiBootInst.WriteConfig (L"\\EFI\\VeraCrypt\\DcsProp", preserveUserConfig, pim, hashAlg, NULL, ParentWindow);
}
else
{
try
{
byte bootLoaderBuf[TC_BOOT_LOADER_AREA_SIZE - TC_BOOT_ENCRYPTION_VOLUME_HEADER_SIZE] = {0};
CreateBootLoaderInMemory (bootLoaderBuf, sizeof (bootLoaderBuf), false, hiddenOSCreation);
@ -3519,6 +3521,9 @@ namespace VeraCrypt
}
}
// perform actual write only if content is different
if (memcmp (mbr, bootLoaderBuf, TC_MAX_MBR_BOOT_CODE_SIZE))
{
memcpy (mbr, bootLoaderBuf, TC_MAX_MBR_BOOT_CODE_SIZE);
device.SeekAt (0);
@ -3530,11 +3535,21 @@ namespace VeraCrypt
if (memcmp (mbr, mbrVerificationBuf, sizeof (mbr)) != 0)
throw ErrorException ("ERROR_MBR_PROTECTED", SRC_POS);
}
if (!PostOOBEMode)
{
// Write boot loader
device.SeekAt (TC_SECTOR_SIZE_BIOS);
device.Write (bootLoaderBuf + TC_SECTOR_SIZE_BIOS, sizeof (bootLoaderBuf) - TC_SECTOR_SIZE_BIOS);
}
}
catch (...)
{
if (!PostOOBEMode)
throw;
}
}
if (!IsAdmin() && IsUacSupported())
{