Changed MemoryBlockSouceInfo into an interface

This commit is contained in:
ghidravore 2019-07-22 15:43:41 -04:00
parent 21d984c093
commit 290f26f100
13 changed files with 126 additions and 45 deletions

View File

@ -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.*;

View File

@ -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.*;

View File

@ -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;

View File

@ -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;
/**

View File

@ -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.*;

View File

@ -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.*;

View File

@ -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.*;

View File

@ -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 it

View File

@ -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
*/
@Override
public 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
*/
@Override
public 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
*/
@Override
public 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
*/
@Override
public 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
*/
@Override
public 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
*/
@Override
public 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
*/
@Override
public 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
*/
@Override
public 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
*/
@Override
public 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
*/
@Override
public boolean contains(Address address) {
return address.compareTo(getMinAddress()) >= 0 && address.compareTo(getMaxAddress()) <= 0;
}

View File

@ -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);
}
/**

View File

@ -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;

View File

@ -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);
}

View File

@ -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;