Skip to content

Instantly share code, notes, and snippets.

@samdmarshall
Last active April 9, 2022 04:56
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save samdmarshall/7a808564d4e93b84f94b7ee0e0005ffd to your computer and use it in GitHub Desktop.
#import <Foundation/Foundation.h>
#include <mach-o/dyld.h>
uint32_t check_image(const struct mach_header *mh) {
struct mach_header *imageHeader;
uint32_t index;
for (index = 0; index < _dyld_image_count(); index++) {
imageHeader = (struct mach_header *)_dyld_get_image_header(index);
if ((int)memcmp(imageHeader, mh, sizeof(struct mach_header)) == 0) {
break;
}
}
return index;
}
void image_load(const struct mach_header* mh, intptr_t vmaddr_slide) {
uint32_t index = check_image(mh);
const char *name = (const char *)_dyld_get_image_name(index);
printf("%s\n", name);
}
int main(int argc, const char * argv[]) {
_dyld_register_func_for_add_image(image_load);
@autoreleasepool {
// insert code here...
NSLog(@"Hello, World!");
CFRunLoopRun();
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment