#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
#include <dlfcn.h>
#include <mach/host_info.h>
#include <mach/mach.h>
#include <mach/mach_host.h>
#include "test_support.h"
void tryPath(const char* prog, const char* path)
{
void* handle = dlopen(path, RTLD_LAZY);
#if HARDENED
if ( handle != NULL ) {
FAIL("dlopen(%s) unexpectedly succeeded", path);
exit(0);
}
#else
if ( handle == NULL ) {
FAIL("dlopen(%s) - %s", path, dlerror());
exit(0);
}
#endif
}
int main(int argc, const char* argv[], const char* envp[], const char* apple[]) {
void* handle = dlopen("libc.dylib", RTLD_LAZY);
if ( handle == NULL ) {
FAIL("dlopen - %s", dlerror());
}
tryPath(argv[0], "libmy.dylib");
tryPath(argv[0], "./libmy.dylib");
tryPath(argv[0], "../amfi-hardened-dlopen-leaf/libmy.dylib");
PASS("Succcess");
}