简体   繁体   English

Apple 如何知道您使用的是私有 API?

[英]How does Apple know you are using private API?

I submitted a binary file to Apple without any source code.我向 Apple 提交了一个二进制文件,没有任何源代码。

Apart from manually checking the source code how does Apple know what was used and what APIs you have called?除了手动检查源代码之外,Apple 如何知道使用了什么以及您调用了哪些 API?

There are 3 ways I know.我知道有3种方法。 These are just some speculation, since I do not work in the Apple review team.这些只是一些猜测,因为我不在 Apple 审查团队工作。

1. otool -L 1. otool -L

This will list all libraries the app has linked to.这将列出应用程序链接到的所有库。 Something clearly you should not use, like IOKit and WebKit can be detected by this.显然你不应该使用的东西,比如 IOKit 和 WebKit 可以通过这个检测到。

2. nm -u 2. nm -u

This will list all linked symbols.这将列出所有链接的符号。 This can detect这可以检测

  • Undocumented C functions such as _UIImageWithName;未公开的 C 函数,例如 _UIImageWithName;
  • Objective-C classes such as UIProgressHUD Objective-C 类,例如 UIProgressHUD
  • Ivars such as UITouch._phase (which could be the cause of rejection of Three20-based apps last few months.)诸如UITouch._phase类的UITouch._phase (这可能是最近几个月 基于 Three20 的应用程序拒绝的原因。)

3. Listing Objective-C selectors, or strings 3. 列出 Objective-C 选择器或strings

Objective-C selectors are stored in a special region of the binary, and therefore Apple could extract the content from there, and check if you've used some undocumented Objective-C methods, such as -[UIDevice setOrientation:] . Objective-C 选择器存储在二进制文件的一个特殊区域,因此 Apple 可以从那里提取内容,并检查您是否使用了一些未公开的 Objective-C 方法,例如-[UIDevice setOrientation:]

Since selectors are independent from the class you're messaging, even if your custom class defines -setOrientation: irrelevant to UIDevice, there will be a possibility of being rejected.由于选择器独立于您正在发送消息的类,即使您的自定义类定义了-setOrientation:与 UIDevice 无关,也有可能被拒绝。


You could use Erica Sadun's APIKit to detect potential rejection due to (false alarms of) private APIs.您可以使用Erica Sadun 的 APIKit来检测由于(误报)私有 API 导致的潜在拒绝。


(If you really really really really want to workaround these checks, you could use runtime features such as (如果你真的真的真的真的很想解决这些检查,你可以使用运行时功能,例如

  • dlopen, dlsym dlopen, dlsym
  • objc_getClass, sel_registerName, objc_msgSend objc_getClass、sel_registerName、objc_msgSend
  • -valueForKey: ; -valueForKey: ; object_getInstanceVariable, object_getIvar, etc. object_getInstanceVariable、object_getIvar 等。

to get those private libraries, classes, methods and ivars.获取那些私有库、类、方法和变量。 ) )

您可以在终端中使用以下单行代码在 Mach-O 程序中列出选择器:

otool -s __TEXT __objc_methname "$1" |expand -8 | cut -c17- | sed -n '3,$p' | perl -n -e 'print join("\n",split(/\x00/,scalar reverse (reverse unpack("(a4)*",pack("(H8)*",split(/\s/,$_))))))'

Let's say you want to use some private API;假设您想使用一些私有 API; objective C allows you to construct any SEL from a string:目标 C 允许您从字符串构造任何 SEL:

   SEL my_sel = NSSelectorFromString([NSString stringWithFormat:\
@"%@%@%@", "se","tOr","ientation:"]);
    [UIDevice performSelector:my_sel ...];

How could a robot or library scan catch this?机器人或图书馆扫描如何捕捉到这一点? They would have to catch this using some tool that monitors private accesses at runtime.他们将不得不使用一些在运行时监控私有访问的工具来捕捉这一点。 Even if they constructed such a runtime tool, it is hard to catch because this call may be hidden in some rarely exercised path.即使他们构建了这样一个运行时工具,也很难捕捉到,因为这个调用可能隐藏在一些很少被执行的路径中。

