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
0d49b587
Commit
0d49b587
authored
4 years ago
by
Andrea Gussoni
Browse files
Options
Downloads
Patches
Plain Diff
Add IDA decompilation scripts
parent
73401675
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
scripting/ida-extraction-scripts/decompile-all-binaries.sh
+25
-0
25 additions, 0 deletions
scripting/ida-extraction-scripts/decompile-all-binaries.sh
scripting/ida-extraction-scripts/decompile-binary.sh
+69
-0
69 additions, 0 deletions
scripting/ida-extraction-scripts/decompile-binary.sh
with
94 additions
and
0 deletions
scripting/ida-extraction-scripts/decompile-all-binaries.sh
0 → 100755
+
25
−
0
View file @
0d49b587
#!/bin/bash
# The first argument should correspond to the name of the arch under analysis.
if
[
$#
-eq
0
]
;
then
echo
"No arguments supplied"
exit
1
fi
arch
=
$1
basepath
=
$(
pwd
)
workdir
=
$basepath
/workdir-
$arch
stripped_dir
=
$workdir
/stripped
source_dir
=
$workdir
/ida-sources
if
[
!
-d
$source_dir
]
;
then
mkdir
$source_dir
;
fi
cd
$stripped_dir
for
filename
in
*
do
echo
"IDA decompile:
$filename
"
$basepath
/scripting/ida-extraction-scripts/decompile-binary.sh
$filename
$source_dir
/
$filename
.c
done
;
This diff is collapsed.
Click to expand it.
scripting/ida-extraction-scripts/decompile-binary.sh
0 → 100755
+
69
−
0
View file @
0d49b587
#!/bin/bash
set
-e
echo
-n
"
$1
"
# Define and create folder for timing information
timing_path
=
"
$(
readlink
-f
$(
pwd
)
/../timings/
)
"
if
[
!
-d
$timing_path
]
;
then
mkdir
$timing_path
;
fi
script_path
=
"
$(
cd
"
$(
dirname
"
${
BASH_SOURCE
[0]
}
"
)
"
&&
pwd
)
"
# Define ida executable path
ida_path
=
"/home/andrea/paper/ida/"
# The input file to decompile
input
=
"
$1
"
# In principle, we would not want to analyze files with debug symbols.
if
[
"
$(
readelf
-s
$input
|
wc
-l
)
"
-gt
0
]
;
then
echo
"This file has symbols!"
# Unfortunately, this check is not always reliable. We want to avoid having
# debug symbols, not every symbol (as such function symbols) at all.
# exit 1
fi
# Select which version of IDA to use (32 vs 64 bit).
if
readelf
-h
"
$input
"
|
grep
ELF64
>
/dev/null
;
then
ida
=
"
$ida_path
/idat64"
extension
=
"i64"
else
ida
=
"
$ida_path
/idat"
extension
=
"idb"
fi
# Make a copy of the input file.
tmp_name
=
"
$input
.tmp"
# Prepare the name for the output file.
export
output
=
"
$(
readlink
-f
$2
)
"
# Make a copy of the input file.
cp
"
$input
"
"
$tmp_name
"
# Disassemble the file.
sudo
unshare
-n
sudo
-u
andrea /usr/bin/time
--format
=
"%S,%U,%e,%M"
-o
"
$timing_path
/
$input
.ida-source-extraction-disassembly.time"
"
$ida
"
-B
"
$tmp_name
"
# Check that the IDA db file has been created.
idb
=
"
$tmp_name
.
$extension
"
test
-e
"
$idb
"
# Delete temp files still around
rm
-rf
/tmp/ida
# Decompile input file.
sudo
unshare
-n
sudo
-u
andrea /usr/bin/time
--format
=
"%S,%U,%e,%M"
-o
"
$timing_path
/
$input
.ida-source-extraction-decompilation.time"
"
$ida
"
-A
-S
"
$script_path
/ida-generate-source.py
$output
"
"
$idb
"
# Remove the temporary files.
rm
"
$tmp_name
.asm"
rm
"
$idb
"
rm
"
$tmp_name
"
# Check that we produced the expected output file.
test
-s
"
$output
"
echo
" OK"
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