2727#import < dlfcn.h>
2828#import < sys/sysctl.h>
2929#import < mach-o/dyld.h>
30+ #import < unistd.h>
31+ #import < stdlib.h>
3032
3133void cn1DetectJailbreakBypassesAndExit () {
3234#if (TARGET_IPHONE_SIMULATOR)
3335 return ;
3436#endif
37+ // Detect common dynamic library injection used by Frida/Objection and similar tools
38+ if (getenv (" DYLD_INSERT_LIBRARIES" ) != NULL ) {
39+ NSLog (@" DYLD_INSERT_LIBRARIES detected." );
40+ exit (0 );
41+ }
42+
3543 // List of known libraries used by bypass tools like Liberty Lite and Substrate
3644 NSArray *bypassLibraries = @[
3745 @" LibertyLite.dylib" ,
@@ -60,10 +68,11 @@ void cn1DetectJailbreakBypassesAndExit() {
6068 // Additional check for file access to system areas (indicates potential bypass)
6169 NSArray *restrictedPaths = @[
6270 @" /Applications/Cydia.app" ,
71+ @" /Library/MobileSubstrate/MobileSubstrate.dylib" ,
6372 @" /usr/sbin/sshd" ,
6473 @" /bin/bash" ,
6574 @" /etc/apt" ,
66- @" /Library/MobileSubstrate/MobileSubstrate.dylib "
75+ @" /private/var/lib/apt/ "
6776 ];
6877
6978 NSFileManager *fileManager = [NSFileManager defaultManager ];
@@ -78,8 +87,9 @@ void cn1DetectJailbreakBypassesAndExit() {
7887 // Check if we can write to a restricted area (bypasses may allow this)
7988 NSString *testPath = @" /private/jailbreakTest.txt" ;
8089 NSError *error;
81- [@" Test" writeToFile: testPath atomically: YES encoding: NSUTF8StringEncoding error: &error];
82- if (!error) {
90+ BOOL wroteFile = [@" Test" writeToFile: testPath atomically: YES encoding: NSUTF8StringEncoding error: &error];
91+ if (wroteFile && !error) {
92+ [fileManager removeItemAtPath: testPath error: nil ];
8393 // Able to write to restricted area, exit the app
8494 NSLog (@" Write access to restricted area detected." );
8595 exit (0 ); // Exit the app if write access to restricted areas is detected
0 commit comments