Ghidra is a software reverse engineering (SRE) framework
Changed MemoryBlockSouceInfo into an interface
ghidravore290f26f100ed
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/memory/MemoryMapModel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/memory/MemoryMapModel.javaindex 97dc4ad512..d80785781c 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/memory/MemoryMapModel.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/memory/MemoryMapModel.java@@ -33,7 +33,6 @@ import docking.widgets.table.AbstractSortedTableModel;import ghidra.framework.model.DomainFile;import ghidra.framework.store.LockException;-import ghidra.program.database.mem.MemoryBlockSourceInfo;import ghidra.program.model.address.*;import ghidra.program.model.listing.Program;import ghidra.program.model.mem.*;diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/xml/MemoryMapXmlMgr.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/xml/MemoryMapXmlMgr.javaindex 71c03e9b4e..a2560fee0b 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/xml/MemoryMapXmlMgr.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/xml/MemoryMapXmlMgr.java@@ -23,7 +23,6 @@ import org.xml.sax.SAXParseException;import ghidra.app.util.MemoryBlockUtils;import ghidra.app.util.importer.MessageLog;-import ghidra.program.database.mem.MemoryBlockSourceInfo;import ghidra.program.model.address.*;import ghidra.program.model.listing.Program;import ghidra.program.model.mem.*;diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/memory/MemoryMapProvider1Test.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/memory/MemoryMapProvider1Test.javaindex e27c884644..bf4c4ac0a0 100644--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/memory/MemoryMapProvider1Test.java+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/memory/MemoryMapProvider1Test.java@@ -35,7 +35,6 @@ import ghidra.app.plugin.core.gotoquery.GoToServicePlugin;import ghidra.app.plugin.core.navigation.NavigationHistoryPlugin;import ghidra.framework.plugintool.PluginTool;import ghidra.program.database.ProgramBuilder;-import ghidra.program.database.mem.MemoryBlockSourceInfo;import ghidra.program.model.address.Address;import ghidra.program.model.listing.CodeUnit;import ghidra.program.model.listing.Program;diff --git a/Ghidra/Features/Base/src/test/java/ghidra/app/cmd/memory/AddMemoryBlockCmdTest.java b/Ghidra/Features/Base/src/test/java/ghidra/app/cmd/memory/AddMemoryBlockCmdTest.javaindex bab3928e42..95ab232f5b 100644--- a/Ghidra/Features/Base/src/test/java/ghidra/app/cmd/memory/AddMemoryBlockCmdTest.java+++ b/Ghidra/Features/Base/src/test/java/ghidra/app/cmd/memory/AddMemoryBlockCmdTest.java@@ -22,11 +22,9 @@ import org.junit.*;import generic.test.AbstractGenericTest;import ghidra.framework.cmd.Command;import ghidra.program.database.ProgramBuilder;-import ghidra.program.database.mem.MemoryBlockSourceInfo;import ghidra.program.model.address.Address;import ghidra.program.model.listing.*;-import ghidra.program.model.mem.MemoryBlock;-import ghidra.program.model.mem.MemoryBlockType;+import ghidra.program.model.mem.*;import ghidra.util.exception.RollbackException;/**diff --git a/Ghidra/Features/Base/src/test/java/ghidra/app/plugin/core/checksums/MyTestMemoryBlock.java b/Ghidra/Features/Base/src/test/java/ghidra/app/plugin/core/checksums/MyTestMemoryBlock.javaindex 56cb91887a..13d09169c1 100644--- a/Ghidra/Features/Base/src/test/java/ghidra/app/plugin/core/checksums/MyTestMemoryBlock.java+++ b/Ghidra/Features/Base/src/test/java/ghidra/app/plugin/core/checksums/MyTestMemoryBlock.java@@ -18,7 +18,6 @@ package ghidra.app.plugin.core.checksums;import java.io.InputStream;import java.util.List;-import ghidra.program.database.mem.MemoryBlockSourceInfo;import ghidra.program.model.address.Address;import ghidra.program.model.mem.*;diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/emulator/memory/ProgramLoadImage.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/emulator/memory/ProgramLoadImage.javaindex 12c7d09314..7a8ff075a9 100644--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/emulator/memory/ProgramLoadImage.java+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/emulator/memory/ProgramLoadImage.java@@ -20,7 +20,6 @@ import java.util.Arrays;import ghidra.pcode.error.LowlevelError;import ghidra.pcode.memstate.MemoryFaultHandler;import ghidra.pcode.memstate.MemoryPage;-import ghidra.program.database.mem.MemoryBlockSourceInfo;import ghidra.program.model.address.*;import ghidra.program.model.listing.Program;import ghidra.program.model.mem.*;diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/emulator/memory/ProgramMappedMemory.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/emulator/memory/ProgramMappedMemory.javaindex 60268b20fc..1650623f8a 100644--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/emulator/memory/ProgramMappedMemory.java+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/emulator/memory/ProgramMappedMemory.java@@ -20,7 +20,6 @@ import java.util.Arrays;import ghidra.pcode.error.LowlevelError;import ghidra.pcode.memstate.MemoryFaultHandler;import ghidra.pcode.memstate.MemoryPage;-import ghidra.program.database.mem.MemoryBlockSourceInfo;import ghidra.program.model.address.*;import ghidra.program.model.listing.Program;import ghidra.program.model.mem.*;diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/mem/AddressSourceInfo.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/mem/AddressSourceInfo.javaindex 769084cfe5..c35f4ce27e 100644--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/mem/AddressSourceInfo.java+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/mem/AddressSourceInfo.java@@ -21,8 +21,7 @@ import java.util.Optional;import ghidra.program.model.address.Address;import ghidra.program.model.address.AddressRange;-import ghidra.program.model.mem.Memory;-import ghidra.program.model.mem.MemoryBlock;+import ghidra.program.model.mem.*;/*** Provides information about the source of a byte value at an address including the file itdiff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/mem/MemoryBlockSourceInfo.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/mem/MemoryBlockSourceInfoDB.javasimilarity index 58%rename from Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/mem/MemoryBlockSourceInfo.javarename to Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/mem/MemoryBlockSourceInfoDB.javaindex 6f145312d4..d7c7f41c7a 100644--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/mem/MemoryBlockSourceInfo.java+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/mem/MemoryBlockSourceInfoDB.java@@ -20,48 +20,49 @@ import java.util.Optional;import ghidra.program.model.address.Address;import ghidra.program.model.address.AddressRange;import ghidra.program.model.mem.MemoryBlock;+import ghidra.program.model.mem.MemoryBlockSourceInfo;/*** Class for describing the source of bytes for a memory block.*/-public class MemoryBlockSourceInfo {+class MemoryBlockSourceInfoDB implements MemoryBlockSourceInfo {private final MemoryBlock block;private final SubMemoryBlock subBlock;- MemoryBlockSourceInfo(MemoryBlock block, SubMemoryBlock subBlock) {+ MemoryBlockSourceInfoDB(MemoryBlock block, SubMemoryBlock subBlock) {this.block = block;this.subBlock = subBlock;}/**- * Returns the length of this block byte source.- * @return the length of this block byte source.+ * @return*/+ @Overridepublic long getLength() {return subBlock.length;}/**- * Returns the start address where this byte source is mapped.- * @return the start address where this byte source is mapped.+ * @return*/+ @Overridepublic Address getMinAddress() {return block.getStart().add(subBlock.startingOffset);}/**- * Returns the end address where this byte source is mapped.- * @return the end address where this byte source is mapped.+ * @return*/+ @Overridepublic Address getMaxAddress() {return block.getStart().add(subBlock.startingOffset + subBlock.length - 1);}/**- * Returns a description of this SourceInfo object.- * @return a description of this SourceInfo object.+ * @return*/+ @Overridepublic String getDescription() {return subBlock.getDescription();}@@ -74,10 +75,9 @@ public class MemoryBlockSourceInfo {}/**- * Returns an {@link Optional} {@link FileBytes} object if a FileBytes object is the byte- * source for this SourceInfo. Otherwise, the Optional will be empty.- * @return the {@link FileBytes} object if it is the byte source for this section+ * @return*/+ @Overridepublic Optional<FileBytes> getFileBytes() {if (subBlock instanceof FileBytesSubMemoryBlock) {return Optional.of(((FileBytesSubMemoryBlock) subBlock).getFileBytes());@@ -86,10 +86,9 @@ public class MemoryBlockSourceInfo {}/**- * Returns the offset into the {@link FileBytes} object where this section starts getting its bytes or- * -1 if this SourceInfo does not have an associated {@link FileBytes}- * @return the offset into the {@link FileBytes} object where this section starts getting its bytes.+ * @return*/+ @Overridepublic long getFileBytesOffset() {if (subBlock instanceof FileBytesSubMemoryBlock) {return ((FileBytesSubMemoryBlock) subBlock).getFileBytesOffset();@@ -98,13 +97,10 @@ public class MemoryBlockSourceInfo {}/**- * Returns the offset into the {@link FileBytes} object for the given address or- * -1 if this MemoryBlockSourceInfo does not have an associated {@link FileBytes} or the address doesn't- * belong to this MemoryBlockSourceInfo.- *- * @param address the address for which to get an offset into the {@link FileBytes} object.- * @return the offset into the {@link FileBytes} object for the given address.+ * @param address+ * @return*/+ @Overridepublic long getFileBytesOffset(Address address) {if (subBlock instanceof FileBytesSubMemoryBlock && contains(address)) {long blockOffset = address.subtract(getMinAddress());@@ -115,11 +111,9 @@ public class MemoryBlockSourceInfo {}/**- * Returns an {@link Optional} {@link AddressRange} for the mapped addresses if this is mapped- * memory block (bit mapped or byte mapped). Otherwise, the Optional is empty.- * @return an {@link Optional} {@link AddressRange} for the mapped addresses if this is mapped- * memory block+ * @return*/+ @Overridepublic Optional<AddressRange> getMappedRange() {if (subBlock instanceof BitMappedSubMemoryBlock) {BitMappedSubMemoryBlock bitMapped = (BitMappedSubMemoryBlock) subBlock;@@ -133,18 +127,18 @@ public class MemoryBlockSourceInfo {}/**- * Returns the containing Memory Block- * @return the containing Memory Block+ * @return*/+ @Overridepublic MemoryBlock getMemoryBlock() {return block;}/**- * Returns true if this SourceInfo object applies to the given address;- * @param address the address to test if this is its SourceInfo- * @return true if this SourceInfo object applies to the given address;+ * @param address+ * @return*/+ @Overridepublic boolean contains(Address address) {return address.compareTo(getMinAddress()) >= 0 && address.compareTo(getMaxAddress()) <= 0;}diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/mem/SubMemoryBlock.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/mem/SubMemoryBlock.javaindex 79a2a2c8c9..31d7e4a96d 100644--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/mem/SubMemoryBlock.java+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/mem/SubMemoryBlock.java@@ -194,7 +194,7 @@ abstract class SubMemoryBlock {* @return the {@link MemoryBlockSourceInfo} object for this SubMemoryBlock*/protected final MemoryBlockSourceInfo getSourceInfo(MemoryBlock block) {- return new MemoryBlockSourceInfo(block, this);+ return new MemoryBlockSourceInfoDB(block, this);}/**diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/mem/MemoryBlock.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/mem/MemoryBlock.javaindex 49a867dea5..bb48bf53b9 100644--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/mem/MemoryBlock.java+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/mem/MemoryBlock.java@@ -20,7 +20,6 @@ import java.io.Serializable;import java.util.List;import ghidra.framework.store.LockException;-import ghidra.program.database.mem.MemoryBlockSourceInfo;import ghidra.program.model.address.Address;import ghidra.program.model.listing.Program;import ghidra.util.exception.DuplicateNameException;diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/mem/MemoryBlockSourceInfo.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/mem/MemoryBlockSourceInfo.javanew file mode 100644index 0000000000..703b58172a--- /dev/null+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/mem/MemoryBlockSourceInfo.java@@ -0,0 +1,98 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.program.model.mem;++import java.util.Optional;++import ghidra.program.database.mem.FileBytes;+import ghidra.program.model.address.Address;+import ghidra.program.model.address.AddressRange;++/**+ * Describes the source of bytes for a memory block.+ */+public interface MemoryBlockSourceInfo {++ /**+ * Returns the length of this block byte source.+ * @return the length of this block byte source.+ */+ long getLength();++ /**+ * Returns the start address where this byte source is mapped.+ * @return the start address where this byte source is mapped.+ */+ Address getMinAddress();++ /**+ * Returns the end address where this byte source is mapped.+ * @return the end address where this byte source is mapped.+ */+ Address getMaxAddress();++ /**+ * Returns a description of this SourceInfo object.+ * @return a description of this SourceInfo object.+ */+ String getDescription();++ /**+ * Returns an {@link Optional} {@link FileBytes} object if a FileBytes object is the byte+ * source for this SourceInfo. Otherwise, the Optional will be empty.+ * @return the {@link FileBytes} object if it is the byte source for this section+ */+ Optional<FileBytes> getFileBytes();++ /**+ * Returns the offset into the {@link FileBytes} object where this section starts getting its bytes or+ * -1 if this SourceInfo does not have an associated {@link FileBytes}+ * @return the offset into the {@link FileBytes} object where this section starts getting its bytes.+ */+ long getFileBytesOffset();++ /**+ * Returns the offset into the {@link FileBytes} object for the given address or+ * -1 if this MemoryBlockSourceInfo does not have an associated {@link FileBytes} or the address doesn't+ * belong to this MemoryBlockSourceInfo.+ *+ * @param address the address for which to get an offset into the {@link FileBytes} object.+ * @return the offset into the {@link FileBytes} object for the given address.+ */+ long getFileBytesOffset(Address address);++ /**+ * Returns an {@link Optional} {@link AddressRange} for the mapped addresses if this is mapped+ * memory block (bit mapped or byte mapped). Otherwise, the Optional is empty.+ * @return an {@link Optional} {@link AddressRange} for the mapped addresses if this is mapped+ * memory block+ */+ Optional<AddressRange> getMappedRange();++ /**+ * Returns the containing Memory Block+ * @return the containing Memory Block+ */+ MemoryBlock getMemoryBlock();++ /**+ * Returns true if this SourceInfo object applies to the given address;+ * @param address the address to test if this is its SourceInfo+ * @return true if this SourceInfo object applies to the given address;+ */+ boolean contains(Address address);++}diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/mem/MemoryBlockStub.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/mem/MemoryBlockStub.javaindex 915e96a9ae..536aa8fffb 100644--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/mem/MemoryBlockStub.java+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/mem/MemoryBlockStub.java@@ -19,7 +19,6 @@ import java.io.InputStream;import java.util.List;import ghidra.framework.store.LockException;-import ghidra.program.database.mem.MemoryBlockSourceInfo;import ghidra.program.model.address.Address;import ghidra.util.exception.DuplicateNameException;