ios 以编程方式确定 iPhone 是否越狱

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1140856/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 16:11:38  来源:igfitidea点击:

Determining if an iPhone is Jail broken Programmatically

iphoneobjective-cioscocoa-touchjailbreak

提问by Richard Stelling

How do you determine (programmatically) if an iPhone/iPod is:

您如何(以编程方式)确定 iPhone/iPod 是否:

  1. Jail broken
  2. Running a cracked copy of your software
  1. 监狱破了
  2. 运行您的软件的破解副本

Pinch Mediacan detect if a phone is jail broken or the software running is cracked, does anyone know how they do this? Are there any libraries?

Pinch Media可以检测手机是否越狱或运行的软件是否已破解,有人知道他们是如何做到的吗?有图书馆吗?

采纳答案by zakovyrya

Hereis one of the ways to detect if your app was cracked.

是检测您的应用程序是否被破解的方法之一。

In short: the cracking usually requires changing the Info.plist. Since it's regular file you have access to, it's pretty easy to determine such changes.

简而言之:破解通常需要更改Info.plist。由于它是您可以访问的常规文件,因此很容易确定此类更改。

回答by rpetrich

Detecting a jailbroken phone is as easy as checking for the presence of /private/var/lib/apt/folder. Although this doesn't detect Installer-only users, by now most have have installed Cydia, Icy or RockYourPhone (all of which use apt)

检测越狱手机就像检查/private/var/lib/apt/文件夹是否存在一样简单。虽然这不会检测到仅安装程序的用户,但现在大多数已经安装了 Cydia、Icy 或 RockYourPhone(所有这些都使用 apt)

To detect pirated users, the easiest way is to check for the presence of a SignerIdentitykey in your app's Info.plist. Since advanced crackers can easily find the standard [[[NSBundle mainBundle] infoDictionary] objectForKey: @"SignerIdentity"]checks, it is best to obscure these calls using the Objective C runtime available via #import <objc/runtime.h>or use alternative equivalents.

要检测盗版用户,最简单的方法是检查SignerIdentity应用程序中是否存在密钥Info.plist。由于高级破解者可以轻松找到标准[[[NSBundle mainBundle] infoDictionary] objectForKey: @"SignerIdentity"]检查,因此最好使用通过可用的 Objective C 运行时#import <objc/runtime.h>或使用替代等效项来隐藏这些调用。

回答by Benjie

Just to expand on zakovyrya's reply, you could use the following code:

只是为了扩展 zakovyrya 的回复,您可以使用以下代码:

if ([[[NSBundle mainBundle] infoDictionary] objectForKey: @"SignerIdentity"] != nil) {
  // Jailbroken
}

HOWEVER, the person jailbreaking your app can hexedit your program and as such, they could edit the string @"SignerIdentity" to read @"siNGeridentity" or something else which would return nil, and thus pass.

但是,越狱您的应用程序的人可以对您的程序进行十六进制编辑,因此,他们可以编辑字符串@"SignerIdentity" 以读取@"siNGeridentity" 或其他返回 nil 的内容,从而通过。

So if you use this (or any of the other suggestions from http://thwart-ipa-cracks.blogspot.com/2008/11/detection.html):

因此,如果您使用它(或来自http://thwart-ipa-cracks.blogspot.com/2008/11/detection.html 的任何其他建议):

  • Don't expect it to work forever
  • Don't use this information to break/hinder your app in any way (otherwise they'll have cause to hexedit it, so your app won't know it is jailbroken)
  • Probably wise to obfuscate this bit of the code. For example, you could put the base64 encoded reversed string in your code, and then decode it in the app by reversing the process.
  • Validate your validation later in your code (e.g. when I said SignerIdentity, did it actually say SignerIdentity or siNGeridentity?)
  • Don't tell people on a public website like stackoverflow how you do it
  • Keep in mind it is only a guide and is not fool-proof (nor cracker-proof!) - with great power comes great responsibility.
  • 不要指望它永远有效
  • 不要使用此信息以任何方式破坏/阻碍您的应用程序(否则他们将有理由对其进行十六进制编辑,因此您的应用程序不会知道它已越狱)
  • 混淆这段代码可能是明智的。例如,您可以将 base64 编码的反转字符串放入您的代码中,然后通过反转过程在应用程序中对其进行解码。
  • 稍后在您的代码中验证您的验证(例如,当我说 SignerIdentity 时,它实际上是说 SignerIdentity 还是 siNGeridentity?)
  • 不要在像 stackoverflow 这样的公共网站上告诉人们你是怎么做的
  • 请记住,它只是一个指南,并不是万无一失(也不是防破解的!) - 能力越大,责任越大。

回答by Benjie

To expand on yonel's and Benjie's comments above:

扩展上面 yonel 和 Benji 的评论:

1) Landon Fuller's methodrelying on encryption check, linked above by yonel, seem to be the only one still not defeated by automated cracking tools. I would not be overly worried about Apple changing the state of the LC_ENCRYPTION_INFO header any time soon. It does seem to have some unpredictable effects on jailbroken iphones (even when the user has purchased a copy...)

1)Landon Fuller 的依靠加密检查的方法,上面由yonel 链接,似乎是唯一一种还没有被自动破解工具打败的方法。我不会过分担心 Apple 会很快更改 LC_ENCRYPTION_INFO 标头的状态。它似乎对越狱的 iphone 有一些不可预测的影响(即使用户购买了副本......)

At any rate, I would not take any rash action against a user based on that code...

无论如何,我不会根据该代码对用户采取任何轻率的行动......

2) To complement Benjie's comment re. obfuscation (an absolute necessity when dealing with any string values in your anti-piracy code): a similar but perhaps even easier way is to always check a saltedhashedversion of the value you are looking for. For example (even though that check is no longer efficient), you would check each MainBundle's key name as md5(keyName + "some secret salt") against the appropriate constant... Rather basic, but sure to defeat any attempt at locating the string.

2)补充本杰的评论re。混淆(处理反盗版代码中的任何字符串值时绝对必要):类似但可能更简单的方法是始终检查您正在寻找的值的加盐散列版本。例如(即使该检查不再有效),您将根据适当的常量检查每个 MainBundle 的密钥名称作为 md5(keyName + "some secret salt") ... 相当基本,但一定要阻止定位细绳。

Of course, this requires you to be able to indirectly query the value you want to compare (for example by going through an array containing it). But this is most often the case.

当然,这要求您能够间接查询要比较的值(例如,通过包含它的数组)。但这是最常见的情况。