diff --git a/xtldr/efiutils.c b/xtldr/efiutils.c index 1f80c9fe..7e1a75d7 100644 --- a/xtldr/efiutils.c +++ b/xtldr/efiutils.c @@ -103,6 +103,54 @@ BlGetConfigurationTable(IN PEFI_GUID TableGuid, return STATUS_EFI_NOT_FOUND; } +/** + * Gets the value of the EFI variable. + * + * @param Vendor + * Supplies a pointer to the unique vendor GUID. + * + * @param VariableName + * Supplies a pointer to tge NULL-terminated string containing the variable name. + * + * @param VariableValue + * Supplies a pointer to the buffer, where the variable value will be stored. + * + * @return This routine returns a status code. + * + * @since XT 1.0 + */ +XTCDECL +EFI_STATUS +BlGetEfiVariable(IN PEFI_GUID Vendor, + IN PWCHAR VariableName, + OUT PVOID *VariableValue) +{ + EFI_STATUS Status; + PVOID Buffer; + UINT_PTR Size; + + /* Allocate a buffer for storing a variable's value */ + Size = EFI_MAXIMUM_VARIABLE_SIZE * sizeof(PWCHAR); + Status = BlAllocateMemoryPool(Size, (PVOID*)&Buffer); + if(Status != STATUS_EFI_SUCCESS) + { + /* Memory allocation failure */ + return Status; + } + + /* Attempt to get variable value */ + Status = EfiSystemTable->RuntimeServices->GetVariable(VariableName, Vendor, NULL, &Size, Buffer); + if(Status != STATUS_EFI_SUCCESS) + { + /* Failed to get variable, probably not found such one */ + return Status; + } + + /* Get variable value and return success */ + *VariableValue = Buffer; + return STATUS_EFI_SUCCESS; +} + /** * Returns a random value based on the initialized RNG buffer. * @@ -250,6 +298,39 @@ BlRebootSystem() return EfiSystemTable->RuntimeServices->ResetSystem(EfiResetCold, STATUS_EFI_SUCCESS, 0, NULL); } +/** + * Sets a value of an EFI variable. + * + * @param Vendor + * Supplies a pointer to the unique vendor GUID. + * + * @param VariableName + * Supplies a pointer to tge NULL-terminated string containing the variable name. + * + * @param VariableValue + * Supplies the contents of the variable. + * + * @param Size + * Supplies the size of the variable data buffer. + * + * @return This routine returns a status code. + * + * @since XT 1.0 + */ +XTCDECL +EFI_STATUS +BlSetEfiVariable(IN PEFI_GUID Vendor, + IN PWCHAR VariableName, + IN PVOID VariableValue, + IN UINT_PTR Size) +{ + ULONG Attributes; + + /* Set EFI variable */ + Attributes = EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS; + return EfiSystemTable->RuntimeServices->SetVariable(VariableName, Vendor, Attributes, Size, VariableValue); +} + /** * Shuts down the machine. * diff --git a/xtldr/includes/xtldr.h b/xtldr/includes/xtldr.h index 03043480..4ba7d0d1 100644 --- a/xtldr/includes/xtldr.h +++ b/xtldr/includes/xtldr.h @@ -137,6 +137,12 @@ EFI_STATUS BlGetEfiPath(IN PWCHAR SystemPath, OUT PWCHAR *EfiPath); +XTCDECL +EFI_STATUS +BlGetEfiVariable(IN PEFI_GUID Vendor, + IN PWCHAR VariableName, + OUT PVOID *VariableValue); + XTCDECL VOID BlGetMappingsCount(IN PXTBL_PAGE_MAPPING PageMap, @@ -327,6 +333,13 @@ VOID BlSetCursorPosition(IN ULONGLONG PosX, IN ULONGLONG PosY); +XTCDECL +EFI_STATUS +BlSetEfiVariable(IN PEFI_GUID Vendor, + IN PWCHAR VariableName, + IN PVOID VariableValue, + IN UINT_PTR Size); + XTCDECL EFI_STATUS BlShutdownSystem();