return name.rstrip(b'\x00').decode()
+def pe_section_size(section: pefile.SectionStructure) -> int:
+ return cast(int, min(section.Misc_VirtualSize, section.SizeOfRawData))
+
+
def call_systemd_measure(uki: UKI, opts: UkifyConfig, profile_start: int = 0) -> None:
measure_tool = find_tool(
'systemd-measure',
continue
print(
- f"Copying section '{n}' from '{profile}': {pesection.Misc_VirtualSize} bytes",
+ f"Copying section '{n}' from '{profile}': {pe_section_size(pesection)} bytes",
file=sys.stderr,
)
uki.add_section(
- Section.create(n, pesection.get_data(length=pesection.Misc_VirtualSize), measure=True)
+ Section.create(n, pesection.get_data(length=pe_section_size(pesection)), measure=True)
)
call_systemd_measure(uki, opts=opts, profile_start=prev_len)
ttype = config.output_mode if config else DEFAULT_SECTIONS_TO_SHOW.get(name, 'binary')
- size = section.Misc_VirtualSize
- # TODO: Use ignore_padding once we can depend on a newer version of pefile
+ size = pe_section_size(section)
data = section.get_data(length=size)
digest = sha256(data).hexdigest()