dyld-750.5.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 #include "test_support.h"
11
12 extern struct mach_header __dso_handle;
13
14 int main(int argc, const char* argv[], const char* envp[], const char* apple[]) {
15 // should succeed
16 dyld_get_image_versions(&__dso_handle, ^(dyld_platform_t platform, uint32_t sdkVersion, uint32_t minOS) {
17 LOG("main binary: platform=%d, sdk=0x%08X, minOS-0x%08X", platform, sdkVersion, minOS);
18 });
19
20 uint8_t badFile[4096];
21 struct mach_header* mh = (struct mach_header*)badFile;
22 mh->magic = MH_MAGIC_64;
23 mh->ncmds = 1;
24 mh->filetype = MH_DYLIB;
25 mh->sizeofcmds = 40;
26 mh->flags = 0;
27 struct load_command* lc = (struct load_command*)&badFile[32];
28 lc->cmd = 1;
29 lc->cmdsize = 4000; // bad load command size
30
31 // should detect the mh is bad and not crash or call the callback
32 dyld_get_image_versions(mh, ^(dyld_platform_t platform, uint32_t sdkVersion, uint32_t minOS) {
33 LOG("bad binary: platform=%d, sdk=0x%08X, minOS-0x%08X", platform, sdkVersion, minOS);
34 });
35
36 PASS("Success");
37 }
38