Created
April 23, 2024 17:54
-
-
Save Cyberax/a60dce723d4e80a5d182d60677f1df98 to your computer and use it in GitHub Desktop.
macOS DYLD
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
#include <stdio.h> | |
__attribute__((constructor)) | |
static void initializer1() { | |
printf("[%s] [%s]\n", __FILE__, __FUNCTION__); | |
} | |
__attribute__((constructor)) | |
static void initializer2() { | |
printf("[%s] [%s]\n", __FILE__, __FUNCTION__); | |
} | |
__attribute__((constructor)) | |
static void initializer3() { | |
printf("[%s] [%s]\n", __FILE__, __FUNCTION__); | |
} | |
__attribute__((destructor)) | |
static void finalizer1() { | |
printf("[%s] [%s]\n", __FILE__, __FUNCTION__); | |
} | |
__attribute__((destructor)) | |
static void finalizer2() { | |
printf("[%s] [%s]\n", __FILE__, __FUNCTION__); | |
} | |
__attribute__((destructor)) | |
static void finalizer3() { | |
printf("[%s] [%s]\n", __FILE__, __FUNCTION__); | |
} |
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
$ gcc -dynamiclib -o test.dyld file.c | |
$ gcc trial.c | |
$ ./a.out | |
[file.c] [initializer1] | |
[file.c] [initializer2] | |
[file.c] [initializer3] | |
[trial.c] [main] Finished loading. Now quitting. | |
[file.c] [finalizer3] | |
[file.c] [finalizer2] | |
[file.c] [finalizer1] |
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
#include <stdio.h> | |
#include <dlfcn.h> | |
int main(int argc, char** argv) { | |
void *lib = dlopen("./test.dyld", RTLD_LAZY); | |
printf("[%s] [%s] Finished loading. Now quitting.\n", __FILE__, __FUNCTION__); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment