Skip to content

Instantly share code, notes, and snippets.

@julian7
Created January 23, 2019 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save julian7/d5b61c981dd84707297e04114b2fcc1e to your computer and use it in GitHub Desktop.
Save julian7/d5b61c981dd84707297e04114b2fcc1e to your computer and use it in GitHub Desktop.
// 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