fork download
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5.  
  6. const volatile int v1 = 0;
  7. volatile unsigned v2 = 0;
  8.  
  9. void Fxn1()
  10. {
  11. if (v1) { v2 = 0x12345601; }
  12. cout << "Fxn1" << endl;
  13. }
  14.  
  15. void Fxn2()
  16. {
  17. if (v1) { v2 = 0x12345602; }
  18. cout << "Fxn2" << endl;
  19. }
  20.  
  21. int FindFxnConst(void(*f)())
  22. {
  23. const unsigned char* p = (const unsigned char*)f;
  24. while (memcmp(p, "\x56\x34\x12", 3))
  25. p++;
  26. return p[-1];
  27. }
  28.  
  29. int main()
  30. {
  31. Fxn1();
  32. cout << FindFxnConst(Fxn1) << endl;
  33. Fxn2();
  34. cout << FindFxnConst(Fxn2) << endl;
  35. return 0;
  36. }
  37.  
Success #stdin #stdout 0s 2896KB
stdin
Standard input is empty
stdout
Fxn1
1
Fxn2
2