//gcc main_hook.c -o main_hook.so -fPIC -shared -ldl
/* Trampoline for the real main() */
static int (*main_orig)(int, char **, char **);
/* Our fake main() that gets called by __libc_start_main() */
int main_hook(int argc, char **argv, char **envp)
//<arg declarations here>
char user_buf[512] = {"\x00"};
//scanf("%512s", user_buf);
int (*do_thing_ptr)(char *, int, int) = 0x401f30;
int ret_val = (*do_thing_ptr)(user_buf, 0, 0);
printf("Ret val %d\n",ret_val);
* Wrapper for __libc_start_main() that replaces the real main
* function with our hooked version.
int (*main)(int, char **, char **),
int (*init)(int, char **, char **),
/* Save the real main function address */
/* Find the real __libc_start_main()... */
typeof(&__uClibc_main) orig = dlsym(RTLD_NEXT, "__uClibc_main");
/* ... and call it with our custom main function */
return orig(main_hook, argc, argv, init, fini, rtld_fini, stack_end);