Ghidra is a software reverse engineering (SRE) framework
GP-525: Module map fix; breakpoint "Image" column uses domain file name
Dan69138ad568a1
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/breakpoint/LogicalBreakpointRow.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/breakpoint/LogicalBreakpointRow.javaindex 3da320177b..06c0200f8a 100644--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/breakpoint/LogicalBreakpointRow.java+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/breakpoint/LogicalBreakpointRow.java@@ -19,6 +19,7 @@ import java.util.concurrent.CompletableFuture;import ghidra.app.services.LogicalBreakpoint;import ghidra.app.services.LogicalBreakpoint.Enablement;+import ghidra.framework.model.DomainFile;import ghidra.framework.model.DomainObject;import ghidra.program.model.address.Address;import ghidra.program.model.listing.Program;@@ -74,7 +75,11 @@ public class LogicalBreakpointRow {if (program == null) {return "";}- return program.getName();+ DomainFile df = program.getDomainFile();+ if (df == null) {+ return program.getName();+ }+ return df.getName();}public Address getAddress() {diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/modules/DebuggerStaticMappingServicePlugin.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/modules/DebuggerStaticMappingServicePlugin.javaindex 63251c414d..16f2f92a80 100644--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/modules/DebuggerStaticMappingServicePlugin.java+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/modules/DebuggerStaticMappingServicePlugin.java@@ -15,9 +15,9 @@*/package ghidra.app.plugin.core.debug.service.modules;+import java.io.File;import java.io.IOException;import java.net.URL;-import java.nio.file.Paths;import java.util.*;import java.util.Map.Entry;import java.util.stream.Collectors;@@ -1292,6 +1292,12 @@ public class DebuggerStaticMappingServicePlugin extends Pluginfor (Program program : programs) {PluginModuleMapProposal map = proposeModuleMap(module, program);double score = map.computeScore();+ if (score == bestScore && programManager != null) {+ // Prefer the current program in ties+ if (programManager.getCurrentProgram() == program) {+ bestMap = map;+ }+ }if (score > bestScore) {bestScore = score;bestMap = map;@@ -1305,7 +1311,7 @@ public class DebuggerStaticMappingServicePlugin extends PluginCollection<? extends TraceModule> modules, Collection<? extends Program> programs) {Map<TraceModule, ModuleMapProposal> result = new LinkedHashMap<>();for (TraceModule module : modules) {- String moduleName = Paths.get(module.getName()).getFileName().toString();+ String moduleName = getLastLower(module.getName());Set<Program> probable = programs.stream().filter(p -> namesContain(p, moduleName)).collect(Collectors.toSet());@@ -1345,24 +1351,39 @@ public class DebuggerStaticMappingServicePlugin extends Pluginreturn bestMap;}+ protected static String getLastLower(String path) {+ return new File(path).getName().toLowerCase();+ }+/**- * Check if either the program's name or its domain file name contains the given module name+ * Check if either the program's name, its executable path, or its domain file name contains the+ * given module name** @param program the program whose names to check- * @param moduleName the module name to check for+ * @param moduleLowerName the module name to check for in lower case* @return true if matched, false if not*/- protected boolean namesContain(Program program, String moduleName) {+ protected boolean namesContain(Program program, String moduleLowerName) {DomainFile df = program.getDomainFile();if (df == null || df.getProjectLocator() == null) {return false;}- String programName = Paths.get(program.getName()).getFileName().toString().toLowerCase();+ String programName = getLastLower(program.getName());+ if (programName.contains(moduleLowerName)) {+ return true;+ }+ String exePath = program.getExecutablePath();+ if (exePath != null) {+ String execName = getLastLower(exePath);+ if (execName.contains(moduleLowerName)) {+ return true;+ }+ }String fileName = df.getName().toLowerCase();- if (!programName.contains(moduleName) && !fileName.contains(moduleName)) {- return false;+ if (fileName.contains(moduleLowerName)) {+ return true;}- return true;+ return false;}@Override@@ -1370,7 +1391,7 @@ public class DebuggerStaticMappingServicePlugin extends PluginCollection<? extends TraceModule> modules, Collection<? extends Program> programs) {Map<TraceModule, SectionMapProposal> result = new LinkedHashMap<>();for (TraceModule module : modules) {- String moduleName = Paths.get(module.getName()).getFileName().toString();+ String moduleName = getLastLower(module.getName());Set<Program> probable = programs.stream().filter(p -> namesContain(p, moduleName)).collect(Collectors.toSet());