fork(1) download
  1. #include <iostream>
  2. #include <sstream>
  3. #include <vector>
  4. #include <string>
  5. #include <map>
  6. #include <unordered_map>
  7. #include <sys/time.h>
  8. using namespace std;
  9.  
  10. class HogeSDKClass {
  11. public:
  12. HogeSDKClass()
  13. : value_(9999)
  14. {
  15.  
  16. }
  17. void print() {
  18. printf("%d\n", value_);
  19. }
  20. private:
  21. int value_; // この値は不可侵である
  22. };
  23.  
  24. class HogeSDKClassHack {
  25. public:
  26. void hackValue() {
  27. this->value_ = 1000;
  28. }
  29. protected:
  30. int value_; // 不可侵な値のダミー
  31. };
  32.  
  33. HogeSDKClass* getHogeSDKInstance() {
  34. return new HogeSDKClass(); // これはSDKからやってくる
  35. }
  36.  
  37. int main() {
  38. HogeSDKClass* hoge = getHogeSDKInstance();
  39. hoge->print(); // この値を書き換えたい……。
  40.  
  41. HogeSDKClassHack* hogeHack = reinterpret_cast<HogeSDKClassHack*>(hoge);
  42.  
  43. hogeHack->hackValue();
  44. hoge->print();
  45.  
  46. return 0;
  47. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
9999
1000