cocoa – 使用otool(递归)查找应用程序所需的共享库

cocoa – 使用otool(递归)查找应用程序所需的共享库,第1张

概述我有一个 Cocoa应用程序,它使用otool来查找应用程序需要正常运行所需的共享库.例如,假设我在使用QTKit.framework的应用程序上运行otool -L.我得到了程序使用的共享库列表(包括Cocoa.framework和AppKit.framework等基本框架): /System/Library/Frameworks/QTKit.framework/Versions/A/QTKit 我有一个 Cocoa应用程序,它使用otool来查找应用程序需要正常运行所需的共享库.例如,假设我在使用QTKit.framework的应用程序上运行otool -L.我得到了程序使用的共享库列表(包括Cocoa.framework和AppKit.framework等基本框架):

/System/library/Frameworks/QTKit.framework/Versions/A/QTKit (compatibility version 1.0.0,current version 1.0.0)/System/library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0,current version 476.0.0)    /System/library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0,current version 949.0.0)..... and so on for a bunch of other frameworks

这表明该应用程序使用QTKit.framework.但是,如果我在QTKit.framework(/System/library/Frameworks/QTKit.framework/Versions/A/QTKit)的二进制文件上再次使用“otool -L”,我会得到:

/System/library/Frameworks/QTKit.framework/Versions/A/QTKit (compatibility version 1.0.0,current version 1.0.0)/System/library/Frameworks/AudioToolBox.framework/Versions/A/AudioToolBox (compatibility version 1.0.0,current version 1.0.0)/System/library/PrivateFrameworks/CoreMedia.framework/Versions/A/CoreMedia (compatibility version 1.0.0,current version 1.0.0)/System/library/PrivateFrameworks/MediaToolBox.framework/Versions/A/MediaToolBox (compatibility version 1.0.0,current version 1.0.0)/System/library/PrivateFrameworks/VIDeoToolBox.framework/Versions/A/VIDeoToolBox (compatibility version 1.0.0,current version 1.0.0)/System/library/PrivateFrameworks/CoreMediaIOServices.framework/Versions/A/CoreMediaIOServices (compatibility version 1.0.0,current version 1.0.0)/System/library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0,current version 751.0.0)/System/library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0,current version 1038.0.0)/System/library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0,current version 275.0.0)/System/library/Frameworks/QuickTime.framework/Versions/A/QuickTime (compatibility version 1.0.0,current version 1584.0.0)/System/library/Frameworks/CoreAudio.framework/Versions/A/CoreAudio (compatibility version 1.0.0,current version 1.0.0)/System/library/Frameworks/OpenGL.framework/Versions/A/OpenGL (compatibility version 1.0.0,current version 1.0.0)/System/library/Frameworks/QuartzCore.framework/Versions/A/QuartzCore (compatibility version 1.2.0,current version 1.6.0)/System/library/Frameworks/IOSurface.framework/Versions/A/IOSurface (compatibility version 1.0.0,current version 1.0.0)/System/library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolBox.framework/Versions/A/HIToolBox (compatibility version 1.0.0,current version 435.0.0)/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0,current version 7.9.0)/usr/lib/libSystem.B.dylib (compatibility version 1.0.0,current version 123.0.0)/usr/lib/libobjc.A.dylib (compatibility version 1.0.0,current version 227.0.0)/System/library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0,current version 44.0.0)/System/library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0,current version 550.0.0)/System/library/Frameworks/applicationservices.framework/Versions/A/applicationservices (compatibility version 1.0.0,current version 38.0.0)/System/library/Frameworks/CoreVIDeo.framework/Versions/A/CoreVIDeo (compatibility version 1.2.0,current version 1.6.0)

这显示了一个负载更多的框架,应用程序二进制文件上的原始otool输出显示.有没有办法让otool以递归方式运行,这意味着它抓住应用程序需要的框架,然后进入并搜索每个框架中的依赖项?

解决方法 不,你必须重复运行otool,或者合并其解析代码( here).不要忘记处理@executable_path.

这是在Python中(没有@executable_path,规范化或带有空格的文件名),因为这比尝试调试伪代码更容易:

import subprocessdef otool(s):    o = subprocess.Popen(['/usr/bin/otool','-L',s],stdout=subprocess.PIPE)    for l in o.stdout:        if l[0] == '\t':            yIEld l.split(' ',1)[0][1:]need = set(['/Applications/iTunes.app/Contents/MacOS/iTunes'])done = set()while need:    needed = set(need)    need = set()    for f in needed:        need.update(otool(f))    done.update(needed)    need.difference_update(done)for f in sorted(done):    print f
总结

以上是内存溢出为你收集整理的cocoa – 使用otool(递归)查找应用程序所需的共享库全部内容,希望文章能够帮你解决cocoa – 使用otool(递归)查找应用程序所需的共享库所遇到的程序开发问题。

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

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1013773.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存