Advertisement
Guest User

Untitled

a guest
Dec 25th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #import "ViewController.h"
  2. #include <stdio.h>
  3. #include <mach-o/dyld.h>
  4. #include <mach/mach.h>
  5. #include <sys/stat.h>
  6. #include <fcntl.h>
  7. #include <sys/types.h>
  8. #include <unistd.h>
  9. #include <sys/mman.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12.  
  13. @interface ViewController ()
  14.  
  15. @end
  16.  
  17. @implementation ViewController
  18.  
  19. - (void)viewDidLoad {
  20.     [super viewDidLoad];
  21.     NSString *logString;
  22.     _logView.text = [_logView.text stringByAppendingString:@"\n"];
  23.     struct mach_header_64 *header = (struct mach_header_64 *)_dyld_get_image_header(0);
  24.  
  25.     uint32_t *magic = &header->magic;
  26.     uint32_t newMagic = 4277001337;
  27.    
  28.     kern_return_t returnValue = vm_protect(mach_task_self(), (vm_address_t)header, sizeof(struct mach_header_64), false, VM_PROT_READ | VM_PROT_WRITE);
  29.     if ( returnValue != KERN_SUCCESS ) {
  30.         fprintf(stderr, "Error %d: Fail to change virtual memory protections\n", returnValue);
  31.         fprintf(stderr, "Mach error: %s\n", mach_error_string(returnValue));
  32.         logString = [NSString stringWithFormat:@"Error %d: Fail to change virtual memory protections\n", returnValue];
  33.         _logView.text = [_logView.text stringByAppendingString:logString];
  34. //        exit(1);
  35.     } else if (returnValue == KERN_SUCCESS) {
  36.         printf("Successfully changed Prot!\n");
  37.         _logView.text = [_logView.text stringByAppendingString:@"Successfully changed Prot!\n"];
  38.     }
  39.    
  40.    
  41.     printf("header address: %p\n", header);
  42.     printf("magic: %u\n", header->magic);
  43.     printf("magic address: %p\n", &header->magic);
  44.     printf("\n");
  45.    
  46.     logString = [NSString stringWithFormat:@"old magic: %u\n", header->magic];
  47.     _logView.text = [_logView.text stringByAppendingString:logString];
  48.  
  49.     if ((returnValue = vm_write(mach_task_self(), (vm_address_t)magic, (vm_address_t)&newMagic, sizeof(header->magic)) == KERN_SUCCESS)) {
  50.         printf("Successfully changed magic!\n");
  51.         printf("new magic: %u\n", header->magic);
  52.        
  53.         logString = [NSString stringWithFormat:@"modded magic to: %u\n", header->magic];
  54.         _logView.text = [_logView.text stringByAppendingString:logString];
  55.     }
  56. }
  57.  
  58. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement