]>
git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/amfi-hardened-dlopen-leaf.dtest/main.c
3 // BOOT_ARGS: dyld_flags=2
5 // BUILD: $CC my.c -dynamiclib -o $BUILD_DIR/libmy.dylib -install_name $RUN_DIR/libmy.dylib
6 // BUILD: $CC main.c -o $BUILD_DIR/amfi-hardened-dlopen-leaf.exe -DHARDENED=1
7 // BUILD: $CC main.c -o $BUILD_DIR/amfi-not-hardened-dlopen-leaf.exe
9 // RUN: DYLD_AMFI_FAKE=0x14 ./amfi-hardened-dlopen-leaf.exe
10 // RUN: DYLD_AMFI_FAKE=0x3F ./amfi-not-hardened-dlopen-leaf.exe
17 #include <mach/host_info.h>
18 #include <mach/mach.h>
19 #include <mach/mach_host.h>
21 void tryPath(const char* prog
, const char* path
)
23 void* handle
= dlopen(path
, RTLD_LAZY
);
25 if ( handle
!= NULL
) {
26 printf("[FAIL] %s dlopen(%s) unexpectedly succeeded\n", prog
, path
);
30 if ( handle
== NULL
) {
31 printf("[FAIL] %s dlopen(%s) - %s\n", prog
, path
, dlerror());
38 int main(int arg
, const char* argv
[])
40 printf("[BEGIN] %s\n", argv
[0]);
42 // verify leaf name leads to dylib in /usr/lib/
43 void* handle
= dlopen("libc.dylib", RTLD_LAZY
);
44 if ( handle
== NULL
) {
45 printf("[FAIL] %s dlopen - %s\n", argv
[0], dlerror());
49 // verify file system relative paths: hardened should fail
50 tryPath(argv
[0], "libmy.dylib");
51 tryPath(argv
[0], "./libmy.dylib");
52 tryPath(argv
[0], "../amfi-hardened-dlopen-leaf/libmy.dylib");
54 printf("[PASS] %s\n", argv
[0]);