from __future__ import annotations __lazy_modules__ = {"struct"} import struct LFANEW_OFFSET = 30 * 2 FILE_HEADER_SIZE = 5 * 4 SUBSYSTEM_OFFSET = 17 * 4 IMAGE_SUBSYSTEM_WINDOWS_GUI = 2 IMAGE_SUBSYSTEM_WINDOWS_CUI = 3 def get_pe_subsystem(filename: str) -> int | None: with open(filename, "rb") as f: if f.read(2) != b"MZ": return None f.seek(LFANEW_OFFSET) # Explicit little-endian widths: the PE fields are fixed 32-/16-bit # values, whereas native "L"/"H" sizes are platform-dependent. lfanew = struct.unpack(" list[str]: return list(__all__)