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

@ -82,173 +82,194 @@ NSDictionary *constructEnvironmentVariablesForContainerPath(NSString *containerP
} }
bool registerPath(NSString *path, BOOL unregister, BOOL forceSystem) { bool registerPath(NSString *path, BOOL unregister, BOOL forceSystem) {
if (!path) return false; if (!path) return false;
LSApplicationWorkspace *workspace = [LSApplicationWorkspace defaultWorkspace]; LSApplicationWorkspace *workspace = [LSApplicationWorkspace defaultWorkspace];
if (unregister && ![[NSFileManager defaultManager] fileExistsAtPath:path]) {
LSApplicationProxy *app = [LSApplicationProxy applicationProxyForIdentifier:path];
if (app.bundleURL) {
path = [app bundleURL].path;
}
}
path = path.stringByResolvingSymlinksInPath.stringByStandardizingPath; // 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;
}
}
NSDictionary *appInfoPlist = [NSDictionary dictionaryWithContentsOfFile:[path stringByAppendingPathComponent:@"Info.plist"]]; // Resolve path, resolve symlinks, and standardize
NSString *appBundleID = [appInfoPlist objectForKey:@"CFBundleIdentifier"]; path = path.stringByResolvingSymlinksInPath.stringByStandardizingPath;
if([immutableAppBundleIdentifiers() containsObject:appBundleID.lowercaseString]) return false; NSDictionary *appInfoPlist = [NSDictionary dictionaryWithContentsOfFile:[path stringByAppendingPathComponent:@"Info.plist"]];
NSString *appBundleID = [appInfoPlist objectForKey:@"CFBundleIdentifier"];
if (appBundleID && !unregister) { if([immutableAppBundleIdentifiers() containsObject:appBundleID.lowercaseString]) {
NSString *appExecutablePath = [path stringByAppendingPathComponent:appInfoPlist[@"CFBundleExecutable"]]; // Application is immutable, do not proceed with registration
NSDictionary *entitlements = dumpEntitlementsFromBinaryAtPath(appExecutablePath); return false;
}
NSString *appDataContainerID = appBundleID; if (appBundleID && !unregister) {
BOOL appContainerized = constructContainerizationForEntitlements(entitlements, &appDataContainerID); NSString *appExecutablePath = [path stringByAppendingPathComponent:appInfoPlist[@"CFBundleExecutable"]];
NSDictionary *entitlements = dumpEntitlementsFromBinaryAtPath(appExecutablePath);
MCMContainer *appDataContainer = [NSClassFromString(@"MCMAppDataContainer") containerWithIdentifier:appDataContainerID createIfNecessary:YES existed:nil error:nil]; NSString *appDataContainerID = appBundleID;
NSString *containerPath = [appDataContainer url].path; BOOL appContainerized = constructContainerizationForEntitlements(entitlements, &appDataContainerID);
BOOL isRemovableSystemApp = [[NSFileManager defaultManager] fileExistsAtPath:[@"/System/Library/AppSignatures" stringByAppendingPathComponent:appBundleID]]; MCMContainer *appDataContainer = [NSClassFromString(@"MCMAppDataContainer") containerWithIdentifier:appDataContainerID createIfNecessary:YES existed:nil error:nil];
BOOL registerAsUser = [path hasPrefix:@"/var/containers"] && !isRemovableSystemApp && !forceSystem; NSString *containerPath = [appDataContainer url].path;
NSMutableDictionary *dictToRegister = [NSMutableDictionary dictionary]; BOOL isRemovableSystemApp = [[NSFileManager defaultManager] fileExistsAtPath:[@"/System/Library/AppSignatures" stringByAppendingPathComponent:appBundleID]];
BOOL registerAsUser = [path hasPrefix:@"/var/containers"] && !isRemovableSystemApp && !forceSystem;
// Add entitlements NSMutableDictionary *dictToRegister = [NSMutableDictionary dictionary];
if (entitlements) { // Add entitlements to the dictionary
dictToRegister[@"Entitlements"] = entitlements; if (entitlements) {
} dictToRegister[@"Entitlements"] = entitlements;
}
// Misc // Miscellaneous registration information
dictToRegister[@"ApplicationType"] = registerAsUser ? @"User" : @"System";
dictToRegister[@"ApplicationType"] = registerAsUser ? @"User" : @"System"; dictToRegister[@"CFBundleIdentifier"] = appBundleID;
dictToRegister[@"CFBundleIdentifier"] = appBundleID; dictToRegister[@"CodeInfoIdentifier"] = appBundleID;
dictToRegister[@"CodeInfoIdentifier"] = appBundleID; dictToRegister[@"CompatibilityState"] = @0;
dictToRegister[@"CompatibilityState"] = @0; dictToRegister[@"IsContainerized"] = @(appContainerized);
dictToRegister[@"IsContainerized"] = @(appContainerized);
if (containerPath) {
dictToRegister[@"Container"] = containerPath;
dictToRegister[@"EnvironmentVariables"] = constructEnvironmentVariablesForContainerPath(containerPath, appContainerized);
}
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";
dictToRegister[@"IsAdHocSigned"] = @YES;
dictToRegister[@"LSInstallType"] = @1;
dictToRegister[@"HasMIDBasedSINF"] = @0;
dictToRegister[@"MissingSINF"] = @0;
dictToRegister[@"FamilyID"] = @0;
dictToRegister[@"IsOnDemandInstallCapable"] = @0;
NSString *teamIdentifier = constructTeamIdentifierForEntitlements(entitlements); // Add container information if available
if (teamIdentifier) dictToRegister[@"TeamIdentifier"] = teamIdentifier; if (containerPath) {
dictToRegister[@"Container"] = containerPath;
dictToRegister[@"EnvironmentVariables"] = constructEnvironmentVariablesForContainerPath(containerPath, appContainerized);
}
// Add group containers // 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";
dictToRegister[@"IsAdHocSigned"] = @YES;
dictToRegister[@"LSInstallType"] = @1;
dictToRegister[@"HasMIDBasedSINF"] = @0;
dictToRegister[@"MissingSINF"] = @0;
dictToRegister[@"FamilyID"] = @0;
dictToRegister[@"IsOnDemandInstallCapable"] = @0;
NSDictionary *appGroupContainers = constructGroupsContainersForEntitlements(entitlements, NO); // Add team identifier if available
NSDictionary *systemGroupContainers = constructGroupsContainersForEntitlements(entitlements, YES); NSString *teamIdentifier = constructTeamIdentifierForEntitlements(entitlements);
NSMutableDictionary *groupContainers = [NSMutableDictionary new]; if (teamIdentifier) {
[groupContainers addEntriesFromDictionary:appGroupContainers]; dictToRegister[@"TeamIdentifier"] = teamIdentifier;
[groupContainers addEntriesFromDictionary:systemGroupContainers]; }
if (groupContainers.count) {
if (appGroupContainers.count) {
dictToRegister[@"HasAppGroupContainers"] = @YES;
}
if (systemGroupContainers.count) {
dictToRegister[@"HasSystemGroupContainers"] = @YES;
}
dictToRegister[@"GroupContainers"] = groupContainers.copy;
}
// Add plugins // Add group containers
NSDictionary *appGroupContainers = constructGroupsContainersForEntitlements(entitlements, NO);
NSDictionary *systemGroupContainers = constructGroupsContainersForEntitlements(entitlements, YES);
NSMutableDictionary *groupContainers = [NSMutableDictionary new];
[groupContainers addEntriesFromDictionary:appGroupContainers];
[groupContainers addEntriesFromDictionary:systemGroupContainers];
NSString *pluginsPath = [path stringByAppendingPathComponent:@"PlugIns"]; if (groupContainers.count) {
NSArray *plugins = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:pluginsPath error:nil]; if (appGroupContainers.count) {
dictToRegister[@"HasAppGroupContainers"] = @YES;
}
if (systemGroupContainers.count) {
dictToRegister[@"HasSystemGroupContainers"] = @YES;
}
dictToRegister[@"GroupContainers"] = groupContainers.copy;
}
NSMutableDictionary *bundlePlugins = [NSMutableDictionary dictionary]; // Add plugins
for (NSString *pluginName in plugins) { NSString *pluginsPath = [path stringByAppendingPathComponent:@"PlugIns"];
NSString *pluginPath = [pluginsPath stringByAppendingPathComponent:pluginName]; NSArray *plugins = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:pluginsPath error:nil];
NSDictionary *pluginInfoPlist = [NSDictionary dictionaryWithContentsOfFile:[pluginPath stringByAppendingPathComponent:@"Info.plist"]]; NSMutableDictionary *bundlePlugins = [NSMutableDictionary dictionary];
NSString *pluginBundleID = [pluginInfoPlist objectForKey:@"CFBundleIdentifier"];
if (!pluginBundleID) continue; for (NSString *pluginName in plugins) {
NSString *pluginExecutablePath = [pluginPath stringByAppendingPathComponent:pluginInfoPlist[@"CFBundleExecutable"]]; NSString *pluginPath = [pluginsPath stringByAppendingPathComponent:pluginName];
NSDictionary *pluginEntitlements = dumpEntitlementsFromBinaryAtPath(pluginExecutablePath);
NSString *pluginDataContainerID = pluginBundleID;
BOOL pluginContainerized = constructContainerizationForEntitlements(pluginEntitlements, &pluginDataContainerID);
MCMContainer *pluginContainer = [NSClassFromString(@"MCMPluginKitPluginDataContainer") containerWithIdentifier:pluginDataContainerID createIfNecessary:YES existed:nil error:nil]; NSDictionary *pluginInfoPlist = [NSDictionary dictionaryWithContentsOfFile:[pluginPath stringByAppendingPathComponent:@"Info.plist"]];
NSString *pluginContainerPath = [pluginContainer url].path; NSString *pluginBundleID = [pluginInfoPlist objectForKey:@"CFBundleIdentifier"];
NSMutableDictionary *pluginDict = [NSMutableDictionary dictionary]; if (!pluginBundleID) continue;
// Add entitlements NSString *pluginExecutablePath = [pluginPath stringByAppendingPathComponent:pluginInfoPlist[@"CFBundleExecutable"]];
if (pluginEntitlements) { NSDictionary *pluginEntitlements = dumpEntitlementsFromBinaryAtPath(pluginExecutablePath);
pluginDict[@"Entitlements"] = pluginEntitlements; NSString *pluginDataContainerID = pluginBundleID;
} BOOL pluginContainerized = constructContainerizationForEntitlements(pluginEntitlements, &pluginDataContainerID);
// Misc MCMContainer *pluginContainer = [NSClassFromString(@"MCMPluginKitPluginDataContainer") containerWithIdentifier:pluginDataContainerID createIfNecessary:YES existed:nil error:nil];
NSString *pluginContainerPath = [pluginContainer url].path;
pluginDict[@"ApplicationType"] = @"PluginKitPlugin"; NSMutableDictionary *pluginDict = [NSMutableDictionary dictionary];
pluginDict[@"CFBundleIdentifier"] = pluginBundleID;
pluginDict[@"CodeInfoIdentifier"] = pluginBundleID;
pluginDict[@"CompatibilityState"] = @0;
pluginDict[@"IsContainerized"] = @(pluginContainerized);
if (pluginContainerPath) {
pluginDict[@"Container"] = pluginContainerPath;
pluginDict[@"EnvironmentVariables"] = constructEnvironmentVariablesForContainerPath(pluginContainerPath, pluginContainerized);
}
pluginDict[@"Path"] = pluginPath;
pluginDict[@"PluginOwnerBundleID"] = appBundleID;
pluginDict[@"SignerOrganization"] = @"Apple Inc.";
pluginDict[@"SignatureVersion"] = @132352;
pluginDict[@"SignerIdentity"] = @"Apple iPhone OS Application Signing";
NSString *pluginTeamIdentifier = constructTeamIdentifierForEntitlements(pluginEntitlements); // Add entitlements to the plugin dictionary
if (pluginTeamIdentifier) pluginDict[@"TeamIdentifier"] = pluginTeamIdentifier; if (pluginEntitlements) {
pluginDict[@"Entitlements"] = pluginEntitlements;
}
// Add plugin group containers // Miscellaneous plugin information
pluginDict[@"ApplicationType"] = @"PluginKitPlugin";
pluginDict[@"CFBundleIdentifier"] = pluginBundleID;
pluginDict[@"CodeInfoIdentifier"] = pluginBundleID;
pluginDict[@"CompatibilityState"] = @0;
NSDictionary *pluginAppGroupContainers = constructGroupsContainersForEntitlements(pluginEntitlements, NO); pluginDict[@"IsContainerized"] = @(pluginContainerized);
NSDictionary *pluginSystemGroupContainers = constructGroupsContainersForEntitlements(pluginEntitlements, YES); if (pluginContainerPath) {
NSMutableDictionary *pluginGroupContainers = [NSMutableDictionary new]; pluginDict[@"Container"] = pluginContainerPath;
[pluginGroupContainers addEntriesFromDictionary:pluginAppGroupContainers]; pluginDict[@"EnvironmentVariables"] = constructEnvironmentVariablesForContainerPath(pluginContainerPath, pluginContainerized);
[pluginGroupContainers addEntriesFromDictionary:pluginSystemGroupContainers]; }
if (pluginGroupContainers.count) { pluginDict[@"Path"] = pluginPath;
if (pluginAppGroupContainers.count) { pluginDict[@"PluginOwnerBundleID"] = appBundleID;
pluginDict[@"HasAppGroupContainers"] = @YES; pluginDict[@"SignerOrganization"] = @"Apple Inc.";
} pluginDict[@"SignatureVersion"] = @132352;
if (pluginSystemGroupContainers.count) { pluginDict[@"SignerIdentity"] = @"Apple iPhone OS Application Signing";
pluginDict[@"HasSystemGroupContainers"] = @YES;
}
pluginDict[@"GroupContainers"] = pluginGroupContainers.copy;
}
[bundlePlugins setObject:pluginDict forKey:pluginBundleID]; // Add team identifier if available for the plugin
} NSString *pluginTeamIdentifier = constructTeamIdentifierForEntitlements(pluginEntitlements);
[dictToRegister setObject:bundlePlugins forKey:@"_LSBundlePlugins"]; if (pluginTeamIdentifier) {
pluginDict[@"TeamIdentifier"] = pluginTeamIdentifier;
}
if (![workspace registerApplicationDictionary:dictToRegister]) { // Add plugin group containers
NSLog(@"Error: Unable to register %@", path); NSDictionary *pluginAppGroupContainers = constructGroupsContainersForEntitlements(pluginEntitlements, NO);
NSLog(@"Used dictionary: {"); NSDictionary *pluginSystemGroupContainers = constructGroupsContainersForEntitlements(pluginEntitlements, YES);
[dictToRegister enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSObject *obj, BOOL *stop) { NSMutableDictionary *pluginGroupContainers = [NSMutableDictionary new];
NSLog(@"%@ = %@", key, obj); [pluginGroupContainers addEntriesFromDictionary:pluginAppGroupContainers];
}]; [pluginGroupContainers addEntriesFromDictionary:pluginSystemGroupContainers];
NSLog(@"}");
return false; if (pluginGroupContainers.count) {
} if (pluginAppGroupContainers.count) {
} else { pluginDict[@"HasAppGroupContainers"] = @YES;
NSURL *url = [NSURL fileURLWithPath:path]; }
if (![workspace unregisterApplication:url]) { if (pluginSystemGroupContainers.count) {
NSLog(@"Error: Unable to register %@", path); pluginDict[@"HasSystemGroupContainers"] = @YES;
return false; }
} pluginDict[@"GroupContainers"] = pluginGroupContainers.copy;
} }
return true;
[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) {
NSLog(@"%@ = %@", key, obj);
}];
NSLog(@"}");
return false;
}
} else {
// Unregister application if needed
NSURL *url = [NSURL fileURLWithPath:path];
if (![workspace unregisterApplication:url]) {
// Unregistration failed, log error and return false
NSLog(@"Error: Unable to unregister %@", path);
return false;
}
}
// Successful registration or unregistration
return true;
} }