| Crates.io | cpg-rs |
| lib.rs | cpg-rs |
| version | 0.1.0 |
| created_at | 2025-03-17 19:10:39.46065+00 |
| updated_at | 2025-03-17 19:10:39.46065+00 |
| description | A Rust library for working with Code Property Graphs (CPG) |
| homepage | |
| repository | https://github.com/gbrigandi/cpg-rs |
| max_upload_size | |
| id | 1595817 |
| size | 106,629 |
A Rust library for working with Code Property Graphs (CPG), a powerful representation of source code that enables advanced static analysis and vulnerability detection.
Code Property Graphs (CPGs) were introduced by Fabian Yamaguchi et al. in their 2014 paper "Modeling and Discovering Vulnerabilities with Code Property Graphs" presented at the IEEE Symposium on Security and Privacy.
CPGs combine multiple program representations into a single unified graph structure:
By merging these representations, CPGs enable more sophisticated code analysis than any single representation could provide alone. This unified approach allows for complex queries that can identify security vulnerabilities, bugs, and code quality issues that would be difficult to detect with traditional methods.
Several open-source projects implement the CPG concept:
This library, cpg-rs, provides a Rust implementation with serialization/deserialization support.
The modify_cpg example demonstrates how to:
cargo run --example modify_cpg
The find_methods example shows how to:
cargo run --example find_methods
The diff_graph example demonstrates how to:
cargo run --example diff_graph
Add this to your Cargo.toml:
[dependencies]
cpg-rs = "0.1.0"
Basic usage:
use cpg_rs::{Cpg, Node, Edge, NodeType, EdgeType};
use std::fs::File;
use std::io::{BufReader, BufWriter};
// Load a CPG
let file = File::open("cpg.json").unwrap();
let reader = BufReader::new(file);
let cpg: Cpg = serde_json::from_reader(reader).unwrap();
// Process the CPG...
// Save the CPG
let file = File::create("modified_cpg.json").unwrap();
let writer = BufWriter::new(file);
serde_json::to_writer_pretty(writer, &cpg).unwrap();
Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
Gianluca Brigandi gbrigand@gmail.com