Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- inline void Setup(void *base, const char * moduleName = false)
- {
- if (base != nullptr)
- class_base = base;
- if (class_base == nullptr)
- return;
- original_vtable = *(std::uintptr_t**)class_base;
- method_count = estimate_vftbl_length(original_vtable) * sizeof(std::uintptr_t);
- if (method_count == 0)
- return;
- if (moduleName)// If provided a module name then we will find a place in that module
- {
- shadow_vtable = search_free_data_page(moduleName, method_count + sizeof(std::uintptr_t));
- std::memset(shadow_vtable, NULL, method_count + sizeof(std::uintptr_t));
- std::memcpy(&shadow_vtable[1], original_vtable, method_count);
- shadow_vtable[0] = original_vtable[-1];
- try {
- auto guard = protect_guard{ class_base, sizeof(std::uintptr_t), PAGE_READWRITE };
- *(std::uintptr_t**)class_base = &shadow_vtable[1];
- if (table_is_hooked(base, moduleName))
- {
- Beep(500, 500);
- }
- }
- catch (...) {
- delete[] shadow_vtable;
- return;
- }
- }
- else // If not then we do regular vmthookinh
- {
- shadow_vtable = new std::uintptr_t[method_count + 1]();
- std::memcpy(&shadow_vtable[1], original_vtable, method_count);
- try {
- auto guard = protect_guard{ class_base, sizeof(std::uintptr_t), PAGE_READWRITE };
- shadow_vtable[0] = original_vtable[-1];
- *(std::uintptr_t**)class_base = &shadow_vtable[1];
- }
- catch (...) {
- delete[] shadow_vtable;
- return;
- }
- }
- return;
- }
- inline void RestoreTable()
- {
- try {
- if (original_vtable != nullptr) {
- auto guard = protect_guard{ class_base, sizeof(std::uintptr_t), PAGE_READWRITE };
- *(std::uintptr_t**)class_base = original_vtable;
- original_vtable = nullptr;
- }
- }
- catch (...) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement