GP-4505 Added writable mutability setting

This commit is contained in:
ghidra1 2024-04-11 15:27:16 -04:00
parent 8ee5734927
commit 616bf82426
8 changed files with 47 additions and 10 deletions

View File

@ -47,6 +47,11 @@ public interface DataAdapterFromSettings extends Data {
return hasMutability(MutabilitySettingsDefinition.CONSTANT);
}
@Override
default boolean isWritable() {
return hasMutability(MutabilitySettingsDefinition.WRITABLE);
}
@Override
default boolean isVolatile() {
return hasMutability(MutabilitySettingsDefinition.VOLATILE);

View File

@ -544,6 +544,11 @@ public class PseudoData extends PseudoCodeUnit implements Data {
return false;
}
@Override
public boolean isWritable() {
return false;
}
@Override
public boolean isVolatile() {
return false;

View File

@ -130,7 +130,7 @@ class DataDB extends CodeUnitDB implements Data {
private void computeLength() {
// NOTE: Data intentionally does not use aligned-length
length = dataType.getLength();
length = dataType.getLength();
// undefined will never change their size
if (dataType instanceof Undefined) {
@ -367,6 +367,11 @@ class DataDB extends CodeUnitDB implements Data {
return hasMutability(MutabilitySettingsDefinition.CONSTANT);
}
@Override
public boolean isWritable() {
return hasMutability(MutabilitySettingsDefinition.WRITABLE);
}
@Override
public boolean isVolatile() {
return hasMutability(MutabilitySettingsDefinition.VOLATILE);

View File

@ -27,9 +27,10 @@ public class MutabilitySettingsDefinition implements EnumSettingsDefinition {
public static final int NORMAL = 0;
public static final int VOLATILE = 1;
public static final int CONSTANT = 2;
public static final int WRITABLE = 3;
//NOTE: if these strings change, the XML needs to changed also...
private static final String[] choices = { "normal", "volatile", "constant" };
private static final String[] choices = { "normal", "volatile", "constant", "writable" };
public static final String MUTABILITY = "mutability";
public static final MutabilitySettingsDefinition DEF = new MutabilitySettingsDefinition();
@ -51,7 +52,7 @@ public class MutabilitySettingsDefinition implements EnumSettingsDefinition {
return NORMAL;
}
int mode = (int) value.longValue();
if ((mode < 0) || (mode > CONSTANT)) {
if ((mode < 0) || (mode > WRITABLE)) {
mode = NORMAL;
}
return mode;
@ -69,7 +70,7 @@ public class MutabilitySettingsDefinition implements EnumSettingsDefinition {
@Override
public void setChoice(Settings settings, int value) {
if (value < 0 || value > CONSTANT) {
if (value < 0 || value > WRITABLE) {
settings.clearSetting(MUTABILITY);
}
else {

View File

@ -54,14 +54,26 @@ public interface Data extends CodeUnit, Settings {
public boolean hasStringValue();
/**
* @return true if data is constant.
* If true, isConstant will always be false
* Determine if this data has explicitly been marked as constant.
* NOTE: This is based upon explicit {@link Data} and {@link DataType} mutability settings
* and does not reflect independent memory block or processor specification settings.
* @return true if data is constant, else false.
*/
public boolean isConstant();
/**
* @return true if data is volatile.
* If true, isVolatile will always be false
* Determine if this data has explicitly been marked as writable.
* NOTE: This is based upon explicit {@link Data} and {@link DataType} mutability settings
* and does not reflect independent memory block or processor specification settings.
* @return true if data is writable, else false.
*/
public boolean isWritable();
/**
* Determine if this data has explicitly been marked as volatile.
* NOTE: This is based upon explicit {@link Data} and {@link DataType} mutability settings
* and does not reflect independent memory block or processor specification settings.
* @return true if data is volatile, else false.
*/
public boolean isVolatile();
@ -285,4 +297,5 @@ public interface Data extends CodeUnit, Settings {
* @return the prefix
*/
public String getDefaultLabelPrefix(DataTypeDisplayOptions options);
}

View File

@ -392,6 +392,11 @@ public class DataStub implements Data {
throw new UnsupportedOperationException();
}
@Override
public boolean isWritable() {
throw new UnsupportedOperationException();
}
@Override
public boolean isVolatile() {
throw new UnsupportedOperationException();

View File

@ -58,6 +58,9 @@ public class MappedDataEntry extends MappedEntry {
@Override
public boolean isReadOnly() {
if (data.isWritable()) {
return false;
}
if (data.isConstant()) {
return true;
}

View File

@ -1119,7 +1119,7 @@ Before you can do anything else, you must first create a project. Projects are u
<li>Decompiler output may change due to program changes</li>
<ul>
<li>Changes to data or functions called by the current function</li>
<li>Changes to data mutability (read-only/constant or volatile)</li>
<li>Changes to data mutability (writable, read-only/constant or volatile)</li>
</ul>
<li>Selections and navigation made in Listing and Decompiler track one another</li>
@ -1214,7 +1214,7 @@ Before you can do anything else, you must first create a project. Projects are u
<br>
<li>Change function signatures to cause global improvements</li>
<li>Make function signature changes to handle specialized types of functions</li>
<li>Apply read-only memory and volatile memory settings correctly</li>
<li>Apply writable memory, read-only memory and volatile memory settings correctly</li>
</ul>
<div role="note">
<br>