我在某些应用程序中注入dylib以获得某些期望的行为。在OSX上挂钩C++方法?
我能够正确挂接平面C API。一旦我注入了dylib,我就会看到符号表,并用我的函数地址更新它的入口,然后调用原来的函数。
因此,符号名称对我来说变得重要。
我的问题是与C++名称mangling。我们怎样才能钩住一个C++函数的名字已经被损坏了。我读了一些堆栈溢出的地方,它可能用mach_override挂钩C++代码,但没有例子或引用。
有人可以举例说明如何实现C++的钩子吗?
编辑: 我用$〇一二三四四五六九二二八六六七〇四五六三二一〇作为一个例子,得到了出来把尽可能WindowData::GetCGContext()
- 是WindowData类或命名空间?
- 如何挂钩?我可能需要一些前向声明和外部使用WindowData :: GetCGContext()正确挂钩。
事情是这样的......
typedef void* (*WindowData_GetCGContextProcPtr)(void* inObj);
static WindowData_GetCGContextProcPtr gWindowDataGetCGContextProcPtr = NULL;
void* try_WindowDataGetCGContextProcPtr(void* inObj)
{
printf("try_WindowDataGetCGContextProcPtr \n");
return gWindowDataGetCGContextProcPtr(inObj);
}
现在,我想修补这个方法。
gWindowDataGetCGContextProcPtr = (WindowData_GetCGContextProcPtr)Patch((const void*)&WindowData::GetCGContext, (const void*)&try_WindowDataGetCGContextProcPtr);
此修补程序给出编译错误。
error: 'WindowData' has not been declared
error: 'GetCGContext' was not declared in this scope
我该如何解决?
谢谢,我能够解除方法的名称。 – MacGeek