-
-
Save ice799/0ee6dfeae09600d30c5e to your computer and use it in GitHub Desktop.
shitty shim code
This file contains 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
gcc -dynamiclib -fno-common -o mallshim.dylib mallshim.c |
This file contains 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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <malloc/malloc.h> | |
void (*real_free)(malloc_zone_t *zone, void *ptr); | |
void (*real_free_definite_size)(malloc_zone_t *zone, void *ptr, size_t size); | |
void my_free(malloc_zone_t *zone, void *ptr) | |
{ | |
char *tmp = ptr; | |
char tmp_buf[1025] = {0}; | |
size_t total = 0; | |
while (*tmp != '\0') { | |
tmp_buf[total] = *tmp; | |
total++; | |
if (total == 1024) | |
break; | |
tmp++; | |
} | |
malloc_printf("%s\n", tmp_buf); | |
real_free(zone, ptr); | |
} | |
void my_free_definite_size(malloc_zone_t *zone, void *ptr, size_t size) | |
{ | |
char tmp_buf[1024] = {0}; | |
if (size < 1024) { | |
memcpy(tmp_buf, ptr, size); | |
} else { | |
memcpy(tmp_buf, ptr, 1023); | |
} | |
malloc_printf("%s\n", tmp_buf); | |
real_free_definite_size(zone, ptr, size); | |
} | |
void __attribute__((constructor)) my_init() { | |
malloc_zone_t *zone = malloc_default_zone(); | |
real_free = zone->free; | |
real_free_definite_size = zone->free_definite_size; | |
zone->free_definite_size = my_free_definite_size; | |
zone->free = my_free; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment