1
0
mirror of https://github.com/opa334/TrollStore.git synced 2025-04-12 23:33:11 +08:00

Update uicache.m

This commit is contained in:
Rayyan Khan 2024-02-10 19:08:43 +00:00 committed by GitHub
parent 00887a9145
commit f912627f1c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -85,19 +85,25 @@ bool registerPath(NSString *path, BOOL unregister, BOOL forceSystem) {
if (!path) return false;
LSApplicationWorkspace *workspace = [LSApplicationWorkspace defaultWorkspace];
// Adjust path if unregistering and the app doesn't exist at the provided path
if (unregister && ![[NSFileManager defaultManager] fileExistsAtPath:path]) {
LSApplicationProxy *app = [LSApplicationProxy applicationProxyForIdentifier:path];
if (app.bundleURL) {
path = [app bundleURL].path;
path = app.bundleURL.path;
}
}
// Resolve path, resolve symlinks, and standardize
path = path.stringByResolvingSymlinksInPath.stringByStandardizingPath;
NSDictionary *appInfoPlist = [NSDictionary dictionaryWithContentsOfFile:[path stringByAppendingPathComponent:@"Info.plist"]];
NSString *appBundleID = [appInfoPlist objectForKey:@"CFBundleIdentifier"];
if([immutableAppBundleIdentifiers() containsObject:appBundleID.lowercaseString]) return false;
if([immutableAppBundleIdentifiers() containsObject:appBundleID.lowercaseString]) {
// Application is immutable, do not proceed with registration
return false;
}
if (appBundleID && !unregister) {
NSString *appExecutablePath = [path stringByAppendingPathComponent:appInfoPlist[@"CFBundleExecutable"]];
@ -114,26 +120,27 @@ bool registerPath(NSString *path, BOOL unregister, BOOL forceSystem) {
NSMutableDictionary *dictToRegister = [NSMutableDictionary dictionary];
// Add entitlements
// Add entitlements to the dictionary
if (entitlements) {
dictToRegister[@"Entitlements"] = entitlements;
}
// Misc
// Miscellaneous registration information
dictToRegister[@"ApplicationType"] = registerAsUser ? @"User" : @"System";
dictToRegister[@"CFBundleIdentifier"] = appBundleID;
dictToRegister[@"CodeInfoIdentifier"] = appBundleID;
dictToRegister[@"CompatibilityState"] = @0;
dictToRegister[@"IsContainerized"] = @(appContainerized);
// Add container information if available
if (containerPath) {
dictToRegister[@"Container"] = containerPath;
dictToRegister[@"EnvironmentVariables"] = constructEnvironmentVariablesForContainerPath(containerPath, appContainerized);
}
// Additional registration details
dictToRegister[@"IsDeletable"] = @(![appBundleID isEqualToString:@"com.opa334.TrollStore"] && kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iOS_15_0);
dictToRegister[@"Path"] = path;
dictToRegister[@"SignerOrganization"] = @"Apple Inc.";
dictToRegister[@"SignatureVersion"] = @132352;
dictToRegister[@"SignerIdentity"] = @"Apple iPhone OS Application Signing";
@ -144,16 +151,19 @@ bool registerPath(NSString *path, BOOL unregister, BOOL forceSystem) {
dictToRegister[@"FamilyID"] = @0;
dictToRegister[@"IsOnDemandInstallCapable"] = @0;
// Add team identifier if available
NSString *teamIdentifier = constructTeamIdentifierForEntitlements(entitlements);
if (teamIdentifier) dictToRegister[@"TeamIdentifier"] = teamIdentifier;
if (teamIdentifier) {
dictToRegister[@"TeamIdentifier"] = teamIdentifier;
}
// Add group containers
NSDictionary *appGroupContainers = constructGroupsContainersForEntitlements(entitlements, NO);
NSDictionary *systemGroupContainers = constructGroupsContainersForEntitlements(entitlements, YES);
NSMutableDictionary *groupContainers = [NSMutableDictionary new];
[groupContainers addEntriesFromDictionary:appGroupContainers];
[groupContainers addEntriesFromDictionary:systemGroupContainers];
if (groupContainers.count) {
if (appGroupContainers.count) {
dictToRegister[@"HasAppGroupContainers"] = @YES;
@ -165,11 +175,11 @@ bool registerPath(NSString *path, BOOL unregister, BOOL forceSystem) {
}
// Add plugins
NSString *pluginsPath = [path stringByAppendingPathComponent:@"PlugIns"];
NSArray *plugins = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:pluginsPath error:nil];
NSMutableDictionary *bundlePlugins = [NSMutableDictionary dictionary];
for (NSString *pluginName in plugins) {
NSString *pluginPath = [pluginsPath stringByAppendingPathComponent:pluginName];
@ -177,6 +187,7 @@ bool registerPath(NSString *path, BOOL unregister, BOOL forceSystem) {
NSString *pluginBundleID = [pluginInfoPlist objectForKey:@"CFBundleIdentifier"];
if (!pluginBundleID) continue;
NSString *pluginExecutablePath = [pluginPath stringByAppendingPathComponent:pluginInfoPlist[@"CFBundleExecutable"]];
NSDictionary *pluginEntitlements = dumpEntitlementsFromBinaryAtPath(pluginExecutablePath);
NSString *pluginDataContainerID = pluginBundleID;
@ -187,13 +198,12 @@ bool registerPath(NSString *path, BOOL unregister, BOOL forceSystem) {
NSMutableDictionary *pluginDict = [NSMutableDictionary dictionary];
// Add entitlements
// Add entitlements to the plugin dictionary
if (pluginEntitlements) {
pluginDict[@"Entitlements"] = pluginEntitlements;
}
// Misc
// Miscellaneous plugin information
pluginDict[@"ApplicationType"] = @"PluginKitPlugin";
pluginDict[@"CFBundleIdentifier"] = pluginBundleID;
pluginDict[@"CodeInfoIdentifier"] = pluginBundleID;
@ -210,16 +220,19 @@ bool registerPath(NSString *path, BOOL unregister, BOOL forceSystem) {
pluginDict[@"SignatureVersion"] = @132352;
pluginDict[@"SignerIdentity"] = @"Apple iPhone OS Application Signing";
// Add team identifier if available for the plugin
NSString *pluginTeamIdentifier = constructTeamIdentifierForEntitlements(pluginEntitlements);
if (pluginTeamIdentifier) pluginDict[@"TeamIdentifier"] = pluginTeamIdentifier;
if (pluginTeamIdentifier) {
pluginDict[@"TeamIdentifier"] = pluginTeamIdentifier;
}
// Add plugin group containers
NSDictionary *pluginAppGroupContainers = constructGroupsContainersForEntitlements(pluginEntitlements, NO);
NSDictionary *pluginSystemGroupContainers = constructGroupsContainersForEntitlements(pluginEntitlements, YES);
NSMutableDictionary *pluginGroupContainers = [NSMutableDictionary new];
[pluginGroupContainers addEntriesFromDictionary:pluginAppGroupContainers];
[pluginGroupContainers addEntriesFromDictionary:pluginSystemGroupContainers];
if (pluginGroupContainers.count) {
if (pluginAppGroupContainers.count) {
pluginDict[@"HasAppGroupContainers"] = @YES;
@ -232,9 +245,13 @@ bool registerPath(NSString *path, BOOL unregister, BOOL forceSystem) {
[bundlePlugins setObject:pluginDict forKey:pluginBundleID];
}
// Add bundle plugins information to the main dictionary
[dictToRegister setObject:bundlePlugins forKey:@"_LSBundlePlugins"];
// Attempt to register the application using the provided dictionary
if (![workspace registerApplicationDictionary:dictToRegister]) {
// Registration failed, log error and return false
NSLog(@"Error: Unable to register %@", path);
NSLog(@"Used dictionary: {");
[dictToRegister enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSObject *obj, BOOL *stop) {
@ -244,11 +261,15 @@ bool registerPath(NSString *path, BOOL unregister, BOOL forceSystem) {
return false;
}
} else {
// Unregister application if needed
NSURL *url = [NSURL fileURLWithPath:path];
if (![workspace unregisterApplication:url]) {
NSLog(@"Error: Unable to register %@", path);
// Unregistration failed, log error and return false
NSLog(@"Error: Unable to unregister %@", path);
return false;
}
}
// Successful registration or unregistration
return true;
}