Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions Ports/iOSPort/nativeSources/CN1JailbreakDetector.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,19 @@
#import <dlfcn.h>
#import <sys/sysctl.h>
#import <mach-o/dyld.h>
#import <unistd.h>
#import <stdlib.h>

void cn1DetectJailbreakBypassesAndExit() {
#if (TARGET_IPHONE_SIMULATOR)
return;
#endif
// Detect common dynamic library injection used by Frida/Objection and similar tools
if (getenv("DYLD_INSERT_LIBRARIES") != NULL) {
NSLog(@"DYLD_INSERT_LIBRARIES detected.");
exit(0);
}

// List of known libraries used by bypass tools like Liberty Lite and Substrate
NSArray *bypassLibraries = @[
@"LibertyLite.dylib",
Expand Down Expand Up @@ -60,10 +68,11 @@ void cn1DetectJailbreakBypassesAndExit() {
// Additional check for file access to system areas (indicates potential bypass)
NSArray *restrictedPaths = @[
@"/Applications/Cydia.app",
@"/Library/MobileSubstrate/MobileSubstrate.dylib",
@"/usr/sbin/sshd",
@"/bin/bash",
@"/etc/apt",
@"/Library/MobileSubstrate/MobileSubstrate.dylib"
@"/private/var/lib/apt/"
];

NSFileManager *fileManager = [NSFileManager defaultManager];
Expand All @@ -78,8 +87,9 @@ void cn1DetectJailbreakBypassesAndExit() {
// Check if we can write to a restricted area (bypasses may allow this)
NSString *testPath = @"/private/jailbreakTest.txt";
NSError *error;
[@"Test" writeToFile:testPath atomically:YES encoding:NSUTF8StringEncoding error:&error];
if (!error) {
BOOL wroteFile = [@"Test" writeToFile:testPath atomically:YES encoding:NSUTF8StringEncoding error:&error];
if (wroteFile && !error) {
[fileManager removeItemAtPath:testPath error:nil];
// Able to write to restricted area, exit the app
NSLog(@"Write access to restricted area detected.");
exit(0); // Exit the app if write access to restricted areas is detected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@ package com.codenameone.examples.hellocodenameone

import com.codename1.system.Lifecycle
import com.codename1.testing.TestReporting
import com.codename1.ui.Display
import com.codenameone.examples.hellocodenameone.tests.Cn1ssDeviceRunner
import com.codenameone.examples.hellocodenameone.tests.Cn1ssDeviceRunnerReporter
import com.codenameone.examples.hellocodenameone.tests.KotlinUiTest

open class HelloCodenameOne : Lifecycle() {
override fun init(context: Any?) {
super.init(context)
check(!Display.getInstance().isJailbrokenDevice()) {
"Jailbroken device detected by Display.isJailbrokenDevice()."
}
Cn1ssDeviceRunner.addTest(KotlinUiTest())
TestReporting.setInstance(Cn1ssDeviceRunnerReporter())
}

override fun runApp() {
Thread(Runnable { Cn1ssDeviceRunner().runSuite() }).start()
}
}
}
Loading