So how can you tell if a cell phone is escaping?
You need to add the following C language library
#import <sys/stat.h>
#import <dlfcn.h>
#import <mach-o/dyld.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#import <ifaddrs.h>
#import <arpa/inet.h>
#import <net/if.h>
1. Through the prison after the increase of prison jailbreak file judgment
Generally speaking, the cell phone after jailbreak will add the following file
/applications/cydia.app
/library/mobilesubstrate/mobilesubstrate.dylib
/bin/bash
/usr/sbin/sshd
/etc/apt
To determine whether these files exist, as long as there is, you can think that the cell phone has escaped.
Nsarray *jailbreak_tool_paths = @[
@ "/applications/cydia.app",
@ "/library/mobilesubstrate/ Mobilesubstrate.dylib ", @"/bin/bash ", @"
/usr/sbin/sshd ",
@"/etc/apt "
];
-(BOOL) Isjailbreak {for
(int i=0; i<jailbreak_tool_paths.count; i++) {
if ([[Nsfilemanager Defaultmanager] Fileexistsatpath:jailbreak_tool_paths[i]]) {
NSLog (@ "The device is jail broken!");
Return YES
}
}
NSLog (@ "The device is not jail broken!");
return NO;
}
2. According to whether can open Cydia judgment
-(BOOL) Isjailbreak {
if ([[UIApplication sharedapplication] canopenurl:[nsurl urlwithstring:@ "cydia://"]]) {
NSLog (@ "The device is jail broken!");
Return YES
}
NSLog (@ "The device is not jail broken!");
return NO;
}
3. According to whether can obtain all the application name judgment
A device without a jailbreak is not authorized to read all the application names.
-(BOOL) Isjailbreak {
if ([[Nsfilemanager Defaultmanager] fileexistsatpath:@ "user/applications/"]) {
NSLog (@ "The device is jail broken!");
Nsarray *applist = [[Nsfilemanager Defaultmanager] contentsofdirectoryatpath:@ "user/applications/" error:nil];
NSLog (@ "applist =%@", applist);
Return YES
}
NSLog (@ "The device is not jail broken!");
return NO;
}
4. Based on the use of stat method to determine whether the existence of Cydia to judge
The idea of this method is determined by Cydia application, but the method is to use the STAT function and to determine whether there is an injection dynamic library.
int Checkinject () {
int ret;
Dl_info Dylib_info;
Int (*func_stat) (const char*, struct stat*) = stat;
Char *dylib_name = "/usr/lib/system/libsystem_kernel.dylib";
if (ret = DLADDR (Func_stat, &dylib_info)) && strncmp (Dylib_info.dli_fname, Dylib_name, strlen (dylib_name) ) {return
0;
}
return 1;
}
int Checkcydia () {
struct stat stat_info;
if (!checkinject ()) {
if (0 = stat ("/applications/cydia.app", &stat_info)) {return
1;
}
} else {return
1;
}
return 0;
}
5. Judging by the value of the Read environment variable
The dyld_insert_libraries environment variable should be empty on a device that is not jailbreak, and the jailbreak equipment will basically have library/mobilesubstrate/mobilesubstrate.dylib
char* printenv (void) {
Charchar *env = getenv ("dyld_insert_libraries");
NSLog (@ "%s", env);
return env;
}
-(BOOL) Isjailbreak {
if (printenv ()) {
NSLog (@ "The device is jail broken!");
Return YES
}
NSLog (@ "The device is not jail broken!");
return NO;
}
All of the above 5 methods can be used to determine whether or not to escape, but in order to ensure the accuracy of the judgement, there are often several methods of joint use.