forked from efidemon69/Voyager
-
Notifications
You must be signed in to change notification settings - Fork 2
/
UefiMain.c
73 lines (63 loc) · 2.27 KB
/
UefiMain.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "BootMgfw.h"
#include "SplashScreen.h"
CHAR8* gEfiCallerBaseName = "Voyager";
const UINT32 _gUefiDriverRevision = 0x200;
EFI_STATUS EFIAPI UefiUnload(EFI_HANDLE ImageHandle)
{
return EFI_SUCCESS;
}
EFI_STATUS EFIAPI UefiMain(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE* SystemTable)
{
EFI_STATUS Result;
EFI_HANDLE BootMgfwHandle;
EFI_DEVICE_PATH* BootMgfwPath = NULL;
gST->ConOut->ClearScreen(gST->ConOut);
gST->ConOut->OutputString(gST->ConOut, AsciiArt);
Print(L"\n");
// since we replaced bootmgfw on disk, we are going to need to restore the image back
// this is simply just moving bootmgfw.efi.backup to bootmgfw.efi...
// x64-86
if (EFI_ERROR((Result = RestoreBootMgfw())))
{
Print(L"unable to restore bootmgfw... reason -> %r\n", Result);
gBS->Stall(SEC_TO_MS(5));
return Result;
}
// the payload is sitting on disk... we are going to load it into memory then delete it...
if (EFI_ERROR((Result = LoadPayLoadFromDisk(&PayLoad))))
{
Print(L"failed to read payload from disk... reason -> %r\n", Result);
gBS->Stall(SEC_TO_MS(5));
return Result;
}
// get the device path to bootmgfw...
if (EFI_ERROR((Result = GetBootMgfwPath(&BootMgfwPath))))
{
Print(L"getting bootmgfw device path failed... reason -> %r\n", Result);
gBS->Stall(SEC_TO_MS(5));
return Result;
}
// load bootmgfw into memory...
if (EFI_ERROR((Result = gBS->LoadImage(TRUE, ImageHandle, BootMgfwPath, NULL, NULL, &BootMgfwHandle))))
{
Print(L"failed to load bootmgfw.efi... reason -> %r\n", Result);
gBS->Stall(SEC_TO_MS(5));
return EFI_ABORTED;
}
// install hooks on bootmgfw...
if (EFI_ERROR((Result = InstallBootMgfwHooks(BootMgfwHandle))))
{
Print(L"Failed to install bootmgfw hooks... reason -> %r\n", Result);
gBS->Stall(SEC_TO_MS(5));
return Result;
}
// wait 5 seconds then call the entry point of bootmgfw...
gBS->Stall(SEC_TO_MS(5));
if (EFI_ERROR((Result = gBS->StartImage(BootMgfwHandle, NULL, NULL))))
{
Print(L"Failed to start bootmgfw.efi... reason -> %r\n", Result);
gBS->Stall(SEC_TO_MS(5));
return EFI_ABORTED;
}
return EFI_SUCCESS;
}