mirror of
https://github.com/veracrypt/VeraCrypt.git
synced 2025-11-11 11:08:02 -06:00
Windows: Add new registry flags for SystemFavoritesService to control updating of EFI BIOS boot menu on shutdown. This will help better manage multi-boot scenarios where we should not mess up with boot order (e.g. grub2 case)
This commit is contained in:
@@ -1030,7 +1030,7 @@ namespace VeraCrypt
|
|||||||
|
|
||||||
static EfiBoot EfiBootInst;
|
static EfiBoot EfiBootInst;
|
||||||
|
|
||||||
BootEncryption::BootEncryption (HWND parent, bool postOOBE, bool setBootNext)
|
BootEncryption::BootEncryption (HWND parent, bool postOOBE, bool setBootEntry, bool forceFirstBootEntry, bool setBootNext)
|
||||||
: DriveConfigValid (false),
|
: DriveConfigValid (false),
|
||||||
ParentWindow (parent),
|
ParentWindow (parent),
|
||||||
RealSystemDriveSizeValid (false),
|
RealSystemDriveSizeValid (false),
|
||||||
@@ -1042,7 +1042,9 @@ namespace VeraCrypt
|
|||||||
SelectedPrfAlgorithmId (0),
|
SelectedPrfAlgorithmId (0),
|
||||||
VolumeHeaderValid (false),
|
VolumeHeaderValid (false),
|
||||||
PostOOBEMode (postOOBE),
|
PostOOBEMode (postOOBE),
|
||||||
SetBootNext (setBootNext)
|
SetBootNext (setBootNext),
|
||||||
|
SetBootEntry (setBootEntry),
|
||||||
|
ForceFirstBootEntry (forceFirstBootEntry)
|
||||||
{
|
{
|
||||||
HiddenOSCandidatePartition.IsGPT = FALSE;
|
HiddenOSCandidatePartition.IsGPT = FALSE;
|
||||||
HiddenOSCandidatePartition.Number = (size_t) -1;
|
HiddenOSCandidatePartition.Number = (size_t) -1;
|
||||||
@@ -2682,7 +2684,7 @@ namespace VeraCrypt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EfiBoot::SetStartExec(wstring description, wstring execPath, bool setBootNext, uint16 statrtOrderNum , wchar_t* type, uint32 attr) {
|
void EfiBoot::SetStartExec(wstring description, wstring execPath, bool setBootEntry, bool forceFirstBootEntry, bool setBootNext, uint16 statrtOrderNum , wchar_t* type, uint32 attr) {
|
||||||
SetPrivilege(SE_SYSTEM_ENVIRONMENT_NAME, TRUE);
|
SetPrivilege(SE_SYSTEM_ENVIRONMENT_NAME, TRUE);
|
||||||
// Check EFI
|
// Check EFI
|
||||||
if (!IsEfiBoot()) {
|
if (!IsEfiBoot()) {
|
||||||
@@ -2799,27 +2801,37 @@ namespace VeraCrypt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create new entry if absent
|
if (setBootEntry)
|
||||||
if (startOrderNumPos == UINT_MAX) {
|
{
|
||||||
if (bDeviceInfoValid)
|
// Create new entry if absent
|
||||||
{
|
if (startOrderNumPos == UINT_MAX) {
|
||||||
for (uint32 i = startOrderLen / 2; i > 0; --i) {
|
if (bDeviceInfoValid)
|
||||||
|
{
|
||||||
|
if (forceFirstBootEntry)
|
||||||
|
{
|
||||||
|
for (uint32 i = startOrderLen / 2; i > 0; --i) {
|
||||||
|
startOrder[i] = startOrder[i - 1];
|
||||||
|
}
|
||||||
|
startOrder[0] = statrtOrderNum;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
startOrder[startOrderLen/2] = statrtOrderNum;
|
||||||
|
}
|
||||||
|
startOrderLen += 2;
|
||||||
|
startOrderUpdate = true;
|
||||||
|
}
|
||||||
|
} else if ((startOrderNumPos > 0) && forceFirstBootEntry) {
|
||||||
|
for (uint32 i = startOrderNumPos; i > 0; --i) {
|
||||||
startOrder[i] = startOrder[i - 1];
|
startOrder[i] = startOrder[i - 1];
|
||||||
}
|
}
|
||||||
startOrder[0] = statrtOrderNum;
|
startOrder[0] = statrtOrderNum;
|
||||||
startOrderLen += 2;
|
|
||||||
startOrderUpdate = true;
|
startOrderUpdate = true;
|
||||||
}
|
}
|
||||||
} else if (startOrderNumPos > 0) {
|
|
||||||
for (uint32 i = startOrderNumPos; i > 0; --i) {
|
|
||||||
startOrder[i] = startOrder[i - 1];
|
|
||||||
}
|
|
||||||
startOrder[0] = statrtOrderNum;
|
|
||||||
startOrderUpdate = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (startOrderUpdate) {
|
if (startOrderUpdate) {
|
||||||
SetFirmwareEnvironmentVariable(order.c_str(), EfiVarGuid, startOrder, startOrderLen);
|
SetFirmwareEnvironmentVariable(order.c_str(), EfiVarGuid, startOrder, startOrderLen);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setBootNext)
|
if (setBootNext)
|
||||||
@@ -3333,7 +3345,7 @@ namespace VeraCrypt
|
|||||||
|
|
||||||
// restore boot menu entry in case of PostOOBE
|
// restore boot menu entry in case of PostOOBE
|
||||||
if (PostOOBEMode)
|
if (PostOOBEMode)
|
||||||
EfiBootInst.SetStartExec(L"VeraCrypt BootLoader (DcsBoot)", L"\\EFI\\VeraCrypt\\DcsBoot.efi", SetBootNext);
|
EfiBootInst.SetStartExec(L"VeraCrypt BootLoader (DcsBoot)", L"\\EFI\\VeraCrypt\\DcsBoot.efi", SetBootEntry, ForceFirstBootEntry, SetBootNext);
|
||||||
|
|
||||||
if (EfiBootInst.FileExists (L"\\EFI\\Microsoft\\Boot\\bootmgfw_ms.vc"))
|
if (EfiBootInst.FileExists (L"\\EFI\\Microsoft\\Boot\\bootmgfw_ms.vc"))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -209,7 +209,7 @@ namespace VeraCrypt
|
|||||||
bool IsEfiBoot();
|
bool IsEfiBoot();
|
||||||
|
|
||||||
void DeleteStartExec(uint16 statrtOrderNum = 0xDC5B, wchar_t* type = NULL);
|
void DeleteStartExec(uint16 statrtOrderNum = 0xDC5B, wchar_t* type = NULL);
|
||||||
void SetStartExec(wstring description, wstring execPath, bool setBootNext = true, uint16 statrtOrderNum = 0xDC5B, wchar_t* type = NULL, uint32 attr = 1);
|
void SetStartExec(wstring description, wstring execPath, bool setBootEntry = true, bool forceFirstBootEntry = true, bool setBootNext = true, uint16 statrtOrderNum = 0xDC5B, wchar_t* type = NULL, uint32 attr = 1);
|
||||||
void SaveFile(const wchar_t* name, byte* data, DWORD size);
|
void SaveFile(const wchar_t* name, byte* data, DWORD size);
|
||||||
void GetFileSize(const wchar_t* name, unsigned __int64& size);
|
void GetFileSize(const wchar_t* name, unsigned __int64& size);
|
||||||
void ReadFile(const wchar_t* name, byte* data, DWORD size);
|
void ReadFile(const wchar_t* name, byte* data, DWORD size);
|
||||||
@@ -240,7 +240,7 @@ namespace VeraCrypt
|
|||||||
class BootEncryption
|
class BootEncryption
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BootEncryption (HWND parent, bool postOOBE = false, bool setBootNext = false);
|
BootEncryption (HWND parent, bool postOOBE = false, bool setBootEntry = true, bool forceFirstBootEntry = true, bool setBootNext = false);
|
||||||
~BootEncryption ();
|
~BootEncryption ();
|
||||||
|
|
||||||
enum FilterType
|
enum FilterType
|
||||||
@@ -353,6 +353,8 @@ namespace VeraCrypt
|
|||||||
bool VolumeHeaderValid;
|
bool VolumeHeaderValid;
|
||||||
bool PostOOBEMode;
|
bool PostOOBEMode;
|
||||||
bool SetBootNext;
|
bool SetBootNext;
|
||||||
|
bool SetBootEntry;
|
||||||
|
bool ForceFirstBootEntry;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -371,6 +373,8 @@ namespace VeraCrypt
|
|||||||
|
|
||||||
#define VC_SYSTEM_FAVORITES_SERVICE_CONFIG_DONT_UPDATE_LOADER 0x1
|
#define VC_SYSTEM_FAVORITES_SERVICE_CONFIG_DONT_UPDATE_LOADER 0x1
|
||||||
#define VC_SYSTEM_FAVORITES_SERVICE_CONFIG_FORCE_SET_BOOTNEXT 0x2
|
#define VC_SYSTEM_FAVORITES_SERVICE_CONFIG_FORCE_SET_BOOTNEXT 0x2
|
||||||
|
#define VC_SYSTEM_FAVORITES_SERVICE_CONFIG_DONT_SET_BOOTENTRY 0x4
|
||||||
|
#define VC_SYSTEM_FAVORITES_SERVICE_CONFIG_DONT_FORCE_FIRST_BOOTENTRY 0x8
|
||||||
|
|
||||||
#define VC_WINDOWS_UPGRADE_POSTOOBE_CMDLINE_OPTION L"/PostOOBE"
|
#define VC_WINDOWS_UPGRADE_POSTOOBE_CMDLINE_OPTION L"/PostOOBE"
|
||||||
|
|
||||||
|
|||||||
@@ -9436,9 +9436,16 @@ static DWORD WINAPI SystemFavoritesServiceCtrlHandler ( DWORD dwControl,
|
|||||||
{
|
{
|
||||||
// re-install our bootloader again in case the update process has removed it.
|
// re-install our bootloader again in case the update process has removed it.
|
||||||
bool bForceSetNextBoot = false;
|
bool bForceSetNextBoot = false;
|
||||||
if (BootEncObj->ReadServiceConfigurationFlags () & VC_SYSTEM_FAVORITES_SERVICE_CONFIG_FORCE_SET_BOOTNEXT)
|
bool bSetBootentry = true;
|
||||||
|
bool bForceFirstBootEntry = true;
|
||||||
|
uint32 flags = BootEncObj->ReadServiceConfigurationFlags ();
|
||||||
|
if (flags & VC_SYSTEM_FAVORITES_SERVICE_CONFIG_FORCE_SET_BOOTNEXT)
|
||||||
bForceSetNextBoot = true;
|
bForceSetNextBoot = true;
|
||||||
BootEncryption bootEnc (NULL, true, bForceSetNextBoot);
|
if (flags & VC_SYSTEM_FAVORITES_SERVICE_CONFIG_DONT_SET_BOOTENTRY)
|
||||||
|
bSetBootentry = false;
|
||||||
|
if (flags & VC_SYSTEM_FAVORITES_SERVICE_CONFIG_DONT_FORCE_FIRST_BOOTENTRY)
|
||||||
|
bForceFirstBootEntry = false;
|
||||||
|
BootEncryption bootEnc (NULL, true, bSetBootentry, bForceFirstBootEntry, bForceSetNextBoot);
|
||||||
bootEnc.InstallBootLoader (true);
|
bootEnc.InstallBootLoader (true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user