From 87f62b7603ac9111debd8caa9e3638e2be3a4c42 Mon Sep 17 00:00:00 2001 From: Ryan Kurtz Date: Wed, 5 Jun 2024 07:28:17 -0400 Subject: [PATCH] GP-4662: Fixing Swift opinion regression --- .../ghidra/app/util/bin/format/swift/SwiftUtils.java | 2 ++ .../java/ghidra/app/util/opinion/MachoLoader.java | 12 +++++++----- .../main/java/ghidra/app/util/opinion/PeLoader.java | 4 ++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/SwiftUtils.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/SwiftUtils.java index db35805e4eb..d7af019d794 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/SwiftUtils.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/swift/SwiftUtils.java @@ -29,6 +29,8 @@ */ public class SwiftUtils { + public static final String SWIFT_COMPILER = "swift"; + /** * A {@link PointerTypedef pointer} to a relative 4-byte offset */ diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/MachoLoader.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/MachoLoader.java index e968c2d3517..03577330348 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/MachoLoader.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/MachoLoader.java @@ -84,11 +84,13 @@ private String detectCompilerName(MachHeader machHeader) throws IOException { .flatMap(seg -> seg.getSections().stream()) .map(section -> section.getSectionName()) .toList(); - String compiler = SwiftUtils.isSwift(sectionNames) ? "swift" : null; - compiler = compiler == null && GoRttiMapper.hasGolangSections(sectionNames) - ? GoConstants.GOLANG_CSPEC_NAME - : null; - return compiler; + if (SwiftUtils.isSwift(sectionNames)) { + return SwiftUtils.SWIFT_COMPILER; + } + if (GoRttiMapper.hasGolangSections(sectionNames)) { + return GoConstants.GOLANG_CSPEC_NAME; + } + return null; } @Override diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/PeLoader.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/PeLoader.java index 0d2c5dc20d1..09b0f881c47 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/PeLoader.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/PeLoader.java @@ -28,8 +28,8 @@ import ghidra.app.util.bin.BinaryReader; import ghidra.app.util.bin.ByteProvider; import ghidra.app.util.bin.format.elf.info.ElfInfoItem.ItemWithAddress; -import ghidra.app.util.bin.format.golang.GoBuildInfo; import ghidra.app.util.bin.format.golang.GoBuildId; +import ghidra.app.util.bin.format.golang.GoBuildInfo; import ghidra.app.util.bin.format.golang.rtti.GoRttiMapper; import ghidra.app.util.bin.format.mz.DOSHeader; import ghidra.app.util.bin.format.pe.*; @@ -922,7 +922,7 @@ public enum CompilerEnum { CLI("cli", "cli"), Rustc(RustConstants.RUST_COMPILER, RustConstants.RUST_COMPILER), GOLANG("golang", "golang"), - Swift("swift", "swift"), + Swift(SwiftUtils.SWIFT_COMPILER, SwiftUtils.SWIFT_COMPILER), Unknown("unknown", "unknown"), // The following values represent the presence of ambiguous indicators