Created
January 23, 2019 17:51
-
-
Save julian7/d5b61c981dd84707297e04114b2fcc1e to your computer and use it in GitHub Desktop.
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 -shared -fPIC -o liboverride_strcmp.so -ldl override_strcmp.c | |
// LD_PRELOAD=$PWD/liboverride_strcmp.so <command> | |
#define _GNU_SOURCE 1 | |
#include <stdio.h> | |
#include <string.h> | |
#include <dlfcn.h> | |
#define MAGIC "MAGIC" | |
int strcmp(const char *s1, const char *s2) { | |
int (*orig_strcmp)(const char *, const char *) = dlsym(RTLD_NEXT, "strcmp"); | |
if (!strncmp(s1, MAGIC, 5)) { | |
printf("Magic s1 vs. %s\n", s2); | |
} else if (!strncmp(s2, MAGIC, 5)) { | |
printf("Magic s2 vs %s\n", s1); | |
} | |
return orig_strcmp(s1, s2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment