Last active
August 29, 2017 19:49
-
-
Save vic511/9c9a759afb5b1d370287fda32c104f71 to your computer and use it in GitHub Desktop.
Dynamic reloading PoC
This file contains hidden or 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 <stdbool.h> | |
| bool hello(void) | |
| { | |
| if (printf("Hello first\n") < 0) | |
| return false; | |
| return true; | |
| } |
This file contains hidden or 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
| CC = gcc | |
| CFLAGS = -Wall -Wextra -std=gnu99 | |
| LDFLAGS = -ldl | |
| RM = rm -f | |
| poc: poc.o first.so second.so | |
| first.so: first.c | |
| $(CC) $(CFLAGS) -shared -fPIC -o $@ $^ | |
| second.so: second.c | |
| $(CC) $(CFLAGS) -shared -fPIC -o $@ $^ | |
| fclean: | |
| $(RM) first.so second.so poc.o poc | |
| re: fclean poc |
This file contains hidden or 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 <stdlib.h> | |
| #include <stdbool.h> | |
| #include <stdio.h> | |
| #include <dlfcn.h> | |
| #define ERROR(NAME) ({ perror(NAME); false; }) | |
| typedef bool (*t_hellofunc)(void); | |
| static bool callhello(void *handle) | |
| { | |
| t_hellofunc hello = NULL; | |
| hello = dlsym(handle, "hello"); | |
| if (hello == NULL) | |
| return ERROR("dlsym"); | |
| return hello(); | |
| } | |
| static bool poc(const char *library) | |
| { | |
| bool ret = true; | |
| void *handle = NULL; | |
| handle = dlopen(library, RTLD_LAZY); | |
| if (handle == NULL) | |
| return ERROR("dlopen"); | |
| ret = callhello(handle); | |
| if (dlclose(handle) != 0) | |
| return ERROR("dlclose"); | |
| return ret; | |
| } | |
| int main(void) | |
| { | |
| if (!poc("first.so")) | |
| return EXIT_FAILURE; | |
| if (!poc("second.so")) | |
| return EXIT_FAILURE; | |
| return EXIT_SUCCESS; | |
| } |
This file contains hidden or 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 <stdbool.h> | |
| bool hello(void) | |
| { | |
| if (printf("Hello second\n") < 0) | |
| return false; | |
| return true; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment