import binascii def decode_pb(b): """Generic protobuf decoder -> list of (field, wiretype, value). value=int for varint/enum, bytes for LD, bytes for fixed.""" out = [] i = 0; n = len(b) while i < n: key = b[i]; i += 1 fn = key >> 3; wt = key & 7 if wt == 0: val = 0; shift = 0 while i < n: byte = b[i]; i += 1 val |= (byte & 0x7f) << shift; shift += 7 if not (byte & 0x80): break out.append((fn, wt, val)) elif wt == 2: ln = 0; shift = 0 while i < n: byte = b[i]; i += 1 ln |= (byte & 0x7f) << shift; shift += 7 if not (byte & 0x80): break data = b[i:i+ln]; i += ln out.append((fn, wt, data)) elif wt == 5: out.append((fn, wt, b[i:i+4])); i += 4 elif wt == 1: out.append((fn, wt, b[i:i+8])); i += 8 else: return out # unknown wiretype, abort return out def show(res): parts = [] for fn, wt, v in res: if wt == 0: parts.append(f"f{fn}:varint({v})") elif wt == 2: parts.append(f"f{fn}:LD({v.hex()} len={len(v)})") else: parts.append(f"f{fn}:wt{wt}({v.hex()})") return " | ".join(parts) OBS = bytes.fromhex("aa55001700010000030100071011a201024200e154") print("OBSERVED_FRAME len =", len(OBS), OBS.hex()) # Try to find the protobuf payload inside by varying header size (1..6) and checksum tail (0..2) print("\n=== brute-force wrapper: find inner protobuf starting with field1 varint 0..42 ===") for hsz in range(1, 7): for csize in (0, 1, 2): if hsz + csize > len(OBS): continue body = OBS[hsz: len(OBS)-csize] if csize else OBS[hsz:] try: res = decode_pb(body) except Exception: continue if not res: continue f1, wt1, v1 = res[0] # plausible: first field is varint (wt0) with small value 0..42 (CommandType range) if wt1 == 0 and isinstance(v1, int) and 0 <= v1 <= 42: # also require it parses cleanly (no leftover impossible) print(f" hsz={hsz} csize={csize} -> {show(res)}") print("\n=== also decode our candidate2 protobuf (ControlCommand mouse click) to confirm schema ===") cand2 = bytes.fromhex("081782010c0800150000003f1d0000003f") print(" cand2:", show(decode_pb(cand2))) print("\n=== enter-mouse-mode correct protobuf (ControlCommand{type=MOUSE_CTRL=23}) ===") enter = bytes.fromhex("0817") print(" enter:", show(decode_pb(enter))) # Known frame: try interpreting whole thing minus aa55(2) as nested, or just print raw struct print("\n=== raw byte-by-byte of OBS ===") print(" ", " ".join(f"{x:02x}" for x in OBS))