"""Offline synthetic sense-category check; never opens a storage device.""" import argparse import ctypes import hashlib import json import platform from datetime import datetime, timezone from pathlib import Path parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--library", required=True, type=Path) args = parser.parse_args() path = args.library.resolve(strict=True) lib = ctypes.CDLL(str(path)) byte_pointer = ctypes.POINTER(ctypes.c_ubyte) lib.sg_err_category_sense.argtypes = [byte_pointer, ctypes.c_int] lib.sg_err_category_sense.restype = ctypes.c_int lib.sg_get_sense_info_fld.argtypes = [ byte_pointer, ctypes.c_int, ctypes.POINTER(ctypes.c_uint64) ] lib.sg_get_sense_info_fld.restype = ctypes.c_bool lib.sg_lib_version.argtypes = [] lib.sg_lib_version.restype = ctypes.c_char_p version = lib.sg_lib_version().decode() rows = [] for asc in (0x10, 0x47): for valid in (False, True): raw = bytearray(18) raw[0] = 0xF0 if valid else 0x70 raw[2] = 0x0B raw[3:7] = (123).to_bytes(4, "big") raw[7] = 10 raw[12] = asc buffer = (ctypes.c_ubyte * len(raw)).from_buffer_copy(raw) info = ctypes.c_uint64() category = lib.sg_err_category_sense(buffer, len(buffer)) available = bool(lib.sg_get_sense_info_fld(buffer, len(buffer), ctypes.byref(info))) expected = 40 if asc == 0x10 else 11 if category != expected or available != valid or (available and info.value != 123): raise RuntimeError("Native library differs from the documented control") rows.append({ "input_hex": raw.hex(), "received_bytes": len(raw), "sense_key_hex": "0b", "asc_hex": format(asc, "02x"), "information_valid_bit": valid, "category_decimal": category, "information_available": available, "information_value": info.value if available else None, }) print(json.dumps({ "schema_version": 1, "generated_utc": datetime.now(timezone.utc).isoformat(), "method": "Four invented fixed-format buffers passed to two native library functions; no device I/O.", "scope": "This is a library-call observation, not a utility exit or a hardware failure measurement.", "library": {"version": version, "path": str(path), "sha256": hashlib.sha256(path.read_bytes()).hexdigest()}, "runtime": {"python": platform.python_version(), "machine": platform.machine()}, "rows": rows, }, indent=2))