From f902f22843146fb04dddadc5765f6582e3096a18 Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Mon, 7 Apr 2025 22:28:32 -0400 Subject: [SharedCache] Include segment in image section name This removes some section name collisions where a section name is in two separate image segments. See https://github.com/Vector35/binaryninja-api/pull/6454 for more information. Co-Authored-By: WeiN76LQh --- view/sharedcache/core/MachO.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'view/sharedcache/core/MachO.cpp') diff --git a/view/sharedcache/core/MachO.cpp b/view/sharedcache/core/MachO.cpp index 0b296af1..e1ec9229 100644 --- a/view/sharedcache/core/MachO.cpp +++ b/view/sharedcache/core/MachO.cpp @@ -435,7 +435,18 @@ std::optional SharedCacheMachOHeader::ParseHeaderForAddr char sectionName[17]; memcpy(sectionName, section.sectname, sizeof(section.sectname)); sectionName[16] = 0; - header.sectionNames.push_back(header.identifierPrefix + "::" + sectionName); + + char segmentName[sizeof(section.segname)+1]; + memcpy(segmentName, section.segname, sizeof(section.segname)); + segmentName[sizeof(segmentName)-1] = 0; + + // Section names used to be image name and section only but some images have duplicate section names + // so we now also use the segment name, this also is more close to what is seen with LLVM. + // Justification: https://github.com/Vector35/binaryninja-api/pull/6454#issuecomment-2777465476 + if (header.identifierPrefix.empty()) + header.sectionNames.push_back(fmt::format("{}.{}", segmentName, sectionName)); + else + header.sectionNames.push_back(fmt::format("{}::{}.{}", header.identifierPrefix, segmentName, sectionName)); } } catch (ReadException&) -- cgit v1.3.1