Created
April 2, 2025 05:33
-
-
Save Catfish-Man/985ca68ebb7a324664dd7a84cdba8604 to your computer and use it in GitHub Desktop.
Malloc?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <mach/mach.h> | |
#import <stdlib.h> | |
#import <stdio.h> | |
__attribute__((constructor)) | |
void setup(void) { | |
void *unused; | |
vm_allocate(mach_task_self(), (vm_address_t *)&unused, (vm_size_t) 0x00000FFFF0000000ULL, VM_FLAGS_ANYWHERE | VM_FLAGS_OVERWRITE); | |
} | |
__attribute__((malloc)) | |
void *usually_malloc(size_t sz) { | |
uint64_t result; | |
arc4random_buf((void *)&result, 8); | |
return (void *)((result >> 20)); | |
} | |
void usually_free(void *ptr) { | |
//ohhhh well | |
} | |
int main(int argc, const char * argv[]) { | |
char *hello = usually_malloc(strlen("Hello, World!")); | |
sprintf(hello, "%s", "Hello, World!"); | |
printf("%s (at %p)\n", hello, hello); | |
usually_free(hello); | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment