From f22abf93dda59ec4289fd8f259eac384b14262a4 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Sat, 26 Oct 2019 22:07:50 +0200 Subject: Windows: Restore veraCrypt boot meny entry for system encryption more often, especially during PostOOBE calls, and handle additional corner cases. --- src/Common/BootEncryption.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/Common/BootEncryption.cpp b/src/Common/BootEncryption.cpp index ed1237c1..a784f57f 100644 --- a/src/Common/BootEncryption.cpp +++ b/src/Common/BootEncryption.cpp @@ -3321,8 +3321,15 @@ namespace VeraCrypt if (preserveUserConfig) { - bool bModifiedMsBoot = true; - EfiBootInst.GetFileSize(L"\\EFI\\Microsoft\\Boot\\bootmgfw.efi", loaderSize); + bool bModifiedMsBoot = true, bMissingMsBoot = false;; + if (EfiBootInst.FileExists (L"\\EFI\\Microsoft\\Boot\\bootmgfw.efi")) + EfiBootInst.GetFileSize(L"\\EFI\\Microsoft\\Boot\\bootmgfw.efi", loaderSize); + else + bMissingMsBoot = true; + + // restore boot menu entry in case of PostOOBE + if (PostOOBEMode) + EfiBootInst.SetStartExec(L"VeraCrypt BootLoader (DcsBoot)", L"\\EFI\\VeraCrypt\\DcsBoot.efi"); if (EfiBootInst.FileExists (L"\\EFI\\Microsoft\\Boot\\bootmgfw_ms.vc")) { @@ -3369,7 +3376,9 @@ namespace VeraCrypt if (EfiBootConf::IsPostExecFileField (conf.actionSuccessValue, loaderPath)) { // check that it is not bootmgfw.efi - if (0 != _wcsicmp (loaderPath.c_str(), L"\\EFI\\Microsoft\\Boot\\bootmgfw.efi")) + if ( (0 != _wcsicmp (loaderPath.c_str(), L"\\EFI\\Microsoft\\Boot\\bootmgfw.efi")) + && (EfiBootInst.FileExists (loaderPath.c_str())) + ) { // look for bootmgfw.efi identifiant string EfiBootInst.GetFileSize(loaderPath.c_str(), loaderSize); @@ -3387,16 +3396,16 @@ namespace VeraCrypt } } - if (!bFound) + if (!bFound && !PostOOBEMode) throw ErrorException ("WINDOWS_EFI_BOOT_LOADER_MISSING", SRC_POS); } } - if (PostOOBEMode) - { + if (PostOOBEMode && EfiBootInst.FileExists (L"\\EFI\\VeraCrypt\\DcsBoot.efi")) + { // check if bootmgfw.efi has been set again to Microsoft version // if yes, replace it with our bootloader after it was copied to bootmgfw_ms.vc - if (!bModifiedMsBoot) + if (!bModifiedMsBoot || bMissingMsBoot) EfiBootInst.CopyFile (L"\\EFI\\VeraCrypt\\DcsBoot.efi", L"\\EFI\\Microsoft\\Boot\\bootmgfw.efi"); if (EfiBootInst.FileExists (szStdEfiBootloader)) -- cgit v1.2.3