start_jailbreakd.m 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //
  2. // jailbreakd.c
  3. // async_wake_ios
  4. //
  5. // Created by CoolStar on 12/25/17.
  6. // Copyright © 2017 Ian Beer. All rights reserved.
  7. //
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <mach/mach.h>
  11. #include <mach/error.h>
  12. #include <mach/message.h>
  13. #include <string.h>
  14. #include <sys/types.h>
  15. #include <sys/socket.h>
  16. #include <netinet/in.h>
  17. #include <arpa/inet.h>
  18. #include <unistd.h>
  19. #include <sys/stat.h>
  20. #import <Foundation/Foundation.h>
  21. #include "utils.h"
  22. int start_jailbreakd(uint64_t kernel_base) {
  23. unlink("/var/tmp/jailbreakd.pid");
  24. unlink("/var/run/jailbreakd.pid");
  25. unlink("/var/log/jailbreakd-stderr.log");
  26. unlink("/var/log/jailbreakd-stdout.log");
  27. NSData *blob = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"jailbreakd" ofType:@"plist"]];
  28. NSMutableDictionary *job = [NSPropertyListSerialization propertyListWithData:blob options:NSPropertyListMutableContainers format:nil error:nil];
  29. job[@"EnvironmentVariables"][@"KernelBase"] = [NSString stringWithFormat:@"0x%16llx", kernel_base];
  30. [job writeToFile:@"/Library/LaunchDaemons/jailbreakd.plist" atomically:YES];
  31. chmod("/Library/LaunchDaemons/jailbreakd.plist", 0644);
  32. chown("/Library/LaunchDaemons/jailbreakd.plist", 0, 0);
  33. pid_t pid = 0;
  34. int rv = run("/bin/launchctl load /Library/LaunchDaemons/jailbreakd.plist");
  35. if (rv == -1) {
  36. return -1;
  37. }
  38. int ex = 0;
  39. waitpid(pid, &ex, 0);
  40. NSLog(@"The dragon becomes me!");
  41. NSLog(@"once it is drawn, it cannot be sheathed without causing death");
  42. return 0;
  43. }