forked from avati/liboindirect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathliboindirect.c
56 lines (43 loc) · 1.36 KB
/
liboindirect.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
Bugs: [email protected]
*/
#include <dlfcn.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <pthread.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <ctype.h>
#define __cons __attribute__((constructor))
#define TRAP(func, params) \
evil_##func params; \
static int (*real_##func) params; \
static void set_real_##func (void) __cons; \
static void set_real_##func (void) \
{ real_##func = dlsym (RTLD_NEXT, #func); } \
int __REDIRECT (evil_##func, params, func); \
int evil_##func params
int
TRAP (open, (const char *path, int flags, mode_t mode))
{
if (flags & O_DIRECT)
flags &= ~O_DIRECT;
return real_open (path, flags, mode);
}
int
TRAP (open64, (const char *path, int flags, mode_t mode))
{
if (flags & O_DIRECT)
flags &= ~O_DIRECT;
return real_open64 (path, flags, mode);
}
int
TRAP (openat, (int dirfd, const char *path, int flags, mode_t mode))
{
if (flags & O_DIRECT)
flags &= ~O_DIRECT;
return real_openat (dirfd, path, flags, mode);
}