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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/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-boundaries-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-boundaries-extraction.time" "$ida" -A -S"$script_path/ida-function-boundaries.py $2" "$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"