"""Read-only instruction contexts for an exact AMD64 PE immediate candidate. Uses exception-table bounds and validates byte candidates against disassembly. No native execution; output is not a proof of a field/command's semantics. """ import argparse import bisect import hashlib import struct from pathlib import Path from capstone import Cs, CS_ARCH_X86, CS_MODE_64 p = argparse.ArgumentParser(description=__doc__) p.add_argument('--binary', type=Path, required=True) p.add_argument('--value', type=lambda s: int(s, 0), required=True) p.add_argument('--width', type=int, choices=(2, 4), default=4) p.add_argument('--output', type=Path, required=True) a = p.parse_args() b = a.binary.read_bytes() pe = struct.unpack_from(' 128: raise SystemExit('Candidate bound reached') a.output.write_text('\n'.join(lines)+'\n', encoding='utf-8') print(f'Wrote {len(seen)} instruction contexts to {a.output}')