Skip to content

Commit

Permalink
Parse UKIs produced by ukify
Browse files Browse the repository at this point in the history
Fixes #46
  • Loading branch information
SoapGentoo committed Dec 4, 2023
1 parent 53eadd0 commit 5a53874
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions ecleankernel/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import enum
import errno
import importlib
import logging
import os
import shutil
import struct
Expand Down Expand Up @@ -247,16 +248,29 @@ def read_version_from_efi(self,
if len(buf) != 40:
raise UnrecognizedKernelError(
f"PE file {self.path}: EOF in section table!")
if buf[:8] == b".linux\0\0":
offset = struct.unpack_from("<I", buf, 20)[0]
size = struct.unpack_from("<I", buf, 8)[0]
offset = struct.unpack_from("<I", buf, 20)[0]
if buf[:8] == b".uname\0\0":
# ukify writes uname -r output into the .uname section
# https://uapi-group.org/specifications/specs/unified_kernel_image/
f.seek(initial_offset + offset)
# the ' (ukify)' suffix is a hack to avoid raising
# an exception in read_internal_version()
ver = f.read(size) + b' (ukify)'
logging.debug(
f"Found version {ver!r} in '.uname' section")
return ver
elif buf[:8] == b".linux\0\0":
f.seek(initial_offset + offset)
for func in (self.read_version_from_bzimage,
self.read_version_from_raw,
):
verbuf = func(f)
if verbuf is not None:
logging.debug(
f"Found version {verbuf!r} in"
f" '.linux' section (generic)")
return verbuf
break
return None

def __repr__(self) -> str:
Expand Down

0 comments on commit 5a53874

Please sign in to comment.