"""Walk the body assuming chunks delimited by 0x10 NN tags. Print each chunk's structure.""" import sys sys.path.insert(0, ".") from analysis.load_bundle import load_bundle def walk(body: bytes, start_offset: int = 7, max_chunks: int = 30): """Find all positions where byte = 0x10 followed by a multiple-of-4 byte. Print chunks.""" chunks = [] i = start_offset while i < len(body) - 1: # Find next `10 NN` where NN is multiple of 4 (and not preceded by another 0x10 immediately, which would be data). if body[i] == 0x10 and (body[i+1] % 4 == 0): chunks.append(i) i += 1 return chunks def main(): for name in ("event-c", "event-d"): b = load_bundle(name) body = b.body positions = [] i = 7 # skip 7-byte preamble while i < len(body) - 1: if body[i] == 0x10 and body[i+1] % 4 == 0 and body[i+1] > 0: positions.append(i) i += 2 # skip past tag else: i += 1 print(f"\n=== {name} === body={len(body)}, total `10 NN` (NN%4==0, NN>0) tags: {len(positions)}") # Print first 20 chunks: show position, NN, gap to next tag for k in range(min(30, len(positions))): pos = positions[k] NN = body[pos + 1] next_pos = positions[k+1] if k+1 < len(positions) else len(body) gap = next_pos - pos data_bytes = body[pos+2 : next_pos] print(f" chunk[{k:>3}] @ {pos:>5} NN=0x{NN:02x} ({NN:>3}, NN/2={NN//2}) gap={gap:>3} " f"data={data_bytes[:24].hex(' ')}{'...' if len(data_bytes) > 24 else ''}") if __name__ == "__main__": main()