Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdint.h>
- typedef void** VTABLE;
- struct Foo {
- virtual void
- bar() {
- printf("Hello\n");
- }
- };
- void
- patchedBar(Foo* foo) {
- printf("Patched\n");
- }
- int
- main(int argc, char *argv[]) {
- Foo* foo = new Foo();
- VTABLE vtable = *(VTABLE*)foo;
- foo->bar();
- void (Foo::* ptr)() = &Foo::bar;
- void* offset = *(VTABLE)&ptr;
- vtable[((uintptr_t)offset)/sizeof(void*)] = (void*)&patchedBar;
- foo->bar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement