Skip to content

Instantly share code, notes, and snippets.

@DerekSelander
Last active November 7, 2021 04:23
Show Gist options
  • Save DerekSelander/d49ca7f401b6c141b0bb70cbbe52f750 to your computer and use it in GitHub Desktop.
Save DerekSelander/d49ca7f401b6c141b0bb70cbbe52f750 to your computer and use it in GitHub Desktop.
Showcase __builtin_dump_struct
//
// clang builtin_print_struct.c && ./a.out
//
// Created by Derek Selander
// dyld_all_image_infos header courtsey of dyld's opensource.apple.com
//
#include <mach/mach.h>
#include <mach/task_info.h>
#include <stdio.h>
#include <stdbool.h>
struct dyld_all_image_infos {
uint32_t version; /* 1 in Mac OS X 10.4 and 10.5 */
uint32_t infoArrayCount;
#if defined(__cplusplus) && (BUILDING_LIBDYLD || BUILDING_DYLD)
std::atomic<const struct dyld_image_info*> infoArray;
#else
const struct dyld_image_info* infoArray;
#endif
void* notification;
bool processDetachedFromSharedRegion;
/* the following fields are only in version 2 (Mac OS X 10.6, iPhoneOS 2.0) and later */
bool libSystemInitialized;
const struct mach_header* dyldImageLoadAddress;
/* the following field is only in version 3 (Mac OS X 10.6, iPhoneOS 3.0) and later */
void* jitInfo;
/* the following fields are only in version 5 (Mac OS X 10.6, iPhoneOS 3.0) and later */
const char* dyldVersion;
const char* errorMessage;
uintptr_t terminationFlags;
/* the following field is only in version 6 (Mac OS X 10.6, iPhoneOS 3.1) and later */
void* coreSymbolicationShmPage;
/* the following field is only in version 7 (Mac OS X 10.6, iPhoneOS 3.1) and later */
uintptr_t systemOrderFlag;
/* the following field is only in version 8 (Mac OS X 10.7, iPhoneOS 3.1) and later */
uintptr_t uuidArrayCount;
const struct dyld_uuid_info* uuidArray; /* only images not in dyld shared cache */
/* the following field is only in version 9 (Mac OS X 10.7, iOS 4.0) and later */
struct dyld_all_image_infos* dyldAllImageInfosAddress;
/* the following field is only in version 10 (Mac OS X 10.7, iOS 4.2) and later */
uintptr_t initialImageCount;
/* the following field is only in version 11 (Mac OS X 10.7, iOS 4.2) and later */
uintptr_t errorKind;
const char* errorClientOfDylibPath;
const char* errorTargetDylibPath;
const char* errorSymbol;
/* the following field is only in version 12 (Mac OS X 10.7, iOS 4.3) and later */
uintptr_t sharedCacheSlide;
/* the following field is only in version 13 (Mac OS X 10.9, iOS 7.0) and later */
uint8_t sharedCacheUUID[16];
/* the following field is only in version 15 (macOS 10.12, iOS 10.0) and later */
uintptr_t sharedCacheBaseAddress;
// the rest is ommitted... you get the idea
};
int main(int argc, const char * argv[]) {
mach_msg_type_number_t count = TASK_DYLD_INFO_COUNT;
struct dyld_all_image_infos *images = NULL;
task_info(mach_task_self(), TASK_DYLD_INFO, (task_info_t)&images, &count);
__builtin_dump_struct(images, &printf);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment