Skip to content

Commit

Permalink
make the rescue disk boot machine directly from disk if "VeraCrypt" f…
Browse files Browse the repository at this point in the history
…older 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.
  • Loading branch information
idrassi committed Sep 23, 2019
1 parent 5135d1a commit 4566f95
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 41 deletions.
93 changes: 52 additions & 41 deletions DcsRe/DcsRe.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
6 changes: 6 additions & 0 deletions Include/Library/CommonLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
16 changes: 16 additions & 0 deletions Library/CommonLib/EfiFile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 4566f95

Please sign in to comment.