Skip to content

Commit

Permalink
rtti::is_vtable
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Sep 25, 2024
1 parent f21fff2 commit 153b177
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/utility/RTTI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ struct _s_RTTICompleteObjectLocator;

namespace utility {
namespace rtti {
bool is_vtable(const void* vtable);
_s_RTTICompleteObjectLocator* get_locator(const void* obj);
std::type_info* get_type_info(const void* obj);
std::type_info* get_type_info(HMODULE m, std::string_view type_name);
Expand Down
22 changes: 22 additions & 0 deletions src/RTTI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,28 @@ std::optional<HMODULE> cached_get_module_within(uintptr_t addr) {
}
}

bool is_vtable(const void* vtable) {
if (vtable == nullptr) {
return false;
}

const auto module_within = detail::cached_get_module_within((uintptr_t)vtable);

if (!module_within) {
return false;
}

bool result = false;

detail::for_each(*module_within, [&](const detail::Vtable& entry) {
if (entry.vtable == (uintptr_t)vtable) {
result = true;
}
});

return result;
}

_s_RTTICompleteObjectLocator* get_locator(const void* obj) {
if (obj == nullptr || *(void**)obj == nullptr) {
return nullptr;
Expand Down

0 comments on commit 153b177

Please sign in to comment.