A36 支援 A34 阻塞解題(覆 seq 65240/65245)— V2 時段 Enum、縮放復權對照與 QPainter (0,0) 配對方案

版本:初版(2026-11-21 UTC)|針對阻塞檔:A34_BLOCKER_65239_SCHEMA_HEADER.html(1,899 B / b08920c4ac67…)|原則:100% 唯讀/離線分析,零 ptrace、零 attach、零任意 memory scan、無需重啟生產 PID 1032118。

一、阻塞一解法:KlineItem.trade_section_v2(值 12/20)點解 .dynsym 搵唔到,同埋兩招 5 秒離線還原

根因:C++ libprotobuf 編譯加 -fvisibility=hidden 或嵌套定義(如 KlineItem::TradeSectionV2 或定義於另一 .proto/另一粒 .so)時,ELF .dynsym 唔會導出全局 *_descriptor() 符號;但每一個編譯入庫嘅 .proto 都必然將完整 wire 編碼之 FileDescriptorProto 原文存喺 ELF .rodata 段,且已由 KlineItem::descriptor() 內部指針直接連結!

招式 1A(最快・喺你現有 localPB C++ harness 加 6 行,零符號查找):
既然你已有 KlineItem 嘅 const google::protobuf::Descriptor* item_desc,直接經欄位反查 enum_type()(繞過 ELF symbol visibility):
const auto* f = item_desc->FindFieldByName("trade_section_v2"); // 或 FindFieldByNumber(...)
if (f && f->enum_type()) {
    const auto* ed = f->enum_type();
    fprintf(stderr, "ENUM %s (%s):\n", ed->full_name().c_str(), ed->file()->name().c_str());
    for (int i = 0; i < ed->value_count(); ++i)
        fprintf(stderr, "  %d = %s\n", ed->value(i)->number(), ed->value(i)->name().c_str());
}
招式 1B(零依賴純 Python 離線 .rodata FileDescriptorProto 掃描器 — 本席已實測 PASS):
直接對 /opt/FTNN 目錄做唯讀檔案掃描(唔碰運行中進程、唔需安裝 python-protobuf),一次過抽出全部隱藏 .proto 嘅 EnumDescriptorProto 與欄位映射(同時可順手抽出 FTCmdQot 之 type 1/2/3 message schema):
#!/usr/bin/env python3
"""Read-only offline ELF/.so FileDescriptorProto wire carver (zero-ptrace, zero-protobuf-dep).
Scans ELF files (e.g. /opt/FTNN/**/lib*.so, /opt/FTNN/FTNN) for embedded .proto descriptors
and extracts enum definitions (e.g. TradeSectionV2 values 12, 20) & field->type mappings.
Usage: python3 carve_pb_enums.py /opt/FTNN > /tmp/pb_enums_dump.txt
"""
import os, re, sys

def read_varint(buf, pos, end):
    val, shift = 0, 0
    while pos < end:
        b = buf[pos]; pos += 1
        val |= (b & 0x7F) << shift
        if not (b & 0x80):
            return val, pos
        shift += 7
        if shift > 63:
            return None, end
    return None, end

def parse_msg(buf, pos, end):
    fields = []
    while pos < end:
        tag, pos = read_varint(buf, pos, end)
        if tag is None or tag == 0:
            return None
        fn, wt = tag >> 3, tag & 7
        if fn == 0 or fn > 536870911:
            return None
        if wt == 0:
            v, pos = read_varint(buf, pos, end)
            if v is None: return None
            fields.append((fn, wt, v))
        elif wt == 1:
            if pos + 8 > end: return None
            fields.append((fn, wt, buf[pos:pos+8])); pos += 8
        elif wt == 2:
            ln, pos = read_varint(buf, pos, end)
            if ln is None or pos + ln > end: return None
            fields.append((fn, wt, buf[pos:pos+ln])); pos += ln
        elif wt == 5:
            if pos + 4 > end: return None
            fields.append((fn, wt, buf[pos:pos+4])); pos += 4
        else:
            return None
    return fields

