Skip to content

Commit

Permalink
RTTI: Fix crash if names demangled in target binary already
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Sep 9, 2023
1 parent de31414 commit 8428a3a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ if(CMKR_ROOT_PROJECT)
configure_file(cmake.toml cmake.toml COPYONLY)
endif()


add_compile_options($<$<CXX_COMPILER_ID:MSVC>:/MP>)

project(regenny)

if(CMKR_ROOT_PROJECT AND NOT CMKR_DISABLE_VCPKG)
Expand Down Expand Up @@ -164,6 +167,10 @@ target_compile_features(regenny PRIVATE
cxx_std_17
)

target_compile_options(regenny PRIVATE
"/EHa"
)

target_include_directories(regenny PRIVATE
"src/"
"thirdparty/scope_gaurd/"
Expand Down
4 changes: 4 additions & 0 deletions cmake.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Reference: https://build-cpp.github.io/cmkr/cmake-toml
[project]
name = "regenny"
cmake-before="""
add_compile_options($<$<CXX_COMPILER_ID:MSVC>:/MP>)
"""

[vcpkg]
version = "2022.08.15"
Expand Down Expand Up @@ -67,6 +70,7 @@ link-libraries = [
]
compile-definitions = ["UTF_CPP_CPLUSPLUS=201103L"]
compile-features = ["cxx_std_17"]
compile-options = ["/EHa"]
cmake-after="""
add_custom_command(
TARGET regenny POST_BUILD
Expand Down
7 changes: 6 additions & 1 deletion src/arch/Windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ std::optional<std::string> WindowsProcess::get_typename(uintptr_t ptr) {
return get_typename_from_vtable(*vtable);
}

std::optional<std::string> WindowsProcess::get_typename_from_vtable(uintptr_t ptr) {
std::optional<std::string> WindowsProcess::get_typename_from_vtable(uintptr_t ptr) try {
if (ptr == 0) {
return std::nullopt;
}
Expand All @@ -285,13 +285,18 @@ std::optional<std::string> WindowsProcess::get_typename_from_vtable(uintptr_t pt
return std::nullopt;
}

auto raw_data = (__std_type_info_data*)((uintptr_t)ti + sizeof(void*));
raw_data->_UndecoratedName = nullptr; // fixes a crash if memory already allocated because it's not allocated by us

const auto result = std::string_view{ti->name()};

if (result.empty() || result == " ") {
return std::nullopt;
}

return std::string{result};
} catch(...) {
return std::nullopt;
}

std::map<uint32_t, std::string> WindowsHelpers::processes() {
Expand Down

0 comments on commit 8428a3a

Please sign in to comment.