如何从函数地址或类中找到CFBundleRef

发布于 2024-10-14 14:17:33 字数 386 浏览 11 评论 0原文

是否可以从Carbon中的函数地址或类名获取Bundle引用(CFBundleRef)??

中有函数,

NSBundle myBundle = [NSBundle bundleForClass:(Class)<SOME_CLASS>];

我知道 Objective-C和 Windows API

GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCTSTR)<SOME_FUNCTION>, &outModule);

在 Mac 上有类似的 C++ 或任何其他方法吗?

谢谢, 阿比奈。

Is it possible to get the Bundle reference (CFBundleRef) from a function address or a class name in Carbon..??

I know there are functions in Objective-C

NSBundle myBundle = [NSBundle bundleForClass:(Class)<SOME_CLASS>];

and with Windows API

GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCTSTR)<SOME_FUNCTION>, &outModule);

Is there anything similar or any other method with C++ on a mac??

Thanks,
Abhinay.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

疏忽 2024-10-21 14:17:33

您可以使用 CFBundle 上运行的 Core Foundation 函数获取对导出给定函数名称的包的包引用:

CFStringRef functionName = CFSTR("someFunctionName");
CFArrayRef allBundles = CFBundleGetAllBundles();
CFIndex i;
CFIndex bundleCount = CFArrayGetCount(allBundles);

for (i = 0; i < bundleCount; i++) {
    CFBundleRef bundle = CFArrayGetValueAtIndex(allBundles, i);
    void *functionPointer = CFBundleGetFunctionPointerForName(bundle, functionName);
    if (functionPointer != NULL) {
        // bundle points to a bundle that exports functionName
    }
}

并且由于 CFBundleGetDataPointerForName() 返回指向给定符号名称的数据指针一个包,我相信它也可以用于类名称,因为类是使用符号名称_OBJC_CLASS_$_导出的,例如_OBJC_CLASS_$ _NSArray

据我所知,没有任何函数允许您通过指定函数地址来检查包是否导出函数。

You can use the Core Foundation functions that operate on CFBundle to get the bundle reference to the bundle that exports a given function name:

CFStringRef functionName = CFSTR("someFunctionName");
CFArrayRef allBundles = CFBundleGetAllBundles();
CFIndex i;
CFIndex bundleCount = CFArrayGetCount(allBundles);

for (i = 0; i < bundleCount; i++) {
    CFBundleRef bundle = CFArrayGetValueAtIndex(allBundles, i);
    void *functionPointer = CFBundleGetFunctionPointerForName(bundle, functionName);
    if (functionPointer != NULL) {
        // bundle points to a bundle that exports functionName
    }
}

And since CFBundleGetDataPointerForName() returns a data pointer to a given symbol name in a bundle, I believe it can be used for class names as well since a class is exported with a symbol name _OBJC_CLASS_$_<className>, e.g. _OBJC_CLASS_$_NSArray.

As far as I can tell, there’s no function that allows to you to inspect whether a bundle exports a function by specifying the function address.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文