Skip to content

Instantly share code, notes, and snippets.

@heatblazer
Created October 28, 2018 12:46
Show Gist options
  • Save heatblazer/35b6c16a577aa53c896a4cd186629e11 to your computer and use it in GitHub Desktop.
Save heatblazer/35b6c16a577aa53c896a4cd186629e11 to your computer and use it in GitHub Desktop.
#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