Skip to content

Instantly share code, notes, and snippets.

@k3170makan
Last active October 6, 2018 04:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k3170makan/400b7d9a41a90a580bf1a8dada546a81 to your computer and use it in GitHub Desktop.
Save k3170makan/400b7d9a41a90a580bf1a8dada546a81 to your computer and use it in GitHub Desktop.
Example of a constructor function
#include <stdio.h>
void never_call(void){
printf("[*] success!! call to function never_call!!!\n\n");
}
void __attribute__ ((destructor)) foo_destructor(void){
printf("[*] hay! you called by destructor!! \n");
return;
}
void __attribute__ ((constructor)) foo_constructor(void){
printf("[*] hay! you called by constructor!! \n");
return;
}
int main(int argc, char **argv){
printf("[*] call to main function\n");
return 0;
}
/*
> ./init_fini.elf
[*] hay! you called by constructor!!
[*] call to main function
[*] hay! you called by destructor!!
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment