fun_objc.m 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. //
  2. // fun_objc.m
  3. // async_wake_ios
  4. //
  5. // Created by George on 16/12/17.
  6. // Copyright © 2017 Ian Beer. All rights reserved.
  7. //
  8. #include <dlfcn.h>
  9. #include <copyfile.h>
  10. #include <stdio.h>
  11. #include <spawn.h>
  12. #include <unistd.h>
  13. #include <mach/mach.h>
  14. #include <mach-o/dyld.h>
  15. #include <sys/stat.h>
  16. #include <sys/mount.h>
  17. #include <sys/utsname.h>
  18. #import <Foundation/Foundation.h>
  19. #import "NSData+GZip.h"
  20. #import "ViewController.h"
  21. #import "utils.h"
  22. #import "fun_objc.h"
  23. const char *userGenerator(void) {
  24. NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
  25. if ([userDefaults objectForKey:@K_GENERATOR] == nil)
  26. return NULL;
  27. const char *generator = [[userDefaults objectForKey:@K_GENERATOR] UTF8String];
  28. char compareString[22];
  29. uint64_t rawGeneratorValue;
  30. sscanf(generator, "0x%16llx", &rawGeneratorValue);
  31. sprintf(compareString, "0x%016llx", rawGeneratorValue);
  32. if(strcmp(compareString, generator) != 0)
  33. return NULL;
  34. return generator;
  35. }
  36. const char *genToSet(void) {
  37. const char *generator = userGenerator();
  38. if (generator == NULL)
  39. generator = strdup(K_ELECTRA_GENERATOR);
  40. return generator;
  41. }
  42. const char* progname(const char* prog) {
  43. char path[4096];
  44. uint32_t size = sizeof(path);
  45. _NSGetExecutablePath(path, &size);
  46. char *pt = realpath(path, NULL);
  47. NSString *execpath = [[NSString stringWithUTF8String:pt] stringByDeletingLastPathComponent];
  48. NSString *bootstrap = [execpath stringByAppendingPathComponent:[NSString stringWithUTF8String:prog]];
  49. return [bootstrap UTF8String];
  50. }
  51. const char* realPath() {
  52. char path[4096];
  53. uint32_t size = sizeof(path);
  54. _NSGetExecutablePath(path, &size);
  55. char *pt = realpath(path, NULL);
  56. return pt;
  57. }
  58. void extractGz(const char *from, const char *to) {
  59. NSData *gz = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@(from) ofType:@"gz"]];
  60. NSData *extracted = [gz gunzippedData];
  61. [extracted writeToFile:@(to) atomically:YES];
  62. }
  63. void update_springboard_plist(){
  64. NSDictionary *springBoardPlist = [NSMutableDictionary dictionaryWithContentsOfFile:@"/var/mobile/Library/Preferences/com.apple.springboard.plist"];
  65. [springBoardPlist setValue:@YES forKey:@"SBShowNonDefaultSystemApps"];
  66. [springBoardPlist writeToFile:@"/var/mobile/Library/Preferences/com.apple.springboard.plist" atomically:YES];
  67. NSDictionary* attr = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithShort:0755], NSFilePosixPermissions,@"mobile",NSFileOwnerAccountName,NULL];
  68. NSError *error = nil;
  69. [[NSFileManager defaultManager] setAttributes:attr ofItemAtPath:@"/var/mobile/Library/Preferences/com.apple.springboard.plist" error:&error];
  70. }
  71. void startDaemons(){
  72. pid_t pd;
  73. NSArray *files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:@"/etc/rc.d" error:nil];
  74. for (NSString *fileName in files){
  75. NSString *fullPath = [@"/etc/rc.d" stringByAppendingPathComponent:fileName];
  76. run([fullPath UTF8String]);
  77. }
  78. files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:@"/Library/LaunchDaemons/" error:nil];
  79. for (NSString *fileName in files){
  80. if ([fileName isEqualToString:@"jailbreakd.plist"])
  81. continue;
  82. if ([fileName isEqualToString:@"com.openssh.sshd.plist"])
  83. continue;
  84. NSString *fullPath = [@"/Library/LaunchDaemons" stringByAppendingPathComponent:fileName];
  85. posix_spawn(&pd, "/bin/launchctl", NULL, NULL, (char **)&(const char*[]){ "launchctl", "load", [fullPath UTF8String], NULL }, NULL);
  86. waitpid(pd, NULL, 0);
  87. }
  88. }
  89. void writeMessagePlain(char *message, ...) {
  90. va_list args;
  91. va_start(args, message);
  92. NSString *string;
  93. string = [[NSString alloc] initWithFormat: [NSString stringWithUTF8String:message] arguments: args];;
  94. va_end(args);
  95. [[ViewController currentViewController] writeText:string];
  96. }
  97. void writeMessage(char *message) {
  98. [[ViewController currentViewController] writeText:[NSString stringWithUTF8String:message]];
  99. }
  100. void displaySnapshotNotice(){
  101. [[ViewController currentViewController] displaySnapshotNotice];
  102. }
  103. void displaySnapshotWarning(){
  104. [[ViewController currentViewController] displaySnapshotWarning];
  105. }
  106. void removingLiberiOS(){
  107. [[ViewController currentViewController] removingLiberiOS];
  108. }
  109. void removingElectraBeta(){
  110. [[ViewController currentViewController] removingElectraBeta];
  111. }
  112. void installingNitoTV(){
  113. [[ViewController currentViewController] installingNitoTV];
  114. }
  115. void nitoTVDone(){
  116. [[ViewController currentViewController] nitoTVDone];
  117. }
  118. void blockSaurikRepo(){
  119. NSString *hostsFile = [NSString stringWithContentsOfFile:@"/etc/hosts" encoding:NSUTF8StringEncoding error:nil];
  120. if ([hostsFile rangeOfString:@"\n0.0.0.0 apt.saurik.com\n"].location == NSNotFound){
  121. FILE *file = fopen("/etc/hosts","a");
  122. fprintf(file, "0.0.0.0 apt.saurik.com\n");
  123. fclose(file);
  124. pid_t pd;
  125. posix_spawn(&pd, "/bin/rm", NULL, NULL, (char **)&(const char*[]){ "rm", "-rf", "/var/mobile/Library/Caches/com.saurik.Cydia", NULL }, NULL);
  126. waitpid(pd, NULL, 0);
  127. NSLog(@"Telesphoreo repo blocked successfully");
  128. }
  129. }