Ghidra is a software reverse engineering (SRE) framework
GP-1893: post-review fixes GP--1893: implements hashCode/equals for DbgModuleMemory
d-millar9a8b3093554e
diff --git a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/manager/DbgModuleMemory.java b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/manager/DbgModuleMemory.javaindex 06d241b399..74c943a710 100644--- a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/manager/DbgModuleMemory.java+++ b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/manager/DbgModuleMemory.java@@ -42,4 +42,10 @@ public interface DbgModuleMemory {boolean isWrite();boolean isExec();++ /* NB: Be sure to implement these in any implementation+ public int hashCode();+ public boolean equals(Object obj);+ */+}diff --git a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/manager/cmd/DbgListMemoryRegionsCommand.java b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/manager/cmd/DbgListMemoryRegionsCommand.javaindex 58499399e7..53b1f2faef 100644--- a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/manager/cmd/DbgListMemoryRegionsCommand.java+++ b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/manager/cmd/DbgListMemoryRegionsCommand.java@@ -44,7 +44,6 @@ public class DbgListMemoryRegionsCommand extends AbstractDbgCommand<List<DbgModuif (memory.containsValue(region)) {continue; // Do nothing, we're in sync}- // Need to create the thread as if we receive =thread-createdif (!memory.isEmpty()) {Msg.warn(this, "Resync: Was missing memory: " + region.getId());}@@ -56,7 +55,6 @@ public class DbgListMemoryRegionsCommand extends AbstractDbgCommand<List<DbgModucontinue; // Do nothing, we're in sync}toRemove.add(entry.getKey());- //manager.removeMemory(entry.getKey());}for (Long key : toRemove) {manager.removeMemory(key);diff --git a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/manager/impl/DbgModuleMemoryImpl.java b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/manager/impl/DbgModuleMemoryImpl.javaindex b70aa32ccd..a3d7b912d4 100644--- a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/manager/impl/DbgModuleMemoryImpl.java+++ b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/manager/impl/DbgModuleMemoryImpl.java@@ -16,6 +16,7 @@package agent.dbgeng.manager.impl;import java.util.List;+import java.util.Objects;import agent.dbgeng.dbgeng.DebugDataSpaces.PageState;import agent.dbgeng.manager.DbgModuleMemory;@@ -33,6 +34,7 @@ public class DbgModuleMemoryImpl implements DbgModuleMemory {private boolean isRead;private boolean isWrite;private boolean isExec;+ private int hashcode;public DbgModuleMemoryImpl(String index, long vmaStart, long vmaEnd, long allocationBase,List<String> allocationProtect, List<String> protect, PageState state, String type,@@ -48,6 +50,7 @@ public class DbgModuleMemoryImpl implements DbgModuleMemory {this.isRead = isRead;this.isWrite = isWrite;this.isExec = isExec;+ this.hashcode = Objects.hash(vmaStart, vmaEnd, getState(), type, isRead, isWrite, isExec);}@Override@@ -106,4 +109,43 @@ public class DbgModuleMemoryImpl implements DbgModuleMemory {public boolean isExec() {return isExec;}++ @Override+ public int hashCode() {+ return hashcode;+ }++ @Override+ public boolean equals(Object obj) {+ if (this == obj) {+ return true;+ }+ if (!(obj instanceof DbgModuleMemory)) {+ return false;+ }+ DbgModuleMemory that = (DbgModuleMemory) obj;+ if (this.getVmaStart() != that.getVmaStart()) {+ return false;+ }+ if (this.getVmaEnd() != that.getVmaEnd()) {+ return false;+ }+ if (!this.getState().equals(that.getState())) {+ return false;+ }+ if (!this.getType().equals(that.getType())) {+ return false;+ }+ if (this.isRead() != that.isRead()) {+ return false;+ }+ if (this.isWrite() != that.isWrite()) {+ return false;+ }+ if (this.isExec() != that.isExec()) {+ return false;+ }+ return true;+ }+}