Skip to content

Commit

Permalink
Merge pull request #163 from emkey1/development
Browse files Browse the repository at this point in the history
Merge 1.3 Build 501 release changes
  • Loading branch information
emkey1 authored Nov 18, 2023
2 parents 06d8c87 + acdabc5 commit 94b374f
Show file tree
Hide file tree
Showing 55 changed files with 1,118 additions and 822 deletions.
4 changes: 4 additions & 0 deletions app/AboutViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#import "CurrentRoot.h"
#import "AppGroup.h"
#import "UserPreferences.h"
#import "iOSFS.h"
#import "UIApplication+OpenURL.h"
#import "NSObject+SaneKVO.h"

Expand All @@ -31,6 +32,7 @@ @interface AboutViewController ()
@property (weak, nonatomic) IBOutlet UILabel *upgradeApkLabel;
@property (weak, nonatomic) IBOutlet UIView *upgradeApkBadge;
@property (weak, nonatomic) IBOutlet UITableViewCell *exportContainerCell;
@property (weak, nonatomic) IBOutlet UITableViewCell *resetMountsCell;

@property (weak, nonatomic) IBOutlet UILabel *versionLabel;

Expand Down Expand Up @@ -113,6 +115,8 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
[NSFileManager.defaultManager copyItemAtURL:[container URLByAppendingPathComponent:@"roots"]
toURL:[documents URLByAppendingPathComponent:@"roots copy"]
error:nil];
} else if (cell == self.resetMountsCell) {
iosfs_clear_all_bookmarks();
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
Expand Down
2 changes: 1 addition & 1 deletion app/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
- (void)exitApp;

#if !ISH_LINUX
+ (int)bootError;
+ (intptr_t)bootError;
#endif

+ (void)maybePresentStartupMessageOnViewController:(UIViewController *)vc;
Expand Down
24 changes: 9 additions & 15 deletions app/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static void ios_handle_exit(struct task *task, int code) {
// pid should be saved now since task would be freed
pid_t pid = task->pid;
// if(pids_lock.pid == pid)
// unlock_pids(&pids_lock);
// unlock(&pids_lock);
// while((critical_region_count(task)) || (locks_held_count(task))) { // Wait for now, task is in one or more critical sections, and/or has locks
// nanosleep(&lock_pause, NULL);
// }
Expand All @@ -82,16 +82,16 @@ void ReportPanic(const char *message) {
}
#endif

static int bootError;
static intptr_t bootError;
static NSString *const kSkipStartupMessage = @"Skip Startup Message";

@implementation AppDelegate

- (int)boot {
- (intptr_t)boot {
#if !ISH_LINUX
NSURL *root = [Roots.instance rootUrl:Roots.instance.defaultRoot];

int err = mount_root(&fakefs, [root URLByAppendingPathComponent:@"data"].fileSystemRepresentation);
intptr_t err = mount_root(&fakefs, [root URLByAppendingPathComponent:@"data"].fileSystemRepresentation);
if (err < 0)
return err;

Expand All @@ -116,6 +116,7 @@ - (int)boot {
generic_mknodat(AT_PWD, "/dev/tty7", S_IFCHR|0666, dev_make(TTY_CONSOLE_MAJOR, 7));

generic_mknodat(AT_PWD, "/dev/tty", S_IFCHR|0666, dev_make(TTY_ALTERNATE_MAJOR, DEV_TTY_MINOR));
//generic_mknodat(AT_PWD, "/dev/console", S_IFCHR|0222, dev_make(136, 0));
generic_mknodat(AT_PWD, "/dev/console", S_IFCHR|0666, dev_make(TTY_ALTERNATE_MAJOR, DEV_CONSOLE_MINOR));
generic_mknodat(AT_PWD, "/dev/ptmx", S_IFCHR|0666, dev_make(TTY_ALTERNATE_MAJOR, DEV_PTMX_MINOR));

Expand All @@ -141,8 +142,9 @@ - (int)boot {
if (err != 0)
return err;
generic_mknodat(AT_PWD, "/dev/location", S_IFCHR|0666, dev_make(DYN_DEV_MAJOR, DEV_LOCATION_MINOR));
//generic_mknodat(AT_PWD, "/dev/rtc0", S_IFCHR|0666, dev_make(DEV_RTC_MAJOR, DEV_RTC_MINOR));
//generic_mknodat(AT_PWD, "/dev/rtc", S_IFCHR|0666, dev_make(DEV_RTC_MAJOR, DEV_RTC_MINOR)); // Technically this should be a link to /dev/rtc0, but I don't want to wrestle with that right now. -mke
// The following does nothing for now. Placeholder
generic_mknodat(AT_PWD, "/dev/rtc0", S_IFCHR|0666, dev_make(DEV_RTC_MAJOR, DEV_RTC_MINOR));
generic_symlinkat("/dev/rtc0", AT_PWD, "/dev/rtc");

do_mount(&procfs, "proc", "/proc", "", 0);
do_mount(&devptsfs, "devpts", "/dev/pts", "", 0);
Expand Down Expand Up @@ -236,7 +238,7 @@ - (void)configureDns {
#endif
}

+ (int)bootError {
+ (intptr_t)bootError {
return bootError;
}

Expand Down Expand Up @@ -290,7 +292,6 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
extern const char *uname_hostname_override;
extern bool doEnableMulticore;
extern bool doEnableExtraLocking;
extern unsigned doLockSleepNanoseconds;
extern pthread_mutex_t multicore_lock;
extern pthread_mutex_t extra_lock;
NSString *hostnameOverride = [NSUserDefaults.standardUserDefaults stringForKey:@"hostnameOverride"];
Expand Down Expand Up @@ -321,13 +322,6 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
pthread_mutex_unlock(&extra_lock); // Be sure not to leave around orphan lock
});
}];
// [UserPreferences.shared observe:@[@"shouldLockSleepNanoseconds"] options:NSKeyValueObservingOptionInitial
// owner:self usingBlock:^(typeof(self) self) {
// dispatch_async(dispatch_get_main_queue(), ^{
// doLockSleepNanoseconds = UserPreferences.shared.shouldLockSleepNanoseconds;
// pthread_mutex_unlock(&extra_lock); // Be sure not to leave around orphan lock
// });
// }];

// This code is IPv4 and IPv6 aware: see https://developer.apple.com/library/archive/samplecode/Reachability/Listings/ReadMe_md.html.
struct sockaddr_in address = {
Expand Down
121 changes: 63 additions & 58 deletions app/AppGroup.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,67 +34,72 @@
};

static NSDictionary *AppEntitlements(void) {
static NSDictionary *entitlements;
if (entitlements != nil)
return entitlements;

// Inspired by codesign.c in Darwin sources for Security.framework

const struct mach_header_64 *header = &_mh_execute_header;

// Simulator executables have fake entitlements in the code signature. The real entitlements can be found in an __entitlements section.
size_t entitlements_size;
char *entitlements_data = (char *) getsectiondata(header, "__TEXT", "__entitlements", &entitlements_size);
if (entitlements_data != NULL) {
NSData *data = [NSData dataWithBytesNoCopy:entitlements_data
length:entitlements_size
freeWhenDone:NO];
return entitlements = [NSPropertyListSerialization propertyListWithData:data
options:NSPropertyListImmutable
format:nil
error:nil];
}

// Find the LC_CODE_SIGNATURE
struct load_command *lc = (void *) (header + 1);
struct linkedit_data_command *cs_lc = NULL;
for (uint32_t i = 0; i < header->ncmds; i++) {
if (lc->cmd == LC_CODE_SIGNATURE) {
cs_lc = (void *) lc;
break;
static NSDictionary *entitlements = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
const struct mach_header_64 *header = &_mh_execute_header;

// Check for entitlements in the __entitlements section (common in simulators)
size_t entitlements_size;
char *entitlements_data = (char *) getsectiondata(header, "__TEXT", "__entitlements", &entitlements_size);
if (entitlements_data != NULL) {
NSData *data = [NSData dataWithBytesNoCopy:entitlements_data length:entitlements_size freeWhenDone:NO];
NSError *error = nil;
entitlements = [NSPropertyListSerialization propertyListWithData:data options:NSPropertyListImmutable format:nil error:&error];
if (entitlements == nil) {
NSLog(@"Failed to parse entitlements: %@", error);
return;
}
return;
}
lc = (void *) ((char *) lc + lc->cmdsize);
}
if (cs_lc == NULL)
return nil;

// Code for fetching entitlements from the code signature
struct load_command *lc = (void *) (header + 1);
struct linkedit_data_command *cs_lc = NULL;
for (uint32_t i = 0; i < header->ncmds; i++) {
if (lc->cmd == LC_CODE_SIGNATURE) {
cs_lc = (void *) lc;
break;
}
lc = (void *) ((char *) lc + lc->cmdsize);
}
if (cs_lc == NULL)
return;

NSFileHandle *fileHandle = [NSFileHandle fileHandleForReadingFromURL:NSBundle.mainBundle.executableURL error:nil];
if (fileHandle == nil)
return;
[fileHandle seekToFileOffset:cs_lc->dataoff];
NSData *csData = [fileHandle readDataOfLength:cs_lc->datasize];
[fileHandle closeFile];
const struct cs_superblob *cs = csData.bytes;
if (ntohl(cs->magic) != CSMAGIC_EMBEDDED_SIGNATURE)
return;

NSData *entitlementsData = nil;
for (uint32_t i = 0; i < ntohl(cs->count); i++) {
struct cs_entitlements *ents = (void *) ((char *) cs + ntohl(cs->index[i].offset));

// Read the magic number in a way that does not assume alignment
uint32_t magic;
memcpy(&magic, &ents->magic, sizeof(uint32_t));
if (ntohl(ents->magic) == CSMAGIC_EMBEDDED_ENTITLEMENTS) {
entitlementsData = [NSData dataWithBytes:ents->entitlements length:ntohl(ents->length) - offsetof(struct cs_entitlements, entitlements)];
break; // Entitlements found
}
}

if (entitlementsData == nil)
return;

// Read the code signature off disk, as it's apparently not loaded into memory
NSFileHandle *fileHandle = [NSFileHandle fileHandleForReadingFromURL:NSBundle.mainBundle.executableURL error:nil];
if (fileHandle == nil)
return nil;
[fileHandle seekToFileOffset:cs_lc->dataoff];
NSData *csData = [fileHandle readDataOfLength:cs_lc->datasize];
[fileHandle closeFile];
const struct cs_superblob *cs = csData.bytes;
if (ntohl(cs->magic) != CSMAGIC_EMBEDDED_SIGNATURE)
return nil;

// Find the entitlements in the code signature
NSData *entitlementsData = nil;
for (uint32_t i = 0; i < ntohl(cs->count); i++) {
struct cs_entitlements *ents = (void *) ((char *) cs + ntohl(cs->index[i].offset));
if (ntohl(ents->magic) == CSMAGIC_EMBEDDED_ENTITLEMENTS) {
entitlementsData = [NSData dataWithBytes:ents->entitlements
length:ntohl(ents->length) - offsetof(struct cs_entitlements, entitlements)];
NSError *serializationError = nil;
entitlements = [NSPropertyListSerialization propertyListWithData:entitlementsData options:NSPropertyListImmutable format:nil error:&serializationError];
if (entitlements == nil) {
NSLog(@"Failed to parse entitlements: %@", serializationError);
return;
}
}
if (entitlementsData == nil)
return nil;

return entitlements = [NSPropertyListSerialization propertyListWithData:entitlementsData
options:NSPropertyListImmutable
format:nil
error:nil];
});
return entitlements;
}

NSArray<NSString *> *CurrentAppGroups(void) {
Expand Down
Loading

0 comments on commit 94b374f

Please sign in to comment.