From 07d0e3f4c4ed089c266b5ccd6ced3f7b109ab2ea Mon Sep 17 00:00:00 2001 From: Mark Rowe Date: Fri, 9 May 2025 16:16:33 -0700 Subject: [RTTI] Handle type names emitted by GCC with a leading `*` GCC emits a leading `*` to indicate that the type info is internal and its name can be compared via pointer equality. It is not part of the type name. This was only being handled when followed with `N`, but it can apply to any mangled name. Additionally, this updates some `std::string::find(...) == 0` calls in the adjacent code to use `std::string::rfind(..., 0) == 0` as that bails out of the string comparison as soon as the prefix does not match, rather than continuing to search the entire string. --- plugins/rtti/rtti.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'plugins/rtti/rtti.cpp') diff --git a/plugins/rtti/rtti.cpp b/plugins/rtti/rtti.cpp index 3f6abe94..23b13fde 100644 --- a/plugins/rtti/rtti.cpp +++ b/plugins/rtti/rtti.cpp @@ -21,14 +21,15 @@ std::optional RTTI::DemangleNameGNU3(BinaryView* view, bool allowMa std::string adjustedMangledName = mangledName; // For some reason some of the names that start with ZN are not prefixed by `_`. - if (adjustedMangledName.find("ZN") == 0) + if (adjustedMangledName.rfind("ZN", 0) == 0) adjustedMangledName = "_" + adjustedMangledName; - // Sometimes some std types will have a * prefixed, IDK what it means, but we need to remove it to demangle. - if (adjustedMangledName.find("*N") == 0) + // GCC emits a leading * to indicate that the type info is internal and its + // name can be compared via pointer equality. It is not part of the type name. + if (adjustedMangledName.rfind("*", 0) == 0) adjustedMangledName = adjustedMangledName.substr(1); // All types at this point should have a _Z prefix, if not, we likely need to just call the demangler directly, as this // function is specific to dealing with mangled _type_ names. - if (adjustedMangledName.find("_Z") != 0) + if (adjustedMangledName.rfind("_Z", 0) != 0) adjustedMangledName = "_Z" + adjustedMangledName; if (!DemangleGNU3(view->GetDefaultArchitecture(), adjustedMangledName, outType, demangledName, true)) -- cgit v1.3.1