""" Walker v4: alternate [10 NN] data chunks and [00 NN] (or other) marker tags. Hypothesis: - [10 NN]: data block, length NN/2 + 2 bytes (2-byte tag + NN/2 bytes data) - [00 NN]: 2-byte marker block (no data) - [20/30/40 NN]: special blocks with type-dependent length """ import sys sys.path.insert(0, ".") from analysis.load_bundle import load_bundle def walk(body, start): i = start blocks = [] while i + 1 < len(body): t0 = body[i] t1 = body[i + 1] if t0 == 0x10 and t1 % 4 == 0 and 0 < t1 <= 0x80: # data chunk: length NN/2 + 2 length = t1 // 2 + 2 blocks.append((i, "10", t1, bytes(body[i + 2 : i + length]), length)) i += length elif t0 == 0x00 and t1 % 4 == 0: # 2-byte marker blocks.append((i, "00", t1, b"", 2)) i += 2 elif t0 == 0x20 and t1 % 4 == 0: # type 2 — try length 2+t1/2 (similar to 10) OR fixed length = t1 // 2 + 2 blocks.append((i, "20", t1, bytes(body[i + 2 : i + length]), length)) i += length elif t0 == 0x30 and t1 % 4 == 0: length = t1 // 2 + 2 blocks.append((i, "30", t1, bytes(body[i + 2 : i + length]), length)) i += length elif t0 == 0x40 and t1 == 0x02: # Special "footer transition" block — try fixed 22 bytes length = 22 blocks.append((i, "40", t1, bytes(body[i + 2 : i + length]), length)) i += length else: # Unknown tag — stop blocks.append((i, "??", t0, bytes(body[i:i+8]), 0)) break return blocks, i def main(): for name in ("event-c", "event-d", "event-a", "event-b"): b = load_bundle(name) body = b.body # Auto-detect start for s in range(15): if body[s] == 0x10 and body[s+1] % 4 == 0 and 0 < body[s+1] <= 0x80: start = s break else: start = 7 blocks, end = walk(body, start) # Categorize from collections import Counter types = Counter(b[1] for b in blocks) print(f"\n=== {name} === body={len(body)} N={len(b.samples['Tran'])} start={start}") print(f" total blocks: {len(blocks)}, walk ended at {end}/{len(body)}") print(f" type counts: {dict(types)}") # Print last 5 blocks print(f" last 5 blocks: {[(bb[0], bb[1], bb[2]) for bb in blocks[-5:]]}") if end < len(body): print(f" bytes at end: {body[end:end+24].hex(' ')}") if __name__ == "__main__": main()