Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import "ViewController.h"
- #include <stdio.h>
- #include <mach-o/dyld.h>
- #include <mach/mach.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <sys/types.h>
- #include <unistd.h>
- #include <sys/mman.h>
- #include <stdlib.h>
- #include <string.h>
- @interface ViewController ()
- @end
- @implementation ViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- NSString *logString;
- _logView.text = [_logView.text stringByAppendingString:@"\n"];
- struct mach_header_64 *header = (struct mach_header_64 *)_dyld_get_image_header(0);
- uint32_t *magic = &header->magic;
- uint32_t newMagic = 4277001337;
- 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);
- if ( returnValue != KERN_SUCCESS ) {
- fprintf(stderr, "Error %d: Fail to change virtual memory protections\n", returnValue);
- fprintf(stderr, "Mach error: %s\n", mach_error_string(returnValue));
- logString = [NSString stringWithFormat:@"Error %d: Fail to change virtual memory protections\n", returnValue];
- _logView.text = [_logView.text stringByAppendingString:logString];
- // exit(1);
- } else if (returnValue == KERN_SUCCESS) {
- printf("Successfully changed Prot!\n");
- _logView.text = [_logView.text stringByAppendingString:@"Successfully changed Prot!\n"];
- }
- printf("header address: %p\n", header);
- printf("magic: %u\n", header->magic);
- printf("magic address: %p\n", &header->magic);
- printf("\n");
- logString = [NSString stringWithFormat:@"old magic: %u\n", header->magic];
- _logView.text = [_logView.text stringByAppendingString:logString];
- if ((returnValue = vm_write(mach_task_self(), (vm_address_t)magic, (vm_address_t)&newMagic, sizeof(header->magic)) == KERN_SUCCESS)) {
- printf("Successfully changed magic!\n");
- printf("new magic: %u\n", header->magic);
- logString = [NSString stringWithFormat:@"modded magic to: %u\n", header->magic];
- _logView.text = [_logView.text stringByAppendingString:logString];
- }
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement