#include <stdlib.h> // EXIT_SUCCESS
#include <stdio.h>
#include <mach-o/dyld.h>
#include <mach-o/dyld_images.h>
#include <mach-o/dyld_priv.h>
#include <mach/mach.h>
#include <Availability.h>
#include <mach/shared_region.h>
#include "test.h"
#include "dyld_cache_format.h"
int main()
{
const struct dyld_all_image_infos* allInfo = _dyld_get_all_image_infos();
if ( allInfo == NULL ) {
FAIL("dyld_shared_cache_iterate_text: _dyld_get_all_image_infos() failed");
exit(0);
}
uuid_t curUuid;
memcpy(curUuid, allInfo->sharedCacheUUID, 16);
int __block imageCount = 0;
int result = dyld_shared_cache_iterate_text(curUuid, ^(const dyld_shared_cache_dylib_text_info* info) {
++imageCount;
});
if ( result != 0 ) {
FAIL("dyld_shared_cache_iterate_text: dyld_shared_cache_iterate_text() failed");
exit(0);
}
if ( imageCount < 500 ) {
FAIL("dyld_shared_cache_iterate_text: dyld_shared_cache_iterate_text() iterated less than 500 dylibs (%d)", imageCount);
exit(0);
}
#if 0
uuid_t fixedUUID = {0xD4, 0x3B, 0x31, 0x2B, 0xA5, 0xA7, 0x3C, 0x55, 0x90, 0xA0, 0x9A, 0x37, 0x60, 0x7D, 0x70, 0xAF};
result = dyld_shared_cache_iterate_text(fixedUUID, ^(const dyld_shared_cache_dylib_text_info* info) {
printf(" my: 0x%09llX -> 0x%09llX %s\n", info->loadAddressUnslid, info->loadAddressUnslid + info->textSegmentSize, info->path);
});
#endif
PASS("dyld_shared_cache_iterate_text");
return EXIT_SUCCESS;
}