Intra-function slicer for C code. This repository a lightweight implementation of extracting forward and backward slices from a given source code.
This slicer is based on Joern Fuzzy Code parser.
- Gradle 2.0, which further requires Java 8 (
sudo apt-get install openjdk-8-jdk
)
wget https://services.gradle.org/distributions/gradle-2.0-bin.zip
sudo mkdir /opt/gradle
sudo unzip gradle-2.0-bin.zip -d /opt/gradle
echo 'export PATH="$PATH:/opt/gradle/gradle-2.0/bin"' >> ~/.bashrc
source ~/.bashrc
- Graphviz (
sudo apt install graphviz-dev
) - Python >= 3.5 with graphviz library (
pip install graphviz
)
- Enter into the source code
cd code-slicer
- Build Joern
cd joern ./build.sh cd ..
To extract slice use
./slicer.sh <Dir> <FileName> <LineNo> <OutDir> <DataFlowOnly(Optional)>
For Example
./slicer.sh test test1.c 7 test-output
- Dir: The directory path of the .C file.
- FileName: Name of the C file (*.c format)
- LineNo: Line Number where the slice will begin.
- OutDir: The Directory path for the output.
- DataFlowOnly: This is optional, if this is mentioned, slicer will produce slices only on dataflow graph.
This slicer will produce 4 outputs in the OutDir.
- <OutDir>/<FileName>.forward will contain the lines in the forward slice.
- <OutDir>/<FileName>.backward will contain the lines in the backward slice.
- <OutDir>/<FileName>pdf will contain the visual representation of the graph.
- <OutDir>/<FileName> will contain the dot representation of the graph.
- As of now, we assume only one function per c file.