Skip to content

Commit 038e625

Browse files
committed
Fallback to GNU3 demangler in Itanium RTTI
1 parent 1aa0bd3 commit 038e625

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

plugins/rtti/rtti.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,27 @@ std::optional<std::string> RTTI::DemangleNameMS(BinaryView* view, bool allowMang
1414
}
1515

1616

17+
std::optional<std::string> RTTI::DemangleNameGNU3(BinaryView* view, bool allowMangled, const std::string &mangledName)
18+
{
19+
QualifiedName demangledName = {};
20+
Ref<Type> outType = {};
21+
22+
// TODO: This is disabled because most of the uses of this were making the problem worse by demangling
23+
// TODO: To a very generic string that dozens of classes would then look like. We likely need to add some extra
24+
// TODO: sauce to the demangler to pickup strings like:
25+
// TODO: REAL: PackageListGui::PackageListGui(Filesystem::Path&&, PackageListGui::UnderSubheader, bool)::$_1[0x0]
26+
// TODO: OURS: PackageListGui::PackageListGui
27+
// TODO: OURS MANGLED: ZN14PackageListGuiC1EON10Filesystem4PathENS_14UnderSubheaderEbE3$_1
28+
// For some reason some of the names that start with ZN are not prefixed by `_`.
29+
// if (mangled.find("ZN") == 0)
30+
// mangled = "_" + mangled;
31+
32+
if (!DemangleGNU3(view->GetDefaultArchitecture(), mangledName, outType, demangledName, true))
33+
return allowMangled ? std::optional(mangledName) : std::nullopt;
34+
return demangledName.GetString();
35+
}
36+
37+
1738
std::string RemoveItaniumPrefix(std::string &name)
1839
{
1940
// Remove numerical prefixes.
@@ -26,7 +47,10 @@ std::string RemoveItaniumPrefix(std::string &name)
2647

2748
std::optional<std::string> RTTI::DemangleNameItanium(BinaryView* view, bool allowMangled, const std::string &mangledName)
2849
{
29-
if (auto demangledName = DemangleNameLLVM(allowMangled, mangledName))
50+
// NOTE: Passing false to allowMangled to fallthrough to GNU3 demangler.
51+
if (auto demangledName = DemangleNameLLVM(false, mangledName))
52+
return RemoveItaniumPrefix(demangledName.value());
53+
if (auto demangledName = DemangleNameGNU3(view, allowMangled, mangledName))
3054
return RemoveItaniumPrefix(demangledName.value());
3155
return std::nullopt;
3256
}

plugins/rtti/rtti.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ constexpr int RTTI_CONFIDENCE = 100;
88
namespace BinaryNinja::RTTI {
99
std::optional<std::string> DemangleNameMS(BinaryView* view, bool allowMangled, const std::string &mangledName);
1010

11+
std::optional<std::string> DemangleNameGNU3(BinaryView* view, bool allowMangled, const std::string &mangledName);
12+
1113
std::optional<std::string> DemangleNameItanium(BinaryView* view, bool allowMangled, const std::string &mangledName);
1214

1315
std::optional<std::string> DemangleNameLLVM(bool allowMangled, const std::string &mangledName);

0 commit comments

Comments
 (0)