我正在为某些应用程序注入dylib以实现所需的行为。我能够正确地挂接扁平的C API。一旦我注入了dylib,我会查看符号表并使用我的函数地址更新其条目,然后调用原始函数。
因此,符号名称对我很重要。
我的问题是C++名称修饰。我们如何挂接名称已被修改的C++函数?我在 stack overflow 上读到过一些地方,说可以使用 mach_override 挂接 C++ 代码,但没有示例或引用。
有人可以给我一个关于如何实现 C++ 挂钩的示例吗?
编辑: 我使用 $
类似这样...
现在,我想修补这个方法。
我该如何解决这个问题?
因此,符号名称对我很重要。
我的问题是C++名称修饰。我们如何挂接名称已被修改的C++函数?我在 stack overflow 上读到过一些地方,说可以使用 mach_override 挂接 C++ 代码,但没有示例或引用。
有人可以给我一个关于如何实现 C++ 挂钩的示例吗?
编辑: 我使用 $
c++filt -n _ZN10WindowData12GetCGContextEv
作为示例,输出如下 WindowData::GetCGContext()
1. WindowData 是类还是命名空间?
2. 我该如何挂接它?我可能需要一些前向声明和外部声明来正确使用 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
我该如何解决这个问题?