Skip to content

Commit

Permalink
Fix bug with Dopamine app getting root, improve jailbreak hiding
Browse files Browse the repository at this point in the history
  • Loading branch information
opa334 committed Feb 24, 2024
1 parent 8475c7f commit 11223e1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
33 changes: 29 additions & 4 deletions Application/Dopamine/Jailbreak/DOEnvironmentManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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:^{
Expand Down Expand Up @@ -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];
}
}
}
};
Expand Down
4 changes: 4 additions & 0 deletions BaseBin/launchdhook/src/update.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 11223e1

Please sign in to comment.