Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- void __cxa_finalize(void *d) {
- // Create environmental variable to track calls to __cxa_finalize().
- // Note that getenv() is called here. The "__cxa_finalize_called" string
- // has not yet been set as an environmental variable, so getenv() will
- // return NULL here.
- const char* cxa_called_str = getenv("__cxa_finalize_called");
- // track number of times __cxa_finalize() is called
- int cxa_called = 0;
- // string buffer
- char buf[100];
- printf("__cxa_finalize() called ");
- if (!cxa_called_str) { // on 1st call to __cxa_finalize(), cxa_called_str is NULL
- setenv("__cxa_finalize_called", "1", 1); // create environmental variable key : value pair
- printf("1 time!\n");
- printf("I <3 LD_PRELOAD\n");
- }
- else {
- cxa_called = atoi(cxa_called_str);
- cxa_called += 1; // increment library function call counter
- printf("%d times!\n", cxa_called);
- sprintf(buf, "%d", cxa_called); // convert integer to string
- setenv("__cxa_finalize_called", buf, 1); // update environmental variable value with new count
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement