| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
#include "translations.h" |
| 16 |
|
| 17 |
#include <gotcha/gotcha.h> |
| 18 |
|
| 19 |
#include "gotcha_utils.h" |
| 20 |
|
| 21 |
int main_wrapped; |
| 22 |
gotcha_wrappee_handle_t gotcha_internal_libc_main_wrappee_handle; |
| 23 |
gotcha_wrappee_handle_t gotcha_internal_main_wrappee_handle; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
int gotcha_internal_main(int argc, char **argv, char **envp) { |
| 30 |
main_t underlying_main = |
| 31 |
gotcha_get_wrappee(gotcha_internal_main_wrappee_handle); |
| 32 |
return underlying_main(argc, argv, envp); |
| 33 |
} |
| 34 |
|
| 35 |
int gotcha_internal_libc_start_main(int (*main_arg)(int, char **, char **) |
| 36 |
KNOWN_UNUSED, |
| 37 |
int argc, char **argv, void (*init)(), |
| 38 |
void (*fini)(), void (*rtld_fini)(), |
| 39 |
void *stack_end) { |
| 40 |
libc_start_main_t underlying_libc_main = |
| 41 |
gotcha_get_wrappee(gotcha_internal_libc_main_wrappee_handle); |
| 42 |
main_t underlying_main = |
| 43 |
gotcha_get_wrappee(gotcha_internal_main_wrappee_handle); |
| 44 |
return underlying_libc_main(underlying_main, argc, argv, init, fini, |
| 45 |
rtld_fini, stack_end); |
| 46 |
} |
| 47 |
|
| 48 |
struct gotcha_binding_t libc_main_wrappers[] = { |
| 49 |
{"__libc_start_main", gotcha_internal_libc_start_main, |
| 50 |
&gotcha_internal_libc_main_wrappee_handle}}; |
| 51 |
struct gotcha_binding_t main_wrappers[] = { |
| 52 |
{"main", gotcha_internal_main, &gotcha_internal_main_wrappee_handle}}; |