Skip to content

Instantly share code, notes, and snippets.

@ice799 ice799/build.sh Secret
Created Aug 19, 2012

Embed
What would you like to do?
shitty shim code
gcc -dynamiclib -fno-common -o mallshim.dylib mallshim.c
#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
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.