🔬 专为Linux驱动开发者设计的静态代码分析和可视化工具
当你拿到一份几千上万行的Linux驱动代码时,如何快速理解它的:
- 📊 函数调用流程 - 从入口点到底层的完整调用链
- 📦 数据结构关系 - 结构体之间如何关联
- ⚡ 异步执行流程 - 中断、工作队列、定时器的执行时机
- 🔌 回调映射关系 - 哪个函数指针对应哪个实现
Linux Driver Analyzer 就是为解决这些问题而生的!
- ✅ 纯静态分析 - 无需编译环境,秒级分析
- ✅ 函数调用图 - 可视化展示函数调用关系
- ✅ 结构体关系图 - 展示数据结构之间的引用关系
- ✅ 函数指针追踪 - 识别 ops 表中的回调映射
- ✅ 异步机制识别 - 工作队列、中断、定时器、Tasklet
- ✅ Linux内核知识库 - 理解驱动框架的回调时机
- ✅ 交互式Web界面 - 点击展开、搜索、过滤
- 🚧 tree-sitter 后端 - 更精确的语法解析
- 🚧 libclang 后端 - 完整的类型推导
- 🚧 跨文件分析 - 支持多文件项目
- 🚧 VSCode 插件 - IDE 集成
方式一:一键安装(推荐)
# 克隆项目
git clone https://github.com/yourusername/linux-driver-analyzer.git
cd linux-driver-analyzer
# 一键安装(自动创建虚拟环境,跨平台通用)
./scripts/setup.sh
# 激活环境后使用
source .venv/bin/activate方式二:手动安装
cd linux-driver-analyzer
# 创建虚拟环境(推荐,避免权限问题)
python3 -m venv .venv
source .venv/bin/activate # Linux/macOS
# .venv\Scripts\activate # Windows
# 安装(推荐配置,包含 tree-sitter)
pip install ".[recommended]"📦 各平台安装说明(点击展开)
# 安装 Python
sudo apt update
sudo apt install python3 python3-pip python3-venv
# 克隆并安装
git clone https://github.com/yourusername/linux-driver-analyzer.git
cd linux-driver-analyzer
./scripts/setup.sh
source .venv/bin/activate# 安装 Python(使用 Homebrew)
brew install python
# 克隆并安装
git clone https://github.com/yourusername/linux-driver-analyzer.git
cd linux-driver-analyzer
./scripts/setup.sh
source .venv/bin/activate# 从 python.org 安装 Python 后
git clone https://github.com/yourusername/linux-driver-analyzer.git
cd linux-driver-analyzer
# 创建虚拟环境
python -m venv .venv
.venv\Scripts\Activate
pip install ".[recommended]"# 基础分析 - 函数调用流
python src/core/basic_analyzer.py your_driver.c -o result.json
# 高级分析 - 包含结构体关系
python src/core/advanced_analyzer.py your_driver.c --structs -o result.json
# 使用新的后端 API
python -c "
from backends import get_backend
backend = get_backend() # 自动选择最佳后端
result = backend.parse_file('your_driver.c')
print(f'发现 {len(result.functions)} 个函数')
"# 方法1:直接打开HTML文件
open web/templates/call_flow_viewer.html # macOS
xdg-open web/templates/call_flow_viewer.html # Linux
start web/templates/call_flow_viewer.html # Windows
# 方法2:启动本地服务器
python -m http.server 8080 --directory web
# 然后访问 http://localhost:8080/templates/call_flow_viewer.html在可视化界面中:
- 点击"导入JSON"按钮
- 选择生成的
result.json - 浏览函数调用流程
linux-driver-analyzer/
├── src/
│ ├── core/ # 核心分析引擎
│ │ ├── basic_analyzer.py # 基础分析器 (正则匹配)
│ │ ├── advanced_analyzer.py # 高级分析器 (结构体+调用图)
│ │ └── knowledge_base.json # Linux内核知识库
│ ├── backends/ # 可插拔后端
│ │ ├── regex_backend.py # 正则匹配后端 (当前)
│ │ ├── treesitter_backend.py # tree-sitter后端 (计划)
│ │ └── clang_backend.py # libclang后端 (计划)
│ └── visualizers/ # 可视化生成器
│ └── json_exporter.py
├── web/
│ ├── js/ # JavaScript模块
│ ├── css/ # 样式文件
│ └── templates/ # HTML模板
│ ├── call_flow_viewer.html
│ └── struct_viewer.html
├── docs/ # 文档
│ ├── ROADMAP.md # 开发路线图
│ ├── ARCHITECTURE.md # 架构设计
│ ├── API.md # API文档
│ └── images/ # 截图和图片
├── tests/ # 测试用例
├── examples/ # 示例驱动代码
├── scripts/ # 辅助脚本
├── requirements.txt
├── setup.py
└── README.md
┌─────────────────────────────────────────────────────────────────────┐
│ Linux Driver Analyzer │
├─────────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
│ │ Regex Backend │ │ TreeSitter │ │ Clang Backend │ │
│ │ (当前) │ │ Backend (计划) │ │ (计划) │ │
│ └────────┬────────┘ └────────┬────────┘ └────────┬────────┘ │
│ │ │ │ │
│ └────────────────────┼────────────────────┘ │
│ │ │
│ ┌───────────▼───────────┐ │
│ │ Core Analyzer │ │
│ │ ├── 符号表 │ │
│ │ ├── 调用图 │ │
│ │ └── 结构体关系 │ │
│ └───────────┬───────────┘ │
│ │ │
│ ┌───────────▼───────────┐ │
│ │ Knowledge Base │ │
│ │ (Linux框架语义) │ │
│ └───────────┬───────────┘ │
│ │ │
│ ┌────────────────────┼────────────────────┐ │
│ │ │ │ │
│ ┌────────▼────────┐ ┌────────▼────────┐ ┌────────▼────────┐ │
│ │ JSON Exporter │ │ Web Viewer │ │ VSCode Plugin │ │
│ └─────────────────┘ └─────────────────┘ └─────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────┘
详见 ROADMAP.md
| 阶段 | 目标 | 状态 |
|---|---|---|
| v0.1 | 基础分析 + Web可视化 | ✅ 完成 |
| v0.2 | tree-sitter 后端 | ✅ 完成 |
| v0.3 | libclang 后端 | 📅 计划中 |
| v0.4 | 跨文件分析 | 📅 计划中 |
| v1.0 | VSCode 插件 | 📅 计划中 |
欢迎贡献!请查看 CONTRIBUTING.md
- Fork 本仓库
- 创建特性分支 (
git checkout -b feature/amazing-feature) - 提交更改 (
git commit -m 'Add some amazing feature') - 推送到分支 (
git push origin feature/amazing-feature) - 打开 Pull Request
- 🐛 修复 Bug
- 📚 完善文档
- 🔧 添加新的内核框架到知识库
- ✨ 实现新功能
- 🧪 添加测试用例
MIT License - 详见 LICENSE
- Linux内核社区
- tree-sitter 项目
- Clang/LLVM 项目
Made with ❤️ for Linux Driver Developers