iPhone是否越狱的检测方法
今天项目中要用到检查iPhone是否越狱的方法。
Umeng统计的Mobclick.h里面已经包含了越狱检测的代码,可以直接使用
/*方法名: * isJailbroken *介绍: * 类方法,判断设备是否越狱,判断方法根据 apt和Cydia.app的path来判断 *参数说明: * 无 * * */ #pragma mark utils api // 类方法,判断当前设备是否已经越狱 + (BOOL)isJailbroken; // 类方法,判断你的App是否被破解 + (BOOL)isPirated;
apt和Cydia的方式来进行判断的,没看见源码
然后再介绍两种方法来查看是否已经越狱,知其然知其所以然、、、
1. apt
- (BOOL) hasAPT
{
return [[NSFileManager defaultManager] fileExistsAtPath:@"/private/var/lib/apt/"];
}
2. system
- (BOOL) successCallSystem
{
return (system("ls") == 0) ? YES : NO;
}
3.
static
const
char
* jailbreak_apps[] =
{
"/Applications/Cydia.app"
,
"/Applications/limera1n.app"
,
"/Applications/greenpois0n.app"
,
"/Applications/blackra1n.app"
,
"/Applications/blacksn0w.app"
,
"/Applications/redsn0w.app"
,
"/Applications/Absinthe.app"
,
NULL
,
};
- (
BOOL
) isJailBroken
{
// Now check for known jailbreak apps. If we encounter one, the device is jailbroken.
for
(
int
i = 0; jailbreak_apps[i] !=
NULL
; ++i)
{
if
([[
NSFileManager
defaultManager] fileExistsAtPath:[
NSString
stringWithUTF8String:jailbreak_apps[i]]])
{
//NSLog(@"isjailbroken: %s", jailbreak_apps[i]);
return
YES
;
}
}
// TODO: Add more checks? This is an arms-race we're bound to lose.
return
NO
;
}
@interface UIDevice (Helper)
- (BOOL)isJailbroken;
@end
@implementation UIDevice (Helper)
- (BOOL)isJailbroken {
BOOL jailbroken = NO;
NSString *cydiaPath = @"/Applications/Cydia.app";
NSString *aptPath = @"/private/var/lib/apt/";
if ([[NSFileManager defaultManager] fileExistsAtPath:cydiaPath]) {
jailbroken = YES;
}
if ([[NSFileManager defaultManager] fileExistsAtPath:aptPath]) {
jailbroken = YES;
}
return jailbroken;
}
@end
仅供参考、、、