Skip to content

Commit f902f22

Browse files
emesareWeiN76LQh
andcommitted
[SharedCache] Include segment in image section name
This removes some section name collisions where a section name is in two separate image segments. See #6454 for more information. Co-Authored-By: WeiN76LQh <WeiN76LQh@github.com>
1 parent 10996dd commit f902f22

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

view/sharedcache/core/MachO.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,18 @@ std::optional<SharedCacheMachOHeader> SharedCacheMachOHeader::ParseHeaderForAddr
435435
char sectionName[17];
436436
memcpy(sectionName, section.sectname, sizeof(section.sectname));
437437
sectionName[16] = 0;
438-
header.sectionNames.push_back(header.identifierPrefix + "::" + sectionName);
438+
439+
char segmentName[sizeof(section.segname)+1];
440+
memcpy(segmentName, section.segname, sizeof(section.segname));
441+
segmentName[sizeof(segmentName)-1] = 0;
442+
443+
// Section names used to be image name and section only but some images have duplicate section names
444+
// so we now also use the segment name, this also is more close to what is seen with LLVM.
445+
// Justification: https://github.com/Vector35/binaryninja-api/pull/6454#issuecomment-2777465476
446+
if (header.identifierPrefix.empty())
447+
header.sectionNames.push_back(fmt::format("{}.{}", segmentName, sectionName));
448+
else
449+
header.sectionNames.push_back(fmt::format("{}::{}.{}", header.identifierPrefix, segmentName, sectionName));
439450
}
440451
}
441452
catch (ReadException&)

0 commit comments

Comments
 (0)