Next-generation codebase analysis toolkit.
Project description
ScubaTrace
Source level code analysis toolkit.
ScubaTrace is a code analysis toolkit that leverages tree-sitter and LSP (Language Server Protocol) to provide parsing, analysis, and context extraction capabilities for multiple programming languages.
Unlike most traditional static analysis tools that rely on compilation to extract Intermediate Representation (IR) for code analysis, ScubaTrace delivers analysis capabilities even when code repositories are incomplete or unable to compile. This resilience makes it particularly valuable for scenarios where traditional analysis approaches would fail, enabling developers and security researchers to gain insights from code that might otherwise be inaccessible to conventional static analysis methodologies.
ScubaTrace serves as a portable analysis solution for IDE development, AI-powered coding tools, and SAST (Static Application Security Testing).
Features
- Multi-Language Support
- No Need To Compile
- Statement-Based AST Abstraction
- Call Graph
- Control Flow Graph
- Data/Control Dependency Graph
- References Inference
- CPG Based Multi-Granularity Slicing
- Built on Tree-sitter and LSP
Install
pip install scubatrace
[!NOTE] If you encounter a
pygraphvizinstallation failure duringpip install, you need to install the Graphviz development package. You can install it using the following command:# For Debian/Ubuntu apt install libgraphviz-dev # For macOS, Ref: https://pygraphviz.github.io/documentation/stable/install.html#homebrew brew install graphviz
Supported Languages
ScubaTrace supports multiple programming languages, including:
| Language | Language Server | Tree-sitter Parser | Maturity |
|---|---|---|---|
| C/C++ | clangd | tree-sitter-cpp | High |
| Java | Eclipse JDT LS | tree-sitter-java | High |
| Python | Pyright | tree-sitter-python | High |
| JavaScript | typescript-language-server | tree-sitter-javascript | Medium |
| Go | gopls | tree-sitter-go | Medium |
| Rust | Rust Analyzer | tree-sitter-rust | Medium |
| Ruby | Solargraph | tree-sitter-ruby | Low |
| Swift | SourceKit-LSP | tree-sitter-swift | Low |
| C# | OmniSharp | tree-sitter-c-sharp | Low |
| PHP | phpactor | tree-sitter-php | Low |
Usage
import scubatrace
# Initialize a ScubaTrace Project
# language can be set to one of the following:
# scubatrace.language.[C, JAVA, PYTHON, JAVASCRIPT, GO, RUST, RUBY, PHP, CSHARP, SWIFT]
project = scubatrace.Project.create("path/to/your/codebase", language=scubatrace.language.C)
[!NOTE] Incomplete or broken codebases may cause parsing errors that could result in inaccurate analysis results.
# Get a file from the project
file = project.files["relative/path/to/your/file.c"]
# Get a function from the file
function = file.functions[0]
print(f"Function Name: {function.name}")
print(f"Source Code: {function.text}")
# Get the function's callers and print their names and callsites
callers = function.callers
for caller, callsites in callers.items():
print(f"Caller: {caller.name}")
for callsite in callsites:
print(f" Callsite: {callsite.text}")
# Get the first statement in file line
statement = file.statements_by_line(10)[0]
# Find the pre/post statements in control flow
pre_statements_in_control_flow = statement.pre_controls
post_statements_in_control_flow = statement.post_controls
# Get the first variable in statement
variable = statement.variables[0]
print(f"Variable: {variable.name}")
# Find the definitions/references of a variable
definitions = variable.definitions
references = variable.references
# Find the pre/post data dependencies of a variable
pre_data_dependencies = variable.pre_data_dependents
post_data_dependencies = variable.post_data_dependents
# Perform slicing in a function based on specified lines
# Configure the slicing with control depth and data-dependent depth
criteria_lines = [10, 12, 18]
sliced_statements = function.slice_by_lines(
lines=criteria_lines, control_depth=5, data_dependent_depth=8
)
# Get tree-sitter node in a file/function/statement
file_node = file.node
function_node = function.node
statement_node = statement.node
For more detailed information, refer to the Documentation.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file scubatrace-1.0.3.tar.gz.
File metadata
- Download URL: scubatrace-1.0.3.tar.gz
- Upload date:
- Size: 55.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d91a1d49455dbeb0c66db543c63783be0943a041870539577be3e219c0b45360
|
|
| MD5 |
11c745d2c9d72f9ef2b8475e479f5678
|
|
| BLAKE2b-256 |
313c392965a7804984522cc42792c4a863843d4706e487f1d40fc986561c9d21
|
Provenance
The following attestation bundles were made for scubatrace-1.0.3.tar.gz:
Publisher:
pypi.yml on SunBK201/ScubaTrace
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
scubatrace-1.0.3.tar.gz -
Subject digest:
d91a1d49455dbeb0c66db543c63783be0943a041870539577be3e219c0b45360 - Sigstore transparency entry: 344848463
- Sigstore integration time:
-
Permalink:
SunBK201/ScubaTrace@47bfe4b029c7222aa578dbf75e3e7a1f63e9b40c -
Branch / Tag:
refs/tags/1.0.3 - Owner: https://github.com/SunBK201
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@47bfe4b029c7222aa578dbf75e3e7a1f63e9b40c -
Trigger Event:
push
-
Statement type:
File details
Details for the file scubatrace-1.0.3-py3-none-any.whl.
File metadata
- Download URL: scubatrace-1.0.3-py3-none-any.whl
- Upload date:
- Size: 71.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6e70d0a55af8a2a292cc0f503760cbda555cb6afee7ddea90d808cb4e925f364
|
|
| MD5 |
78f8501122a8ae0bec071e7d223b7295
|
|
| BLAKE2b-256 |
c6ef1a006a6a2e867aa7de5046c3d7641b5c731c37ee9c76b2cb8b6cde6872b8
|
Provenance
The following attestation bundles were made for scubatrace-1.0.3-py3-none-any.whl:
Publisher:
pypi.yml on SunBK201/ScubaTrace
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
scubatrace-1.0.3-py3-none-any.whl -
Subject digest:
6e70d0a55af8a2a292cc0f503760cbda555cb6afee7ddea90d808cb4e925f364 - Sigstore transparency entry: 344848474
- Sigstore integration time:
-
Permalink:
SunBK201/ScubaTrace@47bfe4b029c7222aa578dbf75e3e7a1f63e9b40c -
Branch / Tag:
refs/tags/1.0.3 - Owner: https://github.com/SunBK201
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@47bfe4b029c7222aa578dbf75e3e7a1f63e9b40c -
Trigger Event:
push
-
Statement type: