Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Test.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <stdio.h>
- #define SEPARATOR printf("====================\n")
- class SomeClass
- {
- public:
- virtual void Init() {}
- virtual void Go() {}
- virtual void SomethingElse() {}
- virtual void Shutdown() {}
- };
- void DumpVTable(void* baseclass)
- {
- void**& vtable = *(void***)baseclass;
- printf("vtable: 0x%p\n", (void*)vtable);
- for (size_t index = 0; vtable[index]; index++)
- {
- // Ignore outliers
- static uintptr_t last_entry = (uintptr_t)vtable[index];
- if (((uintptr_t)vtable[index] - last_entry) > 0xFFF) continue;
- printf("[%i] 0x%p\n", index, (void*)vtable[index]);
- }
- }
- template <typename Fn> void*& Get(Fn a)
- {
- return (void*&)a;
- }
- int main()
- {
- SEPARATOR;
- SomeClass* instance = new SomeClass();
- printf("SomeClass instance: 0x%p\n", (void*)instance);
- SEPARATOR;
- printf("VTable address dump:\n");
- DumpVTable(instance);
- SEPARATOR;
- SomeClass* other_instance = new SomeClass();
- printf("SomeClass other_instance: 0x%p\n", (void*)other_instance);
- SEPARATOR;
- printf("VTable address dump:\n");
- DumpVTable(other_instance);
- SEPARATOR;
- auto init_address = &SomeClass::Init;
- void* init_ptr = Get(init_address);
- printf("Address of SomeClass::Init 0x%p\n", init_ptr);
- void**& instance_vtable = *(void***)instance;
- printf("instance_vtable[0] + 0x%X: 0x%p\n", 0x2D, (uintptr_t)(instance_vtable[0]) + 0x2D);
- auto go_address = &SomeClass::Go;
- void* go_ptr = Get(go_address);
- printf("Address of SomeClass::Go 0x%p\n", go_ptr);
- printf("instance_vtable[1] + 0x%X: 0x%p\n", 0x28, (uintptr_t)(instance_vtable[1]) + 0x28);
- auto something_address = &SomeClass::SomethingElse;
- void* something_ptr = Get(go_address);
- printf("Address of SomeClass::SomethingElse 0x%p\n", something_ptr);
- printf("instance_vtable[2] + 0x%X: 0x%p\n", 0x1E, (uintptr_t)(instance_vtable[2]) + 0x1E);
- auto shutdown_address = &SomeClass::Shutdown;
- void* shutdown_ptr = Get(shutdown_address);
- printf("Address of SomeClass::SomethingElse 0x%p\n", shutdown_ptr);
- printf("instance_vtable[4] + 0x%X: 0x%p\n", 0x2D, (uintptr_t)(instance_vtable[3]) + 0x2D);
- std::cin.get();
- return 0;
- }
Add Comment
Please, Sign In to add comment