fix: Fix style and format
This commit is contained in:
parent
2e5951fe27
commit
00efc77497
63
efivars.py
63
efivars.py
@ -1,16 +1,17 @@
|
||||
#!/usr/bin/python3 -I
|
||||
'''
|
||||
"""
|
||||
What: efivars
|
||||
Description: List EFI variables made available in RAM from the UEFI NV-RAM
|
||||
|
||||
The list of variables is divided into two sections, the first being the UEFI
|
||||
defined variables as described in the UEFI Specification v2.11
|
||||
The list of variables is divided into two sections, the first
|
||||
being the UEFI defined variables as described in the UEFI
|
||||
Specification v2.11
|
||||
(https://uefi.org/sites/default/files/resources/UEFI_Spec_Final_2.11.pdf),
|
||||
and the second section contains all vendor specific variables defined by the
|
||||
vendors UEFI firmware.
|
||||
and the second section contains all vendor specific variables
|
||||
defined by the vendors UEFI firmware.
|
||||
Author: Christian Goeschel Ndjomouo <cgoesc2@wgu.edu>
|
||||
Date: Mar 22 2025
|
||||
'''
|
||||
"""
|
||||
|
||||
import os
|
||||
import re
|
||||
@ -20,6 +21,7 @@ import sys
|
||||
UEFI_GLOBAL_VARIABLE_GUID = "8be4df61-93ca-11d2-aa0d-00e098032b8c"
|
||||
SYSFS_EFIVARSFS = "/sys/firmware/efi/efivars"
|
||||
|
||||
|
||||
# Technically speaking UEFI variables stored in the NV-RAM are not
|
||||
# directly accessible from the OS level. They are rather made residents
|
||||
# of RAM by the UEFI firmware at boot time for exposure to the 'efivarfs'
|
||||
@ -30,7 +32,8 @@ def enum_efi_vars(efivarsfs_path: str = SYSFS_EFIVARSFS) -> list:
|
||||
Enumerates UEFI variables exposed in SYSFS_EFIVARSFS.
|
||||
|
||||
Args:
|
||||
efivarsfs_path (str): Absolute filesystem path to efivarsfs ,default (SYSFS_EFIVARSFS)
|
||||
efivarsfs_path (str):
|
||||
Absolute filesystem path to efivarsfs ,default (SYSFS_EFIVARSFS)
|
||||
|
||||
Returns:
|
||||
list: All found variables in SYSFS_EFIVARSFS
|
||||
@ -42,6 +45,7 @@ def enum_efi_vars(efivarsfs_path: str = SYSFS_EFIVARSFS) -> list:
|
||||
|
||||
return efi_vars
|
||||
|
||||
|
||||
# Here we will sort the enumerated EFI variables into two distinct lists.
|
||||
def sort_efi_vars(efi_vars_list: list, uefi_global_vars_guid: str) -> tuple:
|
||||
"""
|
||||
@ -50,16 +54,21 @@ def sort_efi_vars(efi_vars_list: list, uefi_global_vars_guid: str) -> tuple:
|
||||
and 'vendor_spec_vars' will be vendor defined variables
|
||||
|
||||
Args:
|
||||
list (efi_vars_list): An unsorted list of EFI variables
|
||||
str (uefi_global_vars_guid): UEFI global variables guid for the regex pattern
|
||||
list (efi_vars_list):
|
||||
An unsorted list of EFI variables
|
||||
|
||||
str (uefi_global_vars_guid):
|
||||
UEFI global variables guid for the regex pattern
|
||||
|
||||
Returns:
|
||||
tuple (uefi_spec_vars, vendor_spec_vars): List of UEFI and vendor specific variables, respectively
|
||||
tuple (uefi_spec_vars, vendor_spec_vars):
|
||||
List of UEFI and vendor specific variables, respectively
|
||||
"""
|
||||
uefi_spec_vars = []
|
||||
vendor_spec_vars = []
|
||||
# As defined in UEFI Specification v2.11 8.2.3 variables have to be minimum 1 char long
|
||||
uefi_vars_regex_pattern = re.compile(f"^.+-{uefi_global_vars_guid}$")
|
||||
uefi_spec_vars = []
|
||||
vendor_spec_vars = []
|
||||
# As defined in UEFI Specification v2.11 8.2.3
|
||||
# variables have to be minimum 1 char long
|
||||
uefi_vars_regex_pattern = re.compile(f"^.+-{uefi_global_vars_guid}$")
|
||||
|
||||
for var in efi_vars_list:
|
||||
if not uefi_vars_regex_pattern.match(var):
|
||||
@ -69,12 +78,13 @@ def sort_efi_vars(efi_vars_list: list, uefi_global_vars_guid: str) -> tuple:
|
||||
|
||||
return uefi_spec_vars, vendor_spec_vars
|
||||
|
||||
|
||||
# Pretty print a list
|
||||
def print_list(l: list, l_name: str) -> None:
|
||||
l_size = len(l)
|
||||
def print_list(var_l: list, l_name: str) -> None:
|
||||
l_size = len(var_l)
|
||||
|
||||
print("{} {}\n".format(l_size, l_name))
|
||||
for e in l:
|
||||
for e in var_l:
|
||||
print(e)
|
||||
|
||||
|
||||
@ -88,8 +98,9 @@ def main() -> None:
|
||||
{}\n
|
||||
EFI variables can not be listed on your system
|
||||
|
||||
Please make sure your kernel isn't booted with the 'noefi' parameter and is configured
|
||||
with 'CONFIG_EFI=y', otherwise run the command below as root and try again.
|
||||
Please make sure your kernel isn't booted with the
|
||||
'noefi' parameter and is configured with 'CONFIG_EFI=y',
|
||||
otherwise run the command below as root and try again.
|
||||
|
||||
mount -t efivarfs efivarfs /sys/firmware/efi/efivars""".format(e))
|
||||
sys.exit(2)
|
||||
@ -100,11 +111,19 @@ def main() -> None:
|
||||
print("Something seems wrong, no EFI variables found!")
|
||||
sys.exit(3)
|
||||
|
||||
uefi_spec_vars, vendor_spec_vars = sort_efi_vars(all_efi_vars, UEFI_GLOBAL_VARIABLE_GUID)
|
||||
print_list(uefi_spec_vars, "[UEFI Specification v2.11 defined EFI variables]")
|
||||
uefi_spec_vars, vendor_spec_vars = sort_efi_vars(
|
||||
all_efi_vars,
|
||||
UEFI_GLOBAL_VARIABLE_GUID
|
||||
)
|
||||
|
||||
print_list(
|
||||
uefi_spec_vars,
|
||||
"[UEFI Specification v2.11 defined EFI variables]"
|
||||
)
|
||||
print("")
|
||||
print_list(vendor_spec_vars, "[Vendor defined EFI variables]")
|
||||
|
||||
|
||||
# Enter the entrypoint only if this script is ran directly
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
|
Loading…
x
Reference in New Issue
Block a user