Files
admin 2840e82685 Initial commit: Android GlassMouse + iOS GlassRemote 智能眼镜遥控项目
包含本次会话修复:
- iOS clickReady 警告 bug(默认 false 永远显示)
- BLE 'handle is invalid' 排查(stale handle auto-retry 实验 + 回退)

项目结构:
- glass-mouse/: 眼镜端原生 Kotlin App,前台服务 MouseService + 自定义 BLE GATT 桥接 ProxyBleServer + 无障碍 GestureDescription 注入
- ios/GlassRemote/: iPhone 端 SwiftUI + CoreBluetooth,通过 BLE 直连眼镜
- HTTP 投屏服务(:8000) 接 PPT/WPS 备注宏 POST 推送

技术栈: Android Kotlin (gradle 8.14.4, compileSdk 34), iOS Swift 5.10 (Xcode 26.5)
2026-08-26 10:34:23 +08:00

76 lines
2.8 KiB
Python

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))