Files
zinnia/scripts/get_modinfo.py
T
2026-09-20 05:27:41 +02:00

38 lines
1.1 KiB
Python
Executable File

#!/usr/bin/env python3
# Small script to print all options available inside a built kernel.
# fmt: off
import sys
from elftools.elf.elffile import ELFFile
SIZEOF_PTR = 8
SIZEOF_STRUCT = 40
ENDIAN = "little"
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Provide a path to the kernel binary to use")
sys.exit(1)
with open(sys.argv[1], "rb") as elffile:
file = ELFFile(elffile)
version = "?"
author = "?"
desc = "?"
license = "?"
for segment in file.iter_segments():
match segment["p_type"]:
case 0x60000001: version = segment.data()[:-1].decode()
case 0x60000002: author = segment.data()[:-1].decode()
case 0x60000003: desc = segment.data()[:-1].decode()
case 0x60000004: license = segment.data()[:-1].decode()
print(f"Module info for \"{sys.argv[1]}\"")
print(f"Description:\t{desc}")
print(f"Version:\t{version}")
print(f"Author(s):\t{author}")
print(f"License:\t{license}")