I am trying to find the location of myfunc
in the executable of:
#include <stdio.h>
void myfunc(){
printf("Hello");
}
int main(){
}
I wrote this script:
#!/bin/bash -x
start=$(nm -S a.out|grep -w _start)
start_addr=$(echo $start | awk '{print $1}')
myfun=$(nm -S a.out|grep $1)
myfun_addr=$(echo $myfun | awk '{print $1}')
myfun_length=$(echo $myfun | awk '{print $2}')
echo $myfun_length
myfun_end=$(echo "obase=16;ibase=16;$myfun_addr + $myfun_length" | bc)
offset=$(echo "obase=16;ibase=16;$myfun_addr - $start_addr" | bc)
The last line runs, but the line before it no:
++ echo 'obase=16;ibase=16;0000000000400900 + 00000000000000bc'
++ bc
(standard_in) 1: syntax error
+ myfun_end=
++ echo 'obase=16;ibase=16;0000000000400900 - 0000000000400710'
++ bc
+ offset=1F0