Connecting C ++ methods to OSX?

I am downloading dylib in some applications for some desired behavior.

I can properly connect flat C APIs. As soon as I insert dylib, I look at the symbol table and update its record with my function address and, in turn, call the original one.

Thus, symbol names become important to me.

My problem is with the C ++ name . How can we connect a C ++ function whose name is garbled. I read some places so that it can be connected with C ++ code using mach_override, but there is no example or links.

Can someone give me an example on how to achieve C ++ binding?

Edit: I used $ c++filt -n _ZN10WindowData12GetCGContextEv as an example and got the value out as WindowData::GetCGContext()

  • Is WindowData a class or namespace?
  • How can i connect it? I need some advanced declarations and externs to correctly use WindowData :: GetCGContext () to connect.

Something like that...

 typedef void* (*WindowData_GetCGContextProcPtr)(void* inObj); static WindowData_GetCGContextProcPtr gWindowDataGetCGContextProcPtr = NULL; void* try_WindowDataGetCGContextProcPtr(void* inObj) { printf("try_WindowDataGetCGContextProcPtr \n"); return gWindowDataGetCGContextProcPtr(inObj); } 

Now I want to fix this method.

 gWindowDataGetCGContextProcPtr = (WindowData_GetCGContextProcPtr)Patch((const void*)&WindowData::GetCGContext, (const void*)&try_WindowDataGetCGContextProcPtr); 

This patch gives a compilation error.

 error: 'WindowData' has not been declared error: 'GetCGContext' was not declared in this scope 

How do I fix this?

+7
source share
2 answers

You can use the C ++ filter to decode the manipulation and make an injection.

But the methods built in by the optimizer will not work with this approach

+4
source

In OS X, assuming you are using gcc, the abi::__cxa_demangle in <cxxabi.h> can be used to demonstrate C ++ names. You do not need this to assign a pointer to a method that matches the signature: WindowData::GetCGContext . However, a specification of this class must be provided.

0
source

All Articles