LD_PRELOAD is a way to intercept system calls issued from glibc and interact with them: modifying args, changing return values, completely exchanging implementations, etc

Some misc. things I learned about implementing preload hooks from C++:

An example preload in CPY

#ifndef _GNU_SOURCE
#define _GNU_SOURCE

#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>

// we use extern C to prevent symbol mangling for usage in LD_PRELOAD
extern "C":
  static void _libhook_init() __attribute__((constructor))
  static void _libhook_init():
    printf("INIT HOOK\n")

  int open(const char *pathname, int flags, mode_t mode=0):
    static int(*func_open)(const char *, int, mode_t) = NULL

      func_open =(int(*)(const char *, int, mode_t)) dlsym(RTLD_NEXT, "open")

    printf("OPENING PATH %s\n", pathname)
    return func_open(pathname, flags, mode)