ios - 如何检测动态库负载
<p><p>有没有办法检测应用在运行时加载了哪些动态库?我查看了 Apple 的 <a href="https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/DynamicLibraries/000-Introduction/Introduction.html#//apple_ref/doc/uid/TP40001908-SW1" rel="noreferrer noopener nofollow">documentation</a>对于动态库,但似乎没有讨论这个。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>获取应用程序在运行时加载的所有库的列表:</p>
<pre><code>// 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));
}
</code></pre>
<p>如果要在每次加载库时调用一个函数,可以使用 <code>_dyld_register_func_for_add_image()</code> 或 <code>_dyld_register_func_for_link_module()</code></p>
<p><strong>重要提示</strong>我只在模拟器中检查过。我认为它应该可以在设备上运行,但我现在还有其他事情需要处理。</p>
<p>Apple 文档从这里开始:<a href="https://developer.apple.com/library/prerelease/mac/documentation/DeveloperTools/Reference/MachOReference/" rel="noreferrer noopener nofollow">https://developer.apple.com/library/prerelease/mac/documentation/DeveloperTools/Reference/MachOReference/</a> </p>
<p>这里有一篇关于遍历mach header信息的有趣博客文章:</p>
<p> <a href="http://ddeville.me/2014/04/dynamic-linking/" rel="noreferrer noopener nofollow">http://ddeville.me/2014/04/dynamic-linking/</a> </p></p>
<p style="font-size: 20px;">关于ios - 如何检测动态库负载,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/34759368/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/34759368/
</a>
</p>
页:
[1]