GP-420 relaxed memory block naming restrictions and eliminated throwing of DuplicateNameException from memory block API

This commit is contained in:
ghidra1 2020-11-23 17:35:49 -05:00
parent 90c1ce5d59
commit d7dbcfebf5
30 changed files with 365 additions and 641 deletions

View file

@ -24,7 +24,6 @@ import ghidra.program.model.address.AddressSpace;
import ghidra.program.model.address.OverlayAddressSpace;
import ghidra.program.model.lang.Language;
import ghidra.program.util.LanguageTranslator;
import ghidra.util.exception.AssertException;
import ghidra.util.exception.DuplicateNameException;
class OverlaySpaceAdapterDB {
@ -62,12 +61,12 @@ class OverlaySpaceAdapterDB {
AddressSpace space = factory.getAddressSpace(templateSpaceName);
try {
OverlayAddressSpace sp =
factory.addOverlayAddressSpace(spaceName, space, minOffset, maxOffset);
factory.addOverlayAddressSpace(spaceName, true, space, minOffset, maxOffset);
sp.setDatabaseKey(rec.getKey());
}
catch (DuplicateNameException e) {
throw new AssertException(
"Should not have duplicateNameException when recreating factory");
catch (IllegalArgumentException e) {
throw new RuntimeException(
"Unexpected error initializing overlay address spaces", e);
}
}
}
@ -140,7 +139,7 @@ class OverlaySpaceAdapterDB {
}
catch (DuplicateNameException e) {
throw new RuntimeException(
"Unexpected error1 updating overlay address spaces");
"Unexpected error updating overlay address spaces", e);
}
}
}
@ -151,13 +150,14 @@ class OverlaySpaceAdapterDB {
AddressSpace origSpace =
factory.getAddressSpace(rec.getString(OV_SPACE_BASE_COL));
try {
space = factory.addOverlayAddressSpace(spaceName, origSpace, minOffset,
space = factory.addOverlayAddressSpace(spaceName, true, origSpace,
minOffset,
maxOffset);
space.setDatabaseKey(rec.getKey());
}
catch (DuplicateNameException e) {
catch (IllegalArgumentException e) {
throw new RuntimeException(
"Unexpected error2 updating overlay address spaces");
"Unexpected error updating overlay address spaces", e);
}
}
}

View file

@ -97,23 +97,130 @@ public class ProgramAddressFactory extends DefaultAddressFactory {
return originalFactory;
}
public void addOverlayAddressSpace(OverlayAddressSpace ovSpace) throws DuplicateNameException {
void addOverlayAddressSpace(OverlayAddressSpace ovSpace) throws DuplicateNameException {
addAddressSpace(ovSpace);
}
public OverlayAddressSpace addOverlayAddressSpace(String name, AddressSpace originalSpace,
long minOffset, long maxOffset) throws DuplicateNameException {
/**
* Create a new OverlayAddressSpace based upon the given overlay blockName and base AddressSpace
* @param name the preferred name of the overlay address space to be created.
* This name may be modified if preserveName is false to produce a valid overlay space
* name and avoid duplication.
* @param preserveName if true specified name will be preserved, if false an unique acceptable
* overlay space name will be generated from the specified name.
* @param originalSpace the base AddressSpace to overlay
* @param minOffset the min offset of the space
* @param maxOffset the max offset of the space
* @return the new overlay space
* @throws IllegalArgumentException if originalSpace is not permitted or preserveName is true
* and a space with specified name already exists.
*/
OverlayAddressSpace addOverlayAddressSpace(String name, boolean preserveName,
AddressSpace originalSpace, long minOffset, long maxOffset) {
if (!originalSpace.isMemorySpace() || originalSpace.isOverlaySpace()) {
throw new IllegalArgumentException(
"Invalid address space for overlay: " + originalSpace.getName());
}
AddressSpace space = getAddressSpace(originalSpace.getName());
if (space != originalSpace) {
throw new IllegalArgumentException("Unknown memory address space instance");
}
String spaceName = name;
if (!preserveName) {
spaceName = fixupOverlaySpaceName(name);
spaceName = getUniqueOverlayName(spaceName);
}
else if (getAddressSpace(name) != null) { // check before allocating unique ID
throw new IllegalArgumentException("Space named " + name + " already exists!");
}
int unique = 0;
if (originalSpace.getType() == AddressSpace.TYPE_RAM ||
originalSpace.getType() == AddressSpace.TYPE_OTHER) {
unique = getNextUniqueID();
}
OverlayAddressSpace ovSpace =
new OverlayAddressSpace(name, originalSpace, unique, minOffset, maxOffset);
addAddressSpace(ovSpace);
new OverlayAddressSpace(spaceName, originalSpace, unique, minOffset, maxOffset);
try {
addAddressSpace(ovSpace);
}
catch (DuplicateNameException e) {
throw new RuntimeException(e); // unexpected
}
return ovSpace;
}
/**
* Get a unique address space name based on the specified
* baseOverlayName
* @param baseOverlayName base overlay address space name
* @return unique overlay space name
*/
private String getUniqueOverlayName(String baseOverlayName) {
if (getAddressSpace(baseOverlayName) == null) {
return baseOverlayName;
}
int index = 1;
while (true) {
String revisedName = baseOverlayName + "." + index++;
if (getAddressSpace(revisedName) == null) {
return revisedName;
}
}
}
/**
* Get base overlay name removing any numeric suffix which may
* have been added to avoid duplication. This method is intended
* to be used during rename only.
* @param overlayName existing overlay space name
* @return base overlay name with any trailing index removed
* which may have been added to avoid duplication.
*/
private String getBaseOverlayName(String overlayName) {
int index = overlayName.lastIndexOf('.');
if (index < 1) {
return overlayName;
}
int value;
try {
value = Integer.parseInt(overlayName.substring(index + 1));
}
catch (NumberFormatException e) {
return overlayName;
}
if (value < 1) {
return overlayName;
}
String baseName = overlayName.substring(0, index);
return overlayName.equals(baseName + '.' + value) ? baseName : overlayName;
}
/**
* Generate an allowed address space name from a block name. Use of unsupported
* characters will be converted to underscore (includes colon and all whitespace chars).
* double-underscore to ensure uniqueness.
* @param blockName corresponding memory block name
* @return overlay space name
*/
private String fixupOverlaySpaceName(String blockName) {
int len = blockName.length();
StringBuffer buf = new StringBuffer(len);
for (int i = 0; i < len; i++) {
char c = blockName.charAt(i);
if (c == ':' || c <= 0x20) {
buf.append('_');
}
else {
buf.append(c);
}
}
return buf.toString();
}
@Override
public Address getAddress(int spaceID, long offset) {
Address addr = super.getAddress(spaceID, offset);
@ -146,10 +253,29 @@ public class ProgramAddressFactory extends DefaultAddressFactory {
removeAddressSpace(name);
}
/**
* Rename overlay with preferred newName. Actual name used will be returned
* and may differ from specified newName to ensure validity and avoid
* duplication.
* @param oldOverlaySpaceName the existing overlay address space name
* @param newName the preferred new name of the overlay address space.
* This name may be modified to produce a valid overlay space
* name to avoid duplication.
* @return new name applied to existing overlay space
*/
@Override
protected void renameOverlaySpace(String oldName, String newName)
throws DuplicateNameException {
super.renameOverlaySpace(oldName, newName);
protected String renameOverlaySpace(String oldOverlaySpaceName, String newName) {
try {
String revisedName = fixupOverlaySpaceName(newName);
if (revisedName.equals(getBaseOverlayName(oldOverlaySpaceName))) {
return oldOverlaySpaceName;
}
revisedName = getUniqueOverlayName(revisedName);
return super.renameOverlaySpace(oldOverlaySpaceName, revisedName);
}
catch (DuplicateNameException e) {
throw new RuntimeException(e); // unexpected
}
}
private int getNextUniqueID() {

View file

@ -1184,46 +1184,55 @@ public class ProgramDB extends DomainObjectAdapterDB implements Program, ChangeM
}
/**
* Creates a new OverlayAddressSpace with the given name and base AddressSpace
* @param overlaySpaceName the name of the overlay space to create
* @param templateSpace the base AddressSpace to overlay
* Create a new OverlayAddressSpace based upon the given overlay blockName and base AddressSpace
* @param blockName the name of the overlay memory block which corresponds to the new overlay address
* space to be created. This name may be modified to produce a valid overlay space name and avoid
* duplication.
* @param originalSpace the base AddressSpace to overlay
* @param minOffset the min offset of the space
* @param maxOffset the max offset of the space
* @return the new space
* @throws DuplicateNameException if an AddressSpace already exists with the given name.
* @throws LockException if the program is shared and not checked out exclusively.
* @throws MemoryConflictException if image base override is active
*/
public AddressSpace addOverlaySpace(String overlaySpaceName, AddressSpace templateSpace,
public AddressSpace addOverlaySpace(String blockName, AddressSpace originalSpace,
long minOffset, long maxOffset)
throws DuplicateNameException, LockException, MemoryConflictException {
throws LockException, MemoryConflictException {
checkExclusiveAccess();
if (imageBaseOverride) {
throw new MemoryConflictException(
"Overlay spaces may not be created while an image-base override is active");
}
OverlayAddressSpace ovSpace = addressFactory.addOverlayAddressSpace(overlaySpaceName,
templateSpace, minOffset, maxOffset);
OverlayAddressSpace ovSpace = null;
lock.acquire();
try {
ovSpace = addressFactory.addOverlayAddressSpace(blockName, false, originalSpace,
minOffset, maxOffset);
overlaySpaceAdapter.addOverlaySpace(ovSpace);
}
catch (IOException e) {
dbError(e);
}
finally {
lock.release();
}
return ovSpace;
}
public void renameOverlaySpace(String oldName, String newName)
throws DuplicateNameException, LockException {
public void renameOverlaySpace(String oldOverlaySpaceName, String newName)
throws LockException {
checkExclusiveAccess();
addressFactory.renameOverlaySpace(oldName, newName);
try {
overlaySpaceAdapter.renameOverlaySpace(oldName, newName);
addrMap.renameOverlaySpace(oldName, newName);
}
catch (IOException e) {
dbError(e);
String revisedName = addressFactory.renameOverlaySpace(oldOverlaySpaceName, newName);
if (!revisedName.equals(oldOverlaySpaceName)) {
try {
overlaySpaceAdapter.renameOverlaySpace(oldOverlaySpaceName, revisedName);
addrMap.renameOverlaySpace(oldOverlaySpaceName, revisedName);
}
catch (IOException e) {
dbError(e);
}
}
}

View file

@ -27,7 +27,6 @@ import ghidra.program.database.map.AddressMapDB;
import ghidra.program.model.address.*;
import ghidra.program.model.mem.*;
import ghidra.util.exception.AssertException;
import ghidra.util.exception.DuplicateNameException;
public class MemoryBlockDB implements MemoryBlock {
@ -155,7 +154,7 @@ public class MemoryBlockDB implements MemoryBlock {
}
@Override
public void setName(String name) throws DuplicateNameException, LockException {
public void setName(String name) throws LockException {
String oldName = getName();
memMap.lock.acquire();
try {
@ -163,10 +162,10 @@ public class MemoryBlockDB implements MemoryBlock {
if (oldName.equals(name)) {
return;
}
memMap.checkBlockName(name, isOverlay());
memMap.checkBlockName(name);
try {
if (isOverlay()) {
memMap.overlayBlockRenamed(oldName, name);
memMap.overlayBlockRenamed(startAddress.getAddressSpace().getName(), name);
}
record.setString(MemoryMapDBAdapter.NAME_COL, name);
adapter.updateBlockRecord(record);

View file

@ -556,7 +556,7 @@ public class MemoryMapDB implements Memory, ManagerDB, LiveMemoryListener {
public MemoryBlock createInitializedBlock(String name, Address start, long size,
byte initialValue, TaskMonitor monitor, boolean overlay)
throws LockException, MemoryConflictException, AddressOverflowException,
CancelledException, DuplicateNameException {
CancelledException {
InputStream fillStream = null;
if (initialValue != 0) {
@ -572,17 +572,7 @@ public class MemoryMapDB implements Memory, ManagerDB, LiveMemoryListener {
}
private Address createOverlaySpace(String name, Address start, long dataLength)
throws MemoryConflictException, AddressOverflowException, DuplicateNameException,
LockException {
AddressSpace space = start.getAddressSpace();
if (space.isOverlaySpace()) {
throw new IllegalArgumentException("An overlay block may not be overlayed");
}
if (!space.isMemorySpace()) {
throw new IllegalArgumentException(
"Invalid physical address for overlay block: " + start.toString(true));
}
throws MemoryConflictException, AddressOverflowException, LockException {
start.addNoWrap(dataLength - 1);// just tests the AddressOverflow condition.
@ -596,8 +586,8 @@ public class MemoryMapDB implements Memory, ManagerDB, LiveMemoryListener {
@Override
public MemoryBlock createInitializedBlock(String name, Address start, InputStream is,
long length, TaskMonitor monitor, boolean overlay) throws MemoryConflictException,
AddressOverflowException, CancelledException, LockException, DuplicateNameException {
checkBlockName(name, overlay);
AddressOverflowException, CancelledException, LockException {
checkBlockName(name);
lock.acquire();
try {
checkBlockSize(length, true);
@ -640,10 +630,10 @@ public class MemoryMapDB implements Memory, ManagerDB, LiveMemoryListener {
@Override
public MemoryBlock createInitializedBlock(String name, Address start, FileBytes fileBytes,
long offset, long length, boolean overlay) throws LockException, DuplicateNameException,
long offset, long length, boolean overlay) throws LockException,
MemoryConflictException, AddressOverflowException, IndexOutOfBoundsException {
checkBlockName(name, overlay);
checkBlockName(name);
lock.acquire();
try {
checkBlockSize(length, true);
@ -694,9 +684,9 @@ public class MemoryMapDB implements Memory, ManagerDB, LiveMemoryListener {
@Override
public MemoryBlock createUninitializedBlock(String name, Address start, long size,
boolean overlay) throws MemoryConflictException, AddressOverflowException,
LockException, DuplicateNameException {
LockException {
checkBlockName(name, overlay);
checkBlockName(name);
lock.acquire();
try {
checkBlockSize(size, false);
@ -730,9 +720,9 @@ public class MemoryMapDB implements Memory, ManagerDB, LiveMemoryListener {
@Override
public MemoryBlock createBitMappedBlock(String name, Address start, Address mappedAddress,
long length, boolean overlay) throws MemoryConflictException, AddressOverflowException,
LockException, IllegalArgumentException, DuplicateNameException {
LockException, IllegalArgumentException {
checkBlockName(name, overlay);
checkBlockName(name);
lock.acquire();
try {
checkBlockSize(length, false);
@ -765,10 +755,9 @@ public class MemoryMapDB implements Memory, ManagerDB, LiveMemoryListener {
@Override
public MemoryBlock createByteMappedBlock(String name, Address start, Address mappedAddress,
long length, ByteMappingScheme byteMappingScheme, boolean overlay)
throws MemoryConflictException, AddressOverflowException, LockException,
DuplicateNameException {
throws MemoryConflictException, AddressOverflowException, LockException {
checkBlockName(name, overlay);
checkBlockName(name);
int mappingScheme = 0; // use for 1:1 mapping
if (byteMappingScheme == null) {
@ -810,27 +799,18 @@ public class MemoryMapDB implements Memory, ManagerDB, LiveMemoryListener {
/**
* Check new block name for validity
* @param name new block name
* @param isOverlay true if block is overlay
* @throws IllegalArgumentException if invalid block name specified
* @throws DuplicateNameException if name conflicts with an address space name
*/
void checkBlockName(
String name, boolean isOverlay)
throws IllegalArgumentException, DuplicateNameException {
if (!Memory.isValidAddressSpaceName(name)) {
void checkBlockName(String name) throws IllegalArgumentException {
if (!Memory.isValidMemoryBlockName(name)) {
throw new IllegalArgumentException("Invalid block name: " + name);
}
if (isOverlay && getAddressFactory().getAddressSpace(name) != null) {
throw new DuplicateNameException(
"Block name conflicts with existing address space: " + name);
}
}
@Override
public MemoryBlock createBlock(MemoryBlock block, String name, Address start, long length)
throws MemoryConflictException, AddressOverflowException, LockException,
DuplicateNameException {
checkBlockName(name, false);
throws MemoryConflictException, AddressOverflowException, LockException {
checkBlockName(name);
lock.acquire();
try {
checkBlockSize(length, block.isInitialized());
@ -2054,10 +2034,9 @@ public class MemoryMapDB implements Memory, ManagerDB, LiveMemoryListener {
}
}
public void overlayBlockRenamed(String oldName, String name)
throws DuplicateNameException, LockException {
program.renameOverlaySpace(oldName, name);
public void overlayBlockRenamed(String oldOverlaySpaceName, String name)
throws LockException {
program.renameOverlaySpace(oldOverlaySpaceName, name);
}
@Override

View file

@ -392,17 +392,28 @@ public class DefaultAddressFactory implements AddressFactory {
}
}
protected void renameOverlaySpace(String oldName, String newName)
/**
* Rename overlay with newName.
* @param oldOverlaySpaceName the existing overlay address space name
* @param newName the new name of the overlay address space.
* @return new name applied to existing overlay space
* @throws DuplicateNameException if space with newName already exists
* @throws IllegalArgumentException if specified oldOverlaySpaceName was not found as
* an existing overlay space
*/
protected String renameOverlaySpace(String oldOverlaySpaceName, String newName)
throws DuplicateNameException {
if (getAddressSpace(newName) != null) {
throw new DuplicateNameException("AddressSpace named " + newName + " already exists!");
}
AddressSpace space = getAddressSpace(oldName);
AddressSpace space = getAddressSpace(oldOverlaySpaceName);
if (space != null && space.isOverlaySpace()) {
((OverlayAddressSpace) space).setName(newName);
spaceNameTable.remove(oldName);
spaceNameTable.remove(oldOverlaySpaceName);
spaceNameTable.put(space.getName(), space);
return newName;
}
throw new IllegalArgumentException("No such overlay space: " + oldOverlaySpaceName);
}
/**

View file

@ -23,7 +23,8 @@ import ghidra.framework.store.LockException;
import ghidra.program.database.mem.*;
import ghidra.program.model.address.*;
import ghidra.program.model.listing.Program;
import ghidra.util.exception.*;
import ghidra.util.exception.CancelledException;
import ghidra.util.exception.NotFoundException;
import ghidra.util.task.TaskMonitor;
/**
@ -108,7 +109,7 @@ public interface Memory extends AddressSetView {
/**
* Create an initialized memory block and add it to this Memory.
* @param name block name (See {@link Memory#isValidAddressSpaceName(String)} for
* @param name block name (See {@link Memory#isValidMemoryBlockName(String)} for
* naming rules)
* @param start start address of the block
* @param is source of the data used to fill the block or null for zero initialization.
@ -125,16 +126,15 @@ public interface Memory extends AddressSetView {
* address space
* @throws CancelledException user cancelled operation
* @throws IllegalArgumentException if invalid block name specified
* @throws DuplicateNameException if name conflicts with an existing address space/overlay name
*/
public MemoryBlock createInitializedBlock(String name, Address start, InputStream is,
long length, TaskMonitor monitor, boolean overlay)
throws LockException, MemoryConflictException, AddressOverflowException,
CancelledException, IllegalArgumentException, DuplicateNameException;
CancelledException, IllegalArgumentException;
/**
* Create an initialized memory block and add it to this Memory.
* @param name block name (See {@link Memory#isValidAddressSpaceName(String)} for
* @param name block name (See {@link Memory#isValidMemoryBlockName(String)} for
* naming rules)
* @param start start of the block
* @param size block length (positive non-zero value required)
@ -150,18 +150,17 @@ public interface Memory extends AddressSetView {
* @throws AddressOverflowException if the start is beyond the
* address space
* @throws IllegalArgumentException if invalid block name specified
* @throws DuplicateNameException if name conflicts with an existing address space/overlay name
* @throws CancelledException user cancelled operation
*/
public MemoryBlock createInitializedBlock(String name, Address start, long size,
byte initialValue, TaskMonitor monitor, boolean overlay)
throws LockException, IllegalArgumentException, DuplicateNameException,
MemoryConflictException, AddressOverflowException, CancelledException;
throws LockException, IllegalArgumentException, MemoryConflictException,
AddressOverflowException, CancelledException;
/**
* Create an initialized memory block using bytes from a {@link FileBytes} object.
*
* @param name block name (See {@link Memory#isValidAddressSpaceName(String)} for
* @param name block name (See {@link Memory#isValidMemoryBlockName(String)} for
* naming rules)
* @param start starting address of the block
* @param fileBytes the {@link FileBytes} object to use as the underlying source of bytes.
@ -178,15 +177,14 @@ public interface Memory extends AddressSetView {
* @throws IndexOutOfBoundsException if file bytes range specified by offset and size
* is out of bounds for the specified fileBytes.
* @throws IllegalArgumentException if invalid block name specified
* @throws DuplicateNameException if name conflicts with an existing address space/overlay name
*/
public MemoryBlock createInitializedBlock(String name, Address start, FileBytes fileBytes,
long offset, long size, boolean overlay) throws LockException, IllegalArgumentException,
DuplicateNameException, MemoryConflictException, AddressOverflowException;
MemoryConflictException, AddressOverflowException;
/**
* Create an uninitialized memory block and add it to this Memory.
* @param name block name (See {@link Memory#isValidAddressSpaceName(String)} for
* @param name block name (See {@link Memory#isValidMemoryBlockName(String)} for
* naming rules)
* @param start start of the block
* @param size block length
@ -200,15 +198,14 @@ public interface Memory extends AddressSetView {
* @throws AddressOverflowException if the start is beyond the
* address space
* @throws IllegalArgumentException if invalid block name specified
* @throws DuplicateNameException if name conflicts with an existing address space/overlay name
*/
public MemoryBlock createUninitializedBlock(String name, Address start, long size,
boolean overlay) throws LockException, IllegalArgumentException, DuplicateNameException,
boolean overlay) throws LockException, IllegalArgumentException,
MemoryConflictException, AddressOverflowException;
/**
* Create a bit overlay memory block and add it to this Memory.
* @param name block name (See {@link Memory#isValidAddressSpaceName(String)} for
* @param name block name (See {@link Memory#isValidMemoryBlockName(String)} for
* naming rules)
* @param start start of the block
* @param mappedAddress start address in the source block for the
@ -225,17 +222,15 @@ public interface Memory extends AddressSetView {
* previous block
* @throws AddressOverflowException if block specification exceeds bounds of address space
* @throws IllegalArgumentException if invalid block name specified
* @throws DuplicateNameException if name conflicts with an existing address space/overlay name
*/
public MemoryBlock createBitMappedBlock(String name, Address start, Address mappedAddress,
long length, boolean overlay) throws LockException, MemoryConflictException,
AddressOverflowException,
IllegalArgumentException, DuplicateNameException;
AddressOverflowException, IllegalArgumentException;
/**
* Create a memory block that uses the bytes located at a different location with a 1:1
* byte mapping scheme.
* @param name block name (See {@link Memory#isValidAddressSpaceName(String)} for
* @param name block name (See {@link Memory#isValidMemoryBlockName(String)} for
* naming rules)
* @param start start of the block
* @param mappedAddress start address in the source block for the
@ -250,17 +245,16 @@ public interface Memory extends AddressSetView {
* @throws MemoryConflictException if the new block overlaps with a previous block
* @throws AddressOverflowException if block specification exceeds bounds of address space
* @throws IllegalArgumentException if invalid block name
* @throws DuplicateNameException if name conflicts with an existing address space/overlay name
*/
public MemoryBlock createByteMappedBlock(String name, Address start, Address mappedAddress,
long length, ByteMappingScheme byteMappingScheme, boolean overlay)
throws LockException, MemoryConflictException, AddressOverflowException,
IllegalArgumentException, DuplicateNameException;
IllegalArgumentException;
/**
* Create a memory block that uses the bytes located at a different location with a 1:1
* byte mapping scheme.
* @param name block name (See {@link Memory#isValidAddressSpaceName(String)} for
* @param name block name (See {@link Memory#isValidMemoryBlockName(String)} for
* naming rules)
* @param start start of the block
* @param mappedAddress start address in the source block for the
@ -274,12 +268,11 @@ public interface Memory extends AddressSetView {
* @throws MemoryConflictException if the new block overlaps with a previous block
* @throws AddressOverflowException if block specification exceeds bounds of address space
* @throws IllegalArgumentException if invalid block name
* @throws DuplicateNameException if name conflicts with an existing address space/overlay name
*/
default public MemoryBlock createByteMappedBlock(String name, Address start,
Address mappedAddress, long length, boolean overlay) throws LockException,
MemoryConflictException,
AddressOverflowException, IllegalArgumentException, DuplicateNameException {
AddressOverflowException, IllegalArgumentException {
return createByteMappedBlock(name, start, mappedAddress, length, null, overlay);
}
@ -289,7 +282,7 @@ public interface Memory extends AddressSetView {
* have block filled with 0's. Method will only create physical space blocks
* and will not create an overlay block.
* @param block source block
* @param name block name (See {@link Memory#isValidAddressSpaceName(String)} for
* @param name block name (See {@link Memory#isValidMemoryBlockName(String)} for
* naming rules).
* @param start start of the block
* @param length the size of the new block.
@ -298,12 +291,11 @@ public interface Memory extends AddressSetView {
* @throws MemoryConflictException if block specification conflicts with an existing block
* @throws AddressOverflowException if the new memory block would extend
* beyond the end of the address space.
* @throws IllegalArgumentException if invalid block name specified
* @throws DuplicateNameException if name conflicts with an existing address space/overlay name
* @throws IllegalArgumentException if invalid block name specifiede
*/
public MemoryBlock createBlock(MemoryBlock block, String name, Address start, long length)
throws LockException, IllegalArgumentException, MemoryConflictException,
AddressOverflowException, DuplicateNameException;
AddressOverflowException;
/**
* Remove the memory block.
@ -816,17 +808,22 @@ public interface Memory extends AddressSetView {
public AddressSourceInfo getAddressSourceInfo(Address address);
/**
* Validate the given address space or block name: cannot be null, cannot be an empty string, cannot contain blank
* or reserved characters (e.g., colon).
* Validate the given block name: cannot be null, cannot be an empty string,
* cannot contain control characters (ASCII 0..0x19).
* <BR>
* NOTE: When producing an overlay memory space which corresponds to a block, the space
* name will be modified to be consistent with address space name restrictions
* and to ensure uniqueness.
* @param name memory block name
* @return true if name is valid else false
*/
public static boolean isValidAddressSpaceName(String name) {
public static boolean isValidMemoryBlockName(String name) {
if (name == null || name.length() == 0) {
return false;
}
for (int i = 0; i < name.length(); i++) {
char c = name.charAt(i);
if (c <= 0x20 || c >= 0x7f || c == ':') {
if (c < 0x20) {
return false;
}
}

View file

@ -23,7 +23,6 @@ import ghidra.framework.store.LockException;
import ghidra.program.model.address.Address;
import ghidra.program.model.listing.Program;
import ghidra.util.NamingUtilities;
import ghidra.util.exception.DuplicateNameException;
/**
* Interface that defines a block in memory.
@ -90,12 +89,11 @@ public interface MemoryBlock extends Serializable, Comparable<MemoryBlock> {
* Set the name for this block (See {@link NamingUtilities#isValidName(String)} for
* naming rules). Specified name must not conflict with an address space name.
* @param name the new name for this block.
* @throws DuplicateNameException if name conflicts with an address space name
* @throws IllegalArgumentException if invalid name specified
* @throws LockException renaming an Overlay block without exclusive access
*/
public void setName(String name)
throws IllegalArgumentException, DuplicateNameException, LockException;
throws IllegalArgumentException, LockException;
/**
* Get the comment associated with this block.

View file

@ -20,7 +20,6 @@ import java.util.List;
import ghidra.framework.store.LockException;
import ghidra.program.model.address.Address;
import ghidra.util.exception.DuplicateNameException;
/**
* MemoryBlockStub can be extended for use by tests. It throws an UnsupportedOperationException
@ -81,7 +80,7 @@ public class MemoryBlockStub implements MemoryBlock {
}
@Override
public void setName(String name) throws DuplicateNameException, LockException {
public void setName(String name) throws LockException {
throw new UnsupportedOperationException();
}

View file

@ -24,7 +24,7 @@ import ghidra.framework.store.LockException;
import ghidra.program.database.mem.*;
import ghidra.program.model.address.*;
import ghidra.program.model.listing.Program;
import ghidra.util.exception.*;
import ghidra.util.exception.NotFoundException;
import ghidra.util.task.TaskMonitor;
/**
@ -187,24 +187,19 @@ public class MemoryStub extends AddressSet implements Memory {
@Override
public MemoryBlock createInitializedBlock(String name, Address start, InputStream is,
long length, TaskMonitor monitor, boolean overlay)
throws LockException, MemoryConflictException, AddressOverflowException,
CancelledException, DuplicateNameException {
long length, TaskMonitor monitor, boolean overlay) {
throw new UnsupportedOperationException();
}
@Override
public MemoryBlock createInitializedBlock(String name, Address start, long size,
byte initialValue, TaskMonitor monitor, boolean overlay)
throws LockException, DuplicateNameException, MemoryConflictException,
AddressOverflowException, CancelledException {
byte initialValue, TaskMonitor monitor, boolean overlay) {
throw new UnsupportedOperationException();
}
@Override
public MemoryBlock createUninitializedBlock(String name, Address start, long size,
boolean overlay) throws LockException, DuplicateNameException, MemoryConflictException,
AddressOverflowException {
boolean overlay) {
throw new UnsupportedOperationException();
}
@ -463,8 +458,7 @@ public class MemoryStub extends AddressSet implements Memory {
@Override
public MemoryBlock createInitializedBlock(String name, Address start, FileBytes fileBytes,
long offset, long size, boolean overlay) throws LockException, DuplicateNameException,
MemoryConflictException, AddressOverflowException {
long offset, long size, boolean overlay) {
throw new UnsupportedOperationException();
}