有没有办法检测应用程序在运行时加载哪些动态库?我看过苹果的文档对于动态库,但似乎没有讨论这一点。
要获取应用程序在运行时加载的所有库的列表:
// import the dynamic linker API
#import <mach-o/dyld.h>
// After your application finishes launching, maybe in
// -application:didFinishLaunchingWithOptions:
int imageCount = _dyld_image_count();
for (int i=0; i < imageCount; i++) {
NSLog(@"%d - %s", i, _dyld_get_image_name(i));
}
如果你想在每次加载库时调用一个函数,你可以使用_dyld_register_func_for_add_image()
or _dyld_register_func_for_link_module()
重要的提示我只在模拟器中检查过这一点。我相信它应该可以在设备上运行,但我现在还有其他事情需要处理。
Apple 文档从这里开始:https://developer.apple.com/library/prerelease/mac/documentation/DeveloperTools/Reference/MachOReference/
这里有一篇关于遍历马赫头信息的有趣博客文章:
http://ddeville.me/2014/04/dynamic-linking/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)