aboutsummaryrefslogtreecommitdiff
path: root/darwin-bootstrap/safety-dance/main.m
diff options
context:
space:
mode:
authorcomex2015-02-28 13:16:36 -0500
committercomex2015-02-28 13:16:36 -0500
commitd9a7a8a4d4a23fb65e6319e0e8a435046cc39fea (patch)
treedd219509fc92e695317b82d5dca43296daaf2ab1 /darwin-bootstrap/safety-dance/main.m
parentremove deprecated property usage in safety-dance (diff)
downloadsubstitute-d9a7a8a4d4a23fb65e6319e0e8a435046cc39fea.tar.gz
Rename ios-bootstrap to darwin-bootstrap; cleanup posixspawn-hook and unrestrict.
Not tested yet.
Diffstat (limited to 'darwin-bootstrap/safety-dance/main.m')
-rw-r--r--darwin-bootstrap/safety-dance/main.m159
1 files changed, 159 insertions, 0 deletions
diff --git a/darwin-bootstrap/safety-dance/main.m b/darwin-bootstrap/safety-dance/main.m
new file mode 100644
index 0000000..0d05e00
--- /dev/null
+++ b/darwin-bootstrap/safety-dance/main.m
@@ -0,0 +1,159 @@
+#import <UIKit/UIKit.h>
+#import "AutoGrid.h"
+
+@interface ViewController : UIViewController {
+ AutoGrid *autoGrid;
+}
+
+@end
+
+@implementation ViewController
+
+- (void)viewDidLoad {
+ [super viewDidLoad];
+ [self loadStuff];
+ NSMutableArray *names = [NSMutableArray array];
+ for (int i = 0; i < 100; i++)
+ [names addObject:[NSString stringWithFormat:@"Some Dylib %d", i]];
+ NSMutableArray *views = [NSMutableArray array];
+ for (NSString *name in names) {
+ UILabel *label = [[UILabel alloc] init];
+ label.text = name;
+ [views addObject:label];
+ }
+ [autoGrid setViews:views];
+}
+
+#define EXPLANATION \
+ @"SpringBoard seems to have crashed. The cause might be a Substitute jailbreak extension, or unrelated. Just to be safe, extensions in SpringBoard have been temporarily disabled. You can continue in this mode, or restart SpringBoard normally.\n\nThe following extensions were running:"
+
+static void hugging(UIView *view, UILayoutPriority pri) {
+ [view setContentHuggingPriority:pri forAxis:UILayoutConstraintAxisHorizontal];
+ [view setContentHuggingPriority:pri forAxis:UILayoutConstraintAxisVertical];
+}
+static void compression(UIView *view, UILayoutPriority pri) {
+ [view setContentCompressionResistancePriority:pri forAxis:UILayoutConstraintAxisHorizontal];
+ [view setContentCompressionResistancePriority:pri forAxis:UILayoutConstraintAxisVertical];
+}
+
+- (void)loadStuff {
+ self.view.backgroundColor = [UIColor whiteColor];
+
+ UILabel *top = [[UILabel alloc] init];
+ top.translatesAutoresizingMaskIntoConstraints = NO;
+ top.textAlignment = NSTextAlignmentCenter;
+ hugging(top, 251);
+ top.text = @"libsubstitute";
+ top.font = [UIFont systemFontOfSize:23];
+ [self.view addSubview:top];
+
+ UILabel *big = [[UILabel alloc] init];
+ big.translatesAutoresizingMaskIntoConstraints = NO;
+ big.textAlignment = NSTextAlignmentCenter;
+ hugging(big, 251);
+ [big setContentHuggingPriority:251 forAxis:UILayoutConstraintAxisHorizontal];
+ [big setContentHuggingPriority:251 forAxis:UILayoutConstraintAxisVertical];
+ big.text = @"Safe Mode";
+ big.font = [UIFont systemFontOfSize:32];
+ [self.view addSubview:big];
+
+ UILabel *explain = [[UILabel alloc] init];
+ explain.translatesAutoresizingMaskIntoConstraints = NO;
+ explain.textAlignment = NSTextAlignmentCenter;
+ hugging(explain, 251);
+ compression(explain, 999);
+ explain.text = EXPLANATION;
+ explain.font = [UIFont systemFontOfSize:14];
+ explain.minimumScaleFactor = 0.5; /* test */
+ explain.numberOfLines = 0;
+ [self.view addSubview:explain];
+
+ UIButton *returnButton = [UIButton buttonWithType:UIButtonTypeSystem];
+ returnButton.translatesAutoresizingMaskIntoConstraints = NO;
+ returnButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
+ returnButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
+ returnButton.titleLabel.font = [UIFont systemFontOfSize:17];
+ [returnButton setTitle:@"Return to Normal" forState:UIControlStateNormal];
+ [self.view addSubview:returnButton];
+
+ UIButton *continueButton = [UIButton buttonWithType:UIButtonTypeSystem];
+ continueButton.translatesAutoresizingMaskIntoConstraints = NO;
+ hugging(continueButton, 999);
+ compression(continueButton, 300);
+ continueButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
+ continueButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
+ continueButton.titleLabel.font = [UIFont systemFontOfSize:17];
+ [continueButton setTitle:@"Continue in Safe Mode" forState:UIControlStateNormal];
+ [self.view addSubview:continueButton];
+
+ autoGrid = [[AutoGrid alloc] init];
+ autoGrid.translatesAutoresizingMaskIntoConstraints = NO;
+ [self.view addSubview:autoGrid];
+
+ NSDictionary *viewsDictionary = @{
+ @"top": top,
+ @"big": big,
+ @"explain": explain,
+ @"returnButton": returnButton,
+ @"continueButton": continueButton,
+ @"grid": autoGrid,
+ @"topGuide": self.topLayoutGuide,
+ @"bottomGuide": self.bottomLayoutGuide,
+ };
+ NSMutableArray *constraints = [[NSMutableArray alloc] init];
+ [constraints addObjectsFromArray:
+ [NSLayoutConstraint constraintsWithVisualFormat:
+ @"V:[topGuide]-10-[top]-0@100-[big]-0@100-[explain]-18@200-[grid]-18-[continueButton]-8-[returnButton]-20@100-[bottomGuide]"
+ options:NSLayoutFormatAlignAllCenterX metrics:nil views:viewsDictionary]];
+ NSArray *additional = @[
+ @"[explain(<=650)]",
+ @"|-10-[explain]-10-|",
+ @"|-20-[grid]-20-|",
+ ];
+ for (NSString *fmt in additional) {
+ [constraints addObjectsFromArray:
+ [NSLayoutConstraint constraintsWithVisualFormat:fmt options:0 metrics:nil views:viewsDictionary]];
+ }
+ [self.view addConstraints:constraints];
+}
+
+
+- (NSUInteger)supportedInterfaceOrientations
+{
+ if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad)
+ return UIInterfaceOrientationMaskAll;
+ else if ([UIScreen mainScreen].bounds.size.width >= 414)
+ return UIInterfaceOrientationMaskAllButUpsideDown;
+ else
+ return UIInterfaceOrientationMaskPortrait;
+}
+
+@end
+
+@interface AppDelegate : UIResponder <UIApplicationDelegate> {
+}
+
+@property (strong, nonatomic) UIWindow *window;
+
+
+@end
+
+@implementation AppDelegate
+- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
+ NSLog(@"dflwo");
+ self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
+ ViewController *viewController = [[ViewController alloc] init];
+ self.window.rootViewController = viewController;
+ [self.window makeKeyAndVisible];
+ return YES;
+}
+
+@end
+
+int main(int argc, char *argv[]) {
+ NSLog(@"main");
+ @autoreleasepool {
+ return UIApplicationMain(argc, argv, nil, @"AppDelegate");
+ }
+}
+