iPhone私有API编译 [英] iPhone private API compiling

查看:106
本文介绍了iPhone私有API编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我几个小时后在整个互联网上搜索,我找不到我正在寻找的信息。
我想搞乱私人api,看看有什么可能,等等,但我甚至无法编译。

I'm searching through the whole internet since a few hours now, and I just can't find the informations I'm looking for. I would like to mess around with the private apis, see whats possible, etc., but I can't even compile something.

所以我已经得到了一些非常基本的问题:

So I've got a few pretty basic questions:


  • 我是否必须转储标题?因为我下载了一个样本,其中API加载了

char *framework = "/System/Library/PrivateFrameworks/...";
dlopen(...);

我想使用objc语法(如果可能)而不是使用C(如上所述) ),如果有任何机会。

I would like to use the objc-syntax (if possible) rather than using C (as mentioned above), if there are any opportunities.


  • 如果导入私有API,如何编译Xcode?我是否必须添加其他链接标志? (因为我读到了两个不同的意见)
    我添加了一个私有框架并创建了一个新的文件夹Headers并将所有头文件放在那里,因此框架在Xcode中正确显示。我是否必须导入整个.framework,或者只导入我想要使用的框架中的标题?导入框架后,我得到20多个错误,未知的类型名称等等。

最后,我是阅读有关权利(在iOS 7中似乎是新的)。我如何使用这些权利以及何时使用这些权利?

And, finally, I've read about entitlements (which seem to be new in iOS 7). How do I use these entitlements and when do I use them?

有人可以请输入几行作为示例吗?

Could someone please just type a few lines as an example?

推荐答案

背景



为了使用任何框架中的方法,您可以选择静态地或动态地引用这些框架。我没有在你的问题中看到任何暗示你需要使用动态链接的东西,所以我会避免这种情况(对初学者来说稍微复杂一点)。 (‡)

Background

In order to use methods in any framework, you can choose to either reference those frameworks statically or dynamically. I haven't seen anything in your question that suggests you need to use dynamic linking, so I'm going to avoid that (it's slightly more complicated for a beginner). (‡)

要静态引用框架中的API,您需要导入相关的标头,然后配置Xcode项目以链接到框架。这两个步骤仅为私有 API稍微更改

To statically reference APIs in a framework, you would import the relevant headers, and then configure your Xcode project to link to the framework. These two steps only change slightly for Private APIs.

私有API通常不会为您提供标头(* .h)描述API。我说通常,因为有时候,iOS上私有的API在Mac OS X上实际上是公开的,因此要使用它,只需将标题的OS X版本复制到项目中。

Private APIs usually don't provide you with the headers (*.h) that describe the APIs. I say "usually", because sometimes, an API that's private on iOS is actually public on Mac OS X, so to use it, you simply copy the OS X version of the header into your project.

但可能更常见的是,您必须自己生成标题。如果您知道需要哪个标题,通常可以在某人的github帐户中找到在线发布。如果没有,您需要一个工具,如 class-dump ,或 class-dump-z 。在私有框架上运行类转储工具,在Mac上找到它:

Probably more common, though, is that you have to generate the header yourself. If you know which header you need, often you can find it posted online under someone's github account. If not, you need a tool like class-dump, or class-dump-z. Run the class dump tool on the private framework, by finding it on your Mac:

cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/System/Library/PrivateFrameworks/
class-dump -H -o ~/Headers/7.0/MusicLibrary/ MusicLibrary

然后,进入〜/ Headers / 7.0 / MusicLibrary / 并找到大量转储的头文件。将您需要的标题(仅)复制到Xcode iOS项目目录中。然后,从Xcode内部右键单击Project Navigator视图中的源文件夹,选择将文件添加到< Project Name> ...。选择您需要包含在项目中的转储头文件。

Then, go into ~/Headers/7.0/MusicLibrary/ and find lots of dumped header files. Copy (only) the header(s) you need into your Xcode iOS project directory. Then, from inside Xcode, right click on a source folder in your Project Navigator view, select "Add files to <Project Name> ...". Pick the dumped header file you need to include in your project.

为了成功链接API,您还需要将框架添加到Xcode构建阶段。从项目目标设置中,选择构建阶段,然后选择将二进制文件链接到库。您通常从iOS SDK为您提供的默认列表中选择一个公共框架。但是,您也可以选择浏览Mac以获取第三方框架或私有框架。对于私有框架,您只需要导航到这样的文件夹位置

In order to successfully link against the API, you also need to add the framework to your Xcode Build Phases. From your project Target settings, select Build Phases then Link Binary with Libraries. You normally choose a public framework from the default list that the iOS SDK provides you. However, you can choose to browse your Mac for 3rd-party frameworks, or private frameworks, too. For private frameworks, you're just going to have to navigate to a folder location like this

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/System/Library/PrivateFrameworks/

然后选择 *。framework 目录。

然后,只需像使用任何公共/私有API一样使用API​​。 #import 头文件,调用API,实例化类等。

Then, simply use the APIs like you would use any public/private API. #import the header file, call the APIs, instantiate the classes, etc.

使用此代码:

char *framework = "/System/Library/PrivateFrameworks/...";
dlopen(...);

尝试动态打开私有框架。如果你在编译时知道你想要使用哪个框架,并且让它出现在Mac上以让Xcode链接,那就没有必要了。

is an attempt to dynamically open a private framework. That's not necessary, if you know at compile time which framework you want to use, and have it present on your Mac to let Xcode link against.

权利对于iOS 7来说并不陌生。它们已经存在了相当长的一段时间,并且是iOS用来防止未经授权使用某些私有API的一种技术。 iOS将检查您的应用是否已被授予特定权利(按名称),如果它没有该权利,则调用受保护的API将失败(通常静默,尽管有时您会在控制台日志中查看消息。)

Entitlements are not new to iOS 7. They have existed for quite some time, and are one technique iOS uses to prevent unauthorized usage of some private APIs. iOS will check to see if your app has been granted a particular entitlement (by name), and if it does not have that entitlement, calling the protected API will fail (usually silently, although sometimes you'll see a message in the Console log).

请参阅此处查看示例授予您(越狱)应用程序权利

(‡)更新: iOS 9.3带来了一些私有API和静态与动态链接的变化。请在此处查看此Stack Overflow问题了解更多信息

(‡) Update: iOS 9.3 has brought some changes with respect to Private APIs, and static vs dynamic linking. Please see this Stack Overflow question here for more.

这篇关于iPhone私有API编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