Created
October 28, 2018 12:46
-
-
Save heatblazer/35b6c16a577aa53c896a4cd186629e11 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
class A | |
{ | |
int a, b, c, d; | |
public: | |
A() : a(1), b(2), c(3), d(4) {} | |
int getsum() | |
{ | |
return a+b+c+d; | |
} | |
}; | |
static void hackit() | |
{ | |
struct B | |
{ | |
int a, b, c, d; | |
B() : a(1), b(2), c(3), d(4) {} | |
int getsum() | |
{ | |
return a+b+c+d; | |
} | |
}; | |
A a; | |
B* b = reinterpret_cast<B*>(&a); | |
b->a = 10; | |
b->b = 10; | |
b->c = 10; | |
b->d = 10; | |
std::cout << a.getsum() << "\r\n"; | |
} | |
int main() | |
{ | |
hackit(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment