dyld-732.8.tar.gz
[apple/dyld.git] / testing / test-cases / dyld_get_image_versions.dtest / main.c
1
2 // BUILD: $CC main.c -o $BUILD_DIR/dyld_get_image_versions.exe
3
4 // RUN: ./dyld_get_image_versions.exe
5
6 #include <stdio.h>
7 #include <string.h>
8 #include <mach-o/dyld_priv.h>
9
10 extern struct mach_header __dso_handle;
11
12 int main()
13 {
14 printf("[BEGIN] dyld_get_image_versions\n");
15
16 // should succeed
17 dyld_get_image_versions(&__dso_handle, ^(dyld_platform_t platform, uint32_t sdkVersion, uint32_t minOS) {
18 printf("main binary: platform=%d, sdk=0x%08X, minOS-0x%08X\n", platform, sdkVersion, minOS);
19 });
20
21 uint8_t badFile[4096];
22 struct mach_header* mh = (struct mach_header*)badFile;
23 mh->magic = MH_MAGIC_64;
24 mh->ncmds = 1;
25 mh->filetype = MH_DYLIB;
26 mh->sizeofcmds = 40;
27 mh->flags = 0;
28 struct load_command* lc = (struct load_command*)&badFile[32];
29 lc->cmd = 1;
30 lc->cmdsize = 4000; // bad load command size
31
32 // should detect the mh is bad and not crash or call the callback
33 dyld_get_image_versions(mh, ^(dyld_platform_t platform, uint32_t sdkVersion, uint32_t minOS) {
34 printf("bad binary: platform=%d, sdk=0x%08X, minOS-0x%08X\n", platform, sdkVersion, minOS);
35 });
36
37
38 printf("[PASS] dyld_get_image_versions\n");
39 return 0;
40 }
41