├── .gitignore ├── LICENSE ├── MOJailBrokenDector.swift └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xccheckout 14 | *.moved-aside 15 | DerivedData 16 | *.hmap 17 | *.ipa 18 | *.xcuserstate 19 | 20 | # CocoaPods 21 | # 22 | # We recommend against adding the Pods directory to your .gitignore. However 23 | # you should judge for yourself, the pros and cons are mentioned at: 24 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 25 | # 26 | # Pods/ 27 | 28 | # Carthage 29 | # 30 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 31 | # Carthage/Checkouts 32 | 33 | Carthage/Build 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Ahn Jung Min 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /MOJailBrokenDector.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MOJailBrokenDector.swift 3 | // MOJailBrokenDetector 4 | // 5 | // Created by JungMin Ahn on 2015. 9. 21.. 6 | // Copyright © 2015년 minsOne. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | #if (arch(i386) || arch(x86_64)) && os(iOS) 12 | private let DEVICE_IS_SIMULATOR = true 13 | #else 14 | private let DEVICE_IS_SIMULATOR = false 15 | #endif 16 | 17 | enum JailBrokenError: ErrorType { 18 | case Detected(fileName: String) 19 | } 20 | 21 | private let checkList = [ 22 | "/Applications/Cydia.app", 23 | "/Library/MobileSubstrate/MobileSubstrate.dylib", 24 | "/bin/bash", 25 | "/usr/sbin/sshd", 26 | "/etc/apt", 27 | "/private/var/lib/apt/" 28 | ]; 29 | 30 | public class MOJailBrokenDector { 31 | class func isBroken() throws -> Bool { 32 | if DEVICE_IS_SIMULATOR { return false } 33 | 34 | try isFileExistsAtPaths(checkList) 35 | try isOpenFiles(checkList) 36 | try isWriteToFile("/private/jailbreak.txt") 37 | 38 | return false 39 | } 40 | 41 | class private func isFileExistsAtPaths(fileNames: [String]) throws { 42 | try fileNames.forEach { 43 | if NSFileManager.defaultManager().fileExistsAtPath($0) { 44 | throw JailBrokenError.Detected(fileName: $0) 45 | } 46 | } 47 | } 48 | 49 | class private func isOpenFiles(fileNames: [String]) throws { 50 | try fileNames.forEach { 51 | let file = fopen($0, "r") 52 | if file != nil { 53 | defer { fclose(file) } 54 | throw JailBrokenError.Detected(fileName: $0) 55 | } 56 | } 57 | } 58 | 59 | class private func isWriteToFile(fileName: String) throws { 60 | do { 61 | try "This is a test.".writeToFile(fileName, atomically: true, encoding: NSUTF8StringEncoding) 62 | throw JailBrokenError.Detected(fileName: fileName) 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## MOJailBrokenDector 2 | 3 | I`m inspired [JailBrokenDector](https://github.com/0dayZh/JailbrokenDetector) Project. But JailBrokenDector proejct is writed Objective-C. Then I rewrite this code from Objective-C to Swift 2.0. 4 | 5 | ### How to use it 6 | 7 | // using do-try-catch 8 | do { 9 | try MOJailBrokenDector.isBroken() 10 | } catch JailBrokenError.Detected(let fileName) { 11 | print("Device is broken : \(fileName)") 12 | } catch { 13 | print("Error : \(error)") 14 | } 15 | 16 | // using guard 17 | guard let isBroken = try? MOJailBrokenDector.isBroken() else { 18 | print("Device is broken") 19 | return; 20 | } 21 | 22 | ### But.. 23 | 24 | I don't have jail broken device.. then, I didn`t test real device. 25 | --------------------------------------------------------------------------------