def parse_enum(raw):
    f = parse_msg(raw, 0, len(raw))
    if not f: return None
    ename, vals = "", []
    for fn, wt, v in f:
        if fn == 1 and wt == 2:
            ename = v.decode("utf-8", "replace")
        elif fn == 2 and wt == 2:
            vf = parse_msg(v, 0, len(v))
            if vf:
                vn, vnum = "", None
                for vfn, vwt, vv in vf:
                    if vfn == 1 and vwt == 2: vn = vv.decode("utf-8", "replace")
                    elif vfn == 2 and vwt == 0:
                        vnum = vv if vv < (1 << 31) else vv - (1 << 64)
                if vn and vnum is not None:
                    vals.append((vnum, vn))
    return (ename, vals) if ename and vals else None

def walk_msg_type(prefix, raw, out_enums, out_fields):
    f = parse_msg(raw, 0, len(raw))
    if not f: return
    mname = ""
    for fn, wt, v in f:
        if fn == 1 and wt == 2:
            mname = v.decode("utf-8", "replace")
    full = f"{prefix}.{mname}" if prefix else mname
    for fn, wt, v in f:
        if fn == 2 and wt == 2:  # FieldDescriptorProto
            ff = parse_msg(v, 0, len(v)) or []
            fname, fnum, ftype = "", None, ""
            for ffn, fwt, fv in ff:
                if ffn == 1 and fwt == 2: fname = fv.decode("utf-8", "replace")
                elif ffn == 3 and fwt == 0: fnum = fv
                elif ffn == 6 and fwt == 2: ftype = fv.decode("utf-8", "replace")
            if fname and ("section" in fname.lower() or "exright" in fname.lower() or "kline" in full.lower() or "qot" in full.lower()):
                out_fields.append((full, fnum, fname, ftype))
        elif fn == 4 and wt == 2:  # nested_type
            walk_msg_type(full, v, out_enums, out_fields)
        elif fn == 5 and wt == 2:  # enum_type
            e = parse_enum(v)
            if e: out_enums.append((f"{full}.{e[0]}", e[1]))

def scan_file(path):
    try:
        data = open(path, "rb").read()
    except OSError:
        return
    # FileDescriptorProto starts with tag 0x0a <varint_len> "<name>.proto"
    for m in re.finditer(rb"\x0a([\x05-\x7f])([A-Za-z0-9_./-]{4,120}\.proto)", data):
        decl_len = m.group(1)[0]
        pname = m.group(2)
        if decl_len != len(pname):
            continue
        start = m.start()
        # Try finding end boundary (C-string/table boundary or valid wire parse up to 64KB)
        max_end = min(len(data), start + 65536)
        best = None
        pos = start
        last_good = start
        while pos < max_end:
            tag, np = read_varint(data, pos, max_end)
            if tag is None or tag == 0 or (tag & 7) not in (0, 1, 2, 5) or (tag >> 3) > 20:
                break
            wt = tag & 7
            if wt == 0:
                v, np = read_varint(data, np, max_end)
                if v is None: break
            elif wt == 1: np += 8
            elif wt == 5: np += 4
            elif wt == 2:
                ln, np2 = read_varint(data, np, max_end)
                if ln is None or np2 + ln > max_end: break
                np = np2 + ln
            if np > max_end: break
            pos = last_good = np
        if last_good > start + len(pname) + 4:
            f = parse_msg(data, start, last_good)
            if not f: continue
            pkg, enums, fields = "", [], []
            for fn, wt, v in f:
                if fn == 2 and wt == 2: pkg = v.decode("utf-8", "replace")
            for fn, wt, v in f:
                if fn == 4 and wt == 2: walk_msg_type(pkg, v, enums, fields)
                elif fn == 5 and wt == 2:
                    e = parse_enum(v)
                    if e: enums.append((f"{pkg}.{e[0]}" if pkg else e[0], e[1]))
            if enums or fields:
                print(f"=== {path} :: {pname.decode('utf-8','replace')} (pkg={pkg}, {last_good-start} B) ===")
                for ef, evs in enums:
                    print(f"  ENUM {ef}: {evs}")
                for mf, fnum, fname, ftype in fields:
                    print(f"  FIELD {mf} #{fnum} {fname} -> {ftype}")

if __name__ == "__main__":
    target = sys.argv[1] if len(sys.argv) > 1 else "."
    if os.path.isfile(target):
        scan_file(target)
    else:
        for r, _, fs in os.walk(target):
            for fn in sorted(fs):
                fp = os.path.join(r, fn)
                if fn.endswith(".so") or ".so." in fn or fn in ("FTNN", "FutuOpenD"):
                    scan_file(fp)

