Skip to content

Commit

Permalink
1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
opa334 committed Sep 3, 2022
1 parent a8e7259 commit ee08cfe
Show file tree
Hide file tree
Showing 12 changed files with 179 additions and 74 deletions.
2 changes: 1 addition & 1 deletion Helper/control
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: com.opa334.trollstoreroothelper
Name: trollstoreroothelper
Version: 1.0
Version: 1.0.1
Architecture: iphoneos-arm
Description: An awesome tool of some sort!!
Maintainer: opa334
Expand Down
94 changes: 62 additions & 32 deletions Helper/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,13 @@ BOOL signApp(NSString* appPath, NSError** error)
return ldidRet == 0;
}

BOOL installApp(NSString* appPath, BOOL sign, NSError** error)
// 170: failed to create container for app bundle
// 171: a non trollstore app with the same identifier is already installled
// 172: no info.plist found in app
int installApp(NSString* appPath, BOOL sign, NSError** error)
{
NSString* appId = appIdForAppPath(appPath);
if(!appId) return NO;
if(!appId) return 172;

if(sign)
{
Expand All @@ -261,15 +264,27 @@ BOOL installApp(NSString* appPath, BOOL sign, NSError** error)
if(!appContainer || mcmError)
{
if(error) *error = mcmError;
return NO;
return 170;
}

// check if the bundle is empty
BOOL isEmpty = YES;
NSArray* bundleItems = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:appContainer.url.path error:error];
for(NSString* bundleItem in bundleItems)
{
if([bundleItem.pathExtension isEqualToString:@"app"])
{
isEmpty = NO;
break;
}
}

// Make sure there isn't already an app store app installed with the same identifier
NSURL* trollStoreMarkURL = [appContainer.url URLByAppendingPathComponent:@"_TrollStore"];
if(existed && ![trollStoreMarkURL checkResourceIsReachableAndReturnError:nil])
if(existed && !isEmpty && ![trollStoreMarkURL checkResourceIsReachableAndReturnError:nil])
{
NSLog(@"[installApp] already installed and not a TrollStore app... bailing out");
return NO;
return 171;
}

// Apply correct permissions
Expand Down Expand Up @@ -297,7 +312,7 @@ BOOL installApp(NSString* appPath, BOOL sign, NSError** error)

// chown 0 all root binaries
NSDictionary* mainInfoDictionary = [NSDictionary dictionaryWithContentsOfFile:[appPath stringByAppendingPathComponent:@"Info.plist"]];
if(!mainInfoDictionary) return NO;
if(!mainInfoDictionary) return 172;
NSObject* tsRootBinaries = mainInfoDictionary[@"TSRootBinaries"];
if([tsRootBinaries isKindOfClass:[NSArray class]])
{
Expand Down Expand Up @@ -349,18 +364,18 @@ BOOL installApp(NSString* appPath, BOOL sign, NSError** error)

NSLog(@"[installApp] app installed, adding to icon cache now...");
registerPath((char*)newAppPath.UTF8String, 0);
return YES;
return 0;
}
else
{
return suc;
return 1;
}
}

BOOL uninstallApp(NSString* appId, NSError** error)
int uninstallApp(NSString* appId, NSError** error)
{
NSString* appPath = appPathForAppId(appId, error);
if(!appPath) return NO;
if(!appPath) return 1;

LSApplicationProxy* appProxy = [LSApplicationProxy applicationProxyForIdentifier:appId];
NSLog(@"appProxy: %@", appProxy);
Expand Down Expand Up @@ -398,23 +413,36 @@ BOOL uninstallApp(NSString* appId, NSError** error)
NSLog(@"deleting %@", [appPath stringByDeletingLastPathComponent]);

// delete app
return [[NSFileManager defaultManager] removeItemAtPath:[appPath stringByDeletingLastPathComponent] error:error];
BOOL deleteSuc = [[NSFileManager defaultManager] removeItemAtPath:[appPath stringByDeletingLastPathComponent] error:error];
if(deleteSuc)
{
return 0;
}
else
{
return 1;
}
}

BOOL installIpa(NSString* ipaPath, NSError** error)
// 166: IPA does not exist or is not accessible
// 167: IPA does not appear to contain an app

int installIpa(NSString* ipaPath, NSError** error)
{
if(![[NSFileManager defaultManager] fileExistsAtPath:ipaPath]) return 166;

BOOL suc = NO;
NSString* tmpPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSUUID UUID].UUIDString];

suc = [[NSFileManager defaultManager] createDirectoryAtPath:tmpPath withIntermediateDirectories:NO attributes:nil error:error];
if(!suc) return NO;
if(!suc) return 1;

extract(ipaPath, tmpPath);

NSString* tmpPayloadPath = [tmpPath stringByAppendingPathComponent:@"Payload"];

NSArray* items = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:tmpPayloadPath error:error];
if(!items) return NO;
if(!items) return 167;

NSString* tmpAppPath;
for(NSString* item in items)
Expand All @@ -425,13 +453,13 @@ BOOL installIpa(NSString* ipaPath, NSError** error)
break;
}
}
if(!tmpAppPath) return NO;
if(!tmpAppPath) return 167;

suc = installApp(tmpAppPath, YES, error);
int ret = installApp(tmpAppPath, YES, error);

[[NSFileManager defaultManager] removeItemAtPath:tmpAppPath error:nil];

return suc;
return ret;
}

void uninstallAllApps(void)
Expand Down Expand Up @@ -470,17 +498,17 @@ BOOL installTrollStore(NSString* pathToTar)
/*}*/


if(![[NSFileManager defaultManager] fileExistsAtPath:pathToTar]) return NO;
if(![pathToTar.pathExtension isEqualToString:@"tar"]) return NO;
if(![[NSFileManager defaultManager] fileExistsAtPath:pathToTar]) return 1;
if(![pathToTar.pathExtension isEqualToString:@"tar"]) return 1;

NSString* tmpPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSUUID UUID].UUIDString];
BOOL suc = [[NSFileManager defaultManager] createDirectoryAtPath:tmpPath withIntermediateDirectories:NO attributes:nil error:nil];
if(!suc) return NO;
if(!suc) return 1;

extract(pathToTar, tmpPath);

NSString* tmpTrollStore = [tmpPath stringByAppendingPathComponent:@"TrollStore.app"];
if(![[NSFileManager defaultManager] fileExistsAtPath:tmpTrollStore]) return NO;
if(![[NSFileManager defaultManager] fileExistsAtPath:tmpTrollStore]) return 1;

// Save existing ldid installation if it exists
NSString* existingLdidPath = [trollStoreAppPath() stringByAppendingPathComponent:@"ldid"];
Expand Down Expand Up @@ -629,33 +657,33 @@ int main(int argc, char *argv[], char *envp[]) {
NSBundle* mcmBundle = [NSBundle bundleWithPath:@"/System/Library/PrivateFrameworks/MobileContainerManager.framework"];
[mcmBundle load];

BOOL suc = NO;
int ret = 0;
NSError* error;

NSString* cmd = [NSString stringWithUTF8String:argv[1]];
if([cmd isEqualToString:@"install"])
{
if(argc <= 2) return -2;
if(argc <= 2) return -3;
NSString* ipaPath = [NSString stringWithUTF8String:argv[2]];
suc = installIpa(ipaPath, &error);
ret = installIpa(ipaPath, &error);
} else if([cmd isEqualToString:@"uninstall"])
{
if(argc <= 2) return -2;
if(argc <= 2) return -3;
NSString* appId = [NSString stringWithUTF8String:argv[2]];
suc = uninstallApp(appId, &error);
ret = uninstallApp(appId, &error);
} else if([cmd isEqualToString:@"install-trollstore"])
{
if(argc <= 2) return -2;
if(argc <= 2) return -3;
NSString* tsTar = [NSString stringWithUTF8String:argv[2]];
suc = installTrollStore(tsTar);
NSLog(@"installed troll store? %d", suc);
ret = installTrollStore(tsTar);
NSLog(@"installed troll store? %d", ret==0);
} else if([cmd isEqualToString:@"uninstall-trollstore"])
{
uninstallAllApps();
uninstallTrollStore(YES);
} else if([cmd isEqualToString:@"install-ldid"])
{
if(argc <= 2) return -2;
if(argc <= 2) return -3;
NSString* ldidPath = [NSString stringWithUTF8String:argv[2]];
installLdid(ldidPath);
} else if([cmd isEqualToString:@"refresh"])
Expand All @@ -667,7 +695,7 @@ int main(int argc, char *argv[], char *envp[]) {
refreshAppRegistrations();
} else if([cmd isEqualToString:@"install-persistence-helper"])
{
if(argc <= 2) return -2;
if(argc <= 2) return -3;
NSString* systemAppId = [NSString stringWithUTF8String:argv[2]];
installPersistenceHelper(systemAppId);
} else if([cmd isEqualToString:@"uninstall-persistence-helper"])
Expand All @@ -680,6 +708,8 @@ int main(int argc, char *argv[], char *envp[]) {
NSLog(@"error: %@", error);
}

return !suc;
NSLog(@"returning %d", ret);

return ret;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ Installer</string>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Support iOS 15.0 - 15.1.1" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="s80-eR-fY3">
<rect key="frame" x="114.5" y="249" width="185" height="21"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Supports iOS 15.0 - 15.1.1" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="s80-eR-fY3">
<rect key="frame" x="110.5" y="249" width="193" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
Expand Down
Binary file added PersistenceHelper/Resources/trollstorehelper
Binary file not shown.
4 changes: 2 additions & 2 deletions Store/Resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<string>iPhoneOS</string>
</array>
<key>CFBundleVersion</key>
<string>1.0</string>
<string>1.0.1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIDeviceFamily</key>
Expand Down Expand Up @@ -215,7 +215,7 @@
</dict>
</array>
<key>LSSupportsOpeningDocumentsInPlace</key>
<true/>
<false/>
<key>TSRootBinaries</key>
<array>
<string>trollstorehelper</string>
Expand Down
7 changes: 5 additions & 2 deletions Store/TSAppTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ @implementation TSAppTableViewController

- (void)reloadTable
{
[self.tableView reloadData];
dispatch_async(dispatch_get_main_queue(), ^
{
[self.tableView reloadData];
});
}

- (void)loadView
Expand Down Expand Up @@ -52,7 +55,7 @@ - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEd
{
NSString* appPath = [[TSApplicationsManager sharedInstance] installedAppPaths][indexPath.row];
NSString* appId = [[TSApplicationsManager sharedInstance] appIdForAppPath:appPath];
[[TSApplicationsManager sharedInstance] uninstallApp:appId error:nil];
[[TSApplicationsManager sharedInstance] uninstallApp:appId];
}
}

Expand Down
5 changes: 3 additions & 2 deletions Store/TSApplicationsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
- (NSString*)appIdForAppPath:(NSString*)appPath;
- (NSString*)displayNameForAppPath:(NSString*)appPath;

- (int)installIpa:(NSString*)pathToIpa error:(NSError**)error;
- (int)uninstallApp:(NSString*)appId error:(NSError**)error;
- (NSError*)errorForCode:(int)code;
- (int)installIpa:(NSString*)pathToIpa;
- (int)uninstallApp:(NSString*)appId;

@end
36 changes: 32 additions & 4 deletions Store/TSApplicationsManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#import "TSUtil.h"
#import "../Helper/Shared.h"

#define TrollStoreErrorDomain @"TrollStoreErrorDomain"

@implementation TSApplicationsManager

+ (instancetype)sharedInstance
Expand Down Expand Up @@ -50,16 +52,42 @@ - (NSString*)displayNameForAppPath:(NSString*)appPath
return displayName;
}

- (int)installIpa:(NSString*)pathToIpa error:(NSError**)error
- (NSError*)errorForCode:(int)code
{
NSString* errorDescription = @"Unknown Error";
switch(code)
{
case 166:
errorDescription = @"The IPA file does not exist or is not accessible.";
break;
case 167:
errorDescription = @"The IPA file does not appear to contain an app.";
break;
case 170:
errorDescription = @"Failed to create container for app bundle.";
break;
case 171:
errorDescription = @"A non-TrollStore app with the same identifier is already installed. If you are absolutely sure it is not, try refreshing icon cache in TrollStore settings or try rebooting your device.";
break;
case 172:
errorDescription = @"The app does not seem to contain an Info.plist";
break;
}

NSError* error = [NSError errorWithDomain:TrollStoreErrorDomain code:code userInfo:@{NSLocalizedDescriptionKey : errorDescription}];
return error;
}

- (int)installIpa:(NSString*)pathToIpa
{
int ret = spawnRoot(helperPath(), @[@"install", pathToIpa]) == 0;
int ret = spawnRoot(helperPath(), @[@"install", pathToIpa]);
[[NSNotificationCenter defaultCenter] postNotificationName:@"ApplicationsChanged" object:nil];
return ret;
}

- (int)uninstallApp:(NSString*)appId error:(NSError**)error
- (int)uninstallApp:(NSString*)appId
{
int ret = spawnRoot(helperPath(), @[@"uninstall", appId]) == 0;
int ret = spawnRoot(helperPath(), @[@"uninstall", appId]);
[[NSNotificationCenter defaultCenter] postNotificationName:@"ApplicationsChanged" object:nil];
return ret;
}
Expand Down
Loading

0 comments on commit ee08cfe

Please sign in to comment.