在 iOS 11 或更高版本中检测越狱

Vin*_*nay 8 ios cordova

使用“ https://github.com/leecrossley/cordova-plugin-jailbreak-detection ”但它仍然没有检查越狱,因为在最新的 11+ iOS 版本中绕过了 Cydia 和其他选项

如何使用 Cordova 或本机代码处理最新的 iOS?

Ale*_*rov 22

2021 年更新: 您可以使用这篇文章中的 UIDevice 扩展:https : //developerinsider.co/best-way-to-check-if-your-ios-app-is-running-on-a-jailbroken-phone/

我在这里复制了所有代码。

你可以在 Github 上找到最新版本的代码(作者是 @vineetchoudhary):https : //github.com/developerinsider/isJailBroken/blob/master/IsJailBroken/Extension/UIDevice%2BJailBroken.swift

全码:

import Foundation
import UIKit

extension UIDevice {
    var isSimulator: Bool {
        return TARGET_OS_SIMULATOR != 0
    }
    
    var isJailBroken: Bool {
        get {
            if UIDevice.current.isSimulator { return false }
            if JailBrokenHelper.hasCydiaInstalled() { return true }
            if JailBrokenHelper.isContainsSuspiciousApps() { return true }
            if JailBrokenHelper.isSuspiciousSystemPathsExists() { return true }
            return JailBrokenHelper.canEditSystemFiles()
        }
    }
}
    
private struct JailBrokenHelper {
    static func hasCydiaInstalled() -> Bool {
        return UIApplication.shared.canOpenURL(URL(string: "cydia://")!)
    }
    
    static func isContainsSuspiciousApps() -> Bool {
        for path in suspiciousAppsPathToCheck {
            if FileManager.default.fileExists(atPath: path) {
                return true
            }
        }
        return false
    }
    
    static func isSuspiciousSystemPathsExists() -> Bool {
        for path in suspiciousSystemPathsToCheck {
            if FileManager.default.fileExists(atPath: path) {
                return true
            }
        }
        return false
    }
    
    static func canEditSystemFiles() -> Bool {
        let jailBreakText = "Developer Insider"
        do {
            try jailBreakText.write(toFile: jailBreakText, atomically: true, encoding: .utf8)
            return true
        } catch {
            return false
        }
    }
    
    /**
     Add more paths here to check for jail break
     */
    static var suspiciousAppsPathToCheck: [String] {
        return ["/Applications/Cydia.app",
                "/Applications/blackra1n.app",
                "/Applications/FakeCarrier.app",
                "/Applications/Icy.app",
                "/Applications/IntelliScreen.app",
                "/Applications/MxTube.app",
                "/Applications/RockApp.app",
                "/Applications/SBSettings.app",
                "/Applications/WinterBoard.app"
        ]
    }
    
    static var suspiciousSystemPathsToCheck: [String] {
        return ["/Library/MobileSubstrate/DynamicLibraries/LiveClock.plist",
                "/Library/MobileSubstrate/DynamicLibraries/Veency.plist",
                "/private/var/lib/apt",
                "/private/var/lib/apt/",
                "/private/var/lib/cydia",
                "/private/var/mobile/Library/SBSettings/Themes",
                "/private/var/stash",
                "/private/var/tmp/cydia.log",
                "/System/Library/LaunchDaemons/com.ikey.bbot.plist",
                "/System/Library/LaunchDaemons/com.saurik.Cydia.Startup.plist",
                "/usr/bin/sshd",
                "/usr/libexec/sftp-server",
                "/usr/sbin/sshd",
                "/etc/apt",
                "/bin/bash",
                "/Library/MobileSubstrate/MobileSubstrate.dylib"
        ]
    }
}
Run Code Online (Sandbox Code Playgroud)

另外,您需要cydia在LSApplicationQueriesSchemes里面添加key Info.plist。这是canOpenURL工作所必需的。

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>cydia</string>
</array>
Run Code Online (Sandbox Code Playgroud)

  • 您认为在越狱检查中包含包含“cydia”的字符串是个好主意吗?反编译后,您可以轻松找到字符串“cydia”并在运行时更改函数的返回值。还是我错了? (2认同)

Kev*_*rio 6

在本机代码中:您可以使用DTTJailbreakDetection,它在 Objective-C 中。如果您使用 swift,则需要使用桥接头。

目标-C:

if ([DTTJailbreakDetection isJailbroken]) {

    // your code
}
Run Code Online (Sandbox Code Playgroud)

迅速:

if DTTJailbreakDetection.isJailbroken() {

    // your code 
}
Run Code Online (Sandbox Code Playgroud)

  • DTTJailbreakDetection 使用与接受的答案中的文章几乎相同的代码(/sf/answers/3443690631/) (4认同)