forked from a2o/snoopy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexecve_wrapper.c
79 lines (60 loc) · 2.01 KB
/
execve_wrapper.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
* SNOOPY LOGGER
*
* File: snoopy/eventsource/execve_wrapper.c
*
* Copyright (c) 2000 Marius Aamodt Eriksen <[email protected]>
* Copyright (c) 2000 Mike Baker <[email protected]>
* Copyright (c) 2010-2015 Bostjan Skufca <[email protected]>
*
* Part hacked on flight KL 0617, 30,000 ft or so over the Atlantic :)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* Includes order: from local to global
*/
#include "execve_wrapper.h"
#include "snoopy.h"
#include "log.h"
#include <dlfcn.h>
/*
* Helpers to find pointer to overloaded function
*/
#if defined(RTLD_NEXT)
# define REAL_LIBC RTLD_NEXT
#else
# define REAL_LIBC ((void *) -1L)
#endif
#define FN(ptr, type, name, args) ptr = (type (*)args)dlsym (REAL_LIBC, name)
/*
* Function wrapper - execv()
*/
int execv (const char *filename, char *const argv[]) {
static int (*func)(const char *, char **);
FN(func, int, "execv", (const char *, char **const));
snoopy_log_syscall_execv(filename, argv);
return (*func) (filename, (char **) argv);
}
/*
* Function wrapper - execve()
*/
int execve (const char *filename, char *const argv[], char *const envp[])
{
static int (*func)(const char *, char **, char **);
FN(func, int, "execve", (const char *, char **const, char **const));
snoopy_log_syscall_execve(filename, argv, envp);
return (*func) (filename, (char**) argv, (char **) envp);
}