Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-3001 - Decompiler - Added Double and Float convert actions

dragonmacher761346d888a9
diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/DecompilerProvider.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/DecompilerProvider.java
index 6a0571ca03..16afa2cb92 100644
--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/DecompilerProvider.java
+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/DecompilerProvider.java
@@ -388,7 +388,7 @@ public class DecompilerProvider extends NavigatableComponentProviderAdapter
/**
* Sets the current program and adds/removes itself as a domainObjectListener
- *
+ *
* @param newProgram the new program or null to clear out the current program.
*/
void doSetProgram(Program newProgram) {
@@ -429,7 +429,7 @@ public class DecompilerProvider extends NavigatableComponentProviderAdapter
* sets the current location for this provider. If the provider is not visible, it does not pass
* it on to the controller. When the component is later shown, the current location will then be
* passed to the controller.
- *
+ *
* @param loc the location to compile and set the cursor.
* @param viewerPosition if non-null the position at which to scroll the view.
*/
@@ -914,6 +914,12 @@ public class DecompilerProvider extends NavigatableComponentProviderAdapter
ConvertDecAction convertDecAction = new ConvertDecAction(plugin);
setGroupInfo(convertDecAction, convertGroup, subGroupPosition++);
+ ConvertFloatAction convertFloatAction = new ConvertFloatAction(plugin);
+ setGroupInfo(convertFloatAction, convertGroup, subGroupPosition++);
+
+ ConvertDoubleAction convertDoubleAction = new ConvertDoubleAction(plugin);
+ setGroupInfo(convertDoubleAction, convertGroup, subGroupPosition++);
+
ConvertHexAction convertHexAction = new ConvertHexAction(plugin);
setGroupInfo(convertHexAction, convertGroup, subGroupPosition++);
@@ -1000,6 +1006,8 @@ public class DecompilerProvider extends NavigatableComponentProviderAdapter
addLocalAction(removeAllSecondadryHighlightsAction);
addLocalAction(convertBinaryAction);
addLocalAction(convertDecAction);
+ addLocalAction(convertFloatAction);
+ addLocalAction(convertDoubleAction);
addLocalAction(convertHexAction);
addLocalAction(convertOctAction);
addLocalAction(convertCharAction);
diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ConvertBinaryAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ConvertBinaryAction.java
index fab9f9d6ac..b0c860e629 100644
--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ConvertBinaryAction.java
+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ConvertBinaryAction.java
@@ -41,7 +41,7 @@ public class ConvertBinaryAction extends ConvertConstantAction {
}
@Override
- public String getMenuDisplay(long value, int size, boolean isSigned) {
+ public String getMenuDisplay(long value, int size, boolean isSigned, Program program) {
Scalar scalar = new Scalar(size * 8, value);
long v;
String prefix = "0b";
diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ConvertCharAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ConvertCharAction.java
index 157f08b223..04ff45cfac 100644
--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ConvertCharAction.java
+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ConvertCharAction.java
@@ -98,7 +98,7 @@ public class ConvertCharAction extends ConvertConstantAction {
}
@Override
- public String getMenuDisplay(long value, int size, boolean isSigned) {
+ public String getMenuDisplay(long value, int size, boolean isSigned, Program program) {
StringBuilder buffer = new StringBuilder();
if (size > 1) {
buffer.append('L');
diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ConvertConstantAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ConvertConstantAction.java
index 734c15f7f2..2923423863 100644
--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ConvertConstantAction.java
+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ConvertConstantAction.java
@@ -297,7 +297,8 @@ public abstract class ConvertConstantAction extends AbstractDecompilerAction {
size = 1;
}
value = ConvertConstantTask.signExtendValue(convertIsSigned, value, size);
- String altName = getEquateName(value, size, convertIsSigned, null);
+ String altName =
+ getEquateName(value, size, convertIsSigned, context.getProgram());
if (altName == null) {
altName = equateName;
}
@@ -321,7 +322,11 @@ public abstract class ConvertConstantAction extends AbstractDecompilerAction {
if (task == null) {
return false;
}
- String convDisplay = getMenuDisplay(task.getValue(), task.getSize(), task.isSigned());
+ String convDisplay =
+ getMenuDisplay(task.getValue(), task.getSize(), task.isSigned(), context.getProgram());
+ if (convDisplay == null) {
+ return false;
+ }
if (convDisplay.equals(context.getTokenAtCursor().getText())) {
return false;
}
@@ -355,9 +360,10 @@ public abstract class ConvertConstantAction extends AbstractDecompilerAction {
* @param value is the actual value
* @param size is the number of bytes used for the constant Varnode
* @param isSigned is true if the constant represents a signed data-type
+ * @param program the program
* @return the formatted String
*/
- public abstract String getMenuDisplay(long value, int size, boolean isSigned);
+ public abstract String getMenuDisplay(long value, int size, boolean isSigned, Program program);
/**
* Construct the name of the Equate, either absolutely for a conversion or
diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ConvertConstantTask.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ConvertConstantTask.java
index c432338d56..b7ed01790f 100644
--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ConvertConstantTask.java
+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ConvertConstantTask.java
@@ -31,7 +31,7 @@ import utility.function.Callback;
* Create an equate in the table for the specific Address and hash value.
* The equate is not assumed to be attached to a particular instruction operand and
* uses the dynamic hash value to identify the particular constant (within p-code) to label.
- *
+ *
* If altAddress is non-null and the other alt* fields are filled in, the task attempts
* to set the equation on the altAddress first to get the representation of the p-code
* constant at convertAddress to change. After the decompilation finishes, the representation
@@ -137,7 +137,7 @@ public class ConvertConstantTask implements Callback {
}
/**
- * Remove any preexisting equate reference with the same address and hash as the
+ * Remove any pre-existing equate reference with the same address and hash as the
* primate equate.
*/
private void removePrimaryReference() {
@@ -160,7 +160,7 @@ public class ConvertConstantTask implements Callback {
}
/**
- * Remove and preexisting equate reference with the same address and hash as the
+ * Remove and pre-existing equate reference with the same address and hash as the
* alternate equate.
*/
private void removeAlternateReference() {
diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ConvertDecAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ConvertDecAction.java
index dde6f49ef3..ca748a2518 100644
--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ConvertDecAction.java
+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ConvertDecAction.java
@@ -39,8 +39,8 @@ public class ConvertDecAction extends ConvertConstantAction {
}
@Override
- public String getMenuDisplay(long value, int size, boolean isSigned) {
- return getEquateName(value, size, isSigned, null);
+ public String getMenuDisplay(long value, int size, boolean isSigned, Program program) {
+ return getEquateName(value, size, isSigned, program);
}
@Override
diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ConvertDoubleAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ConvertDoubleAction.java
new file mode 100644
index 0000000000..a894f983d6
--- /dev/null
+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ConvertDoubleAction.java
@@ -0,0 +1,73 @@
+/* ###
+ * 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.app.plugin.core.decompile.actions;
+
+import java.math.BigDecimal;
+
+import docking.action.MenuData;
+import ghidra.app.plugin.core.decompile.DecompilePlugin;
+import ghidra.app.util.HelpTopics;
+import ghidra.pcode.floatformat.*;
+import ghidra.program.model.data.DataOrganization;
+import ghidra.program.model.listing.Program;
+import ghidra.program.model.pcode.EquateSymbol;
+import ghidra.program.model.scalar.Scalar;
+import ghidra.util.HelpLocation;
+
+public class ConvertDoubleAction extends ConvertConstantAction {
+
+ public ConvertDoubleAction(DecompilePlugin plugin) {
+ super(plugin, "Convert To Double", EquateSymbol.FORMAT_DOUBLE);
+ setHelpLocation(new HelpLocation(HelpTopics.DECOMPILER, "ActionConvert"));
+ setPopupMenuData(new MenuData(new String[] { "Double" }, "Decompile"));
+ }
+
+ @Override
+ public String getMenuPrefix() {
+ return "Double: ";
+ }
+
+ @Override
+ public String getMenuDisplay(long value, int size, boolean isSigned, Program program) {
+ return getText(value, size, isSigned, program);
+ }
+
+ @Override
+ public String getEquateName(long value, int size, boolean isSigned, Program program) {
+ return getText(value, size, isSigned, program);
+ }
+
+ private String getText(long value, int size, boolean isSigned, Program program) {
+ DataOrganization organization = program.getDataTypeManager().getDataOrganization();
+ int doubleSize = organization.getDoubleSize();
+ Scalar scalar = new Scalar(size * 8, value);
+ BigDecimal bd = value(doubleSize, scalar);
+ if (bd != null) {
+ return bd.toString();
+ }
+ return null;
+ }
+
+ private static BigDecimal value(int size, Scalar s) {
+ try {
+ FloatFormat format = FloatFormatFactory.getFloatFormat(size);
+ return format.round(format.getHostFloat(s.getBigInteger()));
+ }
+ catch (UnsupportedFloatFormatException e) {
+ return null;
+ }
+ }
+}
diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ConvertFloatAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ConvertFloatAction.java
new file mode 100644
index 0000000000..ba33fb2de9
--- /dev/null
+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ConvertFloatAction.java
@@ -0,0 +1,73 @@
+/* ###
+ * 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.app.plugin.core.decompile.actions;
+
+import java.math.BigDecimal;
+
+import docking.action.MenuData;
+import ghidra.app.plugin.core.decompile.DecompilePlugin;
+import ghidra.app.util.HelpTopics;
+import ghidra.pcode.floatformat.*;
+import ghidra.program.model.data.DataOrganization;
+import ghidra.program.model.listing.Program;
+import ghidra.program.model.pcode.EquateSymbol;
+import ghidra.program.model.scalar.Scalar;
+import ghidra.util.HelpLocation;
+
+public class ConvertFloatAction extends ConvertConstantAction {
+
+ public ConvertFloatAction(DecompilePlugin plugin) {
+ super(plugin, "Convert To Float", EquateSymbol.FORMAT_FLOAT);
+ setHelpLocation(new HelpLocation(HelpTopics.DECOMPILER, "ActionConvert"));
+ setPopupMenuData(new MenuData(new String[] { "Float" }, "Decompile"));
+ }
+
+ @Override
+ public String getMenuPrefix() {
+ return "Float: ";
+ }
+
+ @Override
+ public String getMenuDisplay(long value, int size, boolean isSigned, Program program) {
+ return getText(value, size, isSigned, program);
+ }
+
+ @Override
+ public String getEquateName(long value, int size, boolean isSigned, Program program) {
+ return getText(value, size, isSigned, program);
+ }
+
+ private String getText(long value, int size, boolean isSigned, Program program) {
+ DataOrganization organization = program.getDataTypeManager().getDataOrganization();
+ int floatSize = organization.getFloatSize();
+ Scalar scalar = new Scalar(size * 8, value);
+ BigDecimal bd = value(floatSize, scalar);
+ if (bd != null) {
+ return bd.toString();
+ }
+ return null;
+ }
+
+ private static BigDecimal value(int size, Scalar s) {
+ try {
+ FloatFormat format = FloatFormatFactory.getFloatFormat(size);
+ return format.round(format.getHostFloat(s.getBigInteger()));
+ }
+ catch (UnsupportedFloatFormatException e) {
+ return null;
+ }
+ }
+}
diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ConvertHexAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ConvertHexAction.java
index 14c669b7fd..bcf8a3c5bc 100644
--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ConvertHexAction.java
+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ConvertHexAction.java
@@ -40,7 +40,7 @@ public class ConvertHexAction extends ConvertConstantAction {
}
@Override
- public String getMenuDisplay(long value, int size, boolean isSigned) {
+ public String getMenuDisplay(long value, int size, boolean isSigned, Program program) {
Scalar scalar = new Scalar(size * 8, value);
if (isSigned) {
long v = scalar.getSignedValue();
diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ConvertOctAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ConvertOctAction.java
index 654e2be4bb..e62d917cc7 100644
--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ConvertOctAction.java
+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ConvertOctAction.java
@@ -40,7 +40,7 @@ public class ConvertOctAction extends ConvertConstantAction {
}
@Override
- public String getMenuDisplay(long value, int size, boolean isSigned) {
+ public String getMenuDisplay(long value, int size, boolean isSigned, Program program) {
Scalar scalar = new Scalar(size * 8, value);
if (isSigned) {
long v = scalar.getSignedValue();
diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/SetEquateAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/SetEquateAction.java
index 7c106489cf..3d8dd1ac4e 100644
--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/SetEquateAction.java
+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/SetEquateAction.java
@@ -15,6 +15,8 @@
*/
package ghidra.app.plugin.core.decompile.actions;
+import java.awt.event.KeyEvent;
+
import docking.action.KeyBindingData;
import docking.action.MenuData;
import ghidra.app.plugin.core.decompile.DecompilePlugin;
@@ -25,7 +27,6 @@ import ghidra.program.model.listing.Program;
import ghidra.program.model.pcode.EquateSymbol;
import ghidra.program.model.scalar.Scalar;
import ghidra.util.HelpLocation;
-import java.awt.event.KeyEvent;
public class SetEquateAction extends ConvertConstantAction {
@@ -42,7 +43,7 @@ public class SetEquateAction extends ConvertConstantAction {
}
@Override
- public String getMenuDisplay(long value, int size, boolean isSigned) {
+ public String getMenuDisplay(long value, int size, boolean isSigned, Program program) {
return null; // Menu isn't tailored for this action
}
diff --git a/Ghidra/Features/Decompiler/src/test.slow/java/ghidra/app/plugin/core/decompile/EquateTest.java b/Ghidra/Features/Decompiler/src/test.slow/java/ghidra/app/plugin/core/decompile/EquateTest.java
index aa30abbb09..2667f363a3 100644
--- a/Ghidra/Features/Decompiler/src/test.slow/java/ghidra/app/plugin/core/decompile/EquateTest.java
+++ b/Ghidra/Features/Decompiler/src/test.slow/java/ghidra/app/plugin/core/decompile/EquateTest.java
@@ -62,7 +62,7 @@ public class EquateTest extends AbstractDecompilerTest {
/**
* Simulate the action of "converting" the current token to the given format
- *
+ *
* @param convertType is the given format
*/
private void convertToken(int convertType) {
@@ -84,6 +84,12 @@ public class EquateTest extends AbstractDecompilerTest {
case EquateSymbol.FORMAT_HEX:
action = new ConvertHexAction(decompiler);
break;
+ case EquateSymbol.FORMAT_FLOAT:
+ action = new ConvertFloatAction(decompiler);
+ break;
+ case EquateSymbol.FORMAT_DOUBLE:
+ action = new ConvertDoubleAction(decompiler);
+ break;
default:
action = null;
}
@@ -95,7 +101,7 @@ public class EquateTest extends AbstractDecompilerTest {
/**
* Simulate setting an equate on the current token with the given name
- *
+ *
* @param nm is the given name
*/
private void convertToken(String nm) {
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/DataType.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/DataType.java
index 4e472fab76..7ac8b94c39 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/DataType.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/DataType.java
@@ -44,7 +44,7 @@ public interface DataType {
/**
* Instance of void datatype (never use <code>==</code>)
- *
+ *
* @deprecated should use {@link VoidDataType#dataType} instead
*/
@Deprecated
@@ -61,7 +61,7 @@ public interface DataType {
/**
* Indicates if the length of this data-type is determined based upon the
* {@link DataOrganization} obtained from the associated {@link DataTypeManager}.
- *
+ *
* @return true length is language/compiler-specification dependent, else false
*/
public boolean hasLanguageDependantLength();
@@ -69,14 +69,14 @@ public interface DataType {
/**
* Get the list of settings definitions available for use with this datatype.
* <p>
- * In the case of a {@link TypeDef}, the return list will include the
+ * In the case of a {@link TypeDef}, the return list will include the
* {@link TypeDefSettingsDefinition} list from the associated base data type.
* <p>
* Unlike {@link TypeDefSettingsDefinition} standard settings definitions
- * generally support default, component-default and data-instance use.
+ * generally support default, component-default and data-instance use.
* In addition, standard settings definitions are never considered during
* {@link #isEquivalent(DataType)} checking or during the resolve process.
- *
+ *
* @return list of the settings definitions for this datatype.
*/
public SettingsDefinition[] getSettingsDefinitions();
@@ -84,10 +84,10 @@ public interface DataType {
/**
* Get the list of all settings definitions for this datatype that may be
* used for an associated {@link TypeDef}. When used for an associated
- * {@link TypeDef}, these settings will be considered during a
+ * {@link TypeDef}, these settings will be considered during a
* {@link TypeDef#isEquivalent(DataType)} check and will be preserved
* during the resolve process.
- *
+ *
* @return a list of the settings definitions for a {@link TypeDef}
* associated with this datatype.
*/
@@ -112,14 +112,14 @@ public interface DataType {
* applicable.
* <p>
* This instance will be returned if this datatype's DataTypeManager matches the
- * specified dtm. The recursion depth of a clone will stop on any datatype whose
- * {@link DataTypeManager} matches the specified dtm and simply use the existing datatype
+ * specified dtm. The recursion depth of a clone will stop on any datatype whose
+ * {@link DataTypeManager} matches the specified dtm and simply use the existing datatype
* instance.
* <p>
* NOTE: In general, this method should not be used to obtain an instance to be modified.
- * In most cases changes shuold be made directly to this instance if supported or to a
- * {@link #copy(DataTypeManager)}.
- *
+ * In most cases changes may be made directly to this instance if supported or to a
+ * {@link #copy(DataTypeManager)} of this type.
+ *
* @param dtm the data-type manager instance whose data-organization should apply.
* @return cloned instance which may be the same as this instance
*/
@@ -130,7 +130,7 @@ public interface DataType {
* source archive association.
* <p>
* Any reference to other datatypes will use {@link #clone(DataTypeManager)}.
- *
+ *
* @param dtm the data-type manager instance whose data-organization should apply.
* @return new instanceof of this datatype
*/
@@ -138,21 +138,21 @@ public interface DataType {
/**
* Gets the categoryPath associated with this datatype
- *
+ *
* @return the datatype's category path
*/
public CategoryPath getCategoryPath();
/**
* Returns the dataTypePath for this datatype;
- *
+ *
* @return the dataTypePath for this datatype;
*/
public DataTypePath getDataTypePath();
/**
* Set the categoryPath associated with this datatype
- *
+ *
* @param path the new path
* @throws DuplicateNameException if an attempt to place this datatype into the specified
* category resulted in a name collision. This should not occur for non-DB DataType
@@ -165,21 +165,21 @@ public interface DataType {
* <p>
* This association should not be used to indicate whether this DataType has been resolved, but
* is intended to indicate whether the appropriate DataOrganization is being used.
- *
+ *
* @return the DataTypeManager that is associated with this datatype.
*/
public DataTypeManager getDataTypeManager();
/**
* Gets the name for referring to this datatype.
- *
+ *
* @return generic name for this Data Type (i.e.: Word)
*/
public String getDisplayName();
/**
* Get the name of this datatype.
- *
+ *
* @return the name
*/
public String getName();
@@ -188,14 +188,14 @@ public interface DataType {
* Get the full category path name that includes this datatype's name.
* <p>
* If the category is null, then this just the datatype's name is returned.
- *
+ *
* @return the path, or just this type's name
*/
public String getPathName();
/**
* Sets the name of the datatype
- *
+ *
* @param name the new name for this datatype.
* @throws InvalidNameException if the given name does not form a valid name.
* @throws DuplicateNameException if name change on stored {@link DataType} is a duplicate of
@@ -206,7 +206,7 @@ public interface DataType {
/**
* Sets the name and category of a datatype at the same time.
- *
+ *
* @param path the new category path.
* @param name the new name
* @throws InvalidNameException if the name is invalid
@@ -219,7 +219,7 @@ public interface DataType {
/**
* Get the mnemonic for this DataType.
- *
+ *
* @param settings settings which may influence the result or null
* @return the mnemonic for this DataType.
*/
@@ -232,7 +232,7 @@ public interface DataType {
* {@link Dynamic} datatypes should return -1. If {@link #isZeroLength()} is true a length of 1
* should be returned. Where a zero-length datatype can be handled (e.g., {@link Composite}) the
* {@link #isZeroLength()} method should be used.
- *
+ *
* @return the length of this DataType
*/
public int getLength();
@@ -247,7 +247,7 @@ public interface DataType {
* datatypes used as a component within a {@link Composite} may, or may not, be assigned a
* component length of 0. The method {@link DataTypeComponent#usesZeroLengthComponent(DataType)}
* is used to make this determination.
- *
+ *
* @return true if type definition has a length of 0, else false
*/
public boolean isZeroLength();
@@ -257,7 +257,7 @@ public interface DataType {
* <p>
* Such datatypes should always return a {@link #getLength()} of 1 and true for
* {@link #isZeroLength()}. (example: empty structure)
- *
+ *
* @return true if this type is not yet defined.
*/
public boolean isNotYetDefined();
@@ -271,7 +271,7 @@ public interface DataType {
/**
* Sets a String briefly describing this DataType.
- *
+ *
* @param description a one-liner describing this DataType.
* @throws UnsupportedOperationException if the description is not allowed to be set for this
* datatype.
@@ -290,11 +290,11 @@ public interface DataType {
public URL getDocs();
/**
- * Get the interpretted data value in the form of the appropriate Object for this DataType.
+ * Get the interpreted data value in the form of the appropriate Object for this DataType.
* This method must return a value consistent with {@link #getValueClass(Settings)}.
* <p>
- * For instance, if this datatype is a {@link Pointer} an Address object or null should be returned.
- * A Byte, returns a {@link Scalar} object.
+ * For instance, if this datatype is a {@link Pointer} an Address object or null should be returned.
+ * A Byte, returns a {@link Scalar} object.
*
* @param buf the data buffer.
* @param settings the settings to use.
@@ -310,7 +310,7 @@ public interface DataType {
* {@link #encodeRepresentation(String, MemBuffer, Settings, int)} will always throw an
* exception. Actions which rely on either {@code encode} method should not be displayed if the
* applicable datatype is not encodable.
- *
+ *
* @return true if encoding is supported
*/
public boolean isEncodable();
@@ -322,7 +322,7 @@ public interface DataType {
* seek the nearest encoding to the specified value, since the object may come from a user
* script. For example, a floating-point value may be rounded. Invalid values should be rejected
* with a {@link DataTypeEncodeException}.
- *
+ *
* @param value the desired value.
* @param buf a buffer representing the eventual destination of the bytes.
* @param settings the settings to use.
@@ -338,9 +338,9 @@ public interface DataType {
throws DataTypeEncodeException;
/**
- * Get the Class of the value Object to be returned by this datatype
+ * Get the Class of the value Object to be returned by this datatype
* (see {@link #getValue(MemBuffer, Settings, int)}).
- *
+ *
* @param settings the relevant settings to use or null for default.
* @return Class of the value to be returned by this datatype or null if it can vary or is
* unspecified. Types which correspond to a string or char array will return the String
@@ -350,7 +350,7 @@ public interface DataType {
/**
* Returns the appropriate string to use as the default label prefix in the absence of any data.
- *
+ *
* @return the default label prefix or null if none specified.
*/
public String getDefaultLabelPrefix();
@@ -368,7 +368,7 @@ public interface DataType {
/**
* Returns the appropriate string to use as the default label prefix.
- *
+ *
* @param buf memory buffer containing the bytes.
* @param settings the Settings object
* @param len the length of the data.
@@ -383,7 +383,7 @@ public interface DataType {
* <p>
* This takes into account the fact that there exists a reference to the data that references
* <code>offcutLength</code> bytes into this type
- *
+ *
* @param buf memory buffer containing the bytes.
* @param settings the Settings object
* @param len the length of the data.
@@ -411,7 +411,7 @@ public interface DataType {
* should seek the nearest encoding to the specified value, since the representation is likely
* coming from user input. For example, a floating-point value may be rounded. Invalid
* representations should be rejected with a {@link DataTypeEncodeException}.
- *
+ *
* @param repr the representation of the desired value, as in
* {@link #getRepresentation(MemBuffer, Settings, int)}. The supported formats depend
* on the specific datatype and its settings.
@@ -430,7 +430,7 @@ public interface DataType {
/**
* Returns true if this datatype has been deleted and is no longer valid
- *
+ *
* @return true if this datatype has been deleted and is no longer valid.
*/
public boolean isDeleted();
@@ -441,7 +441,7 @@ public interface DataType {
* The precise meaning of "equivalent" is datatype dependent. <br>
* NOTE: if invoked by a DB object or manager it should be invoked on the DataTypeDB object
* passing the other datatype as the argument.
- *
+ *
* @param dt the datatype being tested for equivalence.
* @return true if the if the given datatype is equivalent to this datatype.
*/
@@ -452,7 +452,7 @@ public interface DataType {
* <p>
* DataTypes may need to make internal changes in response. <br>
* TODO: This method is reserved for internal DB use. <br>
- *
+ *
* @param dt the datatype that has changed.
*/
public void dataTypeSizeChanged(DataType dt);
@@ -462,7 +462,7 @@ public interface DataType {
* <p>
* DataTypes may need to make internal changes in response. <br>
* TODO: This method is reserved for internal DB use. <br>
- *
+ *
* @param dt the datatype that has changed.
*/
public void dataTypeAlignmentChanged(DataType dt);
@@ -471,7 +471,7 @@ public interface DataType {
* Informs this datatype that the given datatype has been deleted.
* <p>
* TODO: This method is reserved for internal DB use. <br>
- *
+ *
* @param dt the datatype that has been deleted.
*/
public void dataTypeDeleted(DataType dt);
@@ -480,7 +480,7 @@ public interface DataType {
* Informs this datatype that the given oldDT has been replaced with newDT
* <p>
* TODO: This method is reserved for internal DB use. <br>
- *
+ *
* @param oldDt old datatype
* @param newDt new datatype
*/
@@ -490,7 +490,7 @@ public interface DataType {
* Inform this data type that it has the given parent
* <br>
* TODO: This method is reserved for internal DB use.
- *
+ *
* @param dt parent data type
*/
public void addParent(DataType dt);
@@ -499,7 +499,7 @@ public interface DataType {
* Remove a parent datatype
* <p>
* TODO: This method is reserved for internal DB use. <br>
- *
+ *
* @param dt parent datatype
*/
public void removeParent(DataType dt);
@@ -508,7 +508,7 @@ public interface DataType {
* Informs this datatype that its name has changed from the indicated old name.
* <p>
* TODO: This method is reserved for internal DB use. <br>
- *
+ *
* @param dt the datatype whose name changed
* @param oldName the datatype's old name
*/
@@ -518,14 +518,14 @@ public interface DataType {
* Get the parents of this datatype.
*
* NOTE: This method is intended to be used on a DB-managed datatype only and is not
- * fully supported for use with non-DB datatype instances.
+ * fully supported for use with non-DB datatype instances.
* @return parents of this datatype
*/
public Collection<DataType> getParents();
/**
* Gets the alignment to be used when aligning this datatype within another datatype.
- *
+ *
* @return this datatype's alignment.
*/
public int getAlignment();
@@ -534,7 +534,7 @@ public interface DataType {
* Check if this datatype depends on the existence of the given datatype.
* <p>
* For example byte[] depends on byte. If byte were deleted, then byte[] would also be deleted.
- *
+ *
* @param dt the datatype to test that this datatype depends on.
* @return true if the existence of this datatype relies on the existence of the specified
* datatype dt.
@@ -543,14 +543,14 @@ public interface DataType {
/**
* Get the source archive where this type originated
- *
+ *
* @return source archive object
*/
public SourceArchive getSourceArchive();
/**
* Set the source archive where this type originated
- *
+ *
* @param archive source archive object
*/
public void setSourceArchive(SourceArchive archive);
@@ -558,7 +558,7 @@ public interface DataType {
/**
* Get the timestamp corresponding to the last time this type was changed within its datatype
* manager
- *
+ *
* @return timestamp of last change within datatype manager
*/
public long getLastChangeTime();
@@ -566,7 +566,7 @@ public interface DataType {
/**
* Get the timestamp corresponding to the last time this type was sync'd within its source
* archive
- *
+ *
* @return timestamp of last sync with source archive
*/
public long getLastChangeTimeInSourceArchive();
@@ -577,7 +577,7 @@ public interface DataType {
* This value is intended to be a unique identifier across all programs and archives. The same
* ID indicates that two datatypes were originally the same one. Keep in mind names, categories,
* and component makeup may differ and have changed since there origin.
- *
+ *
* @return datatype UniversalID
*/
public UniversalID getUniversalID();
@@ -588,7 +588,7 @@ public interface DataType {
* <p>
* The datatypes must be of the same "type" (i.e. structure can only be replacedWith another
* structure.
- *
+ *
* @param dataType the datatype that contains the internals to upgrade to.
* @throws UnsupportedOperationException if the datatype does not support change.
* @throws IllegalArgumentException if the given datatype is not the same type as this datatype.
@@ -601,7 +601,7 @@ public interface DataType {
* Normally, this is updated automatically when a datatype is changed, but when committing or
* updating while synchronizing an archive, the lastChangeTime may need to be updated
* externally.
- *
+ *
* @param lastChangeTime the time to use as the lastChangeTime for this datatype
*/
public void setLastChangeTime(long lastChangeTime);
@@ -610,7 +610,7 @@ public interface DataType {
* Sets the lastChangeTimeInSourceArchive for this datatype.
* <p>
* This is used by when a datatype change is committed back to its source archive.
- *
+ *
* @param lastChangeTimeInSourceArchive the time to use as the lastChangeTimeInSourceArchive for
* this datatype
*/
@@ -618,7 +618,7 @@ public interface DataType {
/**
* Returns the DataOrganization associated with this data-type
- *
+ *
* @return associated data organization
*/
public DataOrganization getDataOrganization();
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/DataTypeComponent.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/DataTypeComponent.java
index 121d33eeb7..68212c0add 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/DataTypeComponent.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/DataTypeComponent.java
@@ -59,9 +59,9 @@ public interface DataTypeComponent {
/**
* Get the byte offset of where this component begins relative to the start of the parent
- * data type.
+ * data type.
* @return offset of start of component relative to the start of the parent
- * data type.
+ * data type.
*/
public int getOffset();
@@ -75,8 +75,8 @@ public interface DataTypeComponent {
/**
* Get the length of this component. Zero-length components will report a length of 0
- * and may overlap other components at the same offset. Similarly, multiple adjacent
- * bit-field components may appear to overlap at the byte-level.
+ * and may overlap other components at the same offset. Similarly, multiple adjacent
+ * bit-field components may appear to overlap at the byte-level.
* @return the length of this component
*/
public int getLength();
@@ -101,7 +101,7 @@ public interface DataTypeComponent {
/**
* Get this component's field name within its parent.
- * If this method returns null {@link #getDefaultFieldName()} can be used to obtain a default
+ * If this method returns null {@link #getDefaultFieldName()} can be used to obtain a default
* generated field name.
* @return this component's field name within its parent or null if one has not been set.
*/
@@ -121,7 +121,7 @@ public interface DataTypeComponent {
/**
* Returns a default field name for this component. Used only if a field name is not set.
- * @return default field name (may be null for nameless fields such as a zero-length bitfield).
+ * @return default field name (may be null for nameless fields such as a zero-length bitfield).
*/
public default String getDefaultFieldName() {
if (isZeroBitFieldComponent()) {
@@ -139,7 +139,7 @@ public interface DataTypeComponent {
* A dataTypeComponent is "equivalent" if the other component has a data type
* that is equivalent to this component's data type. The dataTypeComponents must
* also have the same offset, field name, and comment. The length is only checked
- * for components which are dyanmic and whose size must be specified when creating
+ * for components which are dynamic and whose size must be specified when creating
* a component.
* @param dtc the dataTypeComponent being tested for equivalence.
* @return true if the given dataTypeComponent is equivalent to this dataTypeComponent.
@@ -150,10 +150,10 @@ public interface DataTypeComponent {
* Determine if the specified dataType will be treated as a zero-length component
* allowing it to possibly overlap the next component. If the specified dataType
* returns true for {@link DataType#isZeroLength()} and true for {@link DataType#isNotYetDefined()}
- * this method will return false causing the associated component to use the reported dataType length
+ * this method will return false causing the associated component to use the reported dataType length
* of 1.
* @param dataType datatype to be evaluated
- * @return true if zero-length component
+ * @return true if zero-length component
*/
public static boolean usesZeroLengthComponent(DataType dataType) {
if (dataType.isZeroLength()) {
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/EquateSymbol.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/EquateSymbol.java
index 99a769aeee..50a7858a32 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/EquateSymbol.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/EquateSymbol.java
@@ -31,6 +31,8 @@ public class EquateSymbol extends HighSymbol {
public static final int FORMAT_OCT = 3;
public static final int FORMAT_BIN = 4;
public static final int FORMAT_CHAR = 5;
+ public static final int FORMAT_FLOAT = 6;
+ public static final int FORMAT_DOUBLE = 7;
private long value; // Value of the equate
private int convert; // Non-zero if this is a conversion equate
@@ -100,6 +102,12 @@ public class EquateSymbol extends HighSymbol {
else if (formString.equals("bin")) {
convert = FORMAT_BIN;
}
+ else if (formString.equals("float")) {
+ convert = FORMAT_FLOAT;
+ }
+ else if (formString.equals("double")) {
+ convert = FORMAT_DOUBLE;
+ }
}
int valel = decoder.openElement(ELEM_VALUE);
value = decoder.readUnsignedInteger(ATTRIB_CONTENT);
@@ -128,6 +136,13 @@ public class EquateSymbol extends HighSymbol {
else if (convert == FORMAT_CHAR) {
formString = "char";
}
+ else if (convert == FORMAT_FLOAT) {
+ formString = "float";
+ }
+ else if (convert == FORMAT_DOUBLE) {
+ formString = "double";
+ }
+
encoder.writeString(ATTRIB_FORMAT, formString);
}
encoder.openElement(ELEM_VALUE);