diff options
Diffstat (limited to 'UefiLessonsPkg')
-rw-r--r-- | UefiLessonsPkg/HiddenSettings/Data.h | 17 | ||||
-rw-r--r-- | UefiLessonsPkg/HiddenSettings/Form.vfr | 93 | ||||
-rw-r--r-- | UefiLessonsPkg/HiddenSettings/HiddenSettings.c | 267 | ||||
-rw-r--r-- | UefiLessonsPkg/HiddenSettings/HiddenSettings.inf | 32 | ||||
-rw-r--r-- | UefiLessonsPkg/HiddenSettings/Strings.uni | 28 | ||||
-rw-r--r-- | UefiLessonsPkg/ShowHIIext/ShowHIIext.c | 216 | ||||
-rw-r--r-- | UefiLessonsPkg/ShowHIIext/ShowHIIext.inf | 32 | ||||
-rw-r--r-- | UefiLessonsPkg/ShowHIIext/Strings.uni | 20 | ||||
-rw-r--r-- | UefiLessonsPkg/UefiLessonsPkg.dsc | 2 |
9 files changed, 707 insertions, 0 deletions
diff --git a/UefiLessonsPkg/HiddenSettings/Data.h b/UefiLessonsPkg/HiddenSettings/Data.h new file mode 100644 index 0000000..171e406 --- /dev/null +++ b/UefiLessonsPkg/HiddenSettings/Data.h @@ -0,0 +1,17 @@ +#ifndef _DATA_H_ +#define _DATA_H_ + +#define FORMSET_GUID {0x98259761, 0x6b0b, 0x4531, {0xa7, 0x4b, 0x67, 0xaf, 0x5d, 0x8a, 0x81, 0x53}} +#define DATAPATH_GUID {0x3f3d5b97, 0x48e8, 0x4f4a, {0x85, 0x1e, 0x82, 0xe6, 0x50, 0x93, 0x0a, 0xeb}} +#define STORAGE_GUID {0x3f5996a7, 0x8b56, 0x472c, {0x95, 0x38, 0x47, 0x5f, 0x77, 0x15, 0x7c, 0x84}} +#define STORAGE_EFI_GUID {0x01539e15, 0x2a73, 0x4aaf, {0x9d, 0x3e, 0x43, 0x7b, 0xfa, 0xbb, 0x46, 0x66}} + +#pragma pack(1) +typedef struct { + UINT8 CheckboxValue; + UINT16 NumericValue; + UINT8 OneOfValue; +} VARIABLE_STRUCTURE; +#pragma pack() + +#endif diff --git a/UefiLessonsPkg/HiddenSettings/Form.vfr b/UefiLessonsPkg/HiddenSettings/Form.vfr new file mode 100644 index 0000000..1aafddc --- /dev/null +++ b/UefiLessonsPkg/HiddenSettings/Form.vfr @@ -0,0 +1,93 @@ +#include <Uefi/UefiMultiPhase.h> +#include "Data.h" + +formset + guid = FORMSET_GUID, + title = STRING_TOKEN(FORMSET_TITLE), + help = STRING_TOKEN(FORMSET_HELP), + + varstore VARIABLE_STRUCTURE, + name = FormData, + guid = STORAGE_GUID; + + efivarstore VARIABLE_STRUCTURE, + attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE, + name = FormEfiData, + guid = STORAGE_EFI_GUID; + + defaultstore StandardDefault, + prompt = STRING_TOKEN(STANDARD_DEFAULT_PROMPT), + attribute = 0x0000; + + form + formid = 1, + title = STRING_TOKEN(FORMID1_TITLE); + +suppressif TRUE; + checkbox + varid = FormData.CheckboxValue, + prompt = STRING_TOKEN(CHECKBOX_PROMPT), + help = STRING_TOKEN(CHECKBOX_HELP), + default = FALSE, defaultstore = StandardDefault, + endcheckbox; +endif; + +suppressif ideqval FormData.CheckboxValue == 0; + numeric + name = NumericQuestion, + varid = FormData.NumericValue, + prompt = STRING_TOKEN(NUMERIC_PROMPT), + help = STRING_TOKEN(NUMERIC_HELP), + flags = NUMERIC_SIZE_2 | DISPLAY_UINT_HEX, + minimum = 0, + maximum = 10, + step = 1, + default = 5, defaultstore = StandardDefault, + endnumeric; + + oneof + name = OneOfQuestion, + varid = FormData.OneOfValue, + prompt = STRING_TOKEN(ONEOF_PROMPT), + help = STRING_TOKEN(ONEOF_HELP), + option text = STRING_TOKEN(ONEOF_OPTION1), value = 0x00, flags = 0; + option text = STRING_TOKEN(ONEOF_OPTION2), value = 0x33, flags = DEFAULT; + option text = STRING_TOKEN(ONEOF_OPTION3), value = 0x55, flags = 0; + endoneof; +endif; + +grayoutif TRUE; + checkbox + varid = FormEfiData.CheckboxValue, + prompt = STRING_TOKEN(CHECKBOX_EFI_PROMPT), + help = STRING_TOKEN(CHECKBOX_EFI_HELP), + default = FALSE, defaultstore = StandardDefault, + endcheckbox; +endif; + +grayoutif ideqval FormEfiData.CheckboxValue == 0; + numeric + name = NumericEfiQuestion, + varid = FormEfiData.NumericValue, + prompt = STRING_TOKEN(NUMERIC_EFI_PROMPT), + help = STRING_TOKEN(NUMERIC_EFI_HELP), + flags = NUMERIC_SIZE_2 | DISPLAY_UINT_HEX, + minimum = 0, + maximum = 10, + step = 1, + default = 6, defaultstore = StandardDefault, + endnumeric; + + oneof + name = OneOfEfiQuestion, + varid = FormEfiData.OneOfValue, + prompt = STRING_TOKEN(ONEOF_EFI_PROMPT), + help = STRING_TOKEN(ONEOF_EFI_HELP), + option text = STRING_TOKEN(ONEOF_OPTION1), value = 0x00, flags = 0; + option text = STRING_TOKEN(ONEOF_OPTION2), value = 0x33, flags = 0; + option text = STRING_TOKEN(ONEOF_OPTION3), value = 0x55, flags = DEFAULT; + endoneof; +endif; + + endform; +endformset; diff --git a/UefiLessonsPkg/HiddenSettings/HiddenSettings.c b/UefiLessonsPkg/HiddenSettings/HiddenSettings.c new file mode 100644 index 0000000..58a23d4 --- /dev/null +++ b/UefiLessonsPkg/HiddenSettings/HiddenSettings.c @@ -0,0 +1,267 @@ +/* + * Copyright (c) 2024, Konstantin Aladyshev <aladyshev22@gmail.com> + * + * SPDX-License-Identifier: MIT + */ + +#include <Library/BaseMemoryLib.h> +#include <Library/DevicePathLib.h> +#include <Library/HiiLib.h> +#include <Library/MemoryAllocationLib.h> +#include <Library/PrintLib.h> +#include <Library/UefiBootServicesTableLib.h> +#include <Library/UefiHiiServicesLib.h> +#include <Library/UefiLib.h> +#include <Library/UefiRuntimeServicesTableLib.h> +#include <Protocol/HiiConfigAccess.h> +#include "Data.h" + +extern UINT8 FormBin[]; + +#pragma pack(1) +typedef struct { + VENDOR_DEVICE_PATH VendorDevicePath; + EFI_DEVICE_PATH_PROTOCOL End; +} HII_VENDOR_DEVICE_PATH; +#pragma pack() + +HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath = { + { + { + HARDWARE_DEVICE_PATH, + HW_VENDOR_DP, + { + (UINT8) (sizeof (VENDOR_DEVICE_PATH)), + (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8) + } + }, + DATAPATH_GUID + }, + { + END_DEVICE_PATH_TYPE, + END_ENTIRE_DEVICE_PATH_SUBTYPE, + { + (UINT8) (END_DEVICE_PATH_LENGTH), + (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8) + } + } +}; + +EFI_HII_HANDLE mHiiHandle = NULL; +EFI_HANDLE mDriverHandle = NULL; +EFI_HII_CONFIG_ACCESS_PROTOCOL mConfigAccess; +EFI_GUID StorageGuid = STORAGE_GUID; +EFI_STRING StorageName = L"FormData"; + +VARIABLE_STRUCTURE FormStorage; + +STATIC +EFI_STATUS +EFIAPI +ExtractConfig ( + IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This, + IN CONST EFI_STRING Request, + OUT EFI_STRING *Progress, + OUT EFI_STRING *Results +) +{ + BOOLEAN AllocatedRequest = FALSE; + + if (Progress == NULL || Results == NULL) { + return EFI_INVALID_PARAMETER; + } + + if ((Request != NULL) && !HiiIsConfigHdrMatch(Request, &StorageGuid, StorageName)) { + return EFI_NOT_FOUND; + } + + EFI_STRING ConfigRequest = Request; + if ((Request == NULL) || (StrStr (Request, L"OFFSET") == NULL)) { + EFI_STRING ConfigRequestHdr = HiiConstructConfigHdr(&StorageGuid, StorageName, mDriverHandle); + UINTN Size = (StrLen(ConfigRequestHdr) + StrLen(L"&OFFSET=0&WIDTH=") + sizeof(UINTN)*2 + 1) * sizeof(CHAR16); + ConfigRequest = AllocateZeroPool(Size); + AllocatedRequest = TRUE; + UnicodeSPrint(ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, sizeof(VARIABLE_STRUCTURE)); + FreePool(ConfigRequestHdr); + } + EFI_STATUS Status = gHiiConfigRouting->BlockToConfig(gHiiConfigRouting, + ConfigRequest, + (UINT8*)&FormStorage, + sizeof(VARIABLE_STRUCTURE), + Results, + Progress); + + if (AllocatedRequest) { + FreePool(ConfigRequest); + if (Request == NULL) { + *Progress = NULL; + } else if (StrStr(Request, L"OFFSET") == NULL) { + *Progress = Request + StrLen(Request); + } + } + + return Status; +} + +STATIC +EFI_STATUS +EFIAPI +RouteConfig ( + IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This, + IN CONST EFI_STRING Configuration, + OUT EFI_STRING *Progress +) +{ + if (Configuration == NULL || Progress == NULL) { + return EFI_INVALID_PARAMETER; + } + + UINTN BlockSize = sizeof(VARIABLE_STRUCTURE); + EFI_STATUS Status = gHiiConfigRouting->ConfigToBlock(gHiiConfigRouting, + Configuration, + (UINT8*)&FormStorage, + &BlockSize, + Progress); + + return Status; +} + +STATIC +EFI_STATUS +EFIAPI +Callback ( + IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This, + IN EFI_BROWSER_ACTION Action, + IN EFI_QUESTION_ID QuestionId, + IN UINT8 Type, + IN OUT EFI_IFR_TYPE_VALUE *Value, + OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest + ) +{ + return EFI_UNSUPPORTED; +} + +EFI_STATUS +EFIAPI +HiddenSettingsUnload ( + EFI_HANDLE ImageHandle + ) +{ + if (mHiiHandle != NULL) + HiiRemovePackages(mHiiHandle); + + + EFI_STATUS Status = gBS->UninstallMultipleProtocolInterfaces( + mDriverHandle, + &gEfiDevicePathProtocolGuid, + &mHiiVendorDevicePath, + &gEfiHiiConfigAccessProtocolGuid, + &mConfigAccess, + NULL); + + UINTN BufferSize; + VARIABLE_STRUCTURE EfiVarstore; + BufferSize = sizeof(VARIABLE_STRUCTURE); + EFI_GUID EfiVarGuid = STORAGE_EFI_GUID; + Status = gRT->GetVariable( + L"FormEfiData", + &EfiVarGuid, + NULL, + &BufferSize, + &EfiVarstore); + if (!EFI_ERROR(Status)) { + Status = gRT->SetVariable( + L"FormEfiData", + &EfiVarGuid, + 0, + 0, + NULL); + if (EFI_ERROR(Status)) { + Print(L"Error! Can't delete variable! %r\n", Status); + } + } + + return Status; +} + +EFI_STATUS +EFIAPI +HiddenSettingsEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + mConfigAccess.ExtractConfig = &ExtractConfig; + mConfigAccess.RouteConfig = &RouteConfig; + mConfigAccess.Callback = &Callback; + + EFI_STATUS Status; + Status = gBS->InstallMultipleProtocolInterfaces( + &mDriverHandle, + &gEfiDevicePathProtocolGuid, + &mHiiVendorDevicePath, + &gEfiHiiConfigAccessProtocolGuid, + &mConfigAccess, + NULL + ); + if (EFI_ERROR (Status)) { + return Status; + } + + mHiiHandle = HiiAddPackages( + &gEfiCallerIdGuid, + mDriverHandle, + HiddenSettingsStrings, + FormBin, + NULL + ); + if (mHiiHandle == NULL) { + gBS->UninstallMultipleProtocolInterfaces( + mDriverHandle, + &gEfiDevicePathProtocolGuid, + &mHiiVendorDevicePath, + &gEfiHiiConfigAccessProtocolGuid, + &mConfigAccess, + NULL); + return EFI_OUT_OF_RESOURCES; + } + + EFI_STRING ConfigStr; + UINT16 DefaultId = 0; + + UINTN BufferSize; + VARIABLE_STRUCTURE EfiVarstore; + BufferSize = sizeof(VARIABLE_STRUCTURE); + EFI_GUID EfiVarGuid = STORAGE_EFI_GUID; + Status = gRT->GetVariable ( + L"FormEfiData", + &EfiVarGuid, + NULL, + &BufferSize, + &EfiVarstore); + if (EFI_ERROR(Status)) { + ZeroMem(&EfiVarstore, sizeof(EfiVarstore)); + Status = gRT->SetVariable( + L"FormEfiData", + &EfiVarGuid, + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, + sizeof(EfiVarstore), + &EfiVarstore); + if (EFI_ERROR(Status)) { + Print(L"Error! Can't create variable! %r\n", Status); + } + + ConfigStr = HiiConstructConfigHdr(&EfiVarGuid, L"FormEfiData", mDriverHandle); + UINT16 DefaultId = 0; + if (!HiiSetToDefaults(ConfigStr, DefaultId)) { + Print(L"Error! Can't set default configuration #%d\n", DefaultId); + } + } + + ConfigStr = HiiConstructConfigHdr(&StorageGuid, L"FormData", mDriverHandle); + if (!HiiSetToDefaults(ConfigStr, DefaultId)) { + Print(L"Error! Can't set default configuration #%d\n", DefaultId); + } + + return EFI_SUCCESS; +} diff --git a/UefiLessonsPkg/HiddenSettings/HiddenSettings.inf b/UefiLessonsPkg/HiddenSettings/HiddenSettings.inf new file mode 100644 index 0000000..731f245 --- /dev/null +++ b/UefiLessonsPkg/HiddenSettings/HiddenSettings.inf @@ -0,0 +1,32 @@ +## +# Copyright (c) 2024, Konstantin Aladyshev <aladyshev22@gmail.com> +# +# SPDX-License-Identifier: MIT +## + +[Defines] + INF_VERSION = 1.25 + BASE_NAME = HiddenSettings + FILE_GUID = 269d7962-badc-44da-815a-4af4f293f3e0 + MODULE_TYPE = UEFI_DRIVER + VERSION_STRING = 1.0 + ENTRY_POINT = HiddenSettingsEntryPoint + UNLOAD_IMAGE = HiddenSettingsUnload + +[Sources] + HiddenSettings.c + Strings.uni + Form.vfr + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[LibraryClasses] + UefiDriverEntryPoint + UefiLib + UefiHiiServicesLib + HiiLib + +[Protocols] + gEfiHiiConfigAccessProtocolGuid diff --git a/UefiLessonsPkg/HiddenSettings/Strings.uni b/UefiLessonsPkg/HiddenSettings/Strings.uni new file mode 100644 index 0000000..acca471 --- /dev/null +++ b/UefiLessonsPkg/HiddenSettings/Strings.uni @@ -0,0 +1,28 @@ +// +// Copyright (c) 2024, Konstantin Aladyshev <aladyshev22@gmail.com> +// +// SPDX-License-Identifier: MIT +// + +#langdef en-US "English" + +#string FORMSET_TITLE #language en-US "Formset with hidden settings" +#string FORMSET_HELP #language en-US "Formset with hidden settings" +#string FORMID1_TITLE #language en-US "Form with hidden settings" +#string CHECKBOX_PROMPT #language en-US "Show varstore settings" +#string CHECKBOX_HELP #language en-US "Show varstore settings" +#string NUMERIC_PROMPT #language en-US "Numeric prompt" +#string NUMERIC_HELP #language en-US "Numeric help" +#string ONEOF_PROMPT #language en-US "OneOf list prompt" +#string ONEOF_HELP #language en-US "OneOf list help" +#string ONEOF_OPTION1 #language en-US "OneOf list option 1" +#string ONEOF_OPTION2 #language en-US "OneOf list option 2" +#string ONEOF_OPTION3 #language en-US "OneOf list option 3" +#string STRING_DEFAULT #language en-US "String default" +#string CHECKBOX_EFI_PROMPT #language en-US "Enable efivarstorage settings" +#string CHECKBOX_EFI_HELP #language en-US "Enable efivarstorage settings" +#string NUMERIC_EFI_PROMPT #language en-US "Numeric EFI prompt" +#string NUMERIC_EFI_HELP #language en-US "Numeric EFI help" +#string ONEOF_EFI_PROMPT #language en-US "OneOf list EFI prompt" +#string ONEOF_EFI_HELP #language en-US "OneOf list EFI help" +#string STANDARD_DEFAULT_PROMPT #language en-US "Standard default" diff --git a/UefiLessonsPkg/ShowHIIext/ShowHIIext.c b/UefiLessonsPkg/ShowHIIext/ShowHIIext.c new file mode 100644 index 0000000..5bbb9a8 --- /dev/null +++ b/UefiLessonsPkg/ShowHIIext/ShowHIIext.c @@ -0,0 +1,216 @@ +/* + * Copyright (c) 2024, Konstantin Aladyshev <aladyshev22@gmail.com> + * + * SPDX-License-Identifier: MIT + */ + +#include <Library/UefiBootServicesTableLib.h> +#include <Library/UefiLib.h> + +#include <Protocol/HiiDatabase.h> +#include <Library/MemoryAllocationLib.h> +#include <Library/ShellLib.h> +#include <Library/PrintLib.h> +#include <Library/HiiLib.h> + +GLOBAL_REMOVE_IF_UNREFERENCED EFI_STRING_ID mStringHelpTokenId = STRING_TOKEN(STR_HELP); + +BOOLEAN savePackageLists = FALSE; +UINTN savePackageIndex = 0xffffffff; // ALL + +EFI_STATUS WriteFile(CHAR16* FileName, VOID* Data, UINTN* Size) +{ + SHELL_FILE_HANDLE FileHandle; + EFI_STATUS Status = ShellOpenFileByName( + FileName, + &FileHandle, + EFI_FILE_MODE_CREATE | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_READ, + 0 + ); + if (!EFI_ERROR(Status)) { + Print(L"Save file as %s\n", FileName); + UINTN ToWrite = *Size; + Status = ShellWriteFile( + FileHandle, + Size, + Data + ); + if (EFI_ERROR(Status)) { + Print(L"Can't write file: %r\n", Status); + } + if (*Size != ToWrite) { + Print(L"Error! Not all data was written\n"); + } + Status = ShellCloseFile( + &FileHandle + ); + if (EFI_ERROR(Status)) { + Print(L"Can't close file: %r\n", Status); + } + } else { + Print(L"Can't open file: %r\n", Status); + } + return Status; +} + +CHAR16* PackageType(UINTN Type) +{ + switch(Type) { + case EFI_HII_PACKAGE_TYPE_ALL: + return L"ALL"; + case EFI_HII_PACKAGE_TYPE_GUID: + return L"GUID"; + case EFI_HII_PACKAGE_FORMS: + return L"FORMS"; + case EFI_HII_PACKAGE_STRINGS: + return L"STRINGS"; + case EFI_HII_PACKAGE_FONTS: + return L"FONTS"; + case EFI_HII_PACKAGE_IMAGES: + return L"IMAGES"; + case EFI_HII_PACKAGE_SIMPLE_FONTS: + return L"SIMPLE_FONTS"; + case EFI_HII_PACKAGE_DEVICE_PATH: + return L"DEVICE_PATH"; + case EFI_HII_PACKAGE_KEYBOARD_LAYOUT: + return L"KEYBOARD_LAYOUT"; + case EFI_HII_PACKAGE_ANIMATIONS: + return L"ANIMATIONS"; + case EFI_HII_PACKAGE_END: + return L"END"; + case EFI_HII_PACKAGE_TYPE_SYSTEM_BEGIN: + return L"SYSTEM_BEGIN"; + case EFI_HII_PACKAGE_TYPE_SYSTEM_END: + return L"SYSTEM_END"; + } + return L"UNKNOWN"; +} + +VOID ParseHiiPackageLists(EFI_HII_PACKAGE_LIST_HEADER* HiiDatabase, UINTN HiiDatabaseSize) +{ + EFI_HII_PACKAGE_LIST_HEADER* HiiPackageListHeader; + HiiPackageListHeader = (EFI_HII_PACKAGE_LIST_HEADER*) HiiDatabase; + + UINTN i=0; + while ((UINTN) HiiPackageListHeader < ((UINTN) HiiDatabase + HiiDatabaseSize)) { + UINTN HiiPackageListSize = HiiPackageListHeader->PackageLength; + if (HiiPackageListSize == 0) + break; + if (savePackageLists) { + if ((savePackageIndex == 0xFFFFFFFF) || (savePackageIndex == i)) { + CHAR16 FileName[100]; + UnicodeSPrint(FileName, 100, L"%04d_%g", i, HiiPackageListHeader->PackageListGuid); + UINTN ToWrite = HiiPackageListSize; + EFI_STATUS Status = WriteFile(FileName, HiiPackageListHeader, &ToWrite); + if (EFI_ERROR(Status)) { + Print(L"Error! Failed to write PackageList %d\n", i); + } + } + } + if (!savePackageLists) + Print(L"PackageList[%d]: GUID=%g; size=0x%X\n", i, HiiPackageListHeader->PackageListGuid, HiiPackageListHeader->PackageLength); + i++; + + EFI_HII_PACKAGE_HEADER* HiiPackageHeader = (EFI_HII_PACKAGE_HEADER*)((UINTN) HiiPackageListHeader + sizeof(EFI_HII_PACKAGE_LIST_HEADER)); + UINTN j=0; + while ((UINTN) HiiPackageHeader < ((UINTN) HiiPackageListHeader + HiiPackageListSize)) { + if (!savePackageLists) + Print(L"\tPackage[%d]: type=%s; size=0x%X\n", j++, PackageType(HiiPackageHeader->Type), HiiPackageHeader->Length); + + // Go to next Package + HiiPackageHeader = (EFI_HII_PACKAGE_HEADER*)((UINTN) HiiPackageHeader + HiiPackageHeader->Length); + } + + // Go to next PackageList + HiiPackageListHeader = (EFI_HII_PACKAGE_LIST_HEADER*)((UINTN) HiiPackageListHeader + HiiPackageListSize); + } +} + +VOID Usage() +{ + CHAR16 HelpStr[100]; + UnicodeSPrint(HelpStr, 100, L"%a", gEfiCallerBaseName); + ShellPrintHelp(HelpStr, NULL, FALSE); +} + +INTN EFIAPI ShellAppMain(IN UINTN Argc, IN CHAR16 **Argv) +{ + EFI_STATUS Status; + + UINTN bOptionIndex = Argc; + UINTN hOptionIndex = Argc; + for (UINTN i = 1; i < Argc; i++) { + if (!StrCmp(Argv[i], L"-b")) { + ShellSetPageBreakMode(TRUE); + bOptionIndex = i; + } else if (!StrCmp(Argv[i], L"-?")) { + hOptionIndex = i; + } + } + + for (UINTN i = 1; i < Argc; i++) { + if ((i == bOptionIndex) || (i == hOptionIndex)) + continue; + if (!StrCmp(Argv[i], L"save")) { + savePackageLists = TRUE; + if (((i + 1) < Argc) && ((i + 1) != bOptionIndex) && ((i + 1) != hOptionIndex)) { + CHAR16* EndPointer; + Status = StrDecimalToUintnS(Argv[i + 1], &EndPointer, &savePackageIndex); + if (EFI_ERROR(Status) || (EndPointer == Argv[i + 1])) { + Usage(); + return EFI_INVALID_PARAMETER; + } + i += 1; + } + } else { + Usage(); + return EFI_INVALID_PARAMETER; + } + } + + EFI_HII_DATABASE_PROTOCOL* HiiDbProtocol; + Status = gBS->LocateProtocol(&gEfiHiiDatabaseProtocolGuid, + NULL, + (VOID**)&HiiDbProtocol); + if (EFI_ERROR(Status)) { + Print(L"ERROR: Could not find HII Database protocol: %r\n", Status); + return Status; + } + + UINTN PackageListSize = 0; + EFI_HII_PACKAGE_LIST_HEADER* PackageList = NULL; + + Status = HiiDbProtocol->ExportPackageLists(HiiDbProtocol, + NULL, // All package lists + &PackageListSize, + PackageList); + if (Status != EFI_BUFFER_TOO_SMALL) { + Print(L"ERROR: Could not obtain package list size\n"); + return Status; + } + + Status = gBS->AllocatePool(EfiBootServicesData, + PackageListSize, + (VOID**)&PackageList); + if (EFI_ERROR(Status)) { + Print(L"ERROR: Could not allocate sufficient memory for package list: %r\n", Status); + return Status; + } + + + Status = HiiDbProtocol->ExportPackageLists(HiiDbProtocol, + NULL, + &PackageListSize, + PackageList); + if (EFI_ERROR(Status)) { + Print(L"ERROR: Could not retrieve the package list: %r\n", Status); + FreePool(PackageList); + return Status; + } + + ParseHiiPackageLists(PackageList, PackageListSize); + + FreePool(PackageList); + + return EFI_SUCCESS; +} diff --git a/UefiLessonsPkg/ShowHIIext/ShowHIIext.inf b/UefiLessonsPkg/ShowHIIext/ShowHIIext.inf new file mode 100644 index 0000000..fffbecf --- /dev/null +++ b/UefiLessonsPkg/ShowHIIext/ShowHIIext.inf @@ -0,0 +1,32 @@ +## +# Copyright (c) 2024, Konstantin Aladyshev <aladyshev22@gmail.com> +# +# SPDX-License-Identifier: MIT +## + +[Defines] + INF_VERSION = 1.25 + BASE_NAME = ShowHIIext + FILE_GUID = 9d7386b0-6c1b-4815-94c5-24c385e3d123 + MODULE_TYPE = UEFI_APPLICATION + VERSION_STRING = 1.0 + ENTRY_POINT = ShellCEntryLib + UEFI_HII_RESOURCE_SECTION = TRUE + +[Sources] + ShowHIIext.c + Strings.uni + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + ShellPkg/ShellPkg.dec + +[LibraryClasses] + ShellCEntryLib + UefiLib + ShellLib + HiiLib + +[Protocols] + gEfiHiiDatabaseProtocolGuid diff --git a/UefiLessonsPkg/ShowHIIext/Strings.uni b/UefiLessonsPkg/ShowHIIext/Strings.uni new file mode 100644 index 0000000..8c04771 --- /dev/null +++ b/UefiLessonsPkg/ShowHIIext/Strings.uni @@ -0,0 +1,20 @@ +// +// Copyright (c) 2024, Konstantin Aladyshev <aladyshev22@gmail.com> +// +// SPDX-License-Identifier: MIT +// + +#langdef en-US "English" + +#string STR_HELP #language en-US "" +".TH ShowHIIext 0 "Show HII database packages"\r\n" +".SH NAME\r\n" +"Shows packages installed into the HII database.\r\n" +".SH SYNOPSIS\r\n" +"\r\n" +"SHOWHIIEXT [-b] [save [<index>]]\r\n" +".SH OPTIONS\r\n" +"\r\n" +" -b - Display one screen at a time\r\n" +" save - Save all package lists as files\r\n" +" save <index> - Save package list with index <index> as a file\r\n" diff --git a/UefiLessonsPkg/UefiLessonsPkg.dsc b/UefiLessonsPkg/UefiLessonsPkg.dsc index 14bd3c2..d51eb2c 100644 --- a/UefiLessonsPkg/UefiLessonsPkg.dsc +++ b/UefiLessonsPkg/UefiLessonsPkg.dsc @@ -89,6 +89,8 @@ UefiLessonsPkg/HIIFormDataElementsVarstore/HIIFormDataElementsVarstore.inf UefiLessonsPkg/FfsFile/FfsFile.inf UefiLessonsPkg/SetSku/SetSku.inf + UefiLessonsPkg/HiddenSettings/HiddenSettings.inf + UefiLessonsPkg/ShowHIIext/ShowHIIext.inf #[PcdsFixedAtBuild] # gUefiLessonsPkgTokenSpaceGuid.PcdInt8|0x88|UINT8|0x3B81CDF1 |