Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/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;