This repository has been archived by the owner on Nov 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
r2.sh
executable file
·74 lines (62 loc) · 1.54 KB
/
r2.sh
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
70
71
72
73
74
#!/usr/bin/env bash
bold=`tput bold`
normal=`tput sgr0`
function usage {
echo -e <<USAGE "${bold}Find extract info from a binary using radare2${normal}
usage: `basename $0` [-x] [-f|b] binary
options: -h prints this help
-b find basic blocks
-f find functions
-x prints addresses in hexadecimal format
output bbs: one row per basic block,
columns: starting addr., ending addr. and size
output fncs: one row per function,
columns: name, starting addr., ending addr. and size"
USAGE
exit 1
}
hex_format=false
find_bbs=false
find_fcns=false
while getopts "xhbf", opt; do
case "${opt}" in
x)
hex_format=true
;;
b)
if [ $find_fcns = true ]; then
usage
fi
find_bbs=true;
;;
f)
if [ $find_bbs = true ]; then
usage
fi
find_fcns=true;
;;
*|h)
usage
;;
esac
done
if [ $find_bbs = false ] && [ $find_fcns = false ]; then
usage
fi
shift $((OPTIND-1))
[ ! -e "$1" ] && usage
if [ $find_bbs = true ]; then
r2script='afbj @@f'
jqscript='.[] | "\(.addr) \(.addr + .size) \(.size)"'
awkscript='{printf("0x%x 0x%x %d\n", $1, $2, $3)}'
elif [ $find_fcns = true ]; then
r2script='aflj'
jqscript='.[] | "\(.name) \(.offset) \(.offset + .size) \(.size)"'
awkscript='{printf("%s 0x%x 0x%x %d\n", $1, $2, $3, $4)}'
fi
r2out=`r2 -q0 -A -c "$r2script" $1 | jq "$jqscript" | sed s/\"//g`
if [ $hex_format = true ]; then
echo "$r2out" | awk "$awkscript"
else
echo "$r2out"
fi