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
567839d7
Commit
567839d7
authored
Dec 11, 2020
by
Andrea Gussoni
Browse files
Add main Ghidra decompilation driver
parent
c523fe07
Changes
1
Hide whitespace changes
Inline
Side-by-side
scripting/ghidra-extraction-scripts/clang-parse-all.sh
0 → 100644
View file @
567839d7
#!/bin/bash
if
[
$#
-eq
0
]
;
then
echo
"No arguments supplied"
exit
1
fi
arch
=
$1
basepath
=
$(
pwd
)
workdir
=
$basepath
/workdir-
$arch
ghidra_sources
=
$workdir
/ghidra-sources
ghidra_headers
=
$workdir
/ghidra-headers
clang_dir
=
$basepath
/scripting/ghidra-extraction-scripts/clang-parser
metrics_dir
=
$workdir
/ghidra-cyclomatic
if
[
!
-d
$metrics_dir
]
;
then
mkdir
$metrics_dir
;
fi
cd
$ghidra_sources
for
filename
in
*
do
filename
=
${
filename
%
".c"
}
echo
"Parsing with clang input:
$filename
"
# Copy the source and the header file in the parsing directory.
cp
$filename
.c
$clang_dir
/
cp
$ghidra_headers
/
$filename
.h
$clang_dir
/
cd
$clang_dir
# Remove newlines inhside commands, this will make easier our fixed-point purgin.
clang-format
-style
=
'{ColumnLimit: 5000}'
-i
$filename
.c
# Invoke the normalizer pass for the Ghidra decompiled output.
./ghidra-normalizer-wrapper.sh
$filename
.c
# Parse the source with clang
clang-7
-std
=
c11
-S
-emit-llvm
-w
$filename
.c.normalized.c
# Invoke the analys passes which collect the metrics we are interested in.
revng opt
-cyclomatic
-cyclomatic-output
=
$metrics_dir
/
$filename
.c.csv
-S
-o
/dev/null
$filename
.c.normalized.ll
# Go back to the source directory after cleaning the workdir
rm
$filename
.c
$filename
.h
$filename
.c.normalized.c
$filename
.c.normalized.ll
# Return to the directory with all the decompiled sources.
cd
$ghidra_sources
done
;
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