forked from rtkypoeluev/efitools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShimReplace.c
63 lines (48 loc) · 1.46 KB
/
ShimReplace.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
/*
* Copyright 2016 <[email protected]>
*
* see COPYING file
*
* Replacement for shim.efi which is signed by your own key
* and installs the shim protocol verifier for grub to use
* so the secure boot chain is unbroken
*/
#include <efi.h>
#include <efilib.h>
#include <console.h>
#include <guid.h>
#include <efiauthenticated.h>
#include <execute.h>
#include <shim_protocol.h>
#include <pkcs7verify.h>
static const CHAR16 *loader = L"\\grub.efi";
static const CHAR16 *fallback = L"\\fallback.efi";
EFI_STATUS
efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab)
{
EFI_STATUS efi_status;
EFI_PKCS7_VERIFY_PROTOCOL *p7vp;
CHAR16 *error;
void *ptr;
InitializeLib(image, systab);
efi_status = pkcs7verify_get_protocol(image, &p7vp, &error);
if (efi_status != EFI_SUCCESS) {
console_error(error, efi_status);
return efi_status;
}
efi_status = shim_protocol_install();
if (efi_status != EFI_SUCCESS)
console_error(L"Failed to install shim protocol", efi_status);
efi_status = BS->LocateProtocol(&MOK_OWNER,
NULL, &ptr);
if (efi_status != EFI_SUCCESS)
console_error(L"Failed to locate shim protocol", efi_status);
efi_status = execute(image, loader);
if (efi_status == EFI_SUCCESS)
return efi_status;
console_error(L"Failed to start primary loader", efi_status);
efi_status = execute(image, fallback);
if (efi_status != EFI_SUCCESS)
console_error(L"Failed to start fallback loader", efi_status);
return efi_status;
}