我原来帖子中的代码曾用于优胜美地.在El Capitan,它不起作用.我最终做了以下方法(DYLD_INTERPOSE
+ DYLD_INSERT_LIBRARIES
):
#define _GNU_SOURCE #include#include #include #define DYLD_INTERPOSE(_replacment,_replacee) \ __attribute__((used)) static struct{ const void* replacment; const void* replacee; } _interpose_##_replacee \ __attribute__ ((section ("__DATA,__interpose"))) = { (const void*)(unsigned long)&_replacment, (const void*)(unsigned long)&_replacee }; void* pMalloc(size_t size) //would be nice if I didn't have to rename my function.. { printf("Allocated: %zu\n", size); return malloc(size); } DYLD_INTERPOSE(pMalloc, malloc);