如何检测应用程序是否在越狱设备上运行?

R. *_*ewi 49 iphone jailbreak ipad ios

我刚刚发布了我的iOS应用程序,但我不确定如何让我的应用程序安全不被jailbrakers使用.

我可以做些什么来阻止我的应用程序在越狱设备上工作吗?

Rah*_*yas 50

您可以通过代码检测应用程序是否在监狱设备上运行.通过这种方式,您可以弹出警报并关闭应用程序.你可以做任何你想做的事.这是一个教程:

http://thwart-ipa-cracks.blogspot.com/2008/11/detection.html

这是一个Stack Overflow帖子:

如何检测iOS应用程序是否已在越狱手机上运行?

此外,如果您想要一个完整的解决方案,您可以在tapjoy sdk代码中看到.他们正在检测已越狱的iPhone.这是tapjoy网址https://www.tapjoy.com/

  • 我只是想感谢你给出了很好的答案,我会为此添加书签,因为我将要进入iOS开发阶段,这很有用! (2认同)

onm*_*133 6

检查这些路径

+ (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;
}
Run Code Online (Sandbox Code Playgroud)

此外,你可以看看https://github.com/OneSignal/OneSignal-iOS-SDK/blob/master/iOS_SDK/OneSignalJailbreakDettection/OneSignalJailbreakDetection.m


kar*_*rim 5

尝试找到cydia或越狱设备创建的文件.或者尝试在应用程序的黑盒子外写一个文件.如果你成功了,那么该设备会遭到入侵/越狱:)

- (BOOL)jailbroken
{
    NSFileManager * fileManager = [NSFileManager defaultManager];
    return [fileManager fileExistsAtPath:@"/private/var/lib/apt/"];
}
Run Code Online (Sandbox Code Playgroud)


Cra*_*007 5

/**
     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
    }
Run Code Online (Sandbox Code Playgroud)