In this repository, you will find a Python implementation of our FraMe. FraMe is a novel automated approach that leverages fine-grained reasoning with multi-view fix knowledge to enhance LLM-based vulnerability patch generation. It consists of two modules: stepwise fix-reasoning path collection and multi-view knowledge augmented patch generation.
You can set up the environment by following commands.
conda create -n FraMe python=3.8.5
conda install pytorch==2.2.1 torchvision==0.17.1 torchaudio==2.2.1 pytorch-cuda=11.8 -c pytorch -c nvidia
pip install transformers==4.46.3
pip install openai==1.84.0
pip install scikit-learn
pip install tree-sitter
pip install tree-sitter-c
βββ Code
βββ code_embedding
βββ utils
βββ __init__.py
βββ early_stopping.py
βββ model.py
βββ run.py
βββ graph_embedding
βββ gat.py
βββ loss.py
βββ train.py
βββ utils.py
βββ patch generation
βββ data_preprocess.py
βββ model.py
βββ repair_direct_reasoning.py
βββ repair_frame.py
βββ VulKG_construction
βββ import
βββ bigvul
βββ ...
βββ reposvul
βββ ...
βββ VulKG_Deployment.cypher
βββ Datasets
βββ graph_data
βββ bigvul_graph_data.pkl
βββ reposvul_graph_data.pkl
βββ graph_embedding
βββ bigvul_graph_embeddings.pkl
βββ reposvul_graph_embeddings.pkl
βββ prompt
βββ generate_prompt.txt
βββ repair_prompt.txt
βββ source_code
βββ bigvul
βββ ...
βββ reposvul
βββ ...
Example usage to run repair_frame:
n_example: Number of generated candidate patches.
sample: The maximum number of FiRP generation attempts.
api_key: Place your deepseek access key.
python repair_frame.py --dataset bigvul --n_example 10 --sample 25 --model_dir ./saved_models