简体   繁体   English

如何检测和避免在第三方库中使用私有API

[英]How to detect & avoid the use of private APIs in third party libraries

Now that Apple is running some kind of static analysis to automatically check for private API use, a number of people have been caught because of the Three20 library. 既然Apple正在运行某种静态分析来自动检查私有API的使用,那么很多人都因为Three20库而被捕。 I use another third-party library (which I compile myself from code) and I would like to automatically audit it for private API use before I submit to Apple, so I can eliminate/re-write those parts. 我使用另一个第三方库(我自己从代码中编译),我想在提交给Apple之前自动审核它以供私有API使用,所以我可以删除/重写这些部分。

If I run nm on my application executable, I get a list of symbols, and I am seeing symbols in there that I don't use. 如果我在我的应用程序可执行文件上运行nm ,我会得到一个符号列表,我看到那些我不使用的符号。 For example I see _AudioServicesPlaySystemSound, and if I search for "AudioServicesPlaySystemSound" in XCode I get no results. 例如,我看到_AudioServicesPlaySystemSound,如果我在XCode中搜索“AudioServicesPlaySystemSound”,我得不到任何结果。 Is there any way to automatically discriminate calls to private APIs, for example I notice that Apple has a habit of naming them with an initial underscore. 有没有办法自动区分对私有API的调用,例如我注意到Apple习惯用初始下划线命名它们。

However: if I deliberately include a call to a private API it doesn't show up in the output of nm , but it does show up if I run strings on the binary. 但是:如果我故意包含对私有API的调用,它不会显示在nm的输出中,但如果我在二进制文件上运行strings ,它会显示出来。 Based on this, one idea I had was to compile a huge list of all private API calls into a huge table, and automatically search for them in the strings output. 基于此,我的一个想法是将所有私有API调用的大量列表编译成一个巨大的表,并在字符串输出中自动搜索它们。 I haven't done that yet. 我还没有这样做。

Does anyone have any tips on how to automatically catch this stuff so I'm only going through the review process once? 有没有人有关于如何自动捕捉这些东西的任何提示,所以我只进行一次审查过程?

You could try running nm on the object files instead of the linked executable: 您可以尝试在目标文件上运行nm而不是链接的可执行文件:

nm -g -j *.o  | sort | uniq

The objects should be in the build/<app>.build/*/<app>.build/Objects-normal sub-directory. 对象应位于build/<app>.build/*/<app>.build/Objects-normal子目录中。

You're seeing a reference to AudioServicesPlaySystemSound because one of the functions you did call in turn calls AudioServicesPlaySystemSound . 您正在看到对AudioServicesPlaySystemSound的引用,因为您调用的其中一个函数依次调用AudioServicesPlaySystemSound

Objective C calls won't generally show up in nm dumps, you'll need to use otool for that: 目标C调用通常不会出现在nm转储中,您需要使用otool

otool -ov <object file>

Use this dev tool, App Scanner . 使用此开发工具App Scanner It scans your .app file for private API methods. 它会扫描您的.app文件以获取私有API方法。 A future release will also check for private API instance variables. 未来版本还将检查私有API实例变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM