Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
artifacts-asiaccs20
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Andrea Gussoni
artifacts-asiaccs20
Commits
567839d7
Commit
567839d7
authored
4 years ago
by
Andrea Gussoni
Browse files
Options
Downloads
Patches
Plain Diff
Add main Ghidra decompilation driver
parent
c523fe07
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scripting/ghidra-extraction-scripts/clang-parse-all.sh
+49
-0
49 additions, 0 deletions
scripting/ghidra-extraction-scripts/clang-parse-all.sh
with
49 additions
and
0 deletions
scripting/ghidra-extraction-scripts/clang-parse-all.sh
0 → 100644
+
49
−
0
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
;
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment