#include <stdio.h>
#include <string.h>
#include <dlfcn.h>
#include <mach-o/dyld_priv.h>
typedef void (*NotifyProc)(void);
static bool termDidRun = false;
static void termNotifyFunc()
{
termDidRun = true;
}
int main()
{
printf("[BEGIN] dlclose-static-terminator\n");
void* handle = dlopen(RUN_DIR "/libterm.dylib", RTLD_LAZY);
if ( handle == NULL ) {
printf("[FAIL] dlclose-static-terminator: libterm.dylib could not be loaded, %s\n", dlerror());
return 0;
}
NotifyProc* pointerAddress = (NotifyProc*)dlsym(handle, "gNotifer");
if ( pointerAddress == NULL ) {
printf("[FAIL] dlclose-static-terminator: gNotifer not found in libterm.dylib\n");
return 0;
}
*pointerAddress = &termNotifyFunc;
dlclose(handle);
if ( termDidRun )
printf("[PASS] dlclose-static-terminator\n");
else
printf("[FAIL] dlclose-static-terminator: terminator not run\n");
return 0;
}