Skip to content

Commit f6392da

Browse files
authored
Improvements to iOS Jailbrake detection (#4404)
1 parent 7a77693 commit f6392da

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

Ports/iOSPort/nativeSources/CN1JailbreakDetector.m

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,19 @@
2727
#import <dlfcn.h>
2828
#import <sys/sysctl.h>
2929
#import <mach-o/dyld.h>
30+
#import <unistd.h>
31+
#import <stdlib.h>
3032

3133
void 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

scripts/hellocodenameone/common/src/main/kotlin/com/codenameone/examples/hellocodenameone/HelloCodenameOne.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,22 @@ package com.codenameone.examples.hellocodenameone
22

33
import com.codename1.system.Lifecycle
44
import com.codename1.testing.TestReporting
5+
import com.codename1.ui.Display
56
import com.codenameone.examples.hellocodenameone.tests.Cn1ssDeviceRunner
67
import com.codenameone.examples.hellocodenameone.tests.Cn1ssDeviceRunnerReporter
78
import com.codenameone.examples.hellocodenameone.tests.KotlinUiTest
89

910
open class HelloCodenameOne : Lifecycle() {
1011
override fun init(context: Any?) {
1112
super.init(context)
13+
check(!Display.getInstance().isJailbrokenDevice()) {
14+
"Jailbroken device detected by Display.isJailbrokenDevice()."
15+
}
1216
Cn1ssDeviceRunner.addTest(KotlinUiTest())
1317
TestReporting.setInstance(Cn1ssDeviceRunnerReporter())
1418
}
1519

1620
override fun runApp() {
1721
Thread(Runnable { Cn1ssDeviceRunner().runSuite() }).start()
1822
}
19-
}
23+
}

0 commit comments

Comments
 (0)