summaryrefslogtreecommitdiffstats
path: root/src/ukify/ukify.py
diff options
context:
space:
mode:
authorDaan De Meyer <daan.j.demeyer@gmail.com>2024-10-01 10:24:30 +0200
committerDaan De Meyer <daan.j.demeyer@gmail.com>2024-10-03 23:15:32 +0200
commitdb0f9720d62f4d2930b09c08d98c07b4440cc9b0 (patch)
tree8f61a58cef3d43346a2bb1f996e5c956a50a12e8 /src/ukify/ukify.py
parentRevert "ukify: add new --extend= switch for importing an existing UKI's secti... (diff)
downloadsystemd-db0f9720d62f4d2930b09c08d98c07b4440cc9b0.tar.xz
systemd-db0f9720d62f4d2930b09c08d98c07b4440cc9b0.zip
ukify: Introduce pe_strip_section_name()
Diffstat (limited to 'src/ukify/ukify.py')
-rwxr-xr-xsrc/ukify/ukify.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/ukify/ukify.py b/src/ukify/ukify.py
index e444204eb1..2574b315dd 100755
--- a/src/ukify/ukify.py
+++ b/src/ukify/ukify.py
@@ -491,6 +491,10 @@ def key_path_groups(opts):
pp_groups)
+def pe_strip_section_name(name):
+ return name.rstrip(b"\x00").decode()
+
+
def call_systemd_measure(uki, opts):
measure_tool = find_tool('systemd-measure',
'/usr/lib/systemd/systemd-measure',
@@ -665,7 +669,7 @@ def pe_add_sections(uki: UKI, output: str):
# the one from the kernel to it. It should be small enough to fit in the existing section, so just
# swap the data.
for i, s in enumerate(pe.sections):
- if s.Name.rstrip(b"\x00").decode() == section.name:
+ if pe_strip_section_name(s.Name) == section.name:
if new_section.Misc_VirtualSize > s.SizeOfRawData:
raise PEError(f'Not enough space in existing section {section.name} to append new data.')
@@ -701,7 +705,7 @@ def merge_sbat(input_pe: [pathlib.Path], input_text: [str]) -> str:
continue
for section in pe.sections:
- if section.Name.rstrip(b"\x00").decode() == ".sbat":
+ if pe_strip_section_name(section.Name) == ".sbat":
split = section.get_data().rstrip(b"\x00").decode().splitlines()
if not split[0].startswith('sbat,'):
print(f"{f} does not contain a valid SBAT section, skipping.")
@@ -1042,7 +1046,7 @@ def generate_keys(opts):
def inspect_section(opts, section):
- name = section.Name.rstrip(b"\x00").decode()
+ name = pe_strip_section_name(section.Name)
# find the config for this section in opts and whether to show it
config = opts.sections_by_name.get(name, None)