0

I want to code a function called "CSys::Printf" using LD_Preload, but I think it would not be so easy, as in C you can't have "::" in function name, that would be needed to match the original function name.

A piece of the code used to hook would be like this:

int CSys::Printf(const char *format, ...) {
 void *handle;
 char *error;
 if (conprint == NULL) { 
  handle  = dlopen("dedicated.so", RTLD_LAZY);
  if (!handle) {
   fputs(dlerror(), stderr);
   exit(1);
  }
 conprint = (int (*)(const char *format, ...))dlsym(handle, "CSys::Printf");
 if ((error = dlerror()) != NULL) {
   fprintf(stderr, "%s\n", error);
   exit(1);
 }
 printf("*HOOK CSys::Printf OK*");
}

Well, this should work at hooking any function except this case, where the compiler won't accept the "::" on function name.

What should I do?

Thanks!

Rodrigo
  • 123
  • 2
  • 10
  • 3
    What language is `CSys::Printf` written in? If it is C++, you probably have to deduce the mangled form of the function name and use `dlsym()` to locate that, rather than the raw name. The mangling is, of course, compiler specific. – Jonathan Leffler Dec 27 '14 at 08:47
  • you may find http://stackoverflow.com/questions/12400105/getting-mangled-name-from-demangled-name useful – user3159253 Dec 27 '14 at 09:28

0 Answers0