aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/addr2strongline
blob: 695ddd42af3a2e3be4f3e13784b0f4f4a9989a50 (plain)
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
#!/bin/bash
#
# Wrapper to addr2line.
#
# $0 gets a code line for a shared library. It checks where the
# library is linked to the binary and subtracts that from
# supplied list of addresses in the binary.
#
# This requires stack randomization to be disabled.

LIBNAME=libstrongswan

if [ ! -e $1 ];
then
	echo "Error: file $1 not found"
	exit 1
fi

if [ `cat /proc/sys/kernel/randomize_va_space` != 0 ];
then
	echo "Error: stack randomization enabled: use echo 0 > /proc/sys/kernel/randomize_va_space"
	exit 1
fi

LINK=`ldd $1 | grep $LIBNAME | awk '{print toupper($4) }' | sed -e "s/0X//g"`
LIB=`ldd $1 | grep $LIBNAME | awk '{print $3 }'`

until [ -z "$2" ]
do
  shift
  LEAK=`echo "$1" | sed -e "s/0x//g" | awk '{print toupper($1)}'`
  RES=`echo "ibase=16; obase=10; $LEAK - $LINK;" | bc | sed -e "s/ //g" | awk '{print tolower($1) }'`
  RES="0x$RES"
  addr2line -e $LIB $RES
done