Skip to content

Instantly share code, notes, and snippets.

@garymacindoe
Created July 29, 2015 13:55
Show Gist options
  • Save garymacindoe/580e15c765923feee703 to your computer and use it in GitHub Desktop.
Save garymacindoe/580e15c765923feee703 to your computer and use it in GitHub Desktop.
Calling a private method through the vtable
#include <iostream>
class A {
virtual void function() const {
std::cout << "You bastard!" << std::endl;
}
};
int main() {
A a;
std::size_t * ptr = *(std::size_t **)&a;
((void (*)())ptr[0])();
return 0;
}
@garymacindoe
Copy link
Author

Works in clang 3.6 and gcc 5 compiled with -std=c++11 -pedantic -Wall -Wextra.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment