Advertisement
Guest User

Untitled

a guest
Nov 10th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 KB | None | 0 0
  1. #define echo(x) x
  2.  
  3. #define random_var echo(__)echo(__LINE__)
  4.  
  5. #define MAKE_VAR(x) static void echo(fakeFn)echo(__LINE__)() { if (&x)__debugbreak(); }
  6.  
  7. #define ADD_INITIALIZER(section, function) \
  8.     __pragma(const_seg(section)) \
  9.     static INITIALIZER random_var = function; \
  10.     MAKE_VAR(random_var)
  11.  
  12. typedef void (__cdecl * const INITIALIZER)();
  13.  
  14. #pragma const_seg("mydata$a")  
  15. INITIALIZER firstInitializer = 0;
  16.  
  17. #pragma const_seg("mydata$z")  
  18. INITIALIZER lastInitializer = 0;
  19.  
  20. void InitializeAllTheThings(INITIALIZER * pfbegin, INITIALIZER * pfend) {
  21.     do {
  22.         if (INITIALIZER initializer = *pfbegin++) initializer();
  23.     } while(pfbegin < pfend);
  24. }
  25.  
  26. void InitializeAllTheThings()
  27. {
  28.     InitializeAllTheThings(&firstInitializer, &lastInitializer);
  29. }
  30.  
  31. void __cdecl someFunc1();
  32. void __cdecl someFunc2();
  33. void __cdecl someFunc3();
  34.  
  35. #pragma warning(disable : 4505) // unreferenced local function has been removed
  36.  
  37. ADD_INITIALIZER("mydata$u", someFunc1)
  38. ADD_INITIALIZER("mydata$u", someFunc2)
  39. ADD_INITIALIZER("mydata$c", someFunc3)
  40.  
  41. #pragma warning(default : 4505) // unreferenced local function has been removed
  42.  
  43. ///////////////////////////////////////////////////////////////////////////////
  44.  
  45. void __cdecl someFunc1() {
  46.     DbgPrint("%s\n", __FUNCTION__);
  47. }
  48.  
  49. void __cdecl someFunc2() {
  50.     DbgPrint("%s\n", __FUNCTION__);
  51. }
  52.  
  53. void __cdecl someFunc3() {
  54.     DbgPrint("%s\n", __FUNCTION__);
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement