diff options
author | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2024-09-17 18:25:52 +0200 |
---|---|---|
committer | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2024-09-17 18:25:52 +0200 |
commit | 380850787e59152100eed8c5c06d0e81a34e39e0 (patch) | |
tree | 444cb3c00aa81a6d40b0a6103f7eb34a1d997467 | |
parent | 866fc8f5137925e684ea855111affe2d71612b88 (diff) | |
download | VeraCrypt-380850787e59152100eed8c5c06d0e81a34e39e0.tar.gz VeraCrypt-380850787e59152100eed8c5c06d0e81a34e39e0.zip |
Windows: Simplify error message related to IsEfiBoot since it always fail with ERROR_INVALID_FUNCTION
Proposed by @kriegste on https://github.com/veracrypt/VeraCrypt/issues/360
-rw-r--r-- | src/Common/BootEncryption.cpp | 18 |
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++) { |