Skip to content

Instantly share code, notes, and snippets.

@ethercflow
Created July 2, 2018 07:23
Show Gist options
  • Save ethercflow/1453bc1b0b207c9d9469b48f6723c172 to your computer and use it in GitHub Desktop.
Save ethercflow/1453bc1b0b207c9d9469b48f6723c172 to your computer and use it in GitHub Desktop.
#define _GNU_SOURCE
#include <stdio.h>
#include <unistd.h>
#include <dlfcn.h>
ssize_t read(int fd, void *buf, size_t count) {
ssize_t (*origin_read)(int, void*, size_t) = dlsym(RTLD_NEXT, "read");
sleep(5);
printf("read sleep 5s\n");
return origin_read(fd, buf, count);
}
@ethercflow
Copy link
Author

usage:

  1. gcc -shared -fPIC hook_read.c -o libhook_read.so -ldl;
  2. before run apps export LD_PRELOAD=pwd/libhook_read.so;
  3. run apps under this shell;
  4. after running export LD_PRELOAD=""

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment