Skip to content

Commit

Permalink
1.4.5b2
Browse files Browse the repository at this point in the history
  • Loading branch information
opa334 committed Nov 30, 2022
1 parent d432d38 commit 030ab8f
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 20 deletions.
1 change: 1 addition & 0 deletions RootHelper/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -1163,6 +1163,7 @@ int MAIN_NAME(int argc, char *argv[], char *envp[])
{
cleanRestrictions();
refreshAppRegistrations(NO); // <- fix app permissions resetting
sleep(5); // <- fix app permission fix causing apps to move on home screen (?)
[[LSApplicationWorkspace defaultWorkspace] _LSPrivateRebuildApplicationDatabasesForSystemApps:YES internal:YES user:YES];
refreshAppRegistrations(YES);
killall(@"backboardd", YES);
Expand Down
8 changes: 8 additions & 0 deletions Shared/CoreServices.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ extern NSString *LSInstallTypeKey;
- (void)enumerateApplicationsOfType:(NSUInteger)type block:(void (^)(LSApplicationProxy*))block;
- (BOOL)installApplication:(NSURL*)appPackageURL withOptions:(NSDictionary*)options error:(NSError**)error;
- (BOOL)uninstallApplication:(NSString*)appId withOptions:(NSDictionary*)options;
- (void)addObserver:(id)arg1;
- (void)removeObserver:(id)arg1;
@end

@protocol LSApplicationWorkspaceObserverProtocol <NSObject>
@optional
-(void)applicationsDidInstall:(id)arg1;
-(void)applicationsDidUninstall:(id)arg1;
@end

@interface LSEnumerator : NSEnumerator
Expand Down
78 changes: 66 additions & 12 deletions Shared/TSUtil.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,21 @@ void loadMCMFramework(void)
}
#endif

int fd_is_valid(int fd)
{
return fcntl(fd, F_GETFD) != -1 || errno != EBADF;
}

NSString* getNSStringFromFile(int fd)
{
NSMutableString* ms = [NSMutableString new];
ssize_t num_read;
char c;
if(!fd_is_valid(fd)) return @"";
while((num_read = read(fd, &c, sizeof(c))))
{
[ms appendString:[NSString stringWithFormat:@"%c", c]];
if(c == '\n') break;
}
return ms.copy;
}
Expand All @@ -79,7 +86,7 @@ void printMultilineNSString(NSString* stringToPrint)
int spawnRoot(NSString* path, NSArray* args, NSString** stdOut, NSString** stdErr)
{
NSMutableArray* argsM = args.mutableCopy ?: [NSMutableArray new];
[argsM insertObject:path.lastPathComponent atIndex:0];
[argsM insertObject:path atIndex:0];

NSUInteger argCount = [argsM count];
char **argsC = (char **)malloc((argCount + 1) * sizeof(char*));
Expand Down Expand Up @@ -132,31 +139,78 @@ int spawnRoot(NSString* path, NSArray* args, NSString** stdOut, NSString** stdEr
return spawnError;
}

__block volatile BOOL _isRunning = YES;
NSMutableString* outString = [NSMutableString new];
NSMutableString* errString = [NSMutableString new];
dispatch_semaphore_t sema = 0;
dispatch_queue_t logQueue;
if(stdOut || stdErr)
{
logQueue = dispatch_queue_create("com.opa334.TrollStore.LogCollector", NULL);
sema = dispatch_semaphore_create(0);

int outPipe = out[0];
int outErrPipe = outErr[0];

__block BOOL outEnabled = (BOOL)stdOut;
__block BOOL errEnabled = (BOOL)stdErr;
dispatch_async(logQueue, ^
{
while(_isRunning)
{
@autoreleasepool
{
if(outEnabled)
{
[outString appendString:getNSStringFromFile(outPipe)];
}
if(errEnabled)
{
[errString appendString:getNSStringFromFile(outErrPipe)];
}
}
}
dispatch_semaphore_signal(sema);
});
}

do
{
if (waitpid(task_pid, &status, 0) != -1) {
NSLog(@"Child status %d", WEXITSTATUS(status));
} else
{
perror("waitpid");
_isRunning = NO;
return -222;
}
} while (!WIFEXITED(status) && !WIFSIGNALED(status));

if(stdOut)
_isRunning = NO;
if(stdOut || stdErr)
{
close(out[1]);
NSString* output = getNSStringFromFile(out[0]);
*stdOut = output;
}
if(stdOut)
{
close(out[1]);
}
if(stdErr)
{
close(outErr[1]);
}

if(stdErr)
{
close(outErr[1]);
NSString* errorOutput = getNSStringFromFile(outErr[0]);
*stdErr = errorOutput;
// wait for logging queue to finish
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);

if(stdOut)
{
*stdOut = outString.copy;
}
if(stdErr)
{
*stdErr = errString.copy;
}
}

return WEXITSTATUS(status);
}

Expand Down
1 change: 0 additions & 1 deletion TrollStore/TSAppInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,6 @@ - (int)openArchive
{
[self closeArchive];
}
NSLog(@"open");
_archive = archive_read_new();
archive_read_support_format_all(_archive);
archive_read_support_filter_all(_archive);
Expand Down
3 changes: 2 additions & 1 deletion TrollStore/TSAppTableViewController.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#import <UIKit/UIKit.h>
#import "TSAppInfo.h"
#import <CoreServices.h>

@interface TSAppTableViewController : UITableViewController <UISearchResultsUpdating, UIDocumentPickerDelegate>
@interface TSAppTableViewController : UITableViewController <UISearchResultsUpdating, UIDocumentPickerDelegate, LSApplicationWorkspaceObserverProtocol>
{
UIImage* _placeholderIcon;
NSArray<TSAppInfo*>* _cachedAppInfos;
Expand Down
16 changes: 16 additions & 0 deletions TrollStore/TSAppTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,16 @@ - (instancetype)init
[self loadAppInfos];
_placeholderIcon = [UIImage _applicationIconImageForBundleIdentifier:@"com.apple.WebSheet" format:iconFormatToUse() scale:[UIScreen mainScreen].scale];
_cachedIcons = [NSMutableDictionary new];
[[LSApplicationWorkspace defaultWorkspace] addObserver:self];
}
return self;
}

- (void)dealloc
{
[[LSApplicationWorkspace defaultWorkspace] removeObserver:self];
}

- (void)reloadTable
{
[self loadAppInfos];
Expand Down Expand Up @@ -467,4 +473,14 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
[TSPresentationDelegate presentViewController:appSelectAlert animated:YES completion:nil];
}

- (void)applicationsDidInstall:(id)arg1
{
[self reloadTable];
}

- (void)applicationsDidUninstall:(id)arg1
{
[self reloadTable];
}

@end
10 changes: 4 additions & 6 deletions TrollStore/TSInstallationController.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ + (void)handleAppInstallFromFile:(NSString*)pathToIPA forceInstall:(BOOL)force c
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^
{
// Install IPA
//NSString* log;
int ret = [[TSApplicationsManager sharedInstance] installIpa:pathToIPA force:force log:nil];
NSString* log;
int ret = [[TSApplicationsManager sharedInstance] installIpa:pathToIPA force:force log:&log];

NSError* error;
if(ret != 0)
Expand Down Expand Up @@ -54,12 +54,12 @@ + (void)handleAppInstallFromFile:(NSString*)pathToIPA forceInstall:(BOOL)force c
}
else
{
/*UIAlertAction* copyLogAction = [UIAlertAction actionWithTitle:@"Copy Log" style:UIAlertActionStyleDefault handler:^(UIAlertAction* action)
UIAlertAction* copyLogAction = [UIAlertAction actionWithTitle:@"Copy Debug Log" style:UIAlertActionStyleDefault handler:^(UIAlertAction* action)
{
UIPasteboard* pasteboard = [UIPasteboard generalPasteboard];
pasteboard.string = log;
}];
[errorAlert addAction:copyLogAction];*/
[errorAlert addAction:copyLogAction];
}

[TSPresentationDelegate presentViewController:errorAlert animated:YES completion:nil];
Expand Down Expand Up @@ -187,6 +187,4 @@ + (void)handleAppInstallFromRemoteURL:(NSURL*)remoteURL completion:(void (^)(BOO
});
}

//+ (void)showInstallAppAlertForFile:(NSString*)pathToIPA

@end

0 comments on commit 030ab8f

Please sign in to comment.