0

I am working on Linux.

I would like to hook C program function which is declared as static or global,

For example: I have a function name my_func and I would like to replace it in runtime to hook_my_func, when I am looking at the ELF file (without debugging symbols) I don't see the function symbol of my_func.

Is there a way to hook the function in run time ?

(I am capable to hook this function, only when it reside as a shared library but I want to hook it when it is private function of the C application)

user3498424
  • 47
  • 1
  • 6
  • If you don't have debugging symbols then how can you locate the function you're interested in? What do you see if you run `strings my_prog | grep my_func`? – John Zwinck Jul 02 '14 at 11:10
  • Nothing, plus also from read-elf I don't see it, since there is no debugging symbols. – user3498424 Jul 02 '14 at 11:21
  • And the adress will not be the same each time as i suppose and also will not work. ( I still wonder, how powerful tools hook windows and linux , if let me say, kernel is compiled without debugging symbols). – icbytes Jul 02 '14 at 11:31
  • Are you able to call this function? Do you have source code? – light_keeper Jul 02 '14 at 11:49
  • Yes, I written also the C program, for the purpose of testing, but still without debug symbols I can't locate the function address. – user3498424 Jul 02 '14 at 12:44
  • 1
    You need to add `-rdynamic` when build your app with gcc so that global functions can be seen by `readelf`. –  Jul 02 '14 at 12:55
  • There has been a similar question http://stackoverflow.com/questions/617554/override-a-function-call-in-c. You insist on _runtime_ but peharps this question can be of use for you. Personally I like `--wrap symbol` option (http://linux.about.com/library/cmd/blcmdl1_ld.htm) –  Jul 02 '14 at 13:44

0 Answers0