ios 如何检测应用程序正在越狱设备上运行?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6530364/
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
How to detect that the app is running on a jailbroken device?
提问by R. Dewi
I have just released my app for iOS, but I'm not sure how to make my app safe from being used by jailbrakers.
我刚刚发布了适用于 iOS 的应用程序,但我不确定如何使我的应用程序免受越狱者的使用。
Can I do something to prevent my app working on jailbroken devices?
我可以做些什么来阻止我的应用程序在越狱设备上运行吗?
回答by Rahul Vyas
You can detect through code that if the app is running on a jail broken device or not. Through that way you can pop up an alert and close the app. You can do whatever you want to do. Here is a tutorial for it:
您可以通过代码检测应用程序是否在越狱设备上运行。通过这种方式,您可以弹出警报并关闭应用程序。你可以做任何你想做的事。这是一个教程:
http://thwart-ipa-cracks.blogspot.com/2008/11/detection.html
http://thwart-ipa-cracks.blogspot.com/2008/11/detection.html
and here is a Stack Overflow post:
这是一篇 Stack Overflow 帖子:
How do I detect that an iOS app is running on a jailbroken phone?
Also, if you want a complete solution, you can see in tapjoy sdk code. They are detecting jailbroken iPhone. Here is tapjoy URL https://www.tapjoy.com/
另外,如果你想要一个完整的解决方案,你可以在tapjoy sdk代码中看到。他们正在检测越狱的 iPhone。这是tapjoy URL https://www.tapjoy.com/
回答by onmyway133
Check for these paths
检查这些路径
+ (BOOL)isJailBroken {
#ifdef TARGET_IPHONE_SIMULATOR
return NO;
#endif
NSArray *paths = @[@"/bin/bash",
@"/usr/sbin/sshd",
@"/etc/apt",
@"/private/var/lib/apt/",
@"/Applications/Cydia.app",
];
for (NSString *path in paths) {
if ([self fileExistsAtPath:path]) {
return YES;
}
}
return NO;
}
+ (BOOL)fileExistsAtPath:(NSString *)path {
FILE *pFile;
pFile = fopen([path cStringUsingEncoding:[NSString defaultCStringEncoding]], "r");
if (pFile == NULL) {
return NO;
}
else
fclose(pFile);
return YES;
}
Additionally, you can take a look https://github.com/OneSignal/OneSignal-iOS-SDK/blob/master/iOS_SDK/OneSignalSDK/Source/OneSignalJailbreakDetection.m
回答by karim
Try to find a file which cydia or jailbroken device create. Or try to write in a file outside the app's blackbox. If you succeed to do that, the device is compromised/jailbroken :)
尝试查找 cydia 或越狱设备创建的文件。或者尝试写入应用程序黑匣子之外的文件。如果您成功做到了这一点,则该设备已被盗用/越狱 :)
- (BOOL)jailbroken
{
NSFileManager * fileManager = [NSFileManager defaultManager];
return [fileManager fileExistsAtPath:@"/private/var/lib/apt/"];
}
回答by user3088680
You can detect if a device is jailBroken or not by checking the following
您可以通过检查以下内容来检测设备是否越狱
- Cydia is installed
- Verify some of the system paths
- Can perform a sandbox integrity check
- Perform symlink verification
- Verify whether you create and write files outside your Sandbox
- Cydia 已安装
- 验证一些系统路径
- 可以执行沙箱完整性检查
- 执行符号链接验证
- 验证您是否在沙箱外创建和写入文件
There is an open source libraryI created from various articles and books, try it out.
有一个开源库,我从各种文章和书籍创建的,试试吧。
回答by inVINCEable
Based off of @karim's answer heres a slightly modified swift version:
基于@karim 的回答,这里有一个稍微修改的 swift 版本:
func hasJailbreak() -> Bool {
#if arch(i386) || arch(x86_64)
println("Simulator")
return false
#else
var fileManager = NSFileManager.defaultManager()
if(fileManager.fileExistsAtPath("/private/var/lib/apt")) {
println("Jailbroken Device")
return true
} else {
println("Clean Device")
return false
}
#endif
}
回答by sinh99
-(BOOL) isJailbroken
{
#if TARGET_IPHONE_SIMULATOR
return NO;
#else
FILE *f = fopen("/bin/bash", "r");
if (errno == ENOENT)
{
// device is NOT jailbroken
fclose(f);
NSLog(@"no");
return NO;
}
else {
// device IS jailbroken
fclose(f);
NSLog(@"yes");
return YES;
}
#endif
}
回答by CrazyPro007
/**
Detect that the app is running on a jailbroken device or not
- returns: bool value for jailbroken device or not
*/
public class func isDeviceJailbroken() -> Bool {
#if arch(i386) || arch(x86_64)
return false
#else
let fileManager = FileManager.default
if (fileManager.fileExists(atPath: "/bin/bash") ||
fileManager.fileExists(atPath: "/usr/sbin/sshd") ||
fileManager.fileExists(atPath: "/etc/apt")) ||
fileManager.fileExists(atPath: "/private/var/lib/apt/") ||
fileManager.fileExists(atPath: "/Applications/Cydia.app") ||
fileManager.fileExists(atPath: "/Library/MobileSubstrate/MobileSubstrate.dylib") {
return true
} else {
return false
}
#endif
}
回答by user1846654
Even if your device is jailbroken , ipa applications can only access their own sand boxes, so If device is either jailbroken or not your method will return NO :) Look for another way Also if you try to access somewhere but your sandbox publishing app on the appstore may head problems
即使您的设备已越狱,ipa 应用程序也只能访问它们自己的沙盒,因此,如果设备是否已越狱,您的方法将返回 NO :) 寻找另一种方式此外,如果您尝试访问某个地方,但沙盒发布应用程序在应用商店可能会出现问题
回答by Boobalan
There are many ways to find the jailbroken devices. checking cydia technic will not be work if skilled hacker changes the application path.
有很多方法可以找到越狱的设备。如果熟练的黑客更改了应用程序路径,则检查 cydia 技术将不起作用。
A good way to check for it would be to see if we can modify a file in some other location outside the application bundle.
检查它的一个好方法是查看我们是否可以在应用程序包之外的某个其他位置修改文件。
NSError *error;
NSString *stringToBeWritten = @"This is a test.";
[stringToBeWritten writeToFile:@"/private/jailbreak.txt" atomically:YES
encoding:NSUTF8StringEncoding error:&error];
if(error==nil){
//Device is jailbroken
return YES;
} else {
//Device is not jailbroken
[[NSFileManager defaultManager] removeItemAtPath:@"/private/jailbreak.txt" error:nil];
}
Find more techniques in the below url
在以下网址中查找更多技术
回答by Maksim Kniazev
SWIFT 3:
快速 3:
func hasJailbreak() -> Bool {
#if arch(i386) || arch(x86_64)
print("Simulator")
return false
#else
return FileManager.default.fileExistsAtPath("/private/var/lib/apt")
#endif
}