Advertisement
Guest User

Untitled

a guest
May 24th, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdint.h>
  3.  
  4.  
  5. typedef void** VTABLE;
  6.  
  7.  
  8. struct Foo {
  9. virtual void
  10. bar() {
  11. printf("Hello\n");
  12. }
  13. };
  14.  
  15.  
  16. void
  17. patchedBar(Foo* foo) {
  18. printf("Patched\n");
  19. }
  20.  
  21.  
  22. int
  23. main(int argc, char *argv[]) {
  24. Foo* foo = new Foo();
  25. VTABLE vtable = *(VTABLE*)foo;
  26.  
  27. foo->bar();
  28.  
  29. void (Foo::* ptr)() = &Foo::bar;
  30. void* offset = *(VTABLE)&ptr;
  31. vtable[((uintptr_t)offset)/sizeof(void*)] = (void*)&patchedBar;
  32.  
  33. foo->bar();
  34.  
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement