Last active
April 9, 2022 04:56
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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