PhillipC05/tpt-res

GitHub: tpt-solutions/tpt-res

一套用 Rust 编写的 Linux 硬件驱动逆向工程工具链,通过 eBPF 流量捕获、ML 固件分析与 AI 辅助规范综合,系统性地加速驱动开发流程。

Stars: 0 | Forks: 0

# TPT 逆向工程套件 **TPT-RES** 是一个开源工具链,旨在通过自动化捕获、二进制分析、规范综合、行为验证和合规性认证,系统性地加速 Linux 硬件驱动程序的开发。 [![License: Apache-2.0](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](LICENSE) [![Rust](https://img.shields.io/badge/language-Rust-orange.svg)](https://www.rust-lang.org/) ## 功能简介 让一款新硬件设备在 Linux 上正常运行通常需要数周的手动逆向工程。TPT-RES 将这一过程压缩为一个结构化且可复现的 pipeline: ``` Hardware Device │ ▼ [DriverScope] ── eBPF capture of USB/PCI/I2C/SPI bus traffic │ ▼ [FirmwareX] ── Binary analysis, disassembly, ML pattern recognition │ ▼ [ProtocolForge] ─ HWSpec DSL synthesis, SMT verification, AI import │ ▼ [ShadowDriver] ── Behavioral replay, divergence detection, fault injection │ ▼ [VendorBridge] ── Compliance pipeline, certification, badge generation ``` ## Crates | Crate | 用途 | 状态 | |---|---|---| | `tcr-core` | 共享类型、知识图谱 schema、验证、监控 | 稳定 | | `tcr-crypto` | Ed25519 签名,SHA-256 内容寻址 | 稳定 | | `tcr-storage` | SQLite / PostgreSQL / S3 存储后端 | 稳定 | | `tcr-grpc` | gRPC 工具间通信 | 稳定 | | `tcr-ai` | 统一 LLM 客户端 — OpenRouter & Ollama | 稳定 | | `driverscope` | eBPF 捕获引擎、硬件识别、CLI | 仅限 Linux | | `driverscope-ui` | GTK4/libadwaita 桌面 UI | 仅限 Linux | | `firmwarex` | 二进制分析、反汇编、ONNX ML、AI 标注 | 稳定 | | `protocolforge` | HWSpec 语言、编译器、AI 导入、LKML patch 生成 | 稳定 | | `shadowdriver` | Trace 重放、偏差检测、故障注入 | 稳定 | | `vendorbridge` | 认证 pipeline、徽章生成、通知 | 稳定 | ## AI 集成 TPT-RES 通过 `tcr-ai` 提供原生 LLM 支持,除了运行中的 Ollama 实例或 OpenRouter API key 外,无需任何外部服务。 **Ollama(本地,无需 API key):** ``` # 拉取一次模型 ollama pull codellama # 导入 datasheet 并生成 HWSpec 草稿 protocolforge import-ai --text datasheet.txt --provider ollama --model codellama # 标注反汇编函数 firmwarex annotate-ai --session --addr 0x1234 --provider ollama # 从 driver 源码生成 ONNX 训练数据 firmwarex generate-training-data --count 500 --provider ollama --model codellama --out training.json ``` **OpenRouter(云端):** ``` export OPENROUTER_API_KEY=your_key_here protocolforge import-ai --text datasheet.txt --provider openrouter ``` ## 构建 ### 前置条件 - Rust 1.75+ (`rustup update stable`) - 对于 `driverscope` 和 `driverscope-ui`(仅限 Linux): - GTK 4.10+ 和 libadwaita 1.4+ (`sudo apt install libgtk-4-dev libadwaita-1-dev`) - 用于 eBPF 的 Linux 内核 headers 和 clang (`sudo apt install linux-headers-$(uname -r) clang`) ### 构建所有 crates ``` # 所有平台无关的 crates cargo build --workspace \ --exclude driverscope \ --exclude driverscope-ui # 仅 Linux — 完整 workspace cargo build --workspace ``` ### 运行测试 ``` # 跨平台 cargo test --workspace \ --exclude driverscope \ --exclude driverscope-ui # 完整版 (Linux) cargo test --workspace ``` ## 工具 ### DriverScope — 硬件观测台 ``` # 捕获 30 秒的 USB 流量 driverscope capture --device 046d:0825 --duration 30 # 将 session 导出为独立的 HTML viewer driverscope export --session --format html --out trace.html # 分析并识别硬件 driverscope analyze --session ``` ### FirmwareX — 二进制分析 ``` # 提取并分析 Windows driver 包 firmwarex analyze driver.cab # AI 辅助函数标注 firmwarex annotate-ai --session --provider ollama # 生成 ONNX 训练数据 firmwarex generate-training-data --count 1000 --out training.json ``` ### ProtocolForge — 规范综合器 ``` # 解析并验证 HWSpec 文件 protocolforge validate device.hwspec # 编译为 C headers protocolforge compile --target cheader device.hwspec --out include/ # 使用 AI 从 datasheet 导入 protocolforge import-ai --text datasheet.txt --provider ollama # 生成 LKML patch 系列 protocolforge patch --spec device.hwspec --driver-src ./driver/ --out patches/ ``` ### VendorBridge — 合规性与认证 ``` # 针对 driver 提交运行完整的 compliance pipeline vendorbridge submit --driver-src ./driver/ --vendor "ACME Corp" # 生成 Linux driver 支持徽章 SVG vendorbridge badge --vid 0x046d --pid 0x0825 --tier certified > badge.svg # 通过 webhook 订阅支持变更通知 vendorbridge watch --vid 0x046d --pid 0x0825 --webhook https://hooks.example.com/notify # 生成近期状态变更的 RSS feed vendorbridge rss --out feed.xml ``` ## VS Code 扩展 `vscode-extension/` 目录包含一个 TypeScript 扩展,提供以下功能: - **HWSpec Explorer** 侧边栏 — 树状视图展示所有 `.hwspec` 文件,包含寄存器、序列和不变量 - **寄存器悬停** — 在 C 驱动代码中将鼠标悬停在任何大写的寄存器名称上,即可查看其 HWSpec 中的定义 - **命令**:`TPT-RES: Open in ProtocolForge`、`TPT-RES: Generate LKML Patch Series`、`TPT-RES: Import Datasheet with AI` ``` cd vscode-extension npm install npm run compile # 然后在 VS Code 中通过 "Install from VSIX" 安装 ``` ## HWSpec 语言 HWSpec 是一种领域特定语言,用于描述硬件寄存器映射、初始化序列和行为不变量。 ``` device Webcam { vendor_id: 0x046d; product_id: 0x0825; register CTRL at 0x00 { width: 32; access: rw; reset_value: 0x0000; field ENABLE[0:0] { description: "Enable sensor"; } field MODE[2:1] { description: "Operating mode"; } } sequence init { step write CTRL.ENABLE = 1; step delay_us 500; step read CTRL expect 0x01 mask 0x01; } invariant "CTRL must be non-zero after init" { CTRL != 0; } } ``` ## 架构 ``` ┌─────────────────────────────────────────────────────────┐ │ Shared Infrastructure │ │ tcr-core · tcr-crypto · tcr-storage · tcr-grpc · tcr-ai│ └─────────────────────────────────────────────────────────┘ │ │ │ DriverScope FirmwareX ProtocolForge (eBPF/GTK4) (Binary/ML/AI) (HWSpec/AI) │ │ │ └──────────────┴──────────────┘ │ ShadowDriver (Replay/Validation) │ VendorBridge (Compliance/Badges) ``` 存储:SQLite(本地缓存) · PostgreSQL(共享知识图谱) · S3(trace artifacts) ## License Apache-2.0 — 请参阅 [LICENSE](LICENSE)。 版权所有 2026 TPT Solutions
标签:AI风险缓解, Apex, CNCF毕业项目, Docker镜像, Linux驱动开发, Python工具, Rust, 云资产清单, 人工智能辅助, 可视化界面, 机器学习, 测试用例, 漏洞探索, 硬件分析, 网络流量审计, 逆向工程, 通知系统