diff options
| author | Mason Reed <mason@vector35.com> | 2025-03-19 23:20:09 -0400 |
|---|---|---|
| committer | Mason Reed <mason@vector35.com> | 2025-03-19 23:20:09 -0400 |
| commit | 038e625e0acecd64e4445cf42f154967735db1fd (patch) | |
| tree | 05743ac3dd24cbca3e7faaeccf64c908497c7b62 /plugins | |
| parent | 1aa0bd3b0e15113c90f87744a1c3bae4ae79a283 (diff) | |
Fallback to GNU3 demangler in Itanium RTTI
Diffstat (limited to 'plugins')
| -rw-r--r-- | plugins/rtti/rtti.cpp | 26 | ||||
| -rw-r--r-- | plugins/rtti/rtti.h | 2 |
2 files changed, 27 insertions, 1 deletions
diff --git a/plugins/rtti/rtti.cpp b/plugins/rtti/rtti.cpp index 91d3481c..57cd52cf 100644 --- a/plugins/rtti/rtti.cpp +++ b/plugins/rtti/rtti.cpp @@ -14,6 +14,27 @@ std::optional<std::string> RTTI::DemangleNameMS(BinaryView* view, bool allowMang } +std::optional<std::string> RTTI::DemangleNameGNU3(BinaryView* view, bool allowMangled, const std::string &mangledName) +{ + QualifiedName demangledName = {}; + Ref<Type> outType = {}; + + // TODO: This is disabled because most of the uses of this were making the problem worse by demangling + // TODO: To a very generic string that dozens of classes would then look like. We likely need to add some extra + // TODO: sauce to the demangler to pickup strings like: + // TODO: REAL: PackageListGui::PackageListGui(Filesystem::Path&&, PackageListGui::UnderSubheader, bool)::$_1[0x0] + // TODO: OURS: PackageListGui::PackageListGui + // TODO: OURS MANGLED: ZN14PackageListGuiC1EON10Filesystem4PathENS_14UnderSubheaderEbE3$_1 + // For some reason some of the names that start with ZN are not prefixed by `_`. + // if (mangled.find("ZN") == 0) + // mangled = "_" + mangled; + + if (!DemangleGNU3(view->GetDefaultArchitecture(), mangledName, outType, demangledName, true)) + return allowMangled ? std::optional(mangledName) : std::nullopt; + return demangledName.GetString(); +} + + std::string RemoveItaniumPrefix(std::string &name) { // Remove numerical prefixes. @@ -26,7 +47,10 @@ std::string RemoveItaniumPrefix(std::string &name) std::optional<std::string> RTTI::DemangleNameItanium(BinaryView* view, bool allowMangled, const std::string &mangledName) { - if (auto demangledName = DemangleNameLLVM(allowMangled, mangledName)) + // NOTE: Passing false to allowMangled to fallthrough to GNU3 demangler. + if (auto demangledName = DemangleNameLLVM(false, mangledName)) + return RemoveItaniumPrefix(demangledName.value()); + if (auto demangledName = DemangleNameGNU3(view, allowMangled, mangledName)) return RemoveItaniumPrefix(demangledName.value()); return std::nullopt; } diff --git a/plugins/rtti/rtti.h b/plugins/rtti/rtti.h index e2913db4..b46a33a1 100644 --- a/plugins/rtti/rtti.h +++ b/plugins/rtti/rtti.h @@ -8,6 +8,8 @@ constexpr int RTTI_CONFIDENCE = 100; namespace BinaryNinja::RTTI { std::optional<std::string> DemangleNameMS(BinaryView* view, bool allowMangled, const std::string &mangledName); + std::optional<std::string> DemangleNameGNU3(BinaryView* view, bool allowMangled, const std::string &mangledName); + std::optional<std::string> DemangleNameItanium(BinaryView* view, bool allowMangled, const std::string &mangledName); std::optional<std::string> DemangleNameLLVM(bool allowMangled, const std::string &mangledName); |
