Skip to content

Instantly share code, notes, and snippets.

@nrdmn
Created November 28, 2020 12:54
Show Gist options
  • Save nrdmn/a405ac6f129542866ef1c21e19dfb5d0 to your computer and use it in GitHub Desktop.
Save nrdmn/a405ac6f129542866ef1c21e19dfb5d0 to your computer and use it in GitHub Desktop.
LD_PRELOAD and varargs
#define _GNU_SOURCE
#include <dlfcn.h>
#include <fcntl.h>
int fcntl(int fd, int cmd, ...)
{
if (cmd == F_OFD_SETLKW || cmd == F_OFD_SETLK) {
return 0;
}
int (*orig)(int, int, ...) = dlsym(RTLD_NEXT, "fcntl");
int *arg = __builtin_apply_args();
void *ret = __builtin_apply((void *)orig, arg, 100);
__builtin_return(ret);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment