#!/usr/bin/env python3 """Structural PE32 check; not a Windows ABI or execution test.""" import pathlib, struct, sys p=pathlib.Path(sys.argv[1]); b=p.read_bytes(); kind=sys.argv[2] def u16(o): return struct.unpack_from('0, 'no entry point' sub=u16(h+68); assert sub==(1 if kind=='sys' else 3), 'unexpected subsystem' assert not u16(o+22)&0x2000, 'DLL rather than executable/driver' print(f'{p.name}: PE32 x86, subsystem {sub}, OS {u16(h+40)}.{u16(h+42)}, subsystem version {u16(h+48)}.{u16(h+50)}') except (AssertionError,struct.error) as e: sys.exit(f'{p}: invalid PE: {e}')