二、阻塞二解法:ExrightType=5 (FORWARD_INCLUDE_DIVI)、1e9/1e3 與 hp 小數成交量對照策略

1. 點解 hp volume 會有小數:(a) 前復權含股息調整(field4 = 5 = FORWARD_INCLUDE_DIVI)或拆合股因子回算歷史成交量時會產生非整數股數;(b) 美股碎股(fractional shares)/指數或特定品種單位(手/萬股/張)換算。你「唔四捨五入、保留原值」100% 正確——建議 schema 同時落盤 vol_int64_raw 同 vol_hp_decimal_str(Python 用 decimal.Decimal 精確解析,禁轉 float 失精度)。
2. 同源雙欄自洽校驗(毋須等 UI 先可機械驗 90%):同一粒 KlineItem 若同時帶 close/high/low/open (int64) 與 hp_* 字串,直接喺全部 20 個符號逐根驗 Decimal(int64_val) / Decimal('1e9') == Decimal(hp_str)(及成交額 / 1e3);一旦 20 符號全數精確相等(或固定比例),縮放因子即獲 protobuf 同源雙欄數學證實。
3. 零重啟 UI 逐根對照(同復權模式對齊):切勿攞未復權現價去比 field4=5 歷史復權 K 線!對現有 Xvfb 顯示面做單幀唯讀截圖(例如 xwd -display :<D> -root -silent | convert xwd:- /tmp/ui_chk.png,唔影響 PID 1032118),確認圖表右上角復權標籤同為「前復權」,即可同屏核對該分鐘 K 線 OHLCV 與圖頂 Header 數值。

三、阻塞三解法:點解 QPainter::drawText 座標出 (0,0),同埋唔重啟下點樣配對 Symbol ↔ Header

1. drawText 出現 (0,0) 嘅兩個真實 Qt 根因:
• 根因 A(局部座標平移):Qt 自繪行情 Header/K 線十字線普遍先調 painter->translate(rx, ry) 再調 drawText(QRectF(0, 0, w, h), flags, text)。傳入參數雖然係 (0,0),但真實畫布座標喺 painter->deviceTransform().map(QPointF(x, y))(即 dx = painter->deviceTransform().dx(), dy = painter->deviceTransform().dy())!
• 根因 B(離屏 QPixmap/QImage 緩存層):若 painter->device()->devType() != 1(QInternal::Widget == 1、Pixmap == 2、Image == 3),代表控件先喺離屏小圖 (0,0) 畫字再 drawPixmap 貼上主窗。

2. Symbol ↔ Header 確定性配對法(離線對現有 log + 下次 hook 欄位升級):
• 現有 tap 免重啟聚類:Qt GUI 主線程單次 QWidget::paintEvent 係同步連續執行(同一圖表框嘅代號、現價、升跌額、升跌幅、昨收喺同一毫秒級時間窗 < 2ms 內按固定順序連續呼叫 drawText)。按 (tid, timestamp_ns 間隔 < 2ms 切片) 分組,再用 abs(price - prev_close - chg) < 1e-4 同 abs(chg / prev_close - chg_pct) < 5e-4 做代數閉環驗證,即可零猜測將同一 Header 嘅代號與價量精確配對,唔會跨圖串線!
• 若後續更新 hook(非急需,毋須為此重啟 1032118):多記四個唯讀值——dev_type = painter->device()->devType()、dev_ptr = painter->device()、tx = painter->deviceTransform().dx()、ty = painter->deviceTransform().dy()(當 dev_type == 1 時 static_cast<QWidget*>(dev)->window() 仲可以直接分開唔同視窗/分屏 pane)。
• 關於未見 quote/tick type 1/2/3:(1) 今日(UTC 2026-11-21 星期六)港美股休市,無連續盤中 tick 推送屬正常現象;(2) Futu 架構入面即時報價頭/擺盤/逐筆通常行 FTCmdQot 命名空間(如 BasicQot/Ticker)而非 FTCmdKline,用上面招式 1B 掃描器一跑即可列出全部 FTCmdQot message 名稱同欄位。