-
-
Notifications
You must be signed in to change notification settings - Fork 158
/
Copy pathexecve-wrapper.c
107 lines (77 loc) · 2.71 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
* SNOOPY COMMAND LOGGER
*
* 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 "init-deinit.h"
#include "action/log-syscall-exec.h"
#include "inputdatastorage.h"
#include <dlfcn.h>
#include <stddef.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()
*/
__attribute__((visibility("default"))) int execv (const char *filename, char *const argv[]) {
static int (*func)(const char *, char * const *);
FN(func, int, "execv", (const char *, char * const *));
char *envp[] = { NULL };
snoopy_entrypoint_execve_wrapper_init(filename, argv, envp);
snoopy_action_log_syscall_exec();
snoopy_entrypoint_execve_wrapper_exit();
return (*func) (filename, argv);
}
/*
* Function wrapper - execve()
*/
__attribute__((visibility("default"))) int execve (const char *filename, char *const argv[], char *const envp[])
{
static int (*func)(const char *, char * const *, char * const *);
FN(func, int, "execve", (const char *, char * const *, char * const *));
snoopy_entrypoint_execve_wrapper_init(filename, argv, envp);
snoopy_action_log_syscall_exec();
snoopy_entrypoint_execve_wrapper_exit();
return (*func) (filename, argv, envp);
}
void snoopy_entrypoint_execve_wrapper_init (const char *filename, char *const argv[], char *const envp[])
{
snoopy_init();
snoopy_inputdatastorage_store_filename(filename);
snoopy_inputdatastorage_store_argv(argv);
snoopy_inputdatastorage_store_envp(envp);
}
void snoopy_entrypoint_execve_wrapper_exit ()
{
snoopy_cleanup();
}