github / github/codeql

Whether there are Python SDK for Programmatic Access to CodeQL Database Facts

未关闭
#22,411 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
question
主要语言
CodeQL
星标
10.1k
派生
2.1k
平均合并
2 天 15 小时
30 天内合并 PR
141

描述

CodeQL provides powerful built-in analyses and program representations, such as AST, CFG, data flow, call graphs, and class hierarchies. However, these representations are currently primarily accessed through QL queries after a CodeQL database has been created.

For more complex analyses or for extending CodeQL's existing analyses (e.g., custom data-flow or alias analyses), implementing everything directly in QL can become quite difficult and cumbersome.

Currently, I use the following workaround:

- Build a CodeQL database for the target project.
- Write basic QL queries to export selected facts to CSV., such as:
* Interested AST nodes and their relationships
* Class/interface information and inheritance relationships
* Call sites and call relationships
* Other program facts relevant to my analysis

Define my own schema and load the CSV facts into memory.
Implement more sophisticated analyses using Python and custom algorithms.

This works, but it requires an additional export/import layer and also means that I have to manually reconstruct program representations that CodeQL already maintains internally. Would it be possible to provide an official Python SDK/API (or another programmatic API) that allows users to directly access the facts stored in a CodeQL database?

For example, something along the lines of:

```python
db = codeql.Database("my-project-db")

ast = db.ast()
cfg = db.cfg()
dataflow = db.dataflow()
classes = db.class_hierarchy()
calls = db.call_graph()
```

The exact API is not important; the key idea is that Python code could directly access the program facts represented in the CodeQL database, without first exporting them through QL queries. This would make it possible to use CodeQL as a powerful program representation and fact extraction backend, while implementing more complex or experimental analyses in Python.

贡献指南

打开贡献指南

调研方向

没有指定文件、测试或入口点。首先检查现有的 CodeQL 数据库和 QL-query 接口,然后将它们与提议的 Python 访问模型以及当前的 CSV 导出/导入变通方案进行比较。完成这项工作需要达成一致的 API 范围和实施计划,而不是进行局部修改。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
developer-experience, tooling
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
活跃
描述清晰度
需要澄清
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。