Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bc (standard_in) 1: syntax error

Tags:

c

bash

shell

bc

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
like image 660
robert Avatar asked Aug 31 '25 22:08

robert


1 Answers

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.

like image 134
pmg Avatar answered Sep 03 '25 13:09

pmg