I imagine they look at all symbols your binary's trying to import (info no doubt easily available to them in the symbol table thereof) and ding you if any of those symbols are found in their "private API list".我想他们会查看您的二进制文件试图导入的所有符号(毫无疑问,他们可以在其符号表中轻松获得信息),如果在他们的“私有 API 列表”中找到了这些符号中的任何一个,他们就会告诉您。 Pretty easy to automate, in fact.事实上,很容易实现自动化。

aside from symbol investigation...除了符号调查...

apple could very easily have a version of the sdk that checks each of the private methods stacks when called to make sure it is entered from one of the designated methods.苹果可以很容易地拥有一个 sdk 版本,它在调用时检查每个私有方法堆栈,以确保它是从指定的方法之一输入的。

A executable isn't exactly a black box.可执行文件并不完全是一个黑匣子。 If you call out to a library, it's an easy thing to find.如果你打电话到图书馆,很容易找到。 This is why I lament the loss of the assembly languages in modern CS educations.这就是为什么我对现代 CS 教育中汇编语言的丢失感到遗憾。 =] Tools like ldd will tell you what you have linked in, though I don't remember what incarnation of ldd made it to the mac iPhone dev kit. =] ldd 之类的工具会告诉您链接的内容,尽管我不记得 ldd 的哪个版本使它成为 mac iPhone 开发工具包。

otool -L somebinary

Even if you're statically linking, at worst, they could take samples of the code from the private APIs on their list, and search your binary against them (also relatively easy to automate).即使您是静态链接,在最坏的情况下,他们也可以从其列表中的私有 API 中获取代码样本,并针对它们搜索您的二进制文件(也相对容易自动化)。

Knowing Apple, I'd bet they have a comprehensive, automated system, and any uncertainty is probably either denied or reviewed manually.了解 Apple,我敢打赌他们有一个全面的自动化系统,任何不确定性都可能被拒绝或手动审查。

End of the day, I think it's probably not worth the effort to try and fool Apple.归根结底,我认为尝试愚弄 Apple 可能不值得。

This desktop application, App Scanner , can scan .app files for private api usage by pulling apart the Mach-O Binary file.这个桌面应用程序App Scanner可以通过分离 Mach-O 二进制文件来扫描 .app 文件以获取私有 api 使用。 If it can, then Apple can too!如果可以,那么苹果也可以!

There are a lot of tools for reverse engineering that allows inspect a code有很多逆向工程工具可以检查代码

  • nm - lists the symbols from object files nm - 列出目标文件中的符号
  • objdump - display information from object files. objdump - 显示来自目标文件的信息。
  • otool - view the content of Mach-O [About] executables otool - 查看 Mach-O [About]可执行文件的内容
  • strings - this will get you all the strings. strings - 这将为您提供所有字符串。

You can find examples/representation of using these commands in gists for Objective-C and Swift您可以在Objective-CSwift 的要点中找到使用这些命令的示例/表示

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

相关问题 苹果如何知道您正在MacOS上开发iPhone应用程序? - How does Apple know you are developing iPhone apps on MacOS? 使用Apple80211 API时如何知道OPEN,WPA,WPA2,WEP等安全类型? - How to know the security type like OPEN, WPA, WPA2, WEP, when using Apple80211 api? 苹果拒绝了我的应用程序,因为使用私有Api-allowAnyHTTPSCertificateForHost,为什么? - Apple reject my App, because using private Api - allowsAnyHTTPSCertificateForHost,Why? Apple如何知道您从网站上安装了Apple Store应用程序? - How apple know you have the Apple Store app installed from the website? 苹果如何知道iPhone应用程序使用了隐藏的API? - How could Apple know that an iPhone app makes use of hidden API? iOS应用程序Display Recorder如何在不使用私有API的情况下记录屏幕? - How does the iOS app Display Recorder record the screen without using private API? 有谁知道网站如何生成Apple App Store更新的应用程序源? - Does anyone know how sites are generating the Apple App Store updated apps feeds? 使用Instagram的私有API - using Instagram Private API 苹果公司是否介意您在自己的视图中使用该条纹表视图背景? - Does apple mind you using that striped table view background in your own views? 如何使用私有API在IOS 5.1中打开/关闭飞行模式 - How to turn on/off airplane mode in IOS 5.1 using private API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM