This commit is contained in:
opa334 2022-12-01 00:37:01 +01:00
parent d432d3812a
commit 030ab8fd58
7 changed files with 97 additions and 20 deletions

View File

@ -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);

View File

@ -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

View File

@ -54,14 +54,21 @@ NSString* rootHelperPath(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;
}
@ -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*));
@ -132,6 +139,41 @@ 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) {
@ -139,22 +181,34 @@ int spawnRoot(NSString* path, NSArray* args, NSString** stdOut, NSString** stdEr
} else
{
perror("waitpid");
_isRunning = NO;
return -222;
}
} while (!WIFEXITED(status) && !WIFSIGNALED(status));
_isRunning = NO;
if(stdOut || stdErr)
{
if(stdOut)
{
close(out[1]);
NSString* output = getNSStringFromFile(out[0]);
*stdOut = output;
}
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);

View File

@ -362,7 +362,6 @@ extern UIImage* imageWithSize(UIImage* image, CGSize size);
{
[self closeArchive];
}
NSLog(@"open");
_archive = archive_read_new();
archive_read_support_format_all(_archive);
archive_read_support_filter_all(_archive);

View File

@ -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;

View File

@ -79,10 +79,16 @@ UIImage* imageWithSize(UIImage* image, CGSize size)
[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];
@ -467,4 +473,14 @@ UIImage* imageWithSize(UIImage* image, CGSize size)
[TSPresentationDelegate presentViewController:appSelectAlert animated:YES completion:nil];
}
- (void)applicationsDidInstall:(id)arg1
{
[self reloadTable];
}
- (void)applicationsDidUninstall:(id)arg1
{
[self reloadTable];
}
@end

View File

@ -17,8 +17,8 @@ extern NSUserDefaults* trollStoreUserDefaults(void);
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)
@ -54,12 +54,12 @@ extern NSUserDefaults* trollStoreUserDefaults(void);
}
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];
@ -187,6 +187,4 @@ extern NSUserDefaults* trollStoreUserDefaults(void);
});
}
//+ (void)showInstallAppAlertForFile:(NSString*)pathToIPA
@end