Skip to content

Commit

Permalink
file: Support reading EFI zboot images
Browse files Browse the repository at this point in the history
Signed-off-by: Haochen Tong <[email protected]>
  • Loading branch information
Haochen Tong committed Sep 21, 2024
1 parent 55aa5e8 commit 7a06c90
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ecleankernel/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import contextlib
import enum
import errno
import io
import importlib
import logging
import os
Expand Down Expand Up @@ -226,6 +227,17 @@ def read_version_from_efi(self,
buf = f.read(0x40)
if len(buf) != 0x40 or buf[:2] != b"MZ":
return None

# handle EFI zboot image
# see kernel source code drivers/firmware/efi/libstub/zboot-header.S
if buf[4:8] == b"zimg":
offset, size = struct.unpack_from("<LL", buf, 8)

f.seek(offset)
image = f.read(size)

return self.read_version_from_raw(io.BytesIO(image))

coff_offset = struct.unpack_from("<L", buf, 0x3c)[0]

# at offset, we find PE\0\0 signature and COFF file header
Expand Down

0 comments on commit 7a06c90

Please sign in to comment.