⑫ 第一步(Step 1):只做唯讀偵察,唔重啟、唔影響已登入納指期貨會話
喺寫任何攔截程式之前,先用 10 秒確認而家運行緊嘅 FTNN 進程實際載入咗邊幾個 .so、開緊邊啲本機 cache 檔,同埋實機有邊啲導出符號可用。以下指令全程唯讀,唔會停掉或注入運行緊嘅視窗。
請主持喺運行 FEX + FTNN 嘅同一部主機終端執行:
ps -ef | grep -E "FTNN|FTWebRender|FEX" | grep -v grep
for pid in $(pgrep -f "FTNN"); do
if grep -q "libMainApp\|libFTQuote" /proc/$pid/maps 2>/dev/null; then
echo "=== TARGET_PID=$pid ==="
awk '$6 ~ /libMainApp|libFTQuote|libQotBase|libssl|libQt5Gui|libcef|protobuf/ {print $6}' /proc/$pid/maps | sort -u
echo "=== OPEN_FILES ==="
ls -l /proc/$pid/fd 2>/dev/null | grep -iE "\.db|\.sqlite|\.dat|cache|futu" | head -n 30
for f in $(awk '$6 ~ /libMainApp|libFTQuote|libQotBase|libssl|libQt5Gui/ {print $6}' /proc/$pid/maps | sort -u); do
echo "--- SYM: $f ---"
nm -D "$f" 2>/dev/null | grep -E "SetTitleInfo|setPlainText|drawText|SSL_read|ParseFromArray|KLine|UpdateKL" | head -n 25
done
fi
done
which gcc g++ x86_64-linux-gnu-gcc 2>/dev/null || true
執行完請回貼輸出(若路徑含個人帳號 ID 可先打碼):
ps 輸出:確認 FTNN 同 FTWebRender 各自運行形態。
maps 與 OPEN_FILES:睇清楚有冇本地 .db/.dat/cache 檔可以直接讀(最低風險路徑)。
SYM 符號清單:確認 libQotBase/libFTQuote/libMainApp/libssl 實際導出咗邊幾個函式名,我哋即刻喺第二步畀出對應嘅精準攔截測試。
以下為 第 6 版(Rev 6)至第 1 版(Rev 1)完整原文,依修正保留規範完整留存:
⑪ 本機落地前攔截(Pre-Persistence Hook)防卡死與解耦規範
- 掛鉤點對接:承接 A33 (
64299) 對 .deb 之實核,libFTQuote/libQotBase 保留未剝離 C++ 符號(SetTitleInfo、setPlainText、drawText 及推播介面),Guest x86_64 LD_PRELOAD 可直接掛載。
- Hook 內嚴禁阻塞(保護 FEX UI 幀率):被攔截函式內只做 memcpy 至
/dev/shm 環形緩衝或 O_NONBLOCK pipe,絕對唔好喺 FEX 執行緒內做正則、JSON、磁碟 fsync 或 HTTP POST。
- 原生 ARM64 零轉譯消費端:所有字串解析、
OHLC 不變量校驗、(symbol, bar_ts) 去重與向 srv.js 批次入庫全交由獨立原生 ARM64 進程處理。
- Session 保護:重啟掛載
LD_PRELOAD 前先備份已登入設定目錄。
Rev 6 補充紀錄摘要(Markdown)
# Turn Log 64298 — Local Pre-Persistence Interception Alignment & Non-Blocking Hook Design (A38)
- Target Seq: `64298` (`sender=dj_host1`, `sha12=6d2bceeb9206`)
- Host Alignment: Confirmed that pre-persistence local interception is the right direction because the interception point sits right on the local machine.
- Cross-Ref (`A33` `seq=64299`): `.deb` inspection verified unstripped C++ symbols in `libFTQuote` and `libQotBase` (`SetTitleInfo`, `setPlainText`, `drawText`, quote push handlers).
## Implementation Guardrails for Local `LD_PRELOAD` Interception under FEX
1. **Zero-Stall Hook Body (Critical for FEX UI)**:
- Never run regex parsing, JSON serialization, disk fsync, or HTTP requests inside the intercepted x86_64 hook function (`drawText` / `setPlainText` / `libQotBase` callback).
- Copy the raw UTF-8 string or proto frame + monotonic timestamp into a lock-free ring buffer / non-blocking pipe/socket on `/dev/shm` (`O_NONBLOCK`, drop-on-full counter instead of blocking the Qt/CEF UI thread).
2. **Native ARM64 Consumer Offload**:
- Do all parsing, `OHLC` invariant checks, deduplication `(symbol, bar_ts)`, and `srv.js` batch posting in a separate native ARM64 Python/Node process reading `/dev/shm`—incurring **0% FEX translation overhead**.
3. **Session Protection**:
- Back up the logged-in FTNN user config directory before any test relaunch with `LD_PRELOAD`.
以下為 第 5 版(Rev 5)至第 1 版(Rev 1)完整原文,依修正保留規範完整留存:
本次修正重點(Rev 4 → Rev 5)
- 釐清關鍵技術誤區:FEX「指令集翻譯(x86_64 → ARM64)」≠「協議解密/反編譯」,網路封包依然受 TLS 與私有二進制格式保護,唔會因為經 FEX 執行就自動變成易讀明文。
- 提出 「限時 30–60 分鐘試探+保護已登入 Session+雙軌並行」 方案,回應應否先試攞 data 方向。
⑨ 技術澄清:點解「程序被 FEX 翻譯」唔等於「容易解到 Data Feed」?
| 層面 | FEX 真實做緊嘅嘢 | 對「攞 Data Feed」嘅真實影響 |
| CPU 指令層 |
把 x86_64 機器碼即時轉譯為 ARM64 指令執行。 |
與喺原生 x86 Linux 運行邏輯相同,唔會把加密協議變明文,亦唔會還原源碼或 Protobuf schema。 |
| 網路協議層 |
Socket 收發依然是 TLS/富途私有對稱加密+二進制封裝幀。 |
若相關加密與解包函式是靜態連結/去符號(stripped),FEX 下甚至比原生 x86 更難用傳統 ptrace 動態除錯。 |
| 真正嘅 Linux 用戶空間優勢 |
所有解完密後嘅資料都留在同一個 Linux 用戶空間記憶體內。 |
唔洗硬拆網線協議!只要掛載 Guest LD_PRELOAD 攔截程式「自己已經解完密」嘅下游接口(如 setPlainText/drawText、SSL_read、ParseFromArray),就可拿現成明文。 |
⑩ 「攞 Data」方向可唔可以試先?(限時 30–60 分鐘雙軌守則)
| 階段/動作 | 具體做法 | 風控與 Session 保護重點 |
| 前置保護(必做!) |
先在磁碟唯讀檢查(nm -D 查動態導出符號、lsof 查本地 cache 檔),先備份現有用戶設定目錄再做任何重啟測試。 |
Owner 已親手完成登入驗證,切勿對已登入主進程直接 gdb/ptrace,免觸發閃退或風控強制重登。 |
| 限時試探(30–60 分鐘上限) |
① 先核對 libFTQuote/libMainApp 有無動態導出 SSL_read/EVP_DecryptUpdate/ParseFromArray;② 同時測試 setPlainText/drawText LD_PRELOAD(程式自己已把 N=10 支指標計算並轉成明文字串)。 |
若發現符號被靜態連結或加密層難拆,到鐘即止蝕,唔好無止境卡喺逆向協議。 |
| 雙軌收口結論 |
可以試先,但要設 30–60 分鐘 Timebox:drawText 攔截(或確定性字模 ROI 匹配)先打通生產管線保底;SSL_read+Protobuf Raw Feed 並行驗證,解通即切換。 |
確保「當日即可穩定 DUMP」,同時保留升級成純 Data Feed 嘅上限。 |
Rev 5 補充紀錄摘要(Markdown)
# Turn Log 64293 — Does FEX Instruction Translation Make Extracting the Raw Data Feed Easy? (A38)
- Target Seq: `64293` (`sender=dj_host1`, `sha12=8f62e9131d10`)
- Question:
- FTNN is running under FEX, meaning the program is already being translated/decoded. Does that make extracting the data feed very easy? Should we try the direct data route first because the program is already translated?
## 1. Technical Clarification: ISA Translation != Protocol Decryption / Decompilation
- **What FEX actually translates**: FEX translates **x86_64 machine instructions into ARM64 machine instructions** at runtime (JIT/dynarec). It does **not** decrypt network traffic, strip proprietary encryption/obfuscation, or turn FTNN's binary protocol into readable JSON/source code.
- **Network wire protocol remains unchanged**: Market quotes still arrive over encrypted TLS / proprietary binary framing (e.g., Futu Protobuf + custom packet headers / compression). Moreover, running invasive x86 debuggers/ptrace under FEX can be *more* fragile than on native x86.
## 2. Where Userspace Access *Is* Practical — Two Distinct "Data" Tiers
Instead of reversing wire encryption from scratch, hook points *after* FTNN decrypts its own data in Linux userspace are far easier than Android sandbox scraping:
1. **Tier A (Fastest & Guaranteed — Post-Decode UI Text Buffer)**:
- By the time FTNN calls `QTextDocument::setPlainText` / `QPainter::drawText` (or writes local cache), the client itself has already decrypted the feed and computed the custom `N=5..10` bar indicator strings.
- Intercepting via guest `LD_PRELOAD` gives 100% exact UTF-8 strings on `/dev/shm` with zero protocol reverse-engineering.
2. **Tier B (True Raw Network Feed — Higher Effort, Timeboxed Probe)**:
- Passive inspection (`nm -D` on bundled `.so`s, `lsof` for local cache files, and testing whether standard `SSL_read` / `EVP_DecryptUpdate` / `google::protobuf::MessageLite::ParseFromArray` are dynamically exported) can quickly tell within **30–60 minutes** whether raw K-line push frames are cleanly interceptable—or statically linked/custom-encrypted.
## 3. Recommended Execution Strategy ("Timebox Raw Feed, Never Stall Pipeline")
- **Protect the live logged-in session**: The owner already completed manual login verification. Avoid invasive `ptrace`/debugger attachment on the live process that could crash or trigger session re-verification; test read-only probes (`nm`, `lsof`, local binary inspection) first and back up session state before restarting with any `LD_PRELOAD` wrapper.
- **Yes, test raw data probing first ONLY under a strict 30–60 min timebox**:
- Track 1 (Immediate Baseline): Stand up `setPlainText`/`drawText` `LD_PRELOAD` (or deterministic ROI glyph matching) for the `N=10` custom indicator so production DUMP runs immediately.
- Track 2 (Timeboxed Upgrade): Probe `SSL_read` / `ParseFromArray` / local cache / CEF CDP. If raw K-line frames are cleanly exposed, switch upstream seamlessly; if custom-encrypted/stripped, Track 1 is already delivering clean data with zero schedule slip.
以下為 第 4 版(Rev 4)至第 1 版(Rev 1)完整原文,依修正保留規範完整留存:
本次修正重點(Rev 3 → Rev 4)
- 誠實回答
seq=64286:一般通用 OCR 引擎無法在高頻巡行下保證 100% 且偏慢;唯獨 XShmGetImage +固定字體確定性字模匹配(Glyph Template Matching) 可在「無遮擋純淨背景」下逼近 100% 且耗時 < 1 ms。
- 修正早前提及的
AT-SPI2 探測優先序:採納 A33 (64284) 對 .deb 之實核結果(libFTQuote 零 QAccessible),正式將無誤差首選確認為 Guest LD_PRELOAD 攔 setPlainText/drawText,並為像素讀取路徑設計 4 道 Fail-Closed 防毒穩定守衛。
⑦ Ubuntu GUI 文字辨識方法比較(準確度 × 速度 × 遮擋風險)
| 方案 | 準確度 | 單次耗時 | 弱點/邊界 |
| 通用 OCR(Tesseract / PaddleOCR / EasyOCR) |
~98%–99.5%(小數點、1/7、6/8/9 偶錯) |
15–120 ms(CPU 重) |
抗鋸齒字體與多欄位巡行會累積錯字,直接入庫必毒化 MA/指標環。 |
確定性字模匹配(XShmGetImage+固定字號字模 L1/XOR) |
99.99%–100%(無遮擋條件下) |
< 0.3–1 ms(極快) |
需固定字體、像素字號、關閉 RGB 次像素抗鋸齒;若 K 線柱或十字線壓到文字仍會拒識。 |
真正 100% 首選:Guest LD_PRELOAD 攔繪字(setPlainText/drawText) |
100.000%(原生記憶體字串) |
~0 ms(無截圖/無辨識開銷) |
完全不受 K 線遮擋、縮放、背景色或字體影響(已由 A33 64284 核實 deb 符號)。 |
⑧ OCR 未達 100% 時的四道 Fail-Closed 穩定性守衛(寧缺勿毒)
| 守衛層 | 檢查內容 | 攔截什麼錯誤 |
| 1. 語法正則 + 字模距離閾值 |
強制整行符合標的代碼+時間戳+完整 OHLCV 格式;每個字元最小 L1 誤差必須低於閾值,否則回傳 OCCLUDED_REJECT。 |
K 線疊字、殘缺截圖、背景雜訊、截斷 ...。 |
| 2. K 線數學不變量 + 跳幅閘 |
必驗 High >= max(O, C)、Low <= min(O, C)、Vol >= 0、Amt >= 0、時間單調;並比對上支報價防無理由十倍跳變。 |
漏讀小數點(如 205.12 → 20512)、1 誤讀 7 破高低包絡。 |
| 3. 游標停泊 + 雙幀共識 |
鼠標固定移出圖表區防彈十字線提示;遇錯即間隔 50–100 ms 複檢,連兩幀完全一致才放行。 |
切股渲染半幀(torn frame)或上一隻殘影。 |
| 4. 拒收降級 + N=10 重疊自動補洞 |
連驗 2 次失敗直接丟棄本幀、絕不猜數入庫;靠自訂指標每次出對上 N=5..10 支的特性,下一輪巡行自動補回缺失 K 棒。 |
把偶發讀寫錯誤隔離在單輪單隻之外,保住整體資料庫零毒化與系統長穩運行。 |
決策結論:
1. 若可載入 Guest LD_PRELOAD(攔 setPlainText/drawText 寫 /dev/shm)= 直接 100% 準確+零視覺稅,徹底消滅 OCR 問題。
2. 若暫用畫面讀取=改用「XShmGetImage + 固定字體確定性字模匹配(<1 ms)」+ 強制套用上述 4 道 Fail-Closed 守衛,配合 N=10 棒重疊補洞,即可在非 100% OCR 下維持高穩定性。
Rev 4 補充紀錄摘要(Markdown)
# Turn Log 64286 — Near-100% Fast Ubuntu GUI OCR Feasibility & Stability Guarantees (A38)
- Target Seq: `64286` (`sender=dj_host1`, `sha12=fd6391b87d6d`)
- Context:
- Question 1: Is there a near-100% accurate and ultra-fast OCR method on Ubuntu GUI for reading top-left chart indicator values?
- Question 2: If OCR cannot achieve near-100%, how do we ensure system stability?
- Prior finding (`A33` `seq=64284`): `.deb` inspection shows `libFTQuote` has zero `QAccessible` / accessible plugins (`AT-SPI2` will likely return empty on `CChartView`), whereas `LD_PRELOAD` hooking `setPlainText`/`drawText` captures raw strings directly.
## Q1: Can Ubuntu GUI OCR Reach Near-100% Accuracy AND Ultra-High Speed?
1. **General-Purpose OCR (Tesseract / PaddleOCR / EasyOCR): NO for 100% + Ultra-Fast**:
- Even with upscaling and whitelists, anti-aliased thin UI digits (`1/7`, `6/8/9`, `.` vs `,`, `-`) incur occasional misreads (~0.1–1% character error rate -> frequent row corruption across 50 symbols x 8 fields), and neural OCR engines add 30–120 ms CPU load per crop on ARM64.
2. **Deterministic Font-Glyph Template Matching + `XShmGetImage`: Near-100% AND < 1 ms (ONLY IF Unoccluded)**:
- On Ubuntu X11, desktop Qt/CEF text rendering at a fixed font family, pixel size, and grayscale/non-subpixel AA (`hintfull`) is **pixel-deterministic**.
- **Pipeline**: Capture only the fixed top-left ROI via X11 MIT-SHM (`XShmGetImage`, zero-copy), mask by known indicator foreground RGB color, split glyphs by vertical projection, and match against pre-extracted exact pixel templates (`0-9 . - : , / + K M B 萬 億`) via L1/XOR distance.
- **Performance & Accuracy**: `< 0.3–1 ms` per crop in C/NumPy and `99.99%–100%` accurate on clean backgrounds—**HOWEVER**, if candlesticks, MAs, volume bars, or cursor crosshairs overlap the text, template matching still fails/rejects.
3. **True 100% Zero-Occlusion Alternative (Not OCR)**:
- As verified in `A33` (`seq=64284`), guest `LD_PRELOAD` hooking `setPlainText` / `QPainter::drawText` (or `SSL_read` + Protobuf) captures exact in-memory strings before rasterization—completely immune to occlusion, anti-aliasing, and font scaling.
## Q2: Stability Architecture When OCR Is < 100% (Fail-Closed "Reject Poison, Backfill Later")
Never let an uncertain OCR read enter the downstream `srv.js` MA/bar pipeline. Enforce 4 fail-closed gates:
1. **Strict Grammar + Glyph Distance Threshold**:
- Require exact symbol + timestamp + full field regex match AND max per-glyph L1 template distance below threshold (any partial overlap from candles/crosshair immediately triggers `OCCLUDED_REJECT`).
2. **K-Line Mathematical Invariants + Jump Sanity Gate**:
- Enforce `High >= max(Open, Close)`, `Low <= min(Open, Close)`, `Volume >= 0`, `Turnover >= 0`, monotonic bar timestamps, and a step-ratio sanity bound against the prior bar/quote (e.g., reject an uncorroborated `10x` / `0.1x` digit-drop or decimal-miss outlier).
3. **2-Frame Consensus & Cursor Park**:
- Keep mouse cursor parked outside the chart ROI (no crosshair tooltip); on mismatch, wait ~50–100 ms and re-read until 2 consecutive frames match identically.
4. **Drop-and-Backfill via N=5..10 Overlap**:
- If a symbol fails validation twice, **drop this frame rather than guessing**; the next patrol cycle's `N=10` recent bars automatically backfill any single skipped cycle idempotently by `(symbol, bar_ts)`.
以下為 第 3 版(Rev 3)、第 2 版(Rev 2)及第 1 版(Rev 1)完整原文,依修正保留規範完整留存:
本次修正重點(Rev 2 → Rev 3)
- 回應
seq=64277「一頁幾十隻、下一頁又幾十隻不斷巡行 DUMP」的規模需求,拆解 ① FEX 效能防爆 與 ② 分層排程/視窗分配。
- 修正 Rev 1 關於
FEX_TSOEnabled=0 的激進選項:採納 A43 (64273) 警示,明確建議保留 TSO 安全性(僅用 HalfBarrierTSOEnabled=1 與 Code Cache,不盲目全關 TSO 防 futex 死鎖)。
⑤ 巡行 DUMP 效能策略(桌面版 vs Android 模擬器)
| 要點 | 實作做法 | 避免踩坑(防卡死原因) |
| 1. 單主圖/少格聯動切股(忌多圖並開) |
只留 1 個主圖(或最多 2×2 聯動格),透過自選股清單快鍵/事件逐隻切換標的,在同一個已暖機的圖表實例內換股。 |
Android 一頁幾十隻靠單欄文字或輕量 List;桌面版若同時開幾十個 live 小圖表,CEF/Qt 重繪與 FEX 轉譯稅會呈倍數暴衝導致開市卡死。 |
| 2. 狀態刷新即讀(取代死等 sleep) |
切股後輪詢檢查左上角「標的代碼+時間戳」變動且指標非空(一般 150–400 ms)即刻抽取,毋須每隻固定 sleep(2s)。 |
大幅縮短單頁巡行時間,同時避免切得太快讀到上一隻股票的殘影資料。 |
| 3. 零視覺抽取 + 安全 FEX 參數 |
讀取優先用 AT-SPI2 或 Guest LD_PRELOAD(drawText/SSL_read);退回 ROI OCR 時只抓左上角小框並關掉動畫/新聞/掛盤側欄。FEX 啟用 Code Cache+HalfBarrierTSOEnabled=1(保留 TSO 防 futex 死鎖)。 |
把多餘繪圖從 FEX 轉譯管線拿走,保留 CPU 給行情解碼與指標計算。 |
⑥ 巡行分配與排程設計(分層、休市閘、分片)
| 分層/機制 | 分配規則 | 配合 N 支指標嘅效果 |
| Tier 1(重點長駐/主標的) |
如納指期貨主圖或高分異動股:獨立 1 個固定小窗長駐唔切換,或每 15–30 秒優先插隊掃描。 |
主標的零切換延遲,唔會被幾十隻冷門股拖慢。 |
| Tier 2(活躍池批掃) |
每批一頁/一組(例 20–40 隻),週期 60–180 秒;每批之間保留 300–800 ms 冷卻與隨機抖動(jitter)。 |
維持現有「時間分隔」節奏,防 CEF/X11 佇列積壓及伺服器頻控。 |
| Tier 3(冷門低頻補洞) |
3–5 分鐘掃一次或盤後補掃;利用自訂指標一次輸出對上 N=5..10 支 K 線的特性,靠 (symbol, bar_ts) 冪等去重寫入。 |
指標輸出 N 支=天然容錯緩衝:就算巡行間隔拉長到幾分鐘都唔會漏棒! |
| 休市閘 + 市場分片(Sharding) |
非交易時段市場直接踢出巡行隊列;如多實例擴容只按市場(港股 vs 美期)分片並 taskset 鎖大核(4C 最多 1–2 實例)。 |
唔燒無謂 FEX 轉譯算力於靜止K線,並防止多實例搶核互卡。 |
總結:桌面版唔好「同時畫幾十個圖」,而係「1 個圖高速切股 + N=10 棒指標作緩衝 + Tier 1/2/3 分頻巡行」。
一旦後續打通 Guest SSL_read / CDP WS 直取,巡行只需切換訂閱即可收流,徹底免除 UI 重繪瓶頸。
Rev 3 補充紀錄摘要(Markdown)
# Turn Log 64277 — Multi-Symbol Patrol DUMP Scale: FEX Performance & Scheduling Allocation (A38)
- Target Seq: `64277` (`sender=dj_host1`, `sha12=173a9a1f56ec`)
- Question:
- Previous Android emulator crawler displayed tens of symbols per page, reading the custom K-line indicator across page 1 -> page 2 -> ... continuously with inter-batch delays.
- How should Desktop (FEX + Futu) adapt this patrol DUMP with respect to ① Performance and ② Allocation / Scheduling?
## ① Performance Optimization for Patrol DUMP under FEX
1. **Never Keep Tens of Live Chart Panes Redrawing Simultaneously**:
- In CEF/Qt under FEX, every visible live chart pane incurs x86->ARM64 translation tax on timer ticks and software/GL rasterization. Opening 20–40 chart widgets at once will saturate CPU during market open.
- **Optimal Pattern**: Keep **1 primary chart (or a 2×2 linked grid max)** and cycle symbols via watchlist keyboard/arrow selection (`XTest`/Qt event) within the same warm chart instance—reusing FEX's warmed JIT code cache and memory arena without spawning new renderers.
2. **Event-Driven Settle Instead of Fixed Long Sleeps**:
- After switching symbol, wait only until the top-left timestamp/symbol header updates and indicator text is non-empty (~150–400 ms typical), then dump immediately.
3. **Zero-Render / Low-Render Text Extraction + Safe FEX Flags**:
- Prefer `AT-SPI2` or guest `LD_PRELOAD` (`QPainter::drawText` / `SSL_read`); if falling back to ROI OCR, capture only the tiny top-left indicator box via X11 SHM and disable chart animations/news/orderbook sidebars.
- Enable FEX Code Caching (`ENABLECODECACHINGWIP` / warmed `~/.fex` cache) + `HalfBarrierTSOEnabled=1`. **Caveat (aligning with A43 64273)**: do not blindly force global `TSOEnabled=0` without stress testing, as full TSO disabling can cause futex deadlocks in multi-threaded GUI runtimes.
## ② Scheduling & Allocation Strategy (Replacing Uniform Slow Patrol)
1. **3-Tier Priority Buckets (Dynamic Cadence Instead of Flat Round-Robin)**:
- **Tier 1 (Pinned / High-Priority, e.g., NASDAQ Futures + Active Leaders)**: Keep pinned in its own dedicated non-switching pane (near real-time, zero symbol-switch churn) or poll every 15–30 s.
- **Tier 2 (Active Watchlist, tens per page)**: Batch-scan every 60–180 s with deliberate inter-batch pacing (e.g., 300–800 ms cool-down per batch) to prevent X11/CEF frame-queue buildup and server rate limits.
- **Tier 3 (Cold / Secondary Symbols)**: Poll every 3–5 min (or post-close backfill). Because the custom indicator outputs `N=5..10` recent bars at once, infrequent passes still recover every bar without gaps when deduplicated idempotently by `(symbol, bar_ts)` on `srv.js`.
2. **Market-Session Gating & Sharding**:
- Exclude closed markets from the active patrol ring so FEX CPU is never burned polling static candles.
- Only scale horizontally by market shard (e.g., HK shard vs US Futures shard) with strict CPU core pinning (`taskset`) and per-instance limits matching physical big cores (e.g., max 1–2 instances on 4C).
3. **End-State Upgrade**:
- Once guest `SSL_read` + Protobuf K-line push decoding or CEF CDP WS interception is verified, patrol DUMP collapses from "wait for UI redraw per symbol" to lightweight subscription cycling / pure memory stream ingestion.
以下為 第 2 版(Rev 2,seq=64272)及第 1 版(Rev 1,seq=64269)完整原文,依修正保留規範完整留存:
本次修正重點(Rev 1 → Rev 2)
- 針對
seq=64272 說明的 Android 舊路(自訂技術指標輸出對上 N 支時間+OHLCV+成交額),拆解桌面版如何無縫延續同一套自訂指標並擺脫截圖 OCR 誤差。
- 補入 免 OpenD、直接攞取 K 線 Data Feed 的三條桌面版原生/Guest 旁路(Local Cache、CEF CDP WebSocket、Guest
SSL_read+Protobuf 解包),免除左上角指標字數截斷與 N 支上限。
③ 桌面版配合「自訂指標輸出對上 N 支 K 線」舊做法(回應 seq 64272)
| 環節 | 做法與注意事項 | 相比 Android 爬蟲的優勢 |
| 1. 沿用自訂技術指標 |
原有富途自訂指標公式(輸出對上 5 / 10 支 K 棒之 時間, O, H, L, C, Vol, 成交額)可直接於桌面版圖表套用。桌面版左上角指標文字欄有單行截斷上限,建議改用精簡格式(例 B0:T,O,H,L,C,V,A)或拆成 2–3 條輸出變數,避免第 5–10 支被 ... 截走。 |
無須重寫指標選棒與時間對齊邏輯,舊爬蟲解析器幾乎可直接沿用。 |
| 2. 文字讀取層(三級由優到簡) |
① AT-SPI2 無障礙樹:開 QT_ACCESSIBILITY=1(Qt5)或 --force-renderer-accessibility(CEF),以 pyatspi 直接讀文字節點。
② Guest LD_PRELOAD 攔繪字(最精準):寫輕量 x86_64 .so hook QPainter::drawText/FreeType/XDrawString,依前綴濾出指標文字直寫 /dev/shm JSONL。
③ 固定小框 ROI OCR(保底):只截左上角指標矩形(XGetImage 進 /dev/shm)+ 2–3× 放大二值化 + tesseract 數字白名單。
|
①② 完全免 OCR 誤判(零 8/B、小數點錯位)且不搶佔 FEX CPU;③ 亦只掃極小區域(<15 ms),遠快於全螢幕抓圖。 |
④ 更好、直接攞到 K 線 Raw Data(免指標字數截斷、免 OpenD)
| 優先序 | 直接 Data Feed 路徑 | 適用架構(承 A25 63935) | 優點與實作要點 |
| A(最推薦) |
Guest LD_PRELOAD 攔 SSL_read+Protobuf 解 K 線 Push |
libMainApp.so(原生 Qt5 行情連線) |
富途桌面版行情走加密 TCP/Protobuf Push。喺 FEX guest 層 hook OpenSSL/BoringSSL SSL_read 取得明文封包,解出 K 線 Cmd 即可直接吐出任意 N 支完整 ts, O, H, L, C, V, Turnover——完全不受視窗遮擋、指標截斷或只拿 5–10 支的限制。 |
| B(若屬網頁圖表) |
CEF 本機 CDP 攔截 WebSocket/Chart Store |
FTWebRender(libcef.so) |
啟動加 --remote-debugging-port=9222 --remote-debugging-address=127.0.0.1,監聽 Network.webSocketFrameReceived 或直接讀前端 K 線 Array,一次取全量歷史與實時增量。 |
| C(零注入旁路) |
本機磁碟快取/SQLite 讀取 |
~/.futu 用戶資料目錄 |
檢查本地已落盤之歷史 K 線檔(先確認最新未收盤 bar 是否僅存記憶體未即時 flush)。 |
建議雙軌落地次序(今日即可切換)
1. 短期保底(當日上線):保留自訂指標輸出對上 5–10 支(注意精簡欄位免截斷),先查 AT-SPI2 / QPainter::drawText LD_PRELOAD(或固定左上角小框 ROI OCR)直接接回現有爬蟲格式。
2. 並行升級(徹底脫離 UI):花 5 分鐘分別探測 FTWebRender CDP 與 Guest SSL_read 明文結構;一旦解出 K 線 Protobuf/WS 欄位,即切換為純 Data Feed 直吐,一次拿對上 50–200 支且零 UI 渲染負載。
Rev 2 補充紀錄摘要(Markdown)
# Turn Log 64272 — Desktop Compatibility for Custom-Indicator N-Bar DUMP & Direct Data Feed Routes (A38)
- Target Seq: `64272` (`sender=dj_host1`, `sha12=497fde0c42f7`)
- Context:
- Prior Android crawler read a custom technical indicator on the K-line chart displaying the past N bars (e.g., 5 or 10 bars: timestamp, Open, High, Low, Close, Volume, Turnover).
- Desktop architecture (`A25` `seq=63935`): `FTNN` launcher -> `libMainApp.so` (Qt5) + `FTWebRender` (`libcef.so` + `libX11` + `libQt5Core`).
- `seq=64265`: OpenD rejected (zero-cost desktop route only). `seq=64269`: FEX confirmed working for main UI + live stream.
## Q1: Adapting the Android Custom-Indicator N-Bar DUMP Workflow to Desktop (FEX + Linux X11)
1. **Reuse the Exact Same Futu Custom Indicator Script**:
- The Futu custom indicator formula outputting the last `N` bars (`T,O,H,L,C,V,Amt`) carries over directly to the desktop chart.
- Because desktop chart top-left overlay lines have character truncation limits, format compactly (e.g., `B0:T,O,H,L,C,V,A;B1:...`) or split across 2–3 indicator output variables so 5–10 bars do not get ellipsized (`...`).
2. **Replace Mobile Screenshot/Accessibility Scraping with Cleaner Desktop Extraction**:
- **Check 1 (Qt Accessibility / AT-SPI2)**: Test `QT_ACCESSIBILITY=1` + `pyatspi` (or `--force-renderer-accessibility` for CEF). If the top-left indicator label exposes an accessible node, read text directly with zero OCR and negligible FEX overhead.
- **Check 2 (Guest `LD_PRELOAD` Text-Draw Interception — Best Exact Drop-in)**: Load a tiny x86_64 `.so` via `LD_PRELOAD` inside the FEX guest to hook `QPainter::drawText` (Qt5 `libMainApp.so`) or FreeType/HarfBuzz/XDrawString, filter by indicator prefix/coordinates, and stream structured JSON lines to `/dev/shm/futu_ind.jsonl` or a local FIFO. Zero OCR errors, immune to overlap/DPI scaling.
- **Check 3 (Targeted Top-Left ROI OCR Fallback)**: Only grab the small top-left rectangle (`XGetImage` / MIT-SHM into `/dev/shm`), upscale 2–3x + binarize, and run `tesseract` with digit/delimiter whitelist (`< 15 ms` per poll, minimal impact on FEX).
## Q2: Better / Direct Data-Feed Methods (Zero-Cost, No OpenD, No Indicator String Truncation)
Ranked by intrusiveness & reliability:
1. **Local Cache / Memory-Mapped Files Inspection (Lowest Overhead)**:
- Inspect FTNN's user data directory (`~/.futu` / local SQLite / binary cache files) for persisted K-line chunks; note live forming bars may remain in RAM until bar close/flush.
2. **CEF Remote Debugging / WebSocket Frame Interception (If Chart/Quotes Use `FTWebRender`)**:
- Launch with `--remote-debugging-port=9222 --remote-debugging-address=127.0.0.1` and subscribe to `Network.webSocketFrameReceived` or query the chart JS store via CDP. Directly receives full bar arrays (`N` bars at once, full precision) without UI layout limits.
3. **Guest `LD_PRELOAD` TLS Plaintext (`SSL_read` / `QSslSocket`) + Protobuf Decode (Most Complete Direct Feed)**:
- Futu desktop receives encrypted TCP/Protobuf market pushes. Hooking OpenSSL/BoringSSL `SSL_read` (or `SSL_write` for requests) inside the guest yields raw unencrypted Futu protocol frames on `/dev/shm` or a local socket; decoding the K-line push `Cmd` gives full history/live bars directly—independent of chart zoom, indicator truncation, or UI rendering stalls.
## Recommended Rollout Order
- **Immediate (Day-1 parity)**: Keep the custom N-bar indicator -> probe AT-SPI2 -> fall back to `QPainter::drawText` `LD_PRELOAD` (or small top-left ROI OCR) so the existing crawler pipeline switches over immediately.
- **Parallel Upgrade**: Run a 5-minute probe on `FTWebRender` CDP and `SSL_read` plaintext dumps; once the K-line Protobuf/WS payload is verified, switch the crawler to direct feed consumption and eliminate UI scraping completely.
以下為 第 1 版(Rev 1,seq=64269)完整原文,依修正保留規範完整留存供對照:
① 現階段 FEX 效能優化方案(針對 ARM64 跑 FTNN/FTWebRender)
| 優先序 | 優化層面 | 具體做法 | 預期作用與驗證重點 |
| 1 |
TSO 記憶體屏障減稅(最大槓桿) |
於 FEXConfig / 環境變數啟用 FEX_HalfBarrierTSOEnabled=1、FEX_VectorTSOEnabled=0、FEX_MemcpySetTSOEnabled=0;視穩定度再實測 FEX_TSOEnabled=0(先以只讀圖表實測無崩潰/無數據錯位)。 |
ARM64 無硬體 x86 TSO,CEF/Qt 多線程大量屏障係主要轉譯稅;放寬 TSO 通常可降顯著 CPU 開銷。 |
| 2 |
FEX Thunking 直通原生庫 |
開啟 Host/Guest Thunking(libX11、libxcb、libGL/libEGL、libasound),將 X11/繪圖調用轉交原生 aarch64 庫執行。 |
免去圖形與 X11 協議封裝的 x86 指令轉譯(與 64264 方向一致,屬可實測項)。 |
| 3 |
大核綁定 + JIT 快取 + UI 減繪 |
以 taskset 綁定 ARM64 大核;確保 /dev/shm 容量充足免 Qt/CEF 退回磁碟 IPC;只保留目標期貨圖表分頁、隱藏其他報價板與關掉無謂動畫;使用輕量 X11/Xvfb 免去合成器(compositor)。 |
減少跨核遷移與重繪像素面積,避免開市幀率搶佔數據處理。 |
② 納指期貨圖表左上角技術指標 DUMP 方案(由準確到最簡)
| 方案 | 適用前提(先花 1 分鐘探測) | 實作路徑 | 優缺點 |
| A. CEF CDP 遠端除錯(最乾淨、零 OCR 誤差) |
指標區或圖表由 FTWebRender(CEF)渲染(A25 63935 已核實有 libcef.so)。 |
啟動加 --remote-debugging-port=9222 --remote-debugging-address=127.0.0.1(只限本機),連 WebSocket CDP 讀 DOM/JS 變數或攔截 Network.webSocketFrameReceived。 |
直接拿到精準浮點數與 raw data feed;若指標畫在 <canvas> 上但有內部 JS 狀態亦可直接讀取。 |
B. Guest LD_PRELOAD 文字繪製攔截(無誤差通殺) |
圖表屬原生 Qt5(libMainApp.so)直接繪製,或 CEF Canvas 不露 DOM。 |
寫輕量 x86 .so(於 FEX guest 內 LD_PRELOAD),攔截 QPainter::drawText/XDrawString/FreeType・HarfBuzz glyph 呼叫,按左上角座標濾出指標字串。 |
100% 精準原文與數值,唔使逆向 Futu 加密 TCP 協議,亦無 OCR 誤讀(如 8/B、小數點)。 |
C. AT-SPI2 讀節點 → 定點 ROI OCR(最易落地兜底) |
唔想改啟動參數或注入 LD_PRELOAD。 |
① 先試 QT_ACCESSIBILITY=1+pyatspi 讀介面文字;② 若屬 Canvas/點陣自繪,僅對 X11 視窗左上角固定小框(例 400×80 px)用 XGetImage/mss 抓入 /dev/shm,放大 2–3× 二值化後跑 tesseract --psm 6(限定數字+符號白名單)。 |
全圖截圖慢,但僅截左上角 400×80 px 喺 ARM64 單次 OCR < 15 ms,可立即像 Android 爬蟲般讀出數值。 |
誠實邊界與建議驗證次序(1 分鐘判別)
1. 檢查圖表視窗係 FTWebRender (CEF) 定 libMainApp.so (Qt Widget):xwininfo -tree / ps aux | grep FT
2. 若見 FTWebRender:先試 --remote-debugging-port=9222(本機回環)睇有冇 WS/DOM 數據流(拿正 data feed)。
3. 若屬原生自繪:優先對左上角固定框做 ROI 截圖 OCR 立即先跑通 DUMP,再按需要補 guest LD_PRELOAD drawText 消除 OCR 誤差。
原始紀錄摘要(Markdown Turn Log)
# Turn Log 64269 — FEX Performance Optimization & NASDAQ Futures Chart Indicator DUMP (A38)
- Target Seq: 64269 (sender=dj_host1, sha12=831015175a7b)
- Context verified from inbox:
- seq=64265 (dj_host1): OpenD rejected (cost/limits); zero-cost data route only.
- seq=64269 (dj_host1): Box64 dropped (crashes at main UI); FEX succeeds (main UI + live data stream).
- seq=63935 (A25): FTNN launcher uses libc/libstdc++; libMainApp.so (Qt5) + FTWebRender (CEF/libcef.so + Qt5Core + libX11).
## Q1: FEX Performance Optimization on ARM64 (Beyond dropping Box64)
1. **TSO Barrier Reduction (Largest FEX multi-thread lever)**:
- ARM64 lacks native x86 TSO; FEX inserts DMB barriers around memory accesses. For CEF/Qt heavy multi-threading, test `FEX_HalfBarrierTSOEnabled=1` (safer first step) and `FEX_VectorTSOEnabled=0` / `FEX_MemcpySetTSOEnabled=0`, or per-app testing with `FEX_TSOEnabled=0` (fastest, ~15-30%+ uplift in memory-heavy threads, must verify no crash/corruption in Futu).
2. **FEX Library Thunking (Native ARM64 graphics/X11)**:
- Enable FEX host thunking for `libX11`, `libxcb`, `libGL`/`libEGL`, `libasound` (`FEXConfig` / `ThunkHostLibs` + `ThunkGuestLibs`) so X11/OpenGL/compositing execute as native aarch64 rather than emulated x86.
3. **Code Cache + Core Pinning + Lightweight Display**:
- Enable FEX JIT/AOT object-code cache if available in the installed FEX build; pin `FTNN`/`FTWebRender` to big/performance Cortex cores (`taskset`) and keep `/dev/shm` adequately sized for CEF/Qt IPC.
- Minimize UI redraw scope: keep only the target NASDAQ Futures chart window/tab visible, hide unused market tickers/news panels, run bare Xvfb/lightweight WM without compositor.
## Q2: DUMPing Top-Left Chart Technical Indicator Values (or Data Feed)
Ranked from quickest probe to cleanest exact extraction (all zero-cost, local):
1. **Probe 1 — CEF Remote Debugging / CDP (Exact Data Feed / DOM if chart is in FTWebRender)**:
- If the chart panel is rendered by `FTWebRender` (CEF), launch with `--remote-debugging-port=9222 --remote-debugging-address=127.0.0.1`. Query `http://127.0.0.1:9222/json` and attach via WebSocket CDP (`Runtime.evaluate` or `Network.webSocketFrameReceived`) to extract exact indicator values or raw chart feed JSON/WS frames with zero OCR error.
2. **Probe 2 — Guest `LD_PRELOAD` Text-Draw Hook (Exact String Capture if native Qt/Canvas)**:
- If the chart is native Qt5 (`libMainApp.so`) or CEF `<canvas>` without DOM nodes, an x86 `LD_PRELOAD` `.so` inside the FEX guest hooking `QPainter::drawText` (or `HarfBuzz`/`FreeType`/`XDrawString`/`pango`) intercepts the exact rendered indicator strings and `(x, y)` coordinates before rasterization—100% exact digits, no OCR, no Futu protocol decryption needed.
3. **Probe 3 — Accessibility Tree (`AT-SPI2`) vs Targeted ROI OCR (Simplest Non-Invasive Fallback)**:
- First check `QT_ACCESSIBILITY=1` + `pyatspi`/`accerciser` (or `--force-renderer-accessibility` for CEF); if exposed as accessible text nodes, read directly.
- If painted directly onto bitmap/canvas (invisible to AT-SPI2), crop ONLY the fixed top-left indicator ROI (e.g., ~400x80 px) from X11 (`XGetImage` / `mss` / `ffmpeg x11grab` into `/dev/shm` tmpfs), upscale 2-3x + grayscale threshold, and run `tesseract` (`--psm 6/7`) or `PaddleOCR` on that tiny ROI (<15 ms/frame on ARM64).
- Note: Direct Futu TCP/TLS feed reverse-engineering is higher-effort due to Futu's proprietary binary/encrypted framing compared to CDP or `drawText` hooking.