Skip to content

Instantly share code, notes, and snippets.

@komang4130
Created December 23, 2017 09:26
Show Gist options
  • Save komang4130/61a6c5ad1df2331979603915b3ea78ac to your computer and use it in GitHub Desktop.
Save komang4130/61a6c5ad1df2331979603915b3ea78ac to your computer and use it in GitHub Desktop.
#define _GNU_SOURCE
#include <dlfcn.h>
#include <stdio.h>
#include <string.h>
#include <linux/input.h>
/* Function pointers to hold the value of the glibc functions */
static ssize_t (*real_write)(int fd, const void *buf, size_t count) = NULL;
/* wrapping write function call */
ssize_t write(int fd, const void *buf, size_t count)
{
FILE *file = fopen("/home/komang4130/Desktop/Viettel/challenge1/abc.txt","r");
if ( file == NULL )
{
file = fopen("/home/komang4130/Desktop/Viettel/challenge1/abc.txt","w");
fclose(file);
}
else
fclose(file);
real_write = dlsym(RTLD_NEXT, "write");
real_write(fd, buf, count);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment