GP-4125 Added memory block artificial attribute flag

This commit is contained in:
ghidra1 2024-03-06 16:53:12 -05:00
parent ddf4d15327
commit ae475f743b
48 changed files with 734 additions and 465 deletions

View file

@ -47,7 +47,7 @@ public class MemoryBlockDefinition {
private boolean readPermission = true;
private boolean writePermission = true;
private boolean executePermission = false;
private boolean volatilePermission = false;
private boolean isVolatile = false;
/**
* Construct <code>MemoryBlockDefinition</code> using a text-based specified.
@ -107,7 +107,7 @@ public class MemoryBlockDefinition {
readPermission = mode.indexOf('r') >= 0;
writePermission = mode.indexOf('w') >= 0;
executePermission = mode.indexOf('x') >= 0;
volatilePermission = mode.indexOf('v') >= 0;
isVolatile = mode.indexOf('v') >= 0;
}
try {
length = XmlUtilities.parseInt(lengthString);
@ -186,7 +186,7 @@ public class MemoryBlockDefinition {
block.setRead(readPermission);
block.setWrite(writePermission);
block.setExecute(executePermission);
block.setVolatile(volatilePermission);
block.setVolatile(isVolatile);
}
@Override

View file

@ -117,8 +117,8 @@ public class MemoryBlockDB implements MemoryBlock {
}
@Override
public int getPermissions() {
return record.getByteValue(MemoryMapDBAdapter.PERMISSIONS_COL);
public int getFlags() {
return record.getByteValue(MemoryMapDBAdapter.FLAGS_COL);
}
@Override
@ -224,7 +224,7 @@ public class MemoryBlockDB implements MemoryBlock {
@Override
public boolean isRead() {
return (record.getByteValue(MemoryMapDBAdapter.PERMISSIONS_COL) & READ) != 0;
return (record.getByteValue(MemoryMapDBAdapter.FLAGS_COL) & READ) != 0;
}
@Override
@ -232,8 +232,9 @@ public class MemoryBlockDB implements MemoryBlock {
memMap.lock.acquire();
try {
checkValid();
setPermissionBit(READ, r);
memMap.fireBlockChanged(this);
if (setFlagBit(READ, r)) {
memMap.fireBlockChanged(this);
}
}
finally {
memMap.lock.release();
@ -242,7 +243,7 @@ public class MemoryBlockDB implements MemoryBlock {
@Override
public boolean isWrite() {
return (record.getByteValue(MemoryMapDBAdapter.PERMISSIONS_COL) & WRITE) != 0;
return (record.getByteValue(MemoryMapDBAdapter.FLAGS_COL) & WRITE) != 0;
}
@Override
@ -250,8 +251,9 @@ public class MemoryBlockDB implements MemoryBlock {
memMap.lock.acquire();
try {
checkValid();
setPermissionBit(WRITE, w);
memMap.fireBlockChanged(this);
if (setFlagBit(WRITE, w)) {
memMap.fireBlockChanged(this);
}
}
finally {
memMap.lock.release();
@ -260,7 +262,7 @@ public class MemoryBlockDB implements MemoryBlock {
@Override
public boolean isExecute() {
return (record.getByteValue(MemoryMapDBAdapter.PERMISSIONS_COL) & EXECUTE) != 0;
return (record.getByteValue(MemoryMapDBAdapter.FLAGS_COL) & EXECUTE) != 0;
}
@Override
@ -268,9 +270,10 @@ public class MemoryBlockDB implements MemoryBlock {
memMap.lock.acquire();
try {
checkValid();
setPermissionBit(EXECUTE, x);
memMap.blockExecuteChanged(this);
memMap.fireBlockChanged(this);
if (setFlagBit(EXECUTE, x)) {
memMap.blockExecuteChanged(this);
memMap.fireBlockChanged(this);
}
}
finally {
memMap.lock.release();
@ -282,11 +285,13 @@ public class MemoryBlockDB implements MemoryBlock {
memMap.lock.acquire();
try {
checkValid();
setPermissionBit(READ, read);
setPermissionBit(WRITE, write);
setPermissionBit(EXECUTE, execute);
memMap.blockExecuteChanged(this);
memMap.fireBlockChanged(this);
boolean changed = setFlagBit(READ, read);
changed |= setFlagBit(WRITE, write);
changed |= setFlagBit(EXECUTE, execute);
if (changed) {
memMap.blockExecuteChanged(this);
memMap.fireBlockChanged(this);
}
}
finally {
memMap.lock.release();
@ -295,7 +300,7 @@ public class MemoryBlockDB implements MemoryBlock {
@Override
public boolean isVolatile() {
return (record.getByteValue(MemoryMapDBAdapter.PERMISSIONS_COL) & VOLATILE) != 0;
return (record.getByteValue(MemoryMapDBAdapter.FLAGS_COL) & VOLATILE) != 0;
}
@Override
@ -303,8 +308,28 @@ public class MemoryBlockDB implements MemoryBlock {
memMap.lock.acquire();
try {
checkValid();
setPermissionBit(VOLATILE, v);
memMap.fireBlockChanged(this);
if (setFlagBit(VOLATILE, v)) {
memMap.fireBlockChanged(this);
}
}
finally {
memMap.lock.release();
}
}
@Override
public boolean isArtificial() {
return (record.getByteValue(MemoryMapDBAdapter.FLAGS_COL) & ARTIFICIAL) != 0;
}
@Override
public void setArtificial(boolean a) {
memMap.lock.acquire();
try {
checkValid();
if (setFlagBit(ARTIFICIAL, a)) {
memMap.fireBlockChanged(this);
}
}
finally {
memMap.lock.release();
@ -430,21 +455,28 @@ public class MemoryBlockDB implements MemoryBlock {
}
}
private void setPermissionBit(int permBitMask, boolean enable) {
byte p = record.getByteValue(MemoryMapDBAdapter.PERMISSIONS_COL);
private boolean setFlagBit(int flagBitMask, boolean enable) {
byte p = record.getByteValue(MemoryMapDBAdapter.FLAGS_COL);
if (enable) {
p |= permBitMask;
if ((p & flagBitMask) == flagBitMask) {
return false; // no change
}
p |= flagBitMask;
}
else {
p &= ~permBitMask;
if ((p & flagBitMask) == 0) {
return false; // no change
}
p &= ~flagBitMask;
}
record.setByteValue(MemoryMapDBAdapter.PERMISSIONS_COL, p);
record.setByteValue(MemoryMapDBAdapter.FLAGS_COL, p);
try {
adapter.updateBlockRecord(record);
}
catch (IOException e) {
memMap.dbError(e);
}
return true;
}
@Override
@ -634,8 +666,7 @@ public class MemoryBlockDB implements MemoryBlock {
splitBlocks.addAll(subList);
subList.clear();
}
return adapter.createBlock(getName() + ".split", addr, newLength, getPermissions(),
splitBlocks);
return adapter.createBlock(getName() + ".split", addr, newLength, getFlags(), splitBlocks);
}
private int getIndexOfSubBlockToSplit(long offset) {

View file

@ -901,7 +901,7 @@ public class MemoryMapDB implements Memory, ManagerDB, LiveMemoryListener {
mappedAddr = info.getMappedRange().get().getMinAddress();
}
MemoryBlockDB newBlock = adapter.createBlock(block.getType(), name, start, length,
mappedAddr, block.isInitialized(), block.getPermissions(), mappingScheme);
mappedAddr, block.isInitialized(), block.getFlags(), mappingScheme);
allAddrSet.add(newBlock.getStart(), newBlock.getEnd());
initializeBlocks();
fireBlockAdded(newBlock);

View file

@ -35,7 +35,7 @@ abstract class MemoryMapDBAdapter {
static final int NAME_COL = MemoryMapDBAdapterV3.V3_NAME_COL;
static final int COMMENTS_COL = MemoryMapDBAdapterV3.V3_COMMENTS_COL;
static final int SOURCE_COL = MemoryMapDBAdapterV3.V3_SOURCE_COL;
static final int PERMISSIONS_COL = MemoryMapDBAdapterV3.V3_PERMISSIONS_COL;
static final int FLAGS_COL = MemoryMapDBAdapterV3.V3_FLAGS_COL;
static final int START_ADDR_COL = MemoryMapDBAdapterV3.V3_START_ADDR_COL;
static final int LENGTH_COL = MemoryMapDBAdapterV3.V3_LENGTH_COL;
static final int SEGMENT_COL = MemoryMapDBAdapterV3.V3_SEGMENT_COL;
@ -130,7 +130,7 @@ abstract class MemoryMapDBAdapter {
if (block.isInitialized()) {
DBBuffer buf = block.getBuffer();
newBlock = newAdapter.createInitializedBlock(block.getName(), block.getStart(),
buf, block.getPermissions());
buf, block.getFlags());
}
else {
Address mappedAddress = null;
@ -141,7 +141,7 @@ abstract class MemoryMapDBAdapter {
}
newBlock =
newAdapter.createBlock(block.getType(), block.getName(), block.getStart(),
block.getSize(), mappedAddress, false, block.getPermissions(), 0);
block.getSize(), mappedAddress, false, block.getFlags(), 0);
}
newBlock.setComment(block.getComment());
newBlock.setSourceName(block.getSourceName());
@ -185,26 +185,26 @@ abstract class MemoryMapDBAdapter {
* @param startAddr the start address of the block.
* @param is data source or null for zero initialization
* @param length size of block
* @param permissions the new block permissions
* @param flags the new block flags
* @return new memory block
* @throws IOException
* @throws IOException if a database IO error occurs.
* @throws AddressOverflowException if block length is too large for the underlying space
*/
abstract MemoryBlockDB createInitializedBlock(String name, Address startAddr, InputStream is,
long length, int permissions) throws AddressOverflowException, IOException;
long length, int flags) throws AddressOverflowException, IOException;
/**
* Creates a new initialized block object
* @param name the name of the block
* @param startAddr the start address of the block.
* @param buf the DBBuffer used to hold the bytes for the block.
* @param permissions the new block permissions
* @param flags the new block flags
* @return new memory block
* @throws IOException if a database IO error occurs.
* @throws AddressOverflowException if block length is too large for the underlying space
*/
abstract MemoryBlockDB createInitializedBlock(String name, Address startAddr, DBBuffer buf,
int permissions) throws AddressOverflowException, IOException;
int flags) throws AddressOverflowException, IOException;
/**
* Creates a new memory block that doesn't have associated bytes.
@ -216,14 +216,14 @@ abstract class MemoryMapDBAdapter {
* the block. (used for bit/byte-mapped blocks only)
* @param initializeBytes if true, creates a database buffer for storing the
* bytes in the block (applies to initialized default blocks only)
* @param permissions the new block permissions
* @param flags the new block flags
* @param encodedMappingScheme byte mapping scheme (used by byte-mapped blocks only)
* @return new memory block
* @throws IOException if a database IO error occurs.
* @throws AddressOverflowException if block length is too large for the underlying space
*/
abstract MemoryBlockDB createBlock(MemoryBlockType blockType, String name, Address startAddr,
long length, Address mappedAddress, boolean initializeBytes, int permissions,
long length, Address mappedAddress, boolean initializeBytes, int flags,
int encodedMappingScheme) throws AddressOverflowException, IOException;
/**
@ -289,13 +289,13 @@ abstract class MemoryMapDBAdapter {
* @param name the name of the block
* @param startAddress the start address of the block
* @param length the length of the block
* @param permissions the permissions for the block
* @param flags the flags for the block
* @param splitBlocks the list of subBlock objects that make up this block
* @return the new MemoryBlock
* @throws IOException if a database error occurs
*/
protected abstract MemoryBlockDB createBlock(String name, Address startAddress, long length,
int permissions, List<SubMemoryBlock> splitBlocks) throws IOException;
int flags, List<SubMemoryBlock> splitBlocks) throws IOException;
/**
* Creates a new memory block using a FileBytes
@ -304,12 +304,12 @@ abstract class MemoryMapDBAdapter {
* @param length the length of the block
* @param fileBytes the {@link FileBytes} object that provides the bytes for this block
* @param offset the offset into the {@link FileBytes} object
* @param permissions the permissions for the block
* @param flags the flags for the block
* @return the new MemoryBlock
* @throws IOException if a database error occurs
* @throws AddressOverflowException if block length is too large for the underlying space
*/
protected abstract MemoryBlockDB createFileBytesBlock(String name, Address startAddress,
long length, FileBytes fileBytes, long offset, int permissions)
long length, FileBytes fileBytes, long offset, int flags)
throws IOException, AddressOverflowException;
}

View file

@ -106,15 +106,15 @@ class MemoryMapDBAdapterV0 extends MemoryMapDBAdapter {
RecordIterator it = table.iterator();
while (it.hasNext()) {
DBRecord rec = it.next();
int permissions = 0;
int flags = 0;
if (rec.getBooleanValue(V0_IS_READ_COL)) {
permissions |= MemoryBlock.READ;
flags |= MemoryBlock.READ;
}
if (rec.getBooleanValue(V0_IS_WRITE_COL)) {
permissions |= MemoryBlock.WRITE;
flags |= MemoryBlock.WRITE;
}
if (rec.getBooleanValue(V0_IS_EXECUTE_COL)) {
permissions |= MemoryBlock.EXECUTE;
flags |= MemoryBlock.EXECUTE;
}
Address start = addrFactory.oldGetAddressFromLong(rec.getLongValue(V0_START_ADDR_COL));
long startAddr = addrMap.getKey(start, false);
@ -131,7 +131,7 @@ class MemoryMapDBAdapterV0 extends MemoryMapDBAdapter {
blockRecord.setString(NAME_COL, rec.getString(V0_NAME_COL));
blockRecord.setString(COMMENTS_COL, rec.getString(V0_COMMENTS_COL));
blockRecord.setString(SOURCE_COL, rec.getString(V0_SOURCE_NAME_COL));
blockRecord.setByteValue(PERMISSIONS_COL, (byte) permissions);
blockRecord.setByteValue(FLAGS_COL, (byte) flags);
blockRecord.setLongValue(START_ADDR_COL, startAddr);
blockRecord.setLongValue(LENGTH_COL, length);
blockRecord.setIntValue(SEGMENT_COL, segment);
@ -195,13 +195,13 @@ class MemoryMapDBAdapterV0 extends MemoryMapDBAdapter {
@Override
MemoryBlockDB createInitializedBlock(String name, Address startAddr, InputStream is,
long length, int permissions) throws IOException {
long length, int flags) throws IOException {
throw new UnsupportedOperationException();
}
@Override
MemoryBlockDB createInitializedBlock(String name, Address startAddr, DBBuffer buf,
int permissions) throws IOException {
MemoryBlockDB createInitializedBlock(String name, Address startAddr, DBBuffer buf, int flags)
throws IOException {
throw new UnsupportedOperationException();
}
@ -231,8 +231,7 @@ class MemoryMapDBAdapterV0 extends MemoryMapDBAdapter {
@Override
MemoryBlockDB createBlock(MemoryBlockType blockType, String name, Address startAddr,
long length, Address overlayAddr, boolean initializeBytes, int permissions,
int mappingScheme)
long length, Address overlayAddr, boolean initializeBytes, int flags, int mappingScheme)
throws IOException {
throw new UnsupportedOperationException();
}
@ -267,14 +266,14 @@ class MemoryMapDBAdapterV0 extends MemoryMapDBAdapter {
}
@Override
protected MemoryBlockDB createBlock(String name, Address addr, long length, int permissions,
protected MemoryBlockDB createBlock(String name, Address addr, long length, int flags,
List<SubMemoryBlock> splitBlocks) {
throw new UnsupportedOperationException();
}
@Override
protected MemoryBlockDB createFileBytesBlock(String name, Address startAddress, long length,
FileBytes fileBytes, long offset, int permissions)
FileBytes fileBytes, long offset, int flags)
throws IOException, AddressOverflowException {
throw new UnsupportedOperationException();
}

View file

@ -45,9 +45,6 @@ class MemoryMapDBAdapterV1 extends MemoryMapDBAdapterV0 {
// "Source Block ID","Segment"});
//
/**
* @param handle
*/
MemoryMapDBAdapterV1(DBHandle handle, MemoryMapDB memMap) throws VersionException, IOException {
super(handle, memMap, VERSION);
}

View file

@ -63,7 +63,6 @@ class MemoryMapDBAdapterV2 extends MemoryMapDBAdapter {
// new String[] { "Name", "Comments", "Source Name", "Permissions", "Start Address",
// "Block Type", "Overlay Address", "Length", "Chain Buffer ID", "Segment" });
protected MemoryMapDBAdapterV2(DBHandle handle, MemoryMapDB memMap)
throws VersionException, IOException {
this.handle = handle;
@ -86,7 +85,7 @@ class MemoryMapDBAdapterV2 extends MemoryMapDBAdapter {
RecordIterator it = table.iterator();
while (it.hasNext()) {
DBRecord rec = it.next();
int permissions = rec.getByteValue(V2_PERMISSIONS_COL);
int flags = rec.getByteValue(V2_PERMISSIONS_COL);
long startAddr = rec.getLongValue(V2_START_ADDR_COL);
long length = rec.getLongValue(V2_LENGTH_COL);
@ -99,7 +98,7 @@ class MemoryMapDBAdapterV2 extends MemoryMapDBAdapter {
blockRecord.setString(NAME_COL, rec.getString(V2_NAME_COL));
blockRecord.setString(COMMENTS_COL, rec.getString(V2_COMMENTS_COL));
blockRecord.setString(SOURCE_COL, rec.getString(V2_SOURCE_COL));
blockRecord.setByteValue(PERMISSIONS_COL, (byte) permissions);
blockRecord.setByteValue(FLAGS_COL, (byte) flags);
blockRecord.setLongValue(START_ADDR_COL, startAddr);
blockRecord.setLongValue(LENGTH_COL, length);
blockRecord.setIntValue(SEGMENT_COL, segment);
@ -149,22 +148,21 @@ class MemoryMapDBAdapterV2 extends MemoryMapDBAdapter {
}
@Override
MemoryBlockDB createInitializedBlock(String name, Address startAddr, DBBuffer buf,
int permissions) throws AddressOverflowException, IOException {
MemoryBlockDB createInitializedBlock(String name, Address startAddr, DBBuffer buf, int flags)
throws AddressOverflowException, IOException {
throw new UnsupportedOperationException();
}
@Override
MemoryBlockDB createInitializedBlock(String name, Address startAddr, InputStream is,
long length, int permissions) throws AddressOverflowException, IOException {
long length, int flags) throws AddressOverflowException, IOException {
throw new UnsupportedOperationException();
}
@Override
MemoryBlockDB createBlock(MemoryBlockType blockType, String name, Address startAddr,
long length, Address mappedAddress, boolean initializeBytes, int permissions,
int mappingScheme)
throws AddressOverflowException, IOException {
long length, Address mappedAddress, boolean initializeBytes, int flags,
int mappingScheme) throws AddressOverflowException, IOException {
throw new UnsupportedOperationException();
}
@ -223,14 +221,14 @@ class MemoryMapDBAdapterV2 extends MemoryMapDBAdapter {
}
@Override
protected MemoryBlockDB createBlock(String name, Address addr, long length, int permissions,
protected MemoryBlockDB createBlock(String name, Address addr, long length, int flags,
List<SubMemoryBlock> splitBlocks) {
throw new UnsupportedOperationException();
}
@Override
protected MemoryBlockDB createFileBytesBlock(String name, Address startAddress, long length,
FileBytes fileBytes, long offset, int permissions)
FileBytes fileBytes, long offset, int flags)
throws IOException, AddressOverflowException {
throw new UnsupportedOperationException();
}

View file

@ -39,7 +39,7 @@ public class MemoryMapDBAdapterV3 extends MemoryMapDBAdapter {
static final int V3_NAME_COL = 0;
static final int V3_COMMENTS_COL = 1;
static final int V3_SOURCE_COL = 2;
static final int V3_PERMISSIONS_COL = 3;
static final int V3_FLAGS_COL = 3;
static final int V3_START_ADDR_COL = 4;
static final int V3_LENGTH_COL = 5;
static final int V3_SEGMENT_COL = 6;
@ -60,7 +60,7 @@ public class MemoryMapDBAdapterV3 extends MemoryMapDBAdapter {
static Schema V3_BLOCK_SCHEMA = new Schema(V3_VERSION, "Key",
new Field[] { StringField.INSTANCE, StringField.INSTANCE, StringField.INSTANCE,
ByteField.INSTANCE, LongField.INSTANCE, LongField.INSTANCE, IntField.INSTANCE },
new String[] { "Name", "Comments", "Source Name", "Permissions", "Start Address", "Length",
new String[] { "Name", "Comments", "Source Name", "Flags", "Start Address", "Length",
"Segment" });
static Schema V3_SUB_BLOCK_SCHEMA = new Schema(V3_VERSION, "Key",
@ -116,8 +116,8 @@ public class MemoryMapDBAdapterV3 extends MemoryMapDBAdapter {
void refreshMemory() throws IOException {
Map<Long, List<SubMemoryBlock>> subBlockMap = getSubBlockMap();
Map<Long, MemoryBlockDB> blockMap = memoryBlocks.stream().collect(
Collectors.toMap(MemoryBlockDB::getID, Function.identity()));
Map<Long, MemoryBlockDB> blockMap = memoryBlocks.stream()
.collect(Collectors.toMap(MemoryBlockDB::getID, Function.identity()));
List<MemoryBlockDB> newBlocks = new ArrayList<>();
RecordIterator it = memBlockTable.iterator();
@ -163,14 +163,14 @@ public class MemoryMapDBAdapterV3 extends MemoryMapDBAdapter {
@Override
MemoryBlockDB createInitializedBlock(String name, Address startAddr, InputStream is,
long length, int permissions) throws AddressOverflowException, IOException {
long length, int flags) throws AddressOverflowException, IOException {
// TODO verify that it is necessary to pre-define all segments in the address map
updateAddressMapForAllAddresses(startAddr, length);
List<SubMemoryBlock> subBlocks = new ArrayList<>();
try {
DBRecord blockRecord = createMemoryBlockRecord(name, startAddr, length, permissions);
DBRecord blockRecord = createMemoryBlockRecord(name, startAddr, length, flags);
long key = blockRecord.getKey();
int numFullBlocks = (int) (length / maxSubBlockSize);
int lastSubBlockSize = (int) (length % maxSubBlockSize);
@ -201,30 +201,30 @@ public class MemoryMapDBAdapterV3 extends MemoryMapDBAdapter {
@Override
MemoryBlockDB createBlock(MemoryBlockType blockType, String name, Address startAddr,
long length, Address mappedAddress, boolean initializeBytes, int permissions,
long length, Address mappedAddress, boolean initializeBytes, int flags,
int encodedMappingScheme) throws AddressOverflowException, IOException {
if (blockType == MemoryBlockType.BIT_MAPPED) {
return createBitMappedBlock(name, startAddr, length, mappedAddress, permissions);
return createBitMappedBlock(name, startAddr, length, mappedAddress, flags);
}
if (blockType == MemoryBlockType.BYTE_MAPPED) {
return createByteMappedBlock(name, startAddr, length, mappedAddress, permissions,
return createByteMappedBlock(name, startAddr, length, mappedAddress, flags,
encodedMappingScheme);
}
// DEFAULT block type
if (initializeBytes) {
return createInitializedBlock(name, startAddr, null, length, permissions);
return createInitializedBlock(name, startAddr, null, length, flags);
}
return createUninitializedBlock(name, startAddr, length, permissions);
return createUninitializedBlock(name, startAddr, length, flags);
}
@Override
MemoryBlockDB createInitializedBlock(String name, Address startAddr, DBBuffer buf,
int permissions) throws AddressOverflowException, IOException {
MemoryBlockDB createInitializedBlock(String name, Address startAddr, DBBuffer buf, int flags)
throws AddressOverflowException, IOException {
updateAddressMapForAllAddresses(startAddr, buf.length());
List<SubMemoryBlock> subBlocks = new ArrayList<>();
DBRecord blockRecord = createMemoryBlockRecord(name, startAddr, buf.length(), permissions);
DBRecord blockRecord = createMemoryBlockRecord(name, startAddr, buf.length(), flags);
long key = blockRecord.getKey();
DBRecord subRecord =
@ -239,11 +239,11 @@ public class MemoryMapDBAdapterV3 extends MemoryMapDBAdapter {
}
MemoryBlockDB createUninitializedBlock(String name, Address startAddress, long length,
int permissions) throws IOException, AddressOverflowException {
int flags) throws IOException, AddressOverflowException {
updateAddressMapForAllAddresses(startAddress, length);
List<SubMemoryBlock> subBlocks = new ArrayList<>();
DBRecord blockRecord = createMemoryBlockRecord(name, startAddress, length, permissions);
DBRecord blockRecord = createMemoryBlockRecord(name, startAddress, length, flags);
long key = blockRecord.getKey();
DBRecord subRecord = createSubBlockRecord(key, 0, length, V3_SUB_TYPE_UNINITIALIZED, 0, 0);
@ -256,9 +256,9 @@ public class MemoryMapDBAdapterV3 extends MemoryMapDBAdapter {
}
@Override
protected MemoryBlockDB createBlock(String name, Address startAddress, long length,
int permissions, List<SubMemoryBlock> splitBlocks) throws IOException {
DBRecord blockRecord = createMemoryBlockRecord(name, startAddress, length, permissions);
protected MemoryBlockDB createBlock(String name, Address startAddress, long length, int flags,
List<SubMemoryBlock> splitBlocks) throws IOException {
DBRecord blockRecord = createMemoryBlockRecord(name, startAddress, length, flags);
long key = blockRecord.getKey();
long startingOffset = 0;
@ -274,26 +274,26 @@ public class MemoryMapDBAdapterV3 extends MemoryMapDBAdapter {
}
MemoryBlockDB createBitMappedBlock(String name, Address startAddress, long length,
Address mappedAddress, int permissions) throws IOException, AddressOverflowException {
Address mappedAddress, int flags) throws IOException, AddressOverflowException {
return createMappedBlock(V3_SUB_TYPE_BIT_MAPPED, name, startAddress, length, mappedAddress,
permissions, 0);
flags, 0);
}
MemoryBlockDB createByteMappedBlock(String name, Address startAddress, long length,
Address mappedAddress, int permissions, int mappingScheme)
Address mappedAddress, int flags, int mappingScheme)
throws IOException, AddressOverflowException {
return createMappedBlock(V3_SUB_TYPE_BYTE_MAPPED, name, startAddress, length, mappedAddress,
permissions, mappingScheme);
flags, mappingScheme);
}
@Override
protected MemoryBlockDB createFileBytesBlock(String name, Address startAddress, long length,
FileBytes fileBytes, long offset, int permissions)
FileBytes fileBytes, long offset, int flags)
throws IOException, AddressOverflowException {
updateAddressMapForAllAddresses(startAddress, length);
List<SubMemoryBlock> subBlocks = new ArrayList<>();
DBRecord blockRecord = createMemoryBlockRecord(name, startAddress, length, permissions);
DBRecord blockRecord = createMemoryBlockRecord(name, startAddress, length, flags);
long key = blockRecord.getKey();
DBRecord subRecord = createSubBlockRecord(key, 0, length, V3_SUB_TYPE_FILE_BYTES,
@ -307,13 +307,12 @@ public class MemoryMapDBAdapterV3 extends MemoryMapDBAdapter {
}
private MemoryBlockDB createMappedBlock(byte type, String name, Address startAddress,
long length, Address mappedAddress, int permissions,
int mappingScheme)
long length, Address mappedAddress, int flags, int mappingScheme)
throws IOException, AddressOverflowException {
updateAddressMapForAllAddresses(startAddress, length);
List<SubMemoryBlock> subBlocks = new ArrayList<>();
DBRecord blockRecord = createMemoryBlockRecord(name, startAddress, length, permissions);
DBRecord blockRecord = createMemoryBlockRecord(name, startAddress, length, flags);
long key = blockRecord.getKey();
long encoded = addrMap.getKey(mappedAddress, true);
@ -377,12 +376,12 @@ public class MemoryMapDBAdapterV3 extends MemoryMapDBAdapter {
}
private DBRecord createMemoryBlockRecord(String name, Address startAddr, long length,
int permissions) {
int flags) {
DBRecord record = V3_BLOCK_SCHEMA.createRecord(memBlockTable.getKey());
record.setString(V3_NAME_COL, name);
record.setLongValue(V3_START_ADDR_COL, addrMap.getKey(startAddr, true));
record.setLongValue(V3_LENGTH_COL, length);
record.setByteValue(V3_PERMISSIONS_COL, (byte) permissions);
record.setByteValue(V3_FLAGS_COL, (byte) flags);
record.setIntValue(V3_SEGMENT_COL, getSegment(startAddr));
return record;
}

View file

@ -46,17 +46,22 @@ public interface MemoryBlock extends Serializable, Comparable<MemoryBlock> {
*/
public static final String EXTERNAL_BLOCK_NAME = "EXTERNAL";
// Memory block permission bits
// Memory block flag bits
// NOTE: These are used by stored Flags with DB (8-bits) and
// should be changed other than to add values.
public static int ARTIFICIAL = 0x10;
public static int VOLATILE = 0x8;
public static int READ = 0x4;
public static int WRITE = 0x2;
public static int EXECUTE = 0x1;
/**
* Returns block permissions as a bit mask. Permission bits defined as READ, WRITE, EXECUTE and
* VOLATILE
* Returns block flags (i.e., permissions and attributes) as a bit mask.
* These bits defined as {@link #READ}, {@link #WRITE}, {@link #EXECUTE}, {@link #VOLATILE},
* {@link #ARTIFICIAL}.
* @return block flag bits
*/
public int getPermissions();
public int getFlags();
/**
* Get memory data in the form of an InputStream. Null is returned for thos memory blocks which
@ -107,6 +112,8 @@ public interface MemoryBlock extends Serializable, Comparable<MemoryBlock> {
/**
* Get the name of this block
*
* @return block name
*/
public String getName();
@ -122,6 +129,8 @@ public interface MemoryBlock extends Serializable, Comparable<MemoryBlock> {
/**
* Get the comment associated with this block.
*
* @return block comment string
*/
public String getComment();
@ -134,6 +143,8 @@ public interface MemoryBlock extends Serializable, Comparable<MemoryBlock> {
/**
* Returns the value of the read property associated with this block
*
* @return true if enabled else false
*/
public boolean isRead();
@ -146,6 +157,8 @@ public interface MemoryBlock extends Serializable, Comparable<MemoryBlock> {
/**
* Returns the value of the write property associated with this block
*
* @return true if enabled else false
*/
public boolean isWrite();
@ -158,6 +171,8 @@ public interface MemoryBlock extends Serializable, Comparable<MemoryBlock> {
/**
* Returns the value of the execute property associated with this block
*
* @return true if enabled else false
*/
public boolean isExecute();
@ -178,18 +193,41 @@ public interface MemoryBlock extends Serializable, Comparable<MemoryBlock> {
public void setPermissions(boolean read, boolean write, boolean execute);
/**
* Returns the value of the volatile property associated with this block. This attribute is
* Returns the volatile attribute state of this block. This attribute is
* generally associated with block of I/O regions of memory.
*
* @return true if enabled else false
*/
public boolean isVolatile();
/**
* Sets the volatile property associated with this block.
* Sets the volatile attribute state associated of this block. This attribute is
* generally associated with block of I/O regions of memory.
*
* @param v the value to set the volatile property to.
* @param v the volatile attribute state.
*/
public void setVolatile(boolean v);
/**
* Returns the artificial attribute state of this block. This attribute is
* generally associated with blocks which have been fabricated to facilitate
* analysis but do not exist in the same form within a running/loaded process
* state.
*
* @return true if enabled else false
*/
public boolean isArtificial();
/**
* Sets the artificial attribute state associated with this block. This attribute is
* generally associated with blocks which have been fabricated to facilitate
* analysis but do not exist in the same form within a running/loaded process
* state.
*
* @param a the artificial attribute state.
*/
public void setArtificial(boolean a);
/**
* Get the name of the source of this memory block.
*
@ -208,6 +246,7 @@ public interface MemoryBlock extends Serializable, Comparable<MemoryBlock> {
* Returns the byte at the given address in this block.
*
* @param addr the address.
* @return byte value from this block and specified address
* @throws MemoryAccessException if any of the requested bytes are uninitialized.
* @throws IllegalArgumentException if the Address is not in this block.
*/
@ -246,6 +285,7 @@ public interface MemoryBlock extends Serializable, Comparable<MemoryBlock> {
* Puts the given byte at the given address in this block.
*
* @param addr the address.
* @param b byte value
* @throws MemoryAccessException if the block is uninitialized
* @throws IllegalArgumentException if the Address is not in this block.
*/

View file

@ -46,7 +46,7 @@ public class MemoryBlockStub implements MemoryBlock {
}
@Override
public int getPermissions() {
public int getFlags() {
throw new UnsupportedOperationException();
}
@ -150,6 +150,16 @@ public class MemoryBlockStub implements MemoryBlock {
throw new UnsupportedOperationException();
}
@Override
public boolean isArtificial() {
throw new UnsupportedOperationException();
}
@Override
public void setArtificial(boolean a) {
throw new UnsupportedOperationException();
}
@Override
public boolean isOverlay() {
return false;

View file

@ -92,7 +92,7 @@ public class MemBlockDBTest extends AbstractGenericTest {
assertEquals(false, block.isMapped());
assertNull(block.getComment());
assertNull(block.getSourceName());
assertEquals(MemoryBlock.READ, block.getPermissions());
assertEquals(MemoryBlock.READ, block.getFlags());
List<MemoryBlockSourceInfo> sourceInfos = block.getSourceInfos();
@ -192,7 +192,7 @@ public class MemBlockDBTest extends AbstractGenericTest {
assertEquals(true, block.isMapped());
assertNull(block.getComment());
assertNull(block.getSourceName());
assertEquals(MemoryBlock.READ, block.getPermissions());
assertEquals(MemoryBlock.READ, block.getFlags());
List<MemoryBlockSourceInfo> sourceInfos = block.getSourceInfos();
@ -228,7 +228,7 @@ public class MemBlockDBTest extends AbstractGenericTest {
assertEquals(true, block.isMapped());
assertNull(block.getComment());
assertNull(block.getSourceName());
assertEquals(MemoryBlock.READ, block.getPermissions());
assertEquals(MemoryBlock.READ, block.getFlags());
List<MemoryBlockSourceInfo> sourceInfos = block.getSourceInfos();
@ -264,7 +264,7 @@ public class MemBlockDBTest extends AbstractGenericTest {
assertEquals(false, block.isMapped());
assertNull(block.getComment());
assertNull(block.getSourceName());
assertEquals(MemoryBlock.READ, block.getPermissions());
assertEquals(MemoryBlock.READ, block.getFlags());
List<MemoryBlockSourceInfo> sourceInfos = block.getSourceInfos();