Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Linux Sys Func Hook
#include <assert.h>
#include <dlfcn.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
static bool is_hook = false;
int main() {
int fd = open("/dev/null", O_WRONLY);
const char *buffer = "hello dlsym";
size_t len = write(fd, buffer, strlen(buffer));
assert(len == strlen(buffer));
typedef ssize_t (*WriteFunc)(int fd, const void *buf, size_t nbyte);
static WriteFunc sys_write = (WriteFunc)dlsym(RTLD_NEXT, "write"); // need C++
ssize_t write(int fd, const void *buf, size_t nbyte) {
is_hook = true;
return sys_write(fd, buf, nbyte);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.