diff options
author | Michael Brown <mcb30@ipxe.org> | 2023-05-23 13:25:44 +0100 |
---|---|---|
committer | Michael Brown <mcb30@ipxe.org> | 2023-05-23 13:25:44 +0100 |
commit | 66af429f238b335e97c24e0afd7cedba35ffd63a (patch) | |
tree | 9620a2d17441e1bcc2a8d58d962511ad8ae7745b | |
parent | a95439a5188d96988ad7031cace084a13fcede14 (diff) | |
download | ipxe-shim3.tar.gz |
WIP - first successful sbat hackshim3
-rw-r--r-- | src/config/console.h | 2 | ||||
-rw-r--r-- | src/interface/efi/efi_file.c | 3 | ||||
-rw-r--r-- | src/interface/efi/efi_shim.c | 57 |
3 files changed, 60 insertions, 2 deletions
diff --git a/src/config/console.h b/src/config/console.h index 9f770d094..689e0519f 100644 --- a/src/config/console.h +++ b/src/config/console.h @@ -39,7 +39,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); //#define CONSOLE_SYSLOG /* Syslog console */ //#define CONSOLE_SYSLOGS /* Encrypted syslog console */ //#define CONSOLE_VMWARE /* VMware logfile console */ -//#define CONSOLE_DEBUGCON /* Bochs/QEMU/KVM debug port console */ +#define CONSOLE_DEBUGCON /* Bochs/QEMU/KVM debug port console */ //#define CONSOLE_INT13 /* INT13 disk log console */ /* diff --git a/src/interface/efi/efi_file.c b/src/interface/efi/efi_file.c index 2ae3a0cb4..8aa694ad9 100644 --- a/src/interface/efi/efi_file.c +++ b/src/interface/efi/efi_file.c @@ -538,6 +538,9 @@ static EFI_STATUS efi_file_read_dir ( struct efi_file *file, UINTN *len, /* Construct directory entries for image-backed files */ index = file->pos; + // + DBG ( "***** readdir %d\n", index ); + for_each_image ( image ) { /* Skip hidden images */ diff --git a/src/interface/efi/efi_shim.c b/src/interface/efi/efi_shim.c index 42faaa6dd..fcf68df8d 100644 --- a/src/interface/efi/efi_shim.c +++ b/src/interface/efi/efi_shim.c @@ -91,7 +91,7 @@ struct image_tag efi_shim __image_tag = { /** UEFI shim crutch image */ struct image_tag efi_shim_crutch __image_tag = { - .name = "SHIMCRUTCH", + .name = "CRUTCH", }; /** Original GetMemoryMap() function */ @@ -184,6 +184,7 @@ static int efi_shim_inhibit_pxe ( EFI_HANDLE handle ) { * @ret rc Return status code */ static int efi_shim_cmdline ( struct image *shim, wchar_t **cmdline ) { + struct image *crutch = find_image_tag ( &efi_shim_crutch ); wchar_t *shimcmdline; int len; int rc; @@ -192,6 +193,9 @@ static int efi_shim_cmdline ( struct image *shim, wchar_t **cmdline ) { len = ( shim->cmdline ? efi_asprintf ( &shimcmdline, "%s %s", shim->name, shim->cmdline ) : + crutch ? + efi_asprintf ( &shimcmdline, "%s %s wtf does this do", shim->name, + crutch->name ) : efi_asprintf ( &shimcmdline, "%s %ls", shim->name, *cmdline ) ); if ( len < 0 ) { @@ -208,6 +212,50 @@ static int efi_shim_cmdline ( struct image *shim, wchar_t **cmdline ) { return 0; } +static EFI_GET_VARIABLE orig_get_var; +static EFI_SET_VARIABLE orig_set_var; +static int just_set; + +// +static EFI_STATUS EFIAPI +efi_shim_get_variable ( CHAR16 *name, EFI_GUID *guid, UINT32 *attrs, + UINTN *size, VOID *data ) { + static const CHAR16 foo[] = L"SbatLevel"; + EFI_STATUS efirc; + + efirc = orig_get_var ( name, guid, attrs, size, data ); + DBGC ( &efi_shim, "**** GetVariable ( %ls, %s ):\n", name, + efi_guid_ntoa ( guid ) ); + + if ( ( ! just_set ) && + ( memcmp ( name, foo, sizeof ( foo ) ) == 0 ) ) { + UINT8 *thing = data; + DBGC ( &efi_shim, "**** HAHAHAHAHA\n" ); + *thing = '\0'; + } + if ( data ) + just_set = 0; + + if ( data ) + DBGC_HDA ( &efi_shim, 0, data, *size ); + return efirc; +} + +static EFI_STATUS EFIAPI +efi_shim_set_variable ( CHAR16 *name, EFI_GUID *guid, UINT32 attrs, + UINTN size, VOID *data ) { + EFI_STATUS efirc; + + DBGC ( &efi_shim, "**** SetVariable ( %ls, %s ):\n", name, + efi_guid_ntoa ( guid ) ); + DBGC_HDA ( &efi_shim, 0, data, size ); + efirc = orig_set_var ( name, guid, attrs, size, data ); + + just_set = 1; + + return efirc; +} + /** * Install UEFI shim special handling * @@ -219,8 +267,15 @@ static int efi_shim_cmdline ( struct image *shim, wchar_t **cmdline ) { int efi_shim_install ( struct image *shim, EFI_HANDLE handle, wchar_t **cmdline ) { EFI_BOOT_SERVICES *bs = efi_systab->BootServices; + EFI_RUNTIME_SERVICES *rs = efi_systab->RuntimeServices; int rc; + // + orig_get_var = rs->GetVariable; + orig_set_var = rs->SetVariable; + rs->GetVariable = efi_shim_get_variable; + rs->SetVariable = efi_shim_set_variable; + /* Intercept GetMemoryMap() via boot services table */ efi_shim_orig_map = bs->GetMemoryMap; if ( ! efi_shim_require_loader ) |