"""Machine-check the sos_proc_switch msg-headroom defect directly from firmware bytes. Claim under test: sos_proc_switch (SVC 0xF2) validates the caller-supplied `msg` pointer with only 0x28 bytes of headroom on its third window, while the callee (SYS_DRV's sysdrv_message_handler) reads AND writes 0x7C bytes at that pointer. This script extracts BOTH numbers from the actual images -- the slack constants from sos2.elf and the access size from sys_drv2.elf -- and reports the mismatch. Nothing is hardcoded from the write-up. """ import struct from capstone import * from capstone.arm import * BASE = '/Users/user/dev/amd-psp-re/psp_out/handover/elf/' def seg(path): raw = open(path, 'rb').read() ph = struct.unpack(' ends at %#x" % (ACCESS, maxmsg + ACCESS)) print(" bytes past the window end : %d" % (maxmsg + ACCESS - WIN_END)) print(" msg values that PASS but overflow: %#x .. %#x (%d)" % (WIN_END - ACCESS + 1, maxmsg, maxmsg - (WIN_END - ACCESS + 1) + 1)) ok = bool(slack_4k) and bool(slack_x28) and bool(sizes) and (SLACK < ACCESS) print("\n%s" % ("*** HEADROOM DEFECT CONFIRMED FROM FIRMWARE BYTES ***" if ok else "could not confirm -- check offsets"))