C&C++   发布时间:2022-04-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了在OSX上挂钩C方法?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在某些应用程序中注入一个dylib以获得某些期望的行为.

我能够正确地连接平面C API.一旦我注入了dylib,我会在符号表中查看并使用我的函数地址更新其条目,然后调用原始函数.

因此,符号名称对我来说很重要.

我的问题是C名称错误.我们如何挂钩名称已被破坏的C函数.我读了堆栈溢出的一些地方,可以用mach_override挂钩c代码,但没有示例或引用.

有人能给我举例说明如何实现C的挂钩吗?

编辑:
我使用$c filt -n _ZN10WindowData12GetCGContextEv作为示例,得到了输出为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

我怎么解决

解决方法

您可以使用 c++filt解码修边并进行注射.

但是优化器内联的方法不适用于这种方法

大佬总结

以上是大佬教程为你收集整理的在OSX上挂钩C方法?全部内容,希望文章能够帮你解决在OSX上挂钩C方法?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。