Skip to content
clang-parse-all.sh 1.22 KiB
Newer Older
#!/bin/bash
if [ $# -eq 0 ]; then
  echo "No arguments supplied"
  exit 1
fi

basepath=$(pwd)
workdir=$basepath/workdir-$1
ida_sources=$workdir/ida-sources

clang_dir=$basepath/scripting/ida-extraction-scripts/clang-parser/

cyclomatic_dir=$workdir/ida-cyclomatic

if [ ! -d $cyclomatic_dir ]; then
  mkdir $cyclomatic_dir;
fi

cd $ida_sources

for filename in *
do
  echo "Parsing with clang input: $filename"

  # Copy the file under analysis in the folder with the support scripts.
  cp $filename $clang_dir/
  cd $clang_dir

  # Remove newlines inhside commands, this will make easier our fixed-point purgin.
  clang-format -style='{ColumnLimit: 5000}' -i $filename

  # Invoke the normalizer pass for the IDA decompiled output.
  ./ida-normalizer-wrapper.sh $filename

  # Parse the source with clang
  clang-7 -std=c11 -S -emit-llvm -w $filename.normalized.c

  # Invoke the analys passes which collect the metrics we are interested in.
  revng opt -cyclomatic -cyclomatic-output=$cyclomatic_dir/$filename.csv -S -o /dev/null $filename.normalized.ll

  # Remove the temporary files we created.
  rm $filename $filename.normalized.c $filename.normalized.ll

  # Return to the directory with all the decompiled sources.
  cd $ida_sources
done;