"""Decode a hex-encoded GetTagInfoFromName response into a sanitized field map. USE: pipe one tag's hex on stdin (no spaces), one per line. Identity-bearing string values are reported only as length + non-ASCII flags so the output stays commit-safe. """ import struct import sys import binascii def is_printable_ascii(b: bytes) -> bool: return all(0x20 <= c < 0x7F for c in b) def decode_one(hex_str: str) -> None: raw = binascii.unhexlify(hex_str) n = len(raw) cur = 0 # Fixed prefix desc = raw[cur:cur+4]; cur += 4 type_id = raw[cur:cur+16]; cur += 16 tag_key = struct.unpack_from(' 1e-5: print(f" double @trailing+0x{off:X} (abs 0x{cur+off:02X}) = {d}") except Exception: pass # Look for plausible uint32s (small, non-zero) for off in range(0, len(trailing) - 3, 1): v = struct.unpack_from('= 2: last2 = trailing[-2:] last1 = trailing[-1:] print(f" last 2 bytes: {last2.hex().upper()}") print() def main() -> int: for line in sys.stdin: line = line.strip() if not line: continue # Allow optional "TagName: HEX" prefix if ':' in line: label, hex_str = line.split(':', 1) print(f"=== {label.strip()} ===") decode_one(hex_str.strip()) else: decode_one(line) return 0 if __name__ == "__main__": sys.exit(main())