"""Search for structural repetition in the body bytes.""" import sys sys.path.insert(0, ".") from analysis.load_bundle import load_bundle def find_pattern_offsets(body: bytes, pattern: bytes, max_count=20): out = [] i = 0 while True: i = body.find(pattern, i) if i < 0: break out.append(i) i += 1 if len(out) >= max_count: break return out def main(): for name in ("event-a", "event-b", "event-c", "event-d"): b = load_bundle(name) body = b.body print(f"\n=== {name} (body={len(body)}, N_samples={len(b.samples['Tran'])}) ===") # Try to find repeating substructures (look for 4-byte 0x10-prefixed markers) for prefix in [b"\x10\x10", b"\x10\x04", b"\x10\x08", b"\x10\x0c", b"\x10\x18", b"\x10\x14", b"\x10\x20", b"\x10\x40", b"\x10\x80", b"\x10\x00", b"\x10\x01", b"\x10\x03", b"\x10\xf0", b"\xf1\x10", b"\x00\x10", b"\x40\x02", b"\x20\x04", b"\x30\x04", b"\x30\x08", b"\x00\x1a"]: offs = find_pattern_offsets(body, prefix, max_count=200) if 1 <= len(offs) <= 1000: # Print first 10 offsets first = offs[:6] last = offs[-3:] print(f" '{prefix.hex()}' x{len(offs):>4} first={first} last={last}") if __name__ == "__main__": main()