#!/usr/bin/env python3 """Definitive test: replicate Kelebek's data_array_end shrinking (stop code at first string/array offset), then measure clean decode rate over all Himegari scripts.""" import os, re, sys, collections from pathlib import Path sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) import paths import sys4load CPP=paths.KELEBEK_CPP.read_text(encoding="utf-8") TABLE={}; LABEL={} for m in re.finditer(r'\{\s*(0x[0-9A-Fa-f]+)\s*,\s*"([^"]*)"\s*,\s*(0x[0-9A-Fa-f]+)\s*\}', CPP): TABLE[int(m.group(1),16)]=int(m.group(3),16); LABEL[int(m.group(1),16)]=m.group(2) files=paths.scripts() clean=dirty=0; parsefail=0 still_unknown=collections.Counter(); examples={} instr_total=0 for name,p in sorted(files.items()): try: scr=sys4load.load(p) except Exception: parsefail+=1; continue dw=scr.dwords; cl=scr.code_len end=cl # data_array_end, starts at F8, shrinks to first string/array off i=0; ok=True; reason="" n_instr=0 while iend: ok=False; reason=f"overrun 0x{op:x}@{i}"; break for a in range(argc): atype=dw[base+2*a]; aval=dw[base+2*a+1] if atype==2 and 0<=aval shrink code end end=min(end,aval) if op==0x64 and a==1 and 0<=aval