Lucas Teske ревизий этого фрагмента 8 years ago. К ревизии
1 file changed, 45 insertions
shim_search.c(файл создан)
| @@ -0,0 +1,45 @@ | |||
| 1 | + | // For RTLD_NEXT | |
| 2 | + | #define _GNU_SOURCE | |
| 3 | + | ||
| 4 | + | #include <stdio.h> | |
| 5 | + | #include <dlfcn.h> | |
| 6 | + | #include <stdlib.h> | |
| 7 | + | #include <string.h> | |
| 8 | + | ||
| 9 | + | static FILE *(*real_fopen)(const char *, const char *) = NULL; | |
| 10 | + | ||
| 11 | + | #define SEARCH_TOKEN_SIZE 6 | |
| 12 | + | char mySearchToken[SEARCH_TOKEN_SIZE] = "That's"; | |
| 13 | + | ||
| 14 | + | void *searchData(char *data, int len, void *start, void *end) { | |
| 15 | + | void *i; | |
| 16 | + | ||
| 17 | + | for(i = start; i < end; i += 1) { | |
| 18 | + | if (memcmp(i, data, len) == 0 && i != (void *)data) { | |
| 19 | + | return i; | |
| 20 | + | } | |
| 21 | + | } | |
| 22 | + | ||
| 23 | + | return NULL; | |
| 24 | + | } | |
| 25 | + | ||
| 26 | + | ||
| 27 | + | FILE * fopen ( const char * filename, const char * mode ) { | |
| 28 | + | printf("HUEBR, GIBE DATA PLOS, OR I REPORT U HUEHUE\n"); | |
| 29 | + | printf("MI NO LIK U FIL, MI UPEN HUE.TXT\n"); | |
| 30 | + | ||
| 31 | + | return real_fopen("hue.txt", "w"); | |
| 32 | + | } | |
| 33 | + | ||
| 34 | + | void __attribute__((constructor)) initialize(void) { | |
| 35 | + | real_fopen = dlsym(RTLD_NEXT, "fopen"); | |
| 36 | + | ||
| 37 | + | if (real_fopen == NULL) { | |
| 38 | + | printf("What? We couldn't find our fopen!!!!\n"); | |
| 39 | + | exit(255); // This will crash the program since it isn't expecting to exit in the constructor | |
| 40 | + | } | |
| 41 | + | ||
| 42 | + | void *addr = searchData(mySearchToken, SEARCH_TOKEN_SIZE, (void *)0x4006e0, (void*)0x400791 ); // Thats for 64 bit. | |
| 43 | + | ||
| 44 | + | printf("Token Addr: %p\n", addr); | |
| 45 | + | } | |
Новее
Позже