Skip to content

Instantly share code, notes, and snippets.

@ch1c0t
Last active March 26, 2017 13:32
Show Gist options
  • Save ch1c0t/57f6d9357c9c9b205de2bd31703b62cb to your computer and use it in GitHub Desktop.
Save ch1c0t/57f6d9357c9c9b205de2bd31703b62cb to your computer and use it in GitHub Desktop.
#define _GNU_SOURCE
#include <dlfcn.h>
#include <unistd.h>
#include <stdio.h>
typedef int (*LibcStartMainFnType)(int (*main)(int, char **, char **), int argc, char **argv,
int (*init)(void), void (*fini)(void),
void (*ldso_fini)(void), void (*stack_end));
int __libc_start_main(int (*main)(int, char **, char **), int argc, char **argv,
int (*init)(void), void (*fini)(void),
void (*ldso_fini)(void), void (*stack_end)) {
LibcStartMainFnType original = (LibcStartMainFnType)dlsym(RTLD_NEXT, "__libc_start_main");
puts("before original");
int result = original(main, argc, argv, init, fini, ldso_fini, stack_end);
return result;
}
// gcc -Wall -fPIC -DPIC -c override.c
// ld -shared -o override.so override.o -ldl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment