88#include " NSUserDefaults+appDefaults.h"
99#import " Bootstrap-Swift.h"
1010#import < sys/sysctl.h>
11+ #include < sys/mount.h>
1112#include < sys/utsname.h>
1213
1314#include < Security/SecKey.h>
@@ -51,7 +52,7 @@ BOOL updateOpensshStatus(BOOL notify)
5152{
5253 BOOL status;
5354
54- if (isSystemBootstrapped ()) {
55+ if (isSystemBootstrapped () && spawnRoot ( jbroot ( @" /basebin/bootstrapd " ), @[ @" check " ], nil , nil )== 0 ) {
5556 status = spawnRoot (jbroot (@" /basebin/bootstrapd" ), @[@" openssh" ,@" check" ], nil , nil )==0 ;
5657 } else {
5758 status = [NSUserDefaults .appDefaults boolForKey: @" openssh" ];
@@ -62,6 +63,32 @@ BOOL updateOpensshStatus(BOOL notify)
6263 return status;
6364}
6465
66+ void checkAppsHidden ()
67+ {
68+ if (isAllCTBugAppsHidden ()) {
69+ UIAlertController *alert = [UIAlertController alertControllerWithTitle: Localized (@" Jailbroken Apps are Hidden" ) message: Localized (@" Do you want to restore them now?" ) preferredStyle: UIAlertControllerStyleAlert];
70+ [alert addAction: [UIAlertAction actionWithTitle: Localized (@" NO" ) style: UIAlertActionStyleCancel handler: nil ]];
71+ [alert addAction: [UIAlertAction actionWithTitle: Localized (@" YES" ) style: UIAlertActionStyleDefault handler: ^(UIAlertAction *action){
72+ unhideAllCTBugApps ();
73+ }]];
74+ [AppDelegate showAlert: alert];
75+ }
76+ }
77+
78+ void tryLoadOpenSSH ()
79+ {
80+ if ([NSUserDefaults .appDefaults boolForKey: @" openssh" ] && [NSFileManager .defaultManager fileExistsAtPath: jbroot (@" /usr/libexec/sshd-keygen-wrapper" )])
81+ {
82+ NSString * log=nil ;
83+ NSString * err=nil ;
84+ int status = spawnRoot (jbroot (@" /basebin/bootstrapd" ), @[@" openssh" ,@" start" ], &log, &err);
85+ if (status==0 )
86+ [AppDelegate addLogText: Localized (@" openssh launch successful" )];
87+ else
88+ [AppDelegate addLogText: [NSString stringWithFormat: @" openssh launch faild(%d ):\n %@ \n %@ " , status, log, err]];
89+ }
90+ }
91+
6592BOOL checkServer ()
6693{
6794 static bool alerted = false ;
@@ -83,6 +110,8 @@ BOOL checkServer()
83110 NSString * err=nil ;
84111 if (spawnRoot (jbroot (@" /basebin/bootstrapd" ), @[@" daemon" ,@" -f" ], &log, &err)==0 ) {
85112 [AppDelegate addLogText: Localized (@" bootstrap server restart successful" )];
113+ checkAppsHidden ();
114+ tryLoadOpenSSH ();
86115 } else {
87116 [AppDelegate showMesage: [NSString stringWithFormat: @" %@ \n ERR:%@ " ] title: Localized (@" Error" )];
88117 }
@@ -143,15 +172,7 @@ void initFromSwiftUI()
143172 {
144173 if (checkServer ()) {
145174 [AppDelegate addLogText: Localized (@" bootstrap server check successful" )];
146-
147- if (isAllCTBugAppsHidden ()) {
148- UIAlertController *alert = [UIAlertController alertControllerWithTitle: Localized (@" Jailbreak Apps is Hidden" ) message: Localized (@" Do you want to restore them now?" ) preferredStyle: UIAlertControllerStyleAlert];
149- [alert addAction: [UIAlertAction actionWithTitle: Localized (@" NO" ) style: UIAlertActionStyleCancel handler: nil ]];
150- [alert addAction: [UIAlertAction actionWithTitle: Localized (@" YES" ) style: UIAlertActionStyleDefault handler: ^(UIAlertAction *action){
151- unhideAllCTBugApps ();
152- }]];
153- [AppDelegate showAlert: alert];
154- }
175+ checkAppsHidden ();
155176 }
156177
157178 [[NSNotificationCenter defaultCenter ] addObserverForName: UIApplicationWillEnterForegroundNotification object: nil queue: nil usingBlock: ^(NSNotification * _Nonnull note) {
@@ -511,16 +532,7 @@ void bootstrapAction()
511532 NSString * log=nil ;
512533 NSString * err=nil ;
513534
514- if ([NSUserDefaults .appDefaults boolForKey: @" openssh" ] && [NSFileManager .defaultManager fileExistsAtPath: jbroot (@" /usr/libexec/sshd-keygen-wrapper" )])
515- {
516- NSString * log=nil ;
517- NSString * err=nil ;
518- status = spawnRoot (jbroot (@" /basebin/bootstrapd" ), @[@" openssh" ,@" start" ], &log, &err);
519- if (status==0 )
520- [AppDelegate addLogText: Localized (@" openssh launch successful" )];
521- else
522- [AppDelegate addLogText: [NSString stringWithFormat: @" openssh launch faild(%d ):\n %@ \n %@ " , status, log, err]];
523- }
535+ tryLoadOpenSSH ();
524536
525537 if (gTweakEnabled && ![NSFileManager .defaultManager fileExistsAtPath: jbroot (@" /var/mobile/.tweakenabled" )]) {
526538 ASSERT ([[NSString new ] writeToFile: jbroot (@" /var/mobile/.tweakenabled" ) atomically: YES encoding: NSUTF8StringEncoding error: nil ]);
@@ -609,101 +621,120 @@ void resetMobilePassword()
609621 [AppDelegate showAlert: alert];
610622}
611623
612- void hideAllCTBugApps ( )
624+ int hideBootstrapApp ( BOOL usreboot )
613625{
614- UIAlertController *alert = [UIAlertController alertControllerWithTitle: Localized (@" Warning" ) message: Localized (@" This operation will make all apps installed via TrollStore/Bootstrap disappear from the Home Screen. You can restore them later via TrollStore Helper->[Refresh App Registrations] and Bootstrap->Settings->[Unhide Jailbreak Apps]" ) preferredStyle: UIAlertControllerStyleAlert];
615- [alert addAction: [UIAlertAction actionWithTitle: Localized (@" Cancel" ) style: UIAlertActionStyleDefault handler: nil ]];
616- [alert addAction: [UIAlertAction actionWithTitle: Localized (@" Hide" ) style: UIAlertActionStyleDestructive handler: ^(UIAlertAction *action){
626+ if (![LSApplicationWorkspace.defaultWorkspace unregisterApplication: NSBundle .mainBundle.bundleURL]) {
627+ return -1 ;
628+ }
629+
630+ if (usreboot)
631+ {
632+ sleep (2 );
633+
634+ int status = spawnRoot (jbroot (@" /basebin/bootstrapd" ), @[@" usreboot" ], nil , nil );
635+ if (status != 0 ) {
636+ return -2 ;
637+ }
638+ }
639+
640+ return 0 ;
641+ }
617642
618- dispatch_async (dispatch_get_global_queue (0 , 0 ), ^{
619- [AppDelegate showHudMsg: Localized (@" Hiding All Jailbreak/TrollStore Apps..." )];
620-
621- NSArray * allInstalledApplications = [LSApplicationWorkspace.defaultWorkspace allInstalledApplications ];
622-
623- BOOL TSHelperFound = NO ;
624- for (LSApplicationProxy* proxy in allInstalledApplications) {
625- NSString * TSHelperMarker = [proxy.bundleURL.path stringByAppendingPathComponent: @" .TrollStorePersistenceHelper" ];
626- if ([NSFileManager .defaultManager fileExistsAtPath: TSHelperMarker]) {
627- TSHelperFound = YES ;
628- break ;
629- }
630- }
631-
632- if (!TSHelperFound) {
633- [AppDelegate dismissHud ];
634-
635- UIAlertController *alert = [UIAlertController alertControllerWithTitle: Localized (@" Error" ) message: Localized (@" You haven't installed TrollStore Helper yet, please install it in TrollStore->Settings first." ) preferredStyle: UIAlertControllerStyleAlert];
636- [alert addAction: [UIAlertAction actionWithTitle: Localized (@" OK" ) style: UIAlertActionStyleDefault handler: nil ]];
637- [AppDelegate showAlert: alert];
638-
639- return ;
640- }
641-
642- for (LSApplicationProxy* proxy in allInstalledApplications)
643- {
644- if ([NSFileManager .defaultManager fileExistsAtPath: [proxy.bundleURL.path stringByAppendingString: @" /../_TrollStore" ]])
645- {
646- if ([proxy.bundleIdentifier isEqualToString: NSBundle .mainBundle.bundleIdentifier]) {
647- continue ;
648- }
649-
650- NSString * log=nil ;
651- NSString * err=nil ;
652- int status = spawnBootstrap ((char *[]){" /usr/bin/uicache" ," -u" ,rootfsPrefix (proxy.bundleURL .path ).fileSystemRepresentation ,NULL }, &log, &err);
653- if (status != 0 ) {
654- [AppDelegate dismissHud ];
655-
656- NSString * msg = [NSString stringWithFormat: @" code(%d )\n %@ \n\n stderr:\n %@ " ,status,log,err];
657- UIAlertController *alert = [UIAlertController alertControllerWithTitle: @" " message: msg preferredStyle: UIAlertControllerStyleAlert];
658- [alert addAction: [UIAlertAction actionWithTitle: Localized (@" OK" ) style: UIAlertActionStyleDefault handler: nil ]];
659- [AppDelegate showAlert: alert];
660-
661- return ;
662- }
663- }
643+ void hideAllCTBugAppsAction (BOOL usreboot)
644+ {
645+ [AppDelegate showHudMsg: Localized (@" Hiding All Jailbreak/TrollStore Apps..." )];
646+
647+ NSArray * allInstalledApplications = [LSApplicationWorkspace.defaultWorkspace allInstalledApplications ];
648+
649+ BOOL TSHelperFound = NO ;
650+ for (LSApplicationProxy* proxy in allInstalledApplications) {
651+ NSString * TSHelperMarker = [proxy.bundleURL.path stringByAppendingPathComponent: @" .TrollStorePersistenceHelper" ];
652+ if ([NSFileManager .defaultManager fileExistsAtPath: TSHelperMarker]) {
653+ TSHelperFound = YES ;
654+ break ;
655+ }
656+ }
657+
658+ if (!TSHelperFound) {
659+ [AppDelegate dismissHud ];
660+
661+ UIAlertController *alert = [UIAlertController alertControllerWithTitle: Localized (@" Error" ) message: Localized (@" You haven't installed TrollStore Helper yet, please install it in TrollStore->Settings first." ) preferredStyle: UIAlertControllerStyleAlert];
662+ [alert addAction: [UIAlertAction actionWithTitle: Localized (@" OK" ) style: UIAlertActionStyleDefault handler: nil ]];
663+ [AppDelegate showAlert: alert];
664+
665+ return ;
666+ }
667+
668+ for (LSApplicationProxy* proxy in allInstalledApplications)
669+ {
670+ NSString * appPath = proxy.bundleURL .path ;
671+
672+ if ([proxy.bundleIdentifier isEqualToString: NSBundle .mainBundle.bundleIdentifier]) {
673+ continue ;
674+ }
675+
676+ struct statfs fsb={0 };
677+ statfs (appPath.fileSystemRepresentation , &fsb);
678+ if (strcmp (fsb.f_mntonname , " /" ) == 0 ) {
679+ continue ;
680+ }
681+
682+ if (isDefaultInstallationPath (appPath))
683+ {
684+ if (![NSFileManager .defaultManager fileExistsAtPath: [appPath stringByAppendingString: @" /../_TrollStore" ]]
685+ && ![NSFileManager .defaultManager fileExistsAtPath: [appPath stringByAppendingString: @" /../_TrollStoreLite" ]]) {
686+ continue ;
664687 }
688+ }
689+
690+ if ([proxy.bundleIdentifier hasPrefix: @" com.apple." ] && [NSFileManager .defaultManager fileExistsAtPath: [@" /Applications" stringByAppendingPathComponent: appPath.lastPathComponent]]) {
691+ continue ;
692+ }
665693
666- for (NSString * bundle in [NSFileManager .defaultManager directoryContentsAtPath: jbroot (@" /Applications" )])
667- {
668- NSString * bundlePath = [@" /Applications" stringByAppendingPathComponent: bundle];
669- NSDictionary * appInfo = [NSDictionary dictionaryWithContentsOfFile: [bundlePath stringByAppendingPathComponent: @" Info.plist" ]];
670-
671- if ([appInfo[@" CFBundleIdentifier" ] hasPrefix: @" com.apple." ] && [NSFileManager .defaultManager fileExistsAtPath: bundlePath]) {
672- continue ;
673- }
674-
675- NSString * log=nil ;
676- NSString * err=nil ;
677- int status = spawnBootstrap ((char *[]){" /usr/bin/uicache" ," -u" ,bundlePath.fileSystemRepresentation ,NULL }, &log, &err);
678- if (status != 0 ) {
679- [AppDelegate dismissHud ];
680-
681- NSString * msg = [NSString stringWithFormat: @" code(%d )\n %@ \n\n stderr:\n %@ " ,status,log,err];
682- UIAlertController *alert = [UIAlertController alertControllerWithTitle: @" " message: msg preferredStyle: UIAlertControllerStyleAlert];
683- [alert addAction: [UIAlertAction actionWithTitle: Localized (@" OK" ) style: UIAlertActionStyleDefault handler: nil ]];
684- [AppDelegate showAlert: alert];
685-
686- return ;
687- }
688- }
689694
695+ if (![LSApplicationWorkspace.defaultWorkspace unregisterApplication: proxy.bundleURL]) {
690696 [AppDelegate dismissHud ];
691-
692- [[NSString stringWithFormat: @" %llX " ,jbrand ()] writeToFile: jbroot (@" /var/mobile/.allctbugappshidden" ) atomically: YES encoding: NSUTF8StringEncoding error: nil ];
693-
694- NSString * log=nil ;
695- NSString * err=nil ;
696- int status = spawnBootstrap ((char *[]){" /usr/bin/uicache" ," -u" ,rootfsPrefix (NSBundle .mainBundle .bundlePath ).fileSystemRepresentation ,NULL }, &log, &err);
697- if (status != 0 ) {
698- NSString * msg = [NSString stringWithFormat: @" code(%d )\n %@ \n\n stderr:\n %@ " ,status,log,err];
699- UIAlertController *alert = [UIAlertController alertControllerWithTitle: @" " message: msg preferredStyle: UIAlertControllerStyleAlert];
700- [alert addAction: [UIAlertAction actionWithTitle: Localized (@" OK" ) style: UIAlertActionStyleDefault handler: nil ]];
701- [AppDelegate showAlert: alert];
702- } else {
703- exit (0 );
704- }
705- });
706697
698+ NSString * msg = [NSString stringWithFormat: Localized (@" Failed to Hide %@ : %@ " ),proxy.bundleIdentifier,proxy.bundleURL.path];
699+ UIAlertController *alert = [UIAlertController alertControllerWithTitle: @" " message: msg preferredStyle: UIAlertControllerStyleAlert];
700+ [alert addAction: [UIAlertAction actionWithTitle: Localized (@" OK" ) style: UIAlertActionStyleDefault handler: nil ]];
701+ [AppDelegate showAlert: alert];
702+
703+ return ;
704+ }
705+ }
706+
707+ [[NSString stringWithFormat: @" %llX " ,jbrand ()] writeToFile: jbroot (@" /var/mobile/.allctbugappshidden" ) atomically: YES encoding: NSUTF8StringEncoding error: nil ];
708+
709+ sleep (1 );
710+
711+ NSString * log=nil ;
712+ NSString * err=nil ;
713+ int status = spawnRoot (NSBundle .mainBundle .executablePath , @[@" hidebootstrapapp" ,usreboot?@" usreboot" :@" " ], &log, &err);
714+ if (status != 0 ) {
715+ NSString * msg = [NSString stringWithFormat: @" code(%d )\n %@ \n\n stderr:\n %@ " ,status,log,err];
716+ UIAlertController *alert = [UIAlertController alertControllerWithTitle: @" " message: msg preferredStyle: UIAlertControllerStyleAlert];
717+ [alert addAction: [UIAlertAction actionWithTitle: Localized (@" OK" ) style: UIAlertActionStyleDefault handler: nil ]];
718+ [AppDelegate showAlert: alert];
719+
720+ return ;
721+ }
722+
723+ }
724+
725+ void hideAllCTBugApps ()
726+ {
727+ UIAlertController *alert = [UIAlertController alertControllerWithTitle: Localized (@" Warning" ) message: Localized (@" This operation will make all apps installed via TrollStore/Bootstrap disappear from the Home Screen. You can restore them later via TrollStore Helper->[Refresh App Registrations] and Bootstrap->Settings->[Unhide Jailbreak Apps]" ) preferredStyle: UIAlertControllerStyleAlert];
728+ [alert addAction: [UIAlertAction actionWithTitle: Localized (@" Cancel" ) style: UIAlertActionStyleCancel handler: nil ]];
729+ [alert addAction: [UIAlertAction actionWithTitle: Localized (@" Hide" ) style: UIAlertActionStyleDestructive handler: ^(UIAlertAction *action){
730+ dispatch_async (dispatch_get_global_queue (0 , 0 ), ^{
731+ hideAllCTBugAppsAction (NO );
732+ });
733+ }]];
734+ [alert addAction: [UIAlertAction actionWithTitle: Localized (@" Hide & Reboot Userspace" ) style: UIAlertActionStyleDestructive handler: ^(UIAlertAction *action){
735+ dispatch_async (dispatch_get_global_queue (0 , 0 ), ^{
736+ hideAllCTBugAppsAction (YES );
737+ });
707738 }]];
708739 [AppDelegate showAlert: alert];
709740}
@@ -725,6 +756,8 @@ void unhideAllCTBugApps()
725756 [AppDelegate showAlert: alert];
726757
727758 [NSFileManager .defaultManager removeItemAtPath: jbroot (@" /var/mobile/.allctbugappshidden" ) error: nil ];
759+
760+ [NSNotificationCenter .defaultCenter postNotificationName: @" unhideAllCTBugAppsNotification" object: nil ];
728761 });
729762}
730763
0 commit comments