Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void __cxa_finalize(void *d) {
  5. // Create environmental variable to track calls to __cxa_finalize().
  6. // Note that getenv() is called here. The "__cxa_finalize_called" string
  7. // has not yet been set as an environmental variable, so getenv() will
  8. // return NULL here.
  9. const char* cxa_called_str = getenv("__cxa_finalize_called");
  10.  
  11. // track number of times __cxa_finalize() is called
  12. int cxa_called = 0;
  13.  
  14. // string buffer
  15. char buf[100];
  16.  
  17. printf("__cxa_finalize() called ");
  18. if (!cxa_called_str) { // on 1st call to __cxa_finalize(), cxa_called_str is NULL
  19. setenv("__cxa_finalize_called", "1", 1); // create environmental variable key : value pair
  20. printf("1 time!\n");
  21. printf("I <3 LD_PRELOAD\n");
  22. }
  23. else {
  24. cxa_called = atoi(cxa_called_str);
  25. cxa_called += 1; // increment library function call counter
  26. printf("%d times!\n", cxa_called);
  27. sprintf(buf, "%d", cxa_called); // convert integer to string
  28. setenv("__cxa_finalize_called", buf, 1); // update environmental variable value with new count
  29. }
  30. return;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement