From 11223e1700700d5172cc79f489761885fdf1c981 Mon Sep 17 00:00:00 2001 From: opa334 Date: Sat, 24 Feb 2024 16:44:02 +0100 Subject: [PATCH] Fix bug with Dopamine app getting root, improve jailbreak hiding --- .../Dopamine/Jailbreak/DOEnvironmentManager.m | 33 ++++++++++++++++--- BaseBin/launchdhook/src/update.m | 4 +++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/Application/Dopamine/Jailbreak/DOEnvironmentManager.m b/Application/Dopamine/Jailbreak/DOEnvironmentManager.m index 58fa79867..f3bf611aa 100644 --- a/Application/Dopamine/Jailbreak/DOEnvironmentManager.m +++ b/Application/Dopamine/Jailbreak/DOEnvironmentManager.m @@ -264,7 +264,7 @@ - (void)runAsRoot:(void (^)(void))rootBlock { uint32_t orgUser = getuid(); uint32_t orgGroup = getgid(); - if (orgUser == 0 && orgGroup == 0) { + if (geteuid() == 0 && orgGroup == 0) { rootBlock(); return; } @@ -339,6 +339,22 @@ - (void)refreshJailbreakApps }]; } +- (void)unregisterJailbreakApps +{ + [self runAsRoot:^{ + [self runUnsandboxed:^{ + NSArray *jailbreakApps = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:NSJBRootPath(@"/Applications") error:nil]; + if (jailbreakApps.count) { + for (NSString *jailbreakApp in jailbreakApps) { + NSString *jailbreakAppPath = [NSJBRootPath(@"/Applications") stringByAppendingPathComponent:jailbreakApp]; + exec_cmd(JBRootPath("/usr/bin/uicache"), "-u", jailbreakAppPath.fileSystemRepresentation, NULL); + } + + } + }]; + }]; +} + - (void)reboot { [self runAsRoot:^{ @@ -477,16 +493,25 @@ - (void)setJailbreakHidden:(BOOL)hidden BOOL alreadyHidden = [self isJailbreakHidden]; if (hidden != alreadyHidden) { if (hidden) { - [[NSFileManager defaultManager] removeItemAtPath:@"/var/jb" error:nil]; if ([self isJailbroken]) { + [self unregisterJailbreakApps]; [[NSFileManager defaultManager] removeItemAtPath:NSJBRootPath(@"/basebin/.fakelib/systemhook.dylib") error:nil]; carbonCopy(NSJBRootPath(@"/basebin/.dyld.orig"), NSJBRootPath(@"/basebin/.fakelib/dyld")); + + // For some weird reason after removing systemhook from fakelib, accessing "/usr/lib/systemhook.dylib" still works + // For some even more weird reason, just opening /usr/lib and closing it again fixes it o.O + int fd = open("/usr/lib", O_RDONLY); + close(fd); } + [[NSFileManager defaultManager] removeItemAtPath:@"/var/jb" error:nil]; } else { [[NSFileManager defaultManager] createSymbolicLinkAtPath:@"/var/jb" withDestinationPath:NSJBRootPath(@"/") error:nil]; - carbonCopy(NSJBRootPath(@"/basebin/.dyld.patched"), NSJBRootPath(@"/basebin/.fakelib/dyld")); - carbonCopy(NSJBRootPath(@"/basebin/systemhook.dylib"), NSJBRootPath(@"/basebin/.fakelib/systemhook.dylib")); + if ([self isJailbroken]) { + carbonCopy(NSJBRootPath(@"/basebin/.dyld.patched"), NSJBRootPath(@"/basebin/.fakelib/dyld")); + carbonCopy(NSJBRootPath(@"/basebin/systemhook.dylib"), NSJBRootPath(@"/basebin/.fakelib/systemhook.dylib")); + [self refreshJailbreakApps]; + } } } }; diff --git a/BaseBin/launchdhook/src/update.m b/BaseBin/launchdhook/src/update.m index a8cfbccdb..c9327bf67 100644 --- a/BaseBin/launchdhook/src/update.m +++ b/BaseBin/launchdhook/src/update.m @@ -181,4 +181,8 @@ void jbupdate_finalize_stage2(const char *prevVersion, const char *newVersion) if (!access(JBRootPath("/basebin/.idownloadd_enabled"), F_OK)) { remove(JBRootPath("/basebin/.idownloadd_enabled")); } + + // Seems to fix systemhook taking a while to become updated + int fd = open("/usr/lib", O_RDONLY); + if (fd >= 0) close(fd); } \ No newline at end of file