diff options
| author | Mason Reed <mason@vector35.com> | 2024-12-03 17:49:11 -0500 |
|---|---|---|
| committer | Mason Reed <mason@vector35.com> | 2025-03-19 21:17:34 -0400 |
| commit | 31ef836d222aaa8786d4ac2c36e09e4fd9e02929 (patch) | |
| tree | a114bebf46837d110dbc9e7c560ca52d7348202b /plugins | |
| parent | 7794bcfa9f8c51442a87f10a3475612dfc4435d8 (diff) | |
Replace bad auto symbol for Itanium RTTI
Diffstat (limited to 'plugins')
| -rw-r--r-- | plugins/rtti/itanium.cpp | 12 | ||||
| -rw-r--r-- | plugins/rtti/rtti.cpp | 25 | ||||
| -rw-r--r-- | plugins/rtti/rtti.h | 2 |
3 files changed, 25 insertions, 14 deletions
diff --git a/plugins/rtti/itanium.cpp b/plugins/rtti/itanium.cpp index f7ad9a70..7ac75d94 100644 --- a/plugins/rtti/itanium.cpp +++ b/plugins/rtti/itanium.cpp @@ -247,17 +247,15 @@ std::optional<ClassInfo> ItaniumRTTIProcessor::ProcessRTTI(uint64_t objectAddr) return std::nullopt; auto typeInfo = TypeInfo(m_view, objectAddr); - auto className = DemangleNameGNU3(m_view, allowMangledClassNames, typeInfo.type_name); + auto className = DemangleNameItanium(m_view, allowMangledClassNames, typeInfo.type_name); if (!className.has_value()) return std::nullopt; auto classInfo = ClassInfo{className.value()}; - // TODO: className starts with 7, 9, 14 - // 7 == class_type - // 9 == si_class_type - // 14 == vmi_class_type - auto typeInfoName = fmt::format("_typeinfo_for_{}", classInfo.className); + auto typeInfoSymbol = m_view->GetSymbolByAddress(objectAddr); + if (typeInfoSymbol != nullptr) + m_view->UndefineAutoSymbol(typeInfoSymbol); m_view->DefineAutoSymbol(new Symbol{DataSymbol, typeInfoName, objectAddr}); if (typeInfoVariant == TIVSIClass) @@ -269,7 +267,7 @@ std::optional<ClassInfo> ItaniumRTTIProcessor::ProcessRTTI(uint64_t objectAddr) return std::nullopt; auto subTypeInfo = TypeInfo(m_view, siClassTypeInfo.base_type); // Demangle base class name and set - auto baseClassName = DemangleNameGNU3(m_view, allowMangledClassNames, subTypeInfo.type_name); + auto baseClassName = DemangleNameItanium(m_view, allowMangledClassNames, subTypeInfo.type_name); if (!baseClassName.has_value()) { m_logger->LogWarn("Skipping base class with mangled name %llx", siClassTypeInfo.base_type); diff --git a/plugins/rtti/rtti.cpp b/plugins/rtti/rtti.cpp index d99983ee..623c523b 100644 --- a/plugins/rtti/rtti.cpp +++ b/plugins/rtti/rtti.cpp @@ -14,13 +14,26 @@ std::optional<std::string> RTTI::DemangleNameMS(BinaryView* view, bool allowMang } -std::optional<std::string> RTTI::DemangleNameGNU3(BinaryView* view, bool allowMangled, const std::string &mangledName) +std::string RemoveItaniumPrefix(const std::string& name) { + // Remove class prefixes. + // 7 is class_type + // 9 is si_class_type + // 14 is vmi_class_type + if (name.rfind('7', 0) == 0) + return name.substr(1); + if (name.rfind('9', 0) == 0) + return name.substr(1); + if (name.rfind("14", 0) == 0) + return name.substr(2); + return name; +} + + +std::optional<std::string> RTTI::DemangleNameItanium(BinaryView* view, bool allowMangled, const std::string &mangledName) { - QualifiedName demangledName = {}; - Ref<Type> outType = {}; - if (!DemangleGNU3(view->GetDefaultArchitecture(), mangledName, outType, demangledName, true)) - return DemangleNameLLVM(allowMangled, mangledName); - return demangledName.GetString(); + if (auto demangledName = DemangleNameLLVM(allowMangled, mangledName)) + return RemoveItaniumPrefix(demangledName.value()); + return std::nullopt; } diff --git a/plugins/rtti/rtti.h b/plugins/rtti/rtti.h index e53e1dac..9740b68f 100644 --- a/plugins/rtti/rtti.h +++ b/plugins/rtti/rtti.h @@ -8,7 +8,7 @@ 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); |
