summaryrefslogtreecommitdiff
path: root/plugins/rtti
diff options
context:
space:
mode:
authorMark Rowe <mrowe@bdash.net.nz>2025-05-09 16:16:33 -0700
committerMason Reed <35282038+emesare@users.noreply.github.com>2025-05-09 20:57:33 -0400
commit07d0e3f4c4ed089c266b5ccd6ced3f7b109ab2ea (patch)
treed6372c7dba7a1a6b2ee27e2fec0b2380fb7f9b53 /plugins/rtti
parent77171115175039b2aef96f754005fea13d2b4375 (diff)
[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.
Diffstat (limited to 'plugins/rtti')
-rw-r--r--plugins/rtti/rtti.cpp9
1 files changed, 5 insertions, 4 deletions
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<std::string> 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))