]>
git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/dyld_get_image_versions.dtest/main.c
2 // BUILD: $CC main.c -o $BUILD_DIR/dyld_get_image_versions.exe
4 // RUN: ./dyld_get_image_versions.exe
8 #include <mach-o/dyld_priv.h>
10 #include "test_support.h"
12 extern struct mach_header __dso_handle
;
14 int main(int argc
, const char* argv
[], const char* envp
[], const char* apple
[]) {
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
);
20 uint8_t badFile
[4096];
21 struct mach_header
* mh
= (struct mach_header
*)badFile
;
22 mh
->magic
= MH_MAGIC_64
;
24 mh
->filetype
= MH_DYLIB
;
27 struct load_command
* lc
= (struct load_command
*)&badFile
[32];
29 lc
->cmdsize
= 4000; // bad load command size
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
);