From 4f35a5bb156c2744083d1ce2cf7f04609984dd52 Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Fri, 9 May 2025 20:39:01 -0400 Subject: [RTTI] Loosen section semantic sanity checks in Itanium RTTI processing We need to do this for RTTI info that resides in DefaultSectionSemantic sections, which will happen for some binaries where the data is placed in non-generic sections. --- plugins/rtti/itanium.cpp | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'plugins/rtti/itanium.cpp') diff --git a/plugins/rtti/itanium.cpp b/plugins/rtti/itanium.cpp index 5e1cf0a8..bd031f6a 100644 --- a/plugins/rtti/itanium.cpp +++ b/plugins/rtti/itanium.cpp @@ -41,6 +41,28 @@ uint64_t TypeInfoSize(BinaryView *view) } +// TODO: Delete this function when access semantics are not so screwy. +bool IsOffsetReadOnlyData(BinaryView *view, uint64_t offset) +{ + // Check to see if the section has default section semantics and let it pass. + for (const auto& section : view->GetSectionsAt(offset)) + { + // TODO: Adding external here is weird but its whatever. This whole function needs to go away anyways. + switch (section->GetSemantics()) + { + case DefaultSectionSemantics: + case ReadOnlyDataSectionSemantics: + case ExternalSectionSemantics: + return true; + default: + return false; + } + } + + return false; +} + + std::optional GetTypeInfo(BinaryView* view, uint64_t address) { // TODO: We really need a valid offset range thing. @@ -53,7 +75,9 @@ std::optional GetTypeInfo(BinaryView* view, uint64_t address) if (!view->IsValidOffset(base) || view->IsOffsetCodeSemantics(base)) return std::nullopt; auto typeNameAddr = reader.ReadPointer(); - if (!view->IsValidOffset(typeNameAddr) || view->IsOffsetCodeSemantics(typeNameAddr)) + // NOTE: This used to check IsOffsetCodeSemantics but for some reason the default section semantics + // is picked up as code. This really makes me sad. Hopefully the offset semantics rework is done soon! + if (!view->IsValidOffset(typeNameAddr) || !IsOffsetReadOnlyData(view, typeNameAddr)) return std::nullopt; reader.Seek(typeNameAddr); auto type_name = reader.ReadCString(512); @@ -728,11 +752,13 @@ void ItaniumRTTIProcessor::ProcessRTTI() m_view->BeginBulkModifySymbols(); // Scan data sections for rtti. - for (const Ref
§ion: m_view->GetSections()) + for (const Ref
§ion : m_view->GetSections()) { if (bgTask->IsCancelled()) break; - if (section->GetSemantics() == ReadOnlyDataSectionSemantics) + auto sectionSemantics = section->GetSemantics(); + // Some RTTI unfortunately will get put into a DefaultSectionSemantics section, so we have to check those. + if (sectionSemantics == ReadOnlyDataSectionSemantics || sectionSemantics == DefaultSectionSemantics) { m_logger->LogDebug("Attempting to find RTTI in section %llx", section->GetStart()); scan(section); -- cgit v1.3.1