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?
Macgeek
source share