VeraCrypt
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkavsrf <kavsrf@gmail.com>2017-06-14 09:49:40 (GMT)
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2017-06-18 13:52:10 (GMT)
commitaede42a840cc6e3509048182eb204b5ce8f3187c (patch)
tree49623debea5bda47325e71850a32506209ab9aec
parent37c62bedd36ae255a036fb9e77f529a1021abb9a (diff)
downloadVeraCrypt-DCS-aede42a840cc6e3509048182eb204b5ce8f3187c.zip
VeraCrypt-DCS-aede42a840cc6e3509048182eb204b5ce8f3187c.tar.gz
BML update to sort "BootOrder"
-rw-r--r--DcsBml/DcsBml.c52
-rw-r--r--DcsBoot/DcsBoot.c8
-rw-r--r--Include/Library/CommonLib.h3
-rw-r--r--Library/CommonLib/EfiVar.c9
4 files changed, 44 insertions, 28 deletions
diff --git a/DcsBml/DcsBml.c b/DcsBml/DcsBml.c
index f5aaf3a..3a5406f 100644
--- a/DcsBml/DcsBml.c
+++ b/DcsBml/DcsBml.c
@@ -33,7 +33,7 @@ typedef struct _BML_GLOBALS {
} BML_GLOBALS, *PBML_GLOBALS;
STATIC PBML_GLOBALS gBmlData = NULL;
-STATIC BOOLEAN BootMenuLocked = FALSE;
+STATIC BOOLEAN BootMenuLocked = TRUE;
EFI_EVENT mBmlVirtualAddrChangeEvent;
EFI_SET_VARIABLE orgSetVariable = NULL;
@@ -138,6 +138,32 @@ DcsBmlUnload(
return EFI_SUCCESS;
}
+//////////////////////////////////////////////////////////////////////////
+// Boot order
+//////////////////////////////////////////////////////////////////////////
+EFI_STATUS
+UpdateBootOrder()
+{
+ EFI_STATUS res;
+ UINT16 DcsBootNum = 0x0DC5B;
+ UINTN boIndex = 1;
+ UINTN len;
+ UINT32 attr;
+ CHAR16* tmp = NULL;
+ res = EfiGetVar(L"BootDC5B", &gEfiGlobalVariableGuid, &tmp, &len, &attr);
+ if (EFI_ERROR(res)) {
+ InitFS();
+ res = BootMenuItemCreate(L"BootDC5B", sDcsBootEfiDesc, gFileRootHandle, sDcsBootEfi, TRUE);
+ res = BootOrderInsert(L"BootOrder", 0, 0x0DC5B);
+ } else {
+ if (EFI_ERROR(BootOrderPresent(L"BootOrder", 0x0DC5B, &boIndex) || boIndex != 0)) {
+ res = BootOrderInsert(L"BootOrder", 0, 0x0DC5B);
+ }
+ }
+ res = EfiSetVar(L"BootNext", &gEfiGlobalVariableGuid, &DcsBootNum, sizeof(DcsBootNum), EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS);
+ MEM_FREE(tmp);
+ return res;
+}
/**
The actual entry point for the application.
@@ -173,7 +199,7 @@ DcsBmlMain(
ASSERT_EFI_ERROR(res);
if (EFI_ERROR(res)) {
- Print(L"Install protocol %r\n", res);
+ ERR_PRINT(L"Install protocol %r\n", res);
return res;
}
@@ -185,7 +211,7 @@ DcsBmlMain(
);
if (EFI_ERROR(res)) {
- Print(L"Allocate runtime globals %r\n", res);
+ ERR_PRINT(L"Allocate runtime globals %r\n", res);
return res;
}
@@ -202,29 +228,15 @@ DcsBmlMain(
);
if (EFI_ERROR(res)) {
- Print(L"Register notify %r\n", res);
+ ERR_PRINT(L"Register notify %r\n", res);
return res;
}
+ UpdateBootOrder();
+
orgSetVariable = gST->RuntimeServices->SetVariable;
gST->RuntimeServices->SetVariable = BmlSetVaribale;
- // select boot next
- {
- UINT16 DcsBootNum = 0x0DC5B;
- UINTN len;
- UINT32 attr;
- CHAR16* tmp = NULL;
- res = EfiGetVar(L"BootDC5B", &gEfiGlobalVariableGuid, &tmp, &len, &attr);
- if (EFI_ERROR(res)) {
- InitFS();
- res = BootMenuItemCreate(L"BootDC5B", sDcsBootEfiDesc, gFileRootHandle, sDcsBootEfi, TRUE);
- res = BootOrderInsert(L"BootOrder", 0, 0x0DC5B);
- }
- res = EfiSetVar(L"BootNext", &gEfiGlobalVariableGuid, &DcsBootNum, sizeof(DcsBootNum), EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS);
- MEM_FREE(tmp);
- }
-
// Prepare BootDC5B
return EFI_SUCCESS;
}
diff --git a/DcsBoot/DcsBoot.c b/DcsBoot/DcsBoot.c
index 90dcb5d..de79e93 100644
--- a/DcsBoot/DcsBoot.c
+++ b/DcsBoot/DcsBoot.c
@@ -54,7 +54,7 @@ DoExecCmd()
CHAR16* sDcsBmlEfi = L"EFI\\VeraCrypt\\DcsBml.dcs";
CHAR16* sDcsBmlEfiDesc = L"VeraCrypt(DcsBml) driver";
CHAR16* sDcsBmlDriverVar = L"DriverDC5B";
-UINT16 sDcsBmlDriverNum = 0x0DC5B;
+UINT16 DcsBmlDriverNum = 0x0DC5B;
VOID
UpdateDriverBmlStart() {
@@ -72,12 +72,14 @@ UpdateDriverBmlStart() {
if (EFI_ERROR(res)) {
// No -> install
res = BootMenuItemCreate(sDcsBmlDriverVar, sDcsBmlEfiDesc, gFileRootHandle, sDcsBmlEfi, FALSE);
+// ERR_PRINT(L"Drv %s %r\n", sDcsBmlDriverVar, res);
if (!EFI_ERROR(res)) {
len = 0;
res = EfiGetVar(L"DriverOrder", &gEfiGlobalVariableGuid, &tmp, &len, &attr);
if (!EFI_ERROR(res)) len = len / 2;
- res = BootOrderInsert(L"DriverOrder", len, sDcsBmlDriverNum);
+ res = BootOrderInsert(L"DriverOrder", len, DcsBmlDriverNum);
}
+// ERR_PRINT(L"Drv order %d %r\n", len, res);
}
MEM_FREE(tmp);
}
@@ -86,7 +88,7 @@ UpdateDriverBmlStart() {
res = EfiGetVar(sDcsBmlDriverVar, &gEfiGlobalVariableGuid, &tmp, &len, &attr);
if (!EFI_ERROR(res)) {
BootMenuItemRemove(sDcsBmlDriverVar);
- BootOrderRemove(L"DriverOrder", sDcsBmlDriverNum);
+ BootOrderRemove(L"DriverOrder", DcsBmlDriverNum);
}
}
MEM_FREE(tmp);
diff --git a/Include/Library/CommonLib.h b/Include/Library/CommonLib.h
index d64ae41..cd7e068 100644
--- a/Include/Library/CommonLib.h
+++ b/Include/Library/CommonLib.h
@@ -609,7 +609,8 @@ BootOrderRemove(
EFI_STATUS
BootOrderPresent(
IN CHAR16 *OrderVarName,
- UINT16 value);
+ UINT16 value,
+ UINTN *index);
EFI_STATUS
BootMenuItemCreate(
diff --git a/Library/CommonLib/EfiVar.c b/Library/CommonLib/EfiVar.c
index e9c1082..e03544f 100644
--- a/Library/CommonLib/EfiVar.c
+++ b/Library/CommonLib/EfiVar.c
@@ -148,7 +148,8 @@ BootOrderRemove(
EFI_STATUS
BootOrderPresent(
IN CHAR16 *OrderVarName,
- UINT16 value)
+ UINT16 value,
+ UINTN *index)
{
EFI_STATUS res = EFI_NOT_READY;
UINT16* varBootOrder;
@@ -156,19 +157,19 @@ BootOrderPresent(
UINT32 varBootOrderAttr;
UINTN BootOrderCount;
UINTN i;
- UINTN j;
res = EfiGetVar(OrderVarName, &gEfiGlobalVariableGuid, &varBootOrder, &varBootOrderSize, &varBootOrderAttr);
if (EFI_ERROR(res)) return res;
BootOrderCount = varBootOrderSize / sizeof(UINT16);
res = EFI_NOT_FOUND;
- for (j = 0, i = 0; i < BootOrderCount; ++i) {
+ for (i = 0; i < BootOrderCount; ++i) {
if (varBootOrder[i] == value) {
- MEM_FREE(varBootOrder);
res = EFI_SUCCESS;
break;
}
}
+ if (index != NULL) *index = i;
+ MEM_FREE(varBootOrder);
return res;
}