ukify: pack FWHEADERMAGIC directly instead of using bytes.fromhex
The current implementation
FWHEADERMAGIC = 'feeddead'
magic = bytes.fromhex(FWHEADERMAGIC)
struct.pack('<p', magic)
returns a single null byte b'\x00', which is not equal to 0xfeeddead in any
endianness.
(cherry picked from commit fe689d2d7946593001bb3d0e32d51d694af5d50d)
This commit is contained in:
committed by
Luca Boccassi
parent
3d7fd9fc37
commit
03ae6cf3ce
@@ -21,6 +21,7 @@ import os
|
||||
import pathlib
|
||||
import re
|
||||
import shutil
|
||||
import struct
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
@@ -875,6 +876,20 @@ def test_inspect_json_profiles(tmp_path, capsys):
|
||||
shutil.rmtree(tmp_path)
|
||||
|
||||
|
||||
def test_parse_efifw_dir(tmp_path):
|
||||
fwdir = tmp_path / 'fw0'
|
||||
fwdir.mkdir()
|
||||
payload = b'EFIFW0'
|
||||
(fwdir / 'firmware.bin').write_bytes(payload)
|
||||
|
||||
fwname = fwdir.name.encode() + b'\0'
|
||||
|
||||
comp = (ukify.FWHEADERMAGIC, ukify.EFIFW_HEADER_SIZE, len(fwname), len(payload))
|
||||
blob = ukify.parse_efifw_dir(fwdir)
|
||||
assert comp == struct.unpack_from('<IIII', blob[: ukify.EFIFW_HEADER_SIZE])
|
||||
assert (fwname + payload) == blob[ukify.EFIFW_HEADER_SIZE :]
|
||||
|
||||
|
||||
def test_inspect_json_alternative_set_sections(tmp_path, capsys):
|
||||
# '.dtbauto' and '.efifw' are alternative-sets (one entry per hardware variant): every occurrence
|
||||
# must be preserved, and they are always reported as a list, even for a single entry. The two are
|
||||
|
||||
+3
-4
@@ -1242,8 +1242,8 @@ NULL_DEVICE = b'\0' * DEVICE_STRUCT_SIZE
|
||||
DEVICE_TYPE_DEVICETREE = 1
|
||||
DEVICE_TYPE_UEFI_FW = 2
|
||||
|
||||
# Keep in sync with efifirmware.h
|
||||
FWHEADERMAGIC = 'feeddead'
|
||||
# Keep in sync with src/boot/efi-firmware.h
|
||||
FWHEADERMAGIC = 0xFEEDDEAD
|
||||
EFIFW_HEADER_SIZE = 4 + 4 + 4 + 4
|
||||
|
||||
|
||||
@@ -1358,10 +1358,9 @@ def parse_efifw_dir(path: Path) -> bytes:
|
||||
# terminated by NULL.
|
||||
fwid = b'' + dirname.encode() + b'\0'
|
||||
fwid_len = len(fwid)
|
||||
magic = bytes.fromhex(FWHEADERMAGIC)
|
||||
|
||||
efifw_header_blob = b''
|
||||
efifw_header_blob += struct.pack('<p', magic)
|
||||
efifw_header_blob += struct.pack('<I', FWHEADERMAGIC)
|
||||
efifw_header_blob += struct.pack('<I', EFIFW_HEADER_SIZE)
|
||||
efifw_header_blob += struct.pack('<I', fwid_len)
|
||||
efifw_header_blob += struct.pack('<I', payload_len)
|
||||
|
||||
Reference in New Issue
Block a user