Created
January 27, 2012 12:37
-
-
Save ayosec/1688585 to your computer and use it in GitHub Desktop.
Wrap ioctls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sys/types.h> | |
#include <sys/stat.h> | |
#include <fcntl.h> | |
#include <stdlib.h> | |
#include <stdio.h> | |
#include <string.h> | |
#include <termios.h> | |
/*#include <sys/ioctl.h>*/ | |
#include <assert.h> | |
#include <dlfcn.h> | |
#include <unistd.h> | |
/* Avoid load the sys/ioctl.h header since it will conflict with our ioctl() definition */ | |
#define TIOCMGET 0x5415 | |
typedef int (*type_ioctl)(int __fd, unsigned long int __request, int *x); | |
int ioctl (int __fd, unsigned long int __request, int *x) { | |
static type_ioctl original_ioctl = NULL; | |
if(original_ioctl == NULL) { | |
void* libc = dlopen("libc.so.6", RTLD_LAZY); | |
original_ioctl = (type_ioctl)dlsym(libc, "ioctl"); | |
dlclose(libc); | |
} | |
if(__request == TIOCMGET) { | |
*x = 448; | |
return 0; | |
} | |
return original_ioctl(__fd, __request, x); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
all: fakeioctl.so | |
CFLAGS=-D_GNU_SOURCE -g -Wall | |
fakeioctl.so: fakeioctl.c | |
gcc $(CFLAGS) -fPIC -shared -ldl -o fakeioctl.so fakeioctl.c | |
.PHONY: all clean |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment