SoFunction
Updated on 2025-04-12

Example of iOS method to determine whether to jailbreak device

Preface

Apple attaches great importance to the security of its products, so it designed a complex security mechanism for users. This made programmers who love freedom and advocate openness extremely unhappy, so jailbreaking became a place for Apple to fight repeatedly with hackers. Overall, jailbreaking allows us to install and share applications at will, but it does reduce the security of the device and will provide convenience for some malicious applications.

Sometimes our application wants to know whether the installed device has been jailbroken. Obviously, Apple will not provide a solution, so what should we do? Let's take a look at the detailed introduction below

Jailbreak device printing

(lldb) po [[NSFileManager defaultManager ] fileExistsAtPath:@"/Applications/"]

YES    

 (lldb) po [[NSFileManager defaultManager ] fileExistsAtPath:@"/private/var/lib/apt"]

YES     

 (lldb) po [[NSFileManager defaultManager ] fileExistsAtPath:@"/usr/lib/system/libsystem_kernel.dylib"]

NO   

  (lldb) po [[NSFileManager defaultManager ] fileExistsAtPath:@"Library/MobileSubstrate/"]

YES

(lldb) po [[NSFileManager defaultManager ] fileExistsAtPath:@"/etc/apt"]

YES

Printing of non-jailbreaking devices

(lldb) po [[NSFileManager defaultManager ] fileExistsAtPath:@"/Applications/"]

NO

(lldb)  po [[NSFileManager defaultManager ] fileExistsAtPath:@"/private/var/lib/apt"]

NO

(lldb) po [[NSFileManager defaultManager ] fileExistsAtPath:@"/usr/lib/system/libsystem_kernel.dylib"]

YES

(lldb) po [[NSFileManager defaultManager ] fileExistsAtPath:@"Library/MobileSubstrate/"]

NO

(lldb) po [[NSFileManager defaultManager ] fileExistsAtPath:@"/etc/apt"]

NO

Based on the above printing results, you can see if you want to determine whether the jailbreak is present. Check whether the following path file exists.

1. "/Applications/" exists. Jailbreak

2. "/private/var/lib/apt" exists. Jailbreak

3. "/usr/lib/system/libsystem_kernel.dylib" does not exist * break

4. "Library/MobileSubstrate/" exists. Jailbreak

5. "/etc/apt" exists and jailbreak

- (BOOL)isJailBreak{

 __block BOOL jailBreak = NO;

 NSArray *array = @[@"/Applications/",@"/private/var/lib/apt",@"/usr/lib/system/libsystem_kernel.dylib",@"Library/MobileSubstrate/",@"/etc/apt"];

 [array enumerateObjectsUsingBlock:^(NSString *obj, NSUInteger idx, BOOL * _Nonnull stop) {

  BOOL fileExist = [[NSFileManager defaultManager] fileExistsAtPath:obj];

  if ([obj isEqualToString:@"/usr/lib/system/libsystem_kernel.dylib"]) {

   jailBreak |= !fileExist;

  }else{

   jailBreak |= fileExist;

  }

 }];
 return jailBreak;
}

Summarize

The above is the entire content of this article. I hope that the content of this article has a certain reference value for everyone's study or work. If you have any questions, you can leave a message to communicate. Thank you for your support.