ViewController.m 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. //
  2. // ViewController.m
  3. // g0blin
  4. //
  5. // Created by Sticktron on 2017-12-26.
  6. // Copyright © 2017 Sticktron. All rights reserved.
  7. //
  8. #import "ViewController.h"
  9. #include "v0rtex.h"
  10. #include "common.h"
  11. #include "offsets.h"
  12. #include "kernel.h"
  13. #include "kpp.h"
  14. #include "remount.h"
  15. #include "bootstrap.h"
  16. #include <sys/utsname.h>
  17. #define GRAPE [UIColor colorWithRed:0.5 green:0 blue:1 alpha:1]
  18. @interface ViewController ()
  19. @property (weak, nonatomic) IBOutlet UIButton *goButton;
  20. @property (weak, nonatomic) IBOutlet UIProgressView *progressView;
  21. @property (weak, nonatomic) IBOutlet UITextView *consoleView;
  22. @end
  23. static task_t tfp0;
  24. static uint64_t kslide;
  25. static uint64_t kbase;
  26. @implementation ViewController
  27. - (void)viewDidLoad {
  28. [super viewDidLoad];
  29. // Do any additional setup after loading the view, typically from a nib.
  30. self.progressView.progress = 0;
  31. self.progressView.hidden = YES;
  32. self.consoleView.layer.cornerRadius = 6;
  33. self.consoleView.text = nil;
  34. self.goButton.layer.cornerRadius = 16;
  35. // print kernel version
  36. struct utsname u;
  37. uname(&u);
  38. [self log:[NSString stringWithFormat:@"%s \n", u.version]];
  39. if (init_offsets() != KERN_SUCCESS) {
  40. self.goButton.enabled = NO;
  41. self.goButton.backgroundColor = UIColor.darkGrayColor;
  42. [self.goButton setTitle:@"device not supported" forState:UIControlStateDisabled];
  43. return;
  44. }
  45. [self log:@"Ready. \n"];
  46. }
  47. - (void)didReceiveMemoryWarning {
  48. [super didReceiveMemoryWarning];
  49. // Dispose of any resources that can be recreated.
  50. }
  51. - (void)log:(NSString *)text {
  52. self.consoleView.text = [NSString stringWithFormat:@"%@%@ \n", self.consoleView.text, text];
  53. }
  54. - (IBAction)go:(UIButton *)sender {
  55. self.goButton.enabled = NO;
  56. self.goButton.backgroundColor = UIColor.darkGrayColor;
  57. [self.goButton setTitle:@"jailbreaking" forState:UIControlStateDisabled];
  58. self.progressView.hidden = NO;
  59. [self.progressView setProgress:0.1 animated:YES];
  60. [self log:@"exploiting kernel"];
  61. kern_return_t ret = v0rtex(&tfp0, &kslide);
  62. dispatch_async(dispatch_get_main_queue(), ^{
  63. if (ret != KERN_SUCCESS) {
  64. self.goButton.enabled = YES;
  65. self.goButton.backgroundColor = GRAPE;
  66. [self.goButton setTitle:@"try again" forState:UIControlStateNormal];
  67. [self log:@"ERROR: exploit failed \n"];
  68. return;
  69. }
  70. LOG("v0rtex was successful");
  71. LOG("tfp0 -> %x", tfp0);
  72. LOG("slide -> 0x%llx", kslide);
  73. kbase = kslide + 0xFFFFFFF007004000;
  74. LOG("kern base -> 0x%llx", kbase);
  75. [self bypassKPP];
  76. });
  77. }
  78. - (void)bypassKPP {
  79. [self.progressView setProgress:0.3 animated:YES];
  80. [self log:@"bypassing KPP"];
  81. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  82. if (do_kpp(1, 0, kbase, kslide, tfp0) != KERN_SUCCESS) {
  83. [self log:@"ERROR: kpp bypass failed \n"];
  84. return;
  85. }
  86. LOG("fuck kpp, yolo kjc!");
  87. [self remount];
  88. });
  89. }
  90. - (void)remount {
  91. [self.progressView setProgress:0.5 animated:YES];
  92. [self log:@"remounting / as r/w"];
  93. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  94. if (do_remount(kslide) != KERN_SUCCESS) {
  95. [self log:@"ERROR: failed to remount system partition \n"];
  96. return;
  97. }
  98. [self bootstrap];
  99. });
  100. }
  101. - (void)bootstrap {
  102. // [self.progressView setProgress:0.6 animated:YES];
  103. // [self log:@"installing bootstrap"];
  104. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  105. // if (do_bootstrap() != KERN_SUCCESS) {
  106. // [self log:@"ERROR: failed to install bootstrap \n"];
  107. // return;
  108. // }
  109. [self finish];
  110. });
  111. }
  112. - (void)finish {
  113. [self.progressView setProgress:1 animated:YES];
  114. [self log:@"All done, peace!"];
  115. [self.goButton setTitle:@"jailbroke yo!" forState:UIControlStateDisabled];
  116. }
  117. @end