VeraCrypt
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Common/BootEncryption.cpp18
1 files changed, 2 insertions, 16 deletions
diff --git a/src/Common/BootEncryption.cpp b/src/Common/BootEncryption.cpp
index bf7a0f64..f79e7339 100644
--- a/src/Common/BootEncryption.cpp
+++ b/src/Common/BootEncryption.cpp
@@ -2634,50 +2634,43 @@ namespace VeraCrypt
}
bool EfiBoot::IsEfiBoot() {
DWORD BootOrderLen;
BootOrderLen = GetFirmwareEnvironmentVariable(L"BootOrder", EfiVarGuid, tempBuf, sizeof(tempBuf));
return (BootOrderLen != 0) || (GetLastError() != ERROR_INVALID_FUNCTION);
}
void EfiBoot::DeleteStartExec(uint16 statrtOrderNum, wchar_t* type) {
DWORD dwLastError;
BOOL bPrivilegesSet = IsPrivilegeEnabled (SE_SYSTEM_ENVIRONMENT_NAME);
if (!bPrivilegesSet && !SetPrivilege(SE_SYSTEM_ENVIRONMENT_NAME, TRUE))
{
dwLastError = GetLastError();
wchar_t szMsg[128];
StringCchPrintfW(szMsg, ARRAYSIZE(szMsg), L"Failed to set SE_SYSTEM_ENVIRONMENT_NAME privilege (error code 0x%.8X)", dwLastError);
throw ErrorException(szMsg, SRC_POS);
}
// Check EFI
if (!IsEfiBoot()) {
- dwLastError = GetLastError();
- if (dwLastError != ERROR_SUCCESS)
- {
if (!bPrivilegesSet)
SetPrivilege(SE_SYSTEM_ENVIRONMENT_NAME, FALSE);
- // format message to append the error code to the exception message
- wchar_t szMsg[128];
- StringCchPrintfW(szMsg, ARRAYSIZE(szMsg), L"Failed to detect EFI environment (error code 0x%.8X)", dwLastError);
- throw ErrorException(szMsg, SRC_POS);
- }
+ throw ErrorException(L"Failed to detect EFI environment (error ERROR_INVALID_FUNCTION)", SRC_POS);
}
wchar_t varName[256];
StringCchPrintfW(varName, ARRAYSIZE (varName), L"%s%04X", type == NULL ? L"Boot" : type, statrtOrderNum);
SetFirmwareEnvironmentVariable(varName, EfiVarGuid, NULL, 0);
wstring order = L"Order";
order.insert(0, type == NULL ? L"Boot" : type);
uint32 startOrderLen = GetFirmwareEnvironmentVariable(order.c_str(), EfiVarGuid, tempBuf, sizeof(tempBuf));
uint32 startOrderNumPos = UINT_MAX;
bool startOrderUpdate = false;
uint16* startOrder = (uint16*)tempBuf;
for (uint32 i = 0; i < startOrderLen / 2; i++) {
if (startOrder[i] == statrtOrderNum) {
startOrderNumPos = i;
break;
}
}
// delete entry if present
if (startOrderNumPos != UINT_MAX) {
@@ -2703,50 +2696,43 @@ namespace VeraCrypt
SetFirmwareEnvironmentVariable(next.c_str(), EfiVarGuid, startOrder, 0);
}
}
if (!bPrivilegesSet)
SetPrivilege(SE_SYSTEM_ENVIRONMENT_NAME, FALSE);
}
void EfiBoot::SetStartExec(wstring description, wstring execPath, bool setBootEntry, bool forceFirstBootEntry, bool setBootNext, uint16 statrtOrderNum , wchar_t* type, uint32 attr) {
DWORD dwLastError;
BOOL bPrivilegesSet = IsPrivilegeEnabled (SE_SYSTEM_ENVIRONMENT_NAME);
if (!bPrivilegesSet && !SetPrivilege(SE_SYSTEM_ENVIRONMENT_NAME, TRUE))
{
dwLastError = GetLastError();
wchar_t szMsg[128];
StringCchPrintfW(szMsg, ARRAYSIZE(szMsg), L"Failed to set SE_SYSTEM_ENVIRONMENT_NAME privilege (error code 0x%.8X)", dwLastError);
throw ErrorException(szMsg, SRC_POS);
}
// Check EFI
if (!IsEfiBoot()) {
- dwLastError = GetLastError();
- if (dwLastError != ERROR_SUCCESS)
- {
if (!bPrivilegesSet)
SetPrivilege(SE_SYSTEM_ENVIRONMENT_NAME, FALSE);
- // format message to append the error code to the exception message
- wchar_t szMsg[1024];
- StringCchPrintfW(szMsg, ARRAYSIZE(szMsg), L"Failed to detect EFI environment (error code 0x%.8X)", dwLastError);
- throw ErrorException(szMsg, SRC_POS);
- }
+ throw ErrorException(L"Failed to detect EFI environment (error ERROR_INVALID_FUNCTION)", SRC_POS);
}
if (bDeviceInfoValid)
{
uint32 varSize = 56;
varSize += ((uint32) description.length()) * 2 + 2;
varSize += ((uint32) execPath.length()) * 2 + 2;
uint8 *startVar = new uint8[varSize];
uint8 *pVar = startVar;
// Attributes (1b Active, 1000b - Hidden)
*(uint32 *)pVar = attr;
pVar += sizeof(uint32);
// Size Of device path + file path
*(uint16 *)pVar = (uint16)(50 + execPath.length() * 2 + 2);
pVar += sizeof(uint16);
// description
for (uint32 i = 0; i < description.length(); i++) {