Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Andrea Gussoni
artifacts-asiaccs20
Commits
25900ca2
Commit
25900ca2
authored
Dec 17, 2020
by
Andrea Gussoni
Browse files
Add scripts to compute the cyclomatic increase
parent
774f0ec8
Changes
3
Hide whitespace changes
Inline
Side-by-side
config.sh
View file @
25900ca2
...
...
@@ -9,3 +9,4 @@ function_idx_dir=$workdir/deduplicated-functions-idx-no-goto
revng_json_dir
=
$workdir
/revng-json
ida_json_dir
=
$workdir
/ida-json-normalized
revng_metrics_dir
=
$workdir
/revng-metrics
cyclomatic_metrics_dir
=
$workdir
/cyclomatic-metrics
scripting/computation/compute-cyclomatic-total.py
0 → 100755
View file @
25900ca2
#!/usr/bin/env python3
import
argparse
import
csv
import
json
import
numpy
import
os
import
pandas
import
sys
from
scipy.stats.mstats
import
gmean
def
main
():
parser
=
argparse
.
ArgumentParser
(
description
=
'My nice tool.'
)
parser
.
add_argument
(
'binaries'
,
metavar
=
'BINARIESFILE'
,
help
=
'File containing the names of the binaries'
)
parser
.
add_argument
(
'arch'
,
metavar
=
'ARCH'
,
help
=
'Architecture'
)
parser
.
add_argument
(
'cyclomatic_metrics_dir'
,
metavar
=
'CYCLOMATICMETRICSDIR'
,
help
=
'Architecture'
)
args
=
parser
.
parse_args
()
arch
=
args
.
arch
binaries_file
=
args
.
binaries
cyclomatic_metrics_dir
=
args
.
cyclomatic_metrics_dir
source_cyclomatic_total
=
0
revng_cyclomatic_total
=
0
ida_cyclomatic_total
=
0
ghidra_cyclomatic_total
=
0
with
open
(
binaries_file
,
'r'
)
as
binaries
:
binaries_list
=
[
line
.
rstrip
(
'
\n
'
)
for
line
in
binaries
]
for
binary_name
in
binaries_list
:
# Open the files containing the metrics.
metrics_csv_file
=
cyclomatic_metrics_dir
+
'/'
+
binary_name
+
'.csv'
if
os
.
path
.
isfile
(
metrics_csv_file
):
with
open
(
metrics_csv_file
,
'r'
)
as
metrics_csv
:
df
=
pandas
.
read_csv
(
metrics_csv_file
)
for
index
,
row
in
df
.
iterrows
():
# Load the metrics.
source_current_cyclomatic
=
int
(
row
[
'source_cyclomatic'
])
revng_current_cyclomatic
=
int
(
row
[
'revng_cyclomatic'
])
ida_current_cyclomatic
=
int
(
row
[
'ida_cyclomatic'
])
ghidra_current_cyclomatic
=
int
(
row
[
'ghidra_cyclomatic'
])
# For some functions, we couldn't get the original cyclomatic
# complexity for the source.
if
source_current_cyclomatic
!=
-
1
:
# Unfortunately, due to the `-2` term in the cyclomatic complexity
# computation, some terms goes to 0. A 0 at the denominator is not
# good, round it to 1.
if
source_current_cyclomatic
==
0
:
source_current_cyclomatic
=
1
if
revng_current_cyclomatic
==
0
:
revng_current_cyclomatic
=
1
if
ida_current_cyclomatic
==
0
:
ida_current_cyclomatic
=
1
if
ghidra_current_cyclomatic
==
0
:
ghidra_current_cyclomatic
=
1
# Total.
source_cyclomatic_total
+=
source_current_cyclomatic
revng_cyclomatic_total
+=
revng_current_cyclomatic
ida_cyclomatic_total
+=
ida_current_cyclomatic
ghidra_cyclomatic_total
+=
ghidra_current_cyclomatic
# Print some final information about the cyclomatic complexity.
print
(
"Total source cyclomatic"
)
print
(
source_cyclomatic_total
)
print
(
"Total revng cyclomatic"
)
print
(
revng_cyclomatic_total
)
print
(
"Total ida cyclomatic"
)
print
(
ida_cyclomatic_total
)
print
(
"Total ghidra cyclomatic"
)
print
(
ghidra_cyclomatic_total
)
print
(
"revng/source"
)
print
(
revng_cyclomatic_total
/
source_cyclomatic_total
)
print
(
"ida/source"
)
print
(
ida_cyclomatic_total
/
source_cyclomatic_total
)
print
(
"ghidra/source"
)
print
(
ghidra_cyclomatic_total
/
source_cyclomatic_total
)
if
__name__
==
"__main__"
:
main
()
scripting/computation/compute-cyclomatic-total.sh
0 → 100755
View file @
25900ca2
#!/bin/bash
if
[
$#
-eq
0
]
;
then
echo
"No arguments supplied"
exit
1
fi
arch
=
$1
# Import the config
.
./config.sh
$computation_script_dir
/compute-cyclomatic-total.py
$binaries_file
$arch
$cyclomatic_metrics_dir
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment