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
Hexadecimal numbers in bc are represented with UPPERCASE letters.
Try adding tr
to some pipe
... | tr "a-z" "A-Z" | ...
Do not use IBASE and OBASE, these need to be lowercase.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With