I was hooking few functions in my code and it was working pretty code till today and then I came across a bug due to call back function.
Lets say..
If I do something like
puts("Hi!\n");
works great. I can hook this.
But If I do this...
typeof(puts) *fptr = puts;
fptr("Hi \n");
Hooking does not work?
I am using OSX env and searching for symbols in order to do hooking. Can someone suggest me whats wrong with callback functions and what I should be doing in to hook in hooking algorithm?
EDIT: I did some more debugging, in case if with the following information anyone who can provide some opinion.
I think this can be source of problem?
bool Hook(const char *name, void *impl) {
...
void **EntryInAdressTable = find(name);
if(EntryInAdressTable) {
*EntryInAdressTable = impl;
}
}
...
}
So, What's happening here is, I change the Entry in address table for corresponding symbol with my implementation and the in My implementation I call original function.
So, my guess is, If we use callback function, it means we referred directly to function address without going through the address table and thats why hooked method is not called.
Am I right on this one? If so can any one suggest me any workaround?