Created
February 10, 2020 21:14
-
-
Save haxxinen/c0f0dacb46ba9bd0423b71872fc32414 to your computer and use it in GitHub Desktop.
Detect iOS jailbreak - App
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ViewController.swift | |
import UIKit | |
class ViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do any additional setup after loading the view, typically from a nib. | |
func filenameOnRootDirectory(file: String) -> String { | |
// hex array for for "../" | |
let ddback: String = byteArrayToString( | |
array: [0x2e, 0x2e, 0x2f] | |
) | |
// hex array for ".." | |
let dd: String = byteArrayToString( | |
array: [0x2e, 0x2e] | |
) | |
// how many times to prepend "../" in front of filename | |
let max = Int(arc4random_uniform(UInt32((35 - 15) + 1))) + 15 | |
var preString: String = "" | |
for _ in 0..<max { | |
preString += ddback | |
} | |
preString += dd | |
// "../" * random + ".." + filename | |
// (filename starts with "/") | |
return preString + file | |
} | |
func byteArrayToString(array: [UInt8]) -> String { | |
return String( | |
data: NSData( | |
bytes: array, length: array.count | |
) as Data, | |
encoding: String.Encoding.utf8 | |
)! | |
} | |
// hex array for "/var/lib/apt" | |
let str: String = byteArrayToString(array: [ | |
0x2f, 0x76, 0x61, 0x72, | |
0x2f, 0x6c, 0x69, 0x62, | |
0x2f, 0x61, 0x70, 0x74 | |
]) | |
let str_ddslash = filenameOnRootDirectory(file: str) | |
var jailbroken = false | |
if FileManager.default.fileExists(atPath: str) || FileManager.default.fileExists(atPath: str_ddslash) { | |
jailbroken = true | |
} | |
if let f = fopen(str, "r") { | |
fclose(f) | |
jailbroken = true | |
} | |
if let f = fopen(str_ddslash, "r") { | |
fclose(f) | |
jailbroken = true | |
} | |
print("JB: ", jailbroken); | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
// Dispose of any resources that can be recreated. | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment