Last active
July 30, 2018 06:45
-
-
Save CreatureSurvive/5448249b356268487ab184ca8468cee3 to your computer and use it in GitHub Desktop.
A simple PSListController Implementation that will display an alert notifying the user if their using a pirated copy of the tweak. Provides an action to add the official source for your tweak, and an action to continue using the pirated version. If the user chooses to continue with the pirated version, the support section of the preferences will…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @interface CSPListController : PSListController | |
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @implementation CSPListController | |
| - (void)viewDidAppear:(BOOL)animated { | |
| [super viewDidAppear:animated]; | |
| // declare out variables, we'll need them all | |
| NSString *packageID, *name, *repo; | |
| // check controllers specifier for a packageID before going any further | |
| // if no packageID is provided, then do nothing | |
| if ((packageID = [self.specifier propertyForKey:@"packageID"])) { | |
| // get the name of this tweak from the label in the | |
| // entry specifier for displaying in the alert | |
| name = [self.specifier propertyForKey:@"label"]; | |
| // get the repo provided in the entry specifier for | |
| // displaying in the alert, as well the alert action | |
| repo = [self.specifier propertyForKey:@"repo"]; | |
| // if all required fields are not present, stop | |
| if (!repo || !name || !packageID) return; | |
| // unfortunately, APT nor DPKG offers any real way of determining | |
| // what source a package is installed from, so we'll operate under | |
| // the assumption that most pirate repos change the package identifier. | |
| // we'll improve this later with some crafty hackys, and reconstructing :) | |
| // Get a list of all packages installed on the device using dpkg -l | |
| // to output a list we could use --get-selections for this as well, | |
| // but for our purposes -l (list) will work just fine | |
| NSString *packageList = [CSPTaskRunner stringResultForProcessAtPath:@"/usr/bin/dpkg" arguments:@[@"-l"]]; | |
| // check if the package list contains our packageID, | |
| // if it does, then the package is authentic. no need to continue | |
| if ([packageList containsString:packageID]) return; | |
| // create the piracy warning alert and supply it with the fields above | |
| UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Piracy Warning" message:[NSString stringWithFormat:@"It looks like you've installed %@ from a piracy repo. You can continue using %@ at your own risk, but no support will be provided for issues.\n\n I recommend that you install the official version from %@, before continuing to use this tweak", name, name, repo] preferredStyle:UIAlertControllerStyleAlert]; | |
| // add repo action. use saurik's share api to open the repo in cydia to add the oficial souce | |
| [alertController addAction:[UIAlertAction actionWithTitle:@"Add Official Repo" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { | |
| [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"cydia://url/https://cydia.saurik.com/api/share#?source=%@", repo]] options:@{} completionHandler:nil]; | |
| }]]; | |
| // let the user make the choice if they want to continue using the pirated copy | |
| [alertController addAction:[UIAlertAction actionWithTitle:@"Ignore" style: UIAlertActionStyleDestructive handler:^(UIAlertAction *action){ | |
| // get an array of specifiers we tagged with the 'support' | |
| // key so we can disable them in the event that the user | |
| // continues using the pirated version of this tweak | |
| NSArray *support = [self specifiersForKey:@"support"]; | |
| if (support) { | |
| // even pirates deserve some nice animation!!! | |
| // animate the disabling of the support specifiers | |
| // probably the handiest little block method I've ever written :) | |
| [self applyChanges:^{ | |
| // disable support specifiers | |
| [self setSpecifiers:support enabled:NO]; | |
| } animated:animated]; | |
| } | |
| }]]; | |
| // if we've made it this far and built this alert, we should probably present it... right! | |
| [self presentViewController:alertController animated:YES completion:nil]; | |
| } | |
| } | |
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import <NSTask.h> | |
| @interface CSPTaskRunner : NSObject | |
| + (NSString *)stringResultForProcessAtPath:(NSString *)path arguments:(NSArray <NSString *> *)arguments; | |
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // return the results of a process at the given path as an NSString object, | |
| // of course, you could use posix_spawn for this, but I can't be the only one | |
| // that finds posix_spawn to be hideous. not to mention that I have yet to find a | |
| // way to output a string from posix_spawn results without writing to a file first | |
| + (NSString *)stringResultForProcessAtPath:(NSString *)path arguments:(NSArray <NSString *> *)arguments; { | |
| NSTask *task = [NSTask new]; | |
| NSPipe *pipe = [NSPipe pipe]; | |
| task.launchPath = path; | |
| task.arguments = arguments; | |
| task.standardInput = [NSFileHandle fileHandleWithNullDevice]; | |
| task.standardOutput = pipe; | |
| task.standardError = pipe; | |
| [task launch]; | |
| [task waitUntilExit]; | |
| return [[NSString alloc] initWithData:[pipe.fileHandleForReading readDataToEndOfFile] encoding:NSUTF8StringEncoding]; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="UTF-8"?> | |
| <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
| <plist version="1.0"> | |
| <dict> | |
| <key>entry</key> | |
| <dict> | |
| <key>bundle</key> | |
| <string>awesomeTweak5000</string> | |
| <key>cell</key> | |
| <string>PSLinkCell</string> | |
| <key>detail</key> | |
| <string>CSPListController</string> | |
| <key>icon</key> | |
| <string>SettingsIcon.png</string> | |
| <key>isController</key> | |
| <true/> | |
| <key>label</key> | |
| <string>AwesomeTweak5000</string> | |
| // add the necessary packageID to the entry specifier | |
| <key>packageID</key> | |
| <string>com.creaturecoding.awesomeTweak5000</string> | |
| // add the necessary repo to the specifier | |
| <key>repo</key> | |
| <string>https://creaturesurvive.github.io/</string> | |
| </dict> | |
| </dict> | |
| </plist> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment