From 4566f95fd9f70530866457beb545a794cc80e1d0 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Mon, 23 Sep 2019 18:33:04 +0200 Subject: make the rescue disk boot machine directly from disk if "VeraCrypt" folder is missing. This make it easy to create a bootable disk for VeraCrypt from the rescue disk by just removing or renaming its "VeraCrypt" folder. --- DcsRe/DcsRe.c | 93 +++++++++++++++++++++++++-------------------- Include/Library/CommonLib.h | 6 +++ Library/CommonLib/EfiFile.c | 16 ++++++++ 3 files changed, 74 insertions(+), 41 deletions(-) diff --git a/DcsRe/DcsRe.c b/DcsRe/DcsRe.c index d2b43dd..84f1fee 100644 --- a/DcsRe/DcsRe.c +++ b/DcsRe/DcsRe.c @@ -349,56 +349,67 @@ DcsReMain( ERR_PRINT(L"InitFS %r\n", res); return res; } + + if (!EFI_ERROR(DirectoryExists(NULL, L"EFI\\VeraCrypt"))) + { + item = DcsMenuAppend(NULL, L"Decrypt OS", 'd', ActionDecryptOS, NULL); + gMenu = item; + item = DcsMenuAppend(item, L"Restore VeraCrypt loader to boot menu", 'm', ActionRestoreDcsBootMenu, NULL); + item = DcsMenuAppend(item, L"Remove VeraCrypt loader from boot menu", 'z' , ActionRemoveDcsBootMenu, NULL); - item = DcsMenuAppend(NULL, L"Decrypt OS", 'd', ActionDecryptOS, NULL); - gMenu = item; - item = DcsMenuAppend(item, L"Restore VeraCrypt loader to boot menu", 'm', ActionRestoreDcsBootMenu, NULL); - item = DcsMenuAppend(item, L"Remove VeraCrypt loader from boot menu", 'z' , ActionRemoveDcsBootMenu, NULL); - - if (!EFI_ERROR(FileExist(NULL, L"EFI\\VeraCrypt\\DcsProp"))) { - item = DcsMenuAppend(item, L"Restore VeraCrypt loader configuration to system disk", 'c', ActionRestoreDcsProp, NULL); - } + if (!EFI_ERROR(FileExist(NULL, L"EFI\\VeraCrypt\\DcsProp"))) { + item = DcsMenuAppend(item, L"Restore VeraCrypt loader configuration to system disk", 'c', ActionRestoreDcsProp, NULL); + } - if (!EFI_ERROR(FileExist(NULL, L"EFI\\VeraCrypt\\svh_bak"))) { - item = DcsMenuAppend(item, L"Restore OS header keys", 'k', ActionRestoreHeader, NULL); - } + if (!EFI_ERROR(FileExist(NULL, L"EFI\\VeraCrypt\\svh_bak"))) { + item = DcsMenuAppend(item, L"Restore OS header keys", 'k', ActionRestoreHeader, NULL); + } - if (!EFI_ERROR(FileExist(NULL, L"EFI\\VeraCrypt\\DcsBoot.efi"))) { - item = DcsMenuAppend(item, L"Restore VeraCrypt loader binaries to system disk", 'r', ActionRestoreDcsLoader, NULL); - item = DcsMenuAppend(item, L"Boot VeraCrypt loader from rescue disk", 'v', ActionDcsBoot, NULL); - } - - item = DcsMenuAppend(item, L"Boot Original Windows Loader", 'o', ActionWindowsBoot, NULL); + if (!EFI_ERROR(FileExist(NULL, L"EFI\\VeraCrypt\\DcsBoot.efi"))) { + item = DcsMenuAppend(item, L"Restore VeraCrypt loader binaries to system disk", 'r', ActionRestoreDcsLoader, NULL); + item = DcsMenuAppend(item, L"Boot VeraCrypt loader from rescue disk", 'v', ActionDcsBoot, NULL); + } + + item = DcsMenuAppend(item, L"Boot Original Windows Loader", 'o', ActionWindowsBoot, NULL); - if (!EFI_ERROR(FileExist(NULL, L"EFI\\Boot\\WinPE_boot" ARCHdotEFI))) { - item = DcsMenuAppend(item, L"Boot Windows PE from rescue disk", 'w', ActionBootWinPE, NULL); - } + if (!EFI_ERROR(FileExist(NULL, L"EFI\\Boot\\WinPE_boot" ARCHdotEFI))) { + item = DcsMenuAppend(item, L"Boot Windows PE from rescue disk", 'w', ActionBootWinPE, NULL); + } - if (!EFI_ERROR(FileExist(NULL, L"EFI\\Shell\\Shell.efi"))) { - item = DcsMenuAppend(item, L"Boot Shell.efi from rescue disk", 's', ActionShell, NULL); - } + if (!EFI_ERROR(FileExist(NULL, L"EFI\\Shell\\Shell.efi"))) { + item = DcsMenuAppend(item, L"Boot Shell.efi from rescue disk", 's', ActionShell, NULL); + } - item = DcsMenuAppend(item, L"Help", 'h', ActionHelp, NULL); - item = DcsMenuAppend(item, L"Exit", 'e', ActionExit, NULL); - OUT_PRINT(L"%V%a rescue disk %a%N\n", TC_APP_NAME, VERSION_STRING); - gBS->SetWatchdogTimer(0, 0, 0, NULL); - do { - DcsMenuPrint(gMenu); - item = NULL; - key.UnicodeChar = 0; - while (item == NULL) { - item = gMenu; - key = GetKey(); - while (item != NULL) { - if (item->Select == key.UnicodeChar) break; - item = item->Next; + item = DcsMenuAppend(item, L"Help", 'h', ActionHelp, NULL); + item = DcsMenuAppend(item, L"Exit", 'e', ActionExit, NULL); + OUT_PRINT(L"%V%a rescue disk %a%N\n", TC_APP_NAME, VERSION_STRING); + gBS->SetWatchdogTimer(0, 0, 0, NULL); + do { + DcsMenuPrint(gMenu); + item = NULL; + key.UnicodeChar = 0; + while (item == NULL) { + item = gMenu; + key = GetKey(); + while (item != NULL) { + if (item->Select == key.UnicodeChar) break; + item = item->Next; + } } - } - OUT_PRINT(L"%c\n",key.UnicodeChar); - res = item->Action(item->Context); + OUT_PRINT(L"%c\n",key.UnicodeChar); + res = item->Action(item->Context); + if (EFI_ERROR(res)) { + ERR_PRINT(L"%r\n", res); + } + } while (gContiniue); + } + else + { + /* No VeraCrypt folder. Boot directly from the hard drive */ + res = ActionDcsBoot (NULL); if (EFI_ERROR(res)) { ERR_PRINT(L"%r\n", res); } - } while (gContiniue); + } return EFI_INVALID_PARAMETER; } diff --git a/Include/Library/CommonLib.h b/Include/Library/CommonLib.h index 4d207ca..0bfb631 100644 --- a/Include/Library/CommonLib.h +++ b/Include/Library/CommonLib.h @@ -663,6 +663,12 @@ DirectoryCreate( IN EFI_FILE* root, IN CHAR16* name ); + +EFI_STATUS +DirectoryExists( + IN EFI_FILE* root, + IN CHAR16* name + ); EFI_STATUS FileOpenRoot( diff --git a/Library/CommonLib/EfiFile.c b/Library/CommonLib/EfiFile.c index 8a9d6d7..4ea164e 100644 --- a/Library/CommonLib/EfiFile.c +++ b/Library/CommonLib/EfiFile.c @@ -57,6 +57,22 @@ DirectoryCreate( return res; } +EFI_STATUS +DirectoryExists( + IN EFI_FILE* root, + IN CHAR16* name + ) +{ + EFI_FILE* file; + EFI_STATUS res; + if (!name) { return EFI_INVALID_PARAMETER; } + + res = FileOpen(root, name, &file, EFI_FILE_MODE_READ, EFI_FILE_DIRECTORY); + if (EFI_ERROR(res)) return res; + FileClose(file); + return EFI_SUCCESS; +} + EFI_STATUS FileOpenRoot( IN EFI_HANDLE rootHandle, -- cgit v1.2.3