Merge remote-tracking branch 'origin/GT-3170_ghidra1_BoolBitFields' into Ghidra_9.1

This commit is contained in:
ghidra1 2019-09-20 10:38:34 -04:00
commit ef7809d9f2
10 changed files with 61 additions and 56 deletions

View file

@ -1313,7 +1313,7 @@
entry can be directly entered or via the mouse wheel while the cursor is over this entry field.</P> entry can be directly entered or via the mouse wheel while the cursor is over this entry field.</P>
<P><B>Base Datatype</B> - (required) specifies the numeric datatype associated with the bitfield. <P><B>Base Datatype</B> - (required) specifies the numeric datatype associated with the bitfield.
Valid datatypes include primitive integer types (e.g., char, int, etc.), enum types, and Valid datatypes include primitive integer types (e.g., char, bool, int, etc.), enum types, and
typedef types of integer or enum types. This input allows direct text input with auto-complete typedef types of integer or enum types. This input allows direct text input with auto-complete
assistance or via full access to a datatype tree chooser by clicking the '...' button.</P> assistance or via full access to a datatype tree chooser by clicking the '...' button.</P>

View file

@ -23,7 +23,9 @@ import javax.swing.JMenuItem;
import docking.action.MenuData; import docking.action.MenuData;
import ghidra.app.context.ListingActionContext; import ghidra.app.context.ListingActionContext;
import ghidra.app.context.ListingContextAction; import ghidra.app.context.ListingContextAction;
import ghidra.program.model.data.*; import ghidra.docking.settings.FormatSettingsDefinition;
import ghidra.program.model.data.AbstractIntegerDataType;
import ghidra.program.model.data.DataType;
import ghidra.program.model.listing.*; import ghidra.program.model.listing.*;
import ghidra.program.model.scalar.Scalar; import ghidra.program.model.scalar.Scalar;
import ghidra.program.util.OperandFieldLocation; import ghidra.program.util.OperandFieldLocation;
@ -65,7 +67,11 @@ public abstract class AbstractConvertAction extends ListingContextAction {
// unsupported data action // unsupported data action
return false; return false;
} }
DataType dataType = ((Data) cu).getBaseDataType(); Data data = (Data) cu;
if (!data.isDefined()) {
return false;
}
DataType dataType = data.getBaseDataType();
if (!(dataType instanceof AbstractIntegerDataType)) { if (!(dataType instanceof AbstractIntegerDataType)) {
return false; return false;
} }

View file

@ -95,7 +95,7 @@ public class ConvertCommand extends BackgroundCommand {
DataType dt = data.getBaseDataType(); DataType dt = data.getBaseDataType();
Settings settings = data; Settings settings = data;
Settings defaultSettings = dt.getDefaultSettings(); Settings defaultSettings = dt.getDefaultSettings();
if (!(dt instanceof AbstractIntegerDataType)) { if (Scalar.class.equals(data.getValueClass()) || !(dt instanceof AbstractIntegerDataType)) {
msg = "Unsupported data type for convert: " + data.getDataType().getDisplayName(); msg = "Unsupported data type for convert: " + data.getDataType().getDisplayName();
return false; return false;
} }

View file

@ -36,8 +36,7 @@ import ghidra.framework.cmd.CompoundBackgroundCommand;
import ghidra.framework.plugintool.*; import ghidra.framework.plugintool.*;
import ghidra.framework.plugintool.util.PluginStatus; import ghidra.framework.plugintool.util.PluginStatus;
import ghidra.program.model.address.*; import ghidra.program.model.address.*;
import ghidra.program.model.data.DataType; import ghidra.program.model.data.*;
import ghidra.program.model.data.DataTypeManager;
import ghidra.program.model.data.Enum; import ghidra.program.model.data.Enum;
import ghidra.program.model.listing.*; import ghidra.program.model.listing.*;
import ghidra.program.model.scalar.Scalar; import ghidra.program.model.scalar.Scalar;
@ -165,6 +164,10 @@ public class EquatePlugin extends Plugin {
if (!data.isDefined()) { if (!data.isDefined()) {
return false; return false;
} }
DataType dataType = data.getBaseDataType();
if (!(dataType instanceof AbstractIntegerDataType)) {
return false;
}
} }
Equate equate = getEquate(context); Equate equate = getEquate(context);

View file

@ -710,6 +710,9 @@ public class DWARFFunctionImporter {
if (!(dataDT instanceof Enum || dataDT instanceof AbstractIntegerDataType)) { if (!(dataDT instanceof Enum || dataDT instanceof AbstractIntegerDataType)) {
return false; return false;
} }
if (dataDT instanceof BooleanDataType) {
return false;
}
if (dataDT.getLength() != enumDT.getLength()) { if (dataDT.getLength() != enumDT.getLength()) {
return false; return false;
} }

View file

@ -56,6 +56,8 @@ public class RenameConstantTask extends RenameTask {
*/ */
@Override @Override
public boolean runDialog() { public boolean runDialog() {
// NOTE: acstion must ensure that HighConstant datatype produces Scalar value and is integer type
// BooleanDataType and CharDataType do not produce scalar values in assembly listing.
SetEquateDialog setEquateDialog = new SetEquateDialog(tool, program, high.getScalar()); SetEquateDialog setEquateDialog = new SetEquateDialog(tool, program, high.getScalar());
setEquateDialog.setHelpLocation(new HelpLocation("EquatesPlugin", "Set_Equate")); setEquateDialog.setHelpLocation(new HelpLocation("EquatesPlugin", "Set_Equate"));

View file

@ -33,8 +33,6 @@ import ghidra.util.StringFormat;
*/ */
public abstract class AbstractIntegerDataType extends BuiltIn implements ArrayStringable { public abstract class AbstractIntegerDataType extends BuiltIn implements ArrayStringable {
private static final long serialVersionUID = 1L;
static final String C_SIGNED_CHAR = "signed char"; static final String C_SIGNED_CHAR = "signed char";
static final String C_UNSIGNED_CHAR = "unsigned char"; static final String C_UNSIGNED_CHAR = "unsigned char";
static final String C_SIGNED_SHORT = "short"; static final String C_SIGNED_SHORT = "short";
@ -59,7 +57,7 @@ public abstract class AbstractIntegerDataType extends BuiltIn implements ArraySt
/** /**
* Constructor * Constructor
* @param name a unique signed/unsigned data-type name (also used as the mnemonic) * @param name a unique signed/unsigned data-type name (also used as the mnemonic)
* @param signed * @param signed true if signed, false if unsigned
* @param dtm data-type manager whose data organization should be used * @param dtm data-type manager whose data organization should be used
*/ */
public AbstractIntegerDataType(String name, boolean signed, DataTypeManager dtm) { public AbstractIntegerDataType(String name, boolean signed, DataTypeManager dtm) {
@ -92,7 +90,7 @@ public abstract class AbstractIntegerDataType extends BuiltIn implements ArraySt
} }
/** /**
* Returns true if this is a signed integer data-type * @return true if this is a signed integer data-type
*/ */
public boolean isSigned() { public boolean isSigned() {
return signed; return signed;
@ -116,7 +114,7 @@ public abstract class AbstractIntegerDataType extends BuiltIn implements ArraySt
} }
/** /**
* Returns the Assembly style data-type declaration * @return the Assembly style data-type declaration
* for this data-type. * for this data-type.
*/ */
public String getAssemblyMnemonic() { public String getAssemblyMnemonic() {
@ -124,7 +122,7 @@ public abstract class AbstractIntegerDataType extends BuiltIn implements ArraySt
} }
/** /**
* Returns the C style data-type mnemonic * @return the C style data-type mnemonic
* for this data-type. * for this data-type.
* NOTE: currently the same as getCDeclaration(). * NOTE: currently the same as getCDeclaration().
*/ */
@ -134,7 +132,7 @@ public abstract class AbstractIntegerDataType extends BuiltIn implements ArraySt
} }
/** /**
* Returns the C style data-type declaration * @return the C style data-type declaration
* for this data-type. Null is returned if * for this data-type. Null is returned if
* no appropriate declaration exists. * no appropriate declaration exists.
*/ */
@ -162,28 +160,6 @@ public abstract class AbstractIntegerDataType extends BuiltIn implements ArraySt
return null; return null;
} }
/**
* Get the value of integer data as a BigInteger
* @param buf the data buffer.
* @param settings the settings to use.
* @return BigInteger data value
*/
public BigInteger getBigIntegerValue(MemBuffer buf, Settings settings) {
Object value = getValue(buf, settings, getLength());
if (value instanceof Scalar) {
Scalar s = (Scalar) value;
return s.getBigInteger();
}
if (value instanceof BigInteger) {
return (BigInteger) value;
}
if (value instanceof Character) {
// FIXME: consider flipping around getValue and getBigIntegerValue
return BigInteger.valueOf((Character) value);
}
return null;
}
@Override @Override
public Object getValue(MemBuffer buf, Settings settings, int length) { public Object getValue(MemBuffer buf, Settings settings, int length) {
@ -233,9 +209,6 @@ public abstract class AbstractIntegerDataType extends BuiltIn implements ArraySt
return Scalar.class; return Scalar.class;
} }
/**
* @see ghidra.program.model.data.DataType#getRepresentation(ghidra.program.model.mem.MemBuffer, ghidra.docking.settings.Settings, int)
*/
@Override @Override
public String getRepresentation(MemBuffer buf, Settings settings, int length) { public String getRepresentation(MemBuffer buf, Settings settings, int length) {
@ -269,6 +242,7 @@ public abstract class AbstractIntegerDataType extends BuiltIn implements ArraySt
* Get integer representation of the big-endian value. * Get integer representation of the big-endian value.
* @param bigInt BigInteger value with the appropriate sign * @param bigInt BigInteger value with the appropriate sign
* @param settings integer format settings (PADDING, FORMAT, etc.) * @param settings integer format settings (PADDING, FORMAT, etc.)
* @param bitLength number of value bits to be used from bigInt
* @return formatted integer string * @return formatted integer string
*/ */
public String getRepresentation(BigInteger bigInt, Settings settings, int bitLength) { public String getRepresentation(BigInteger bigInt, Settings settings, int bitLength) {
@ -382,7 +356,7 @@ public abstract class AbstractIntegerDataType extends BuiltIn implements ArraySt
* the element at index <code>i</code> points to the datatype of size <code>i+1</code>, * the element at index <code>i</code> points to the datatype of size <code>i+1</code>,
* with additional types with no size restriction appended after the first 8. * with additional types with no size restriction appended after the first 8.
* *
* @return * @return array of all signed integer types (char and bool types excluded)
*/ */
private static AbstractIntegerDataType[] getSignedTypes() { private static AbstractIntegerDataType[] getSignedTypes() {
if (signedTypes == null) { if (signedTypes == null) {
@ -400,7 +374,7 @@ public abstract class AbstractIntegerDataType extends BuiltIn implements ArraySt
* the element at index <code>i</code> points to the datatype of size <code>i+1</code>, * the element at index <code>i</code> points to the datatype of size <code>i+1</code>,
* with additional types with no size restriction appended after the first 8. * with additional types with no size restriction appended after the first 8.
* *
* @return * @return array of all unsigned integer types (char and bool types excluded)
*/ */
private static AbstractIntegerDataType[] getUnsignedTypes() { private static AbstractIntegerDataType[] getUnsignedTypes() {
if (unsignedTypes == null) { if (unsignedTypes == null) {
@ -455,6 +429,7 @@ public abstract class AbstractIntegerDataType extends BuiltIn implements ArraySt
* Returns all built-in signed integer data-types. * Returns all built-in signed integer data-types.
* @param dtm optional program data-type manager, if specified * @param dtm optional program data-type manager, if specified
* generic data-types will be returned in place of fixed-sized data-types. * generic data-types will be returned in place of fixed-sized data-types.
* @return array of all signed integer types (char and bool types excluded)
*/ */
public static AbstractIntegerDataType[] getSignedDataTypes(DataTypeManager dtm) { public static AbstractIntegerDataType[] getSignedDataTypes(DataTypeManager dtm) {
AbstractIntegerDataType[] dataTypes = getSignedTypes().clone(); AbstractIntegerDataType[] dataTypes = getSignedTypes().clone();
@ -524,6 +499,7 @@ public abstract class AbstractIntegerDataType extends BuiltIn implements ArraySt
* Returns all built-in unsigned integer data-types * Returns all built-in unsigned integer data-types
* @param dtm optional program data-type manager, if specified * @param dtm optional program data-type manager, if specified
* generic data-types will be returned in place of fixed-sized data-types. * generic data-types will be returned in place of fixed-sized data-types.
* @return array of all unsigned integer types (char and bool types excluded)
*/ */
public static AbstractIntegerDataType[] getUnsignedDataTypes(DataTypeManager dtm) { public static AbstractIntegerDataType[] getUnsignedDataTypes(DataTypeManager dtm) {
AbstractIntegerDataType[] dataTypes = getUnsignedTypes().clone(); AbstractIntegerDataType[] dataTypes = getUnsignedTypes().clone();

View file

@ -15,6 +15,8 @@
*/ */
package ghidra.program.model.data; package ghidra.program.model.data;
import java.math.BigInteger;
import ghidra.docking.settings.Settings; import ghidra.docking.settings.Settings;
import ghidra.docking.settings.SettingsDefinition; import ghidra.docking.settings.SettingsDefinition;
import ghidra.program.model.lang.DecompilerLanguage; import ghidra.program.model.lang.DecompilerLanguage;
@ -24,7 +26,7 @@ import ghidra.program.model.mem.MemoryAccessException;
/** /**
* Provides a definition of an Ascii byte in a program. * Provides a definition of an Ascii byte in a program.
*/ */
public class BooleanDataType extends BuiltIn { public class BooleanDataType extends AbstractIntegerDataType {
private final static long serialVersionUID = 1; private final static long serialVersionUID = 1;
@ -40,7 +42,7 @@ public class BooleanDataType extends BuiltIn {
} }
public BooleanDataType(DataTypeManager dtm) { public BooleanDataType(DataTypeManager dtm) {
super(null, "bool", dtm); super("bool", false, dtm);
} }
@Override @Override
@ -55,6 +57,11 @@ public class BooleanDataType extends BuiltIn {
return name; return name;
} }
@Override
public String getCDeclaration() {
return name;
}
@Override @Override
public int getLength() { public int getLength() {
return 1; // TODO: Size should probably be based upon data organization return 1; // TODO: Size should probably be based upon data organization
@ -94,9 +101,11 @@ public class BooleanDataType extends BuiltIn {
return b.booleanValue() ? "TRUE" : "FALSE"; return b.booleanValue() ? "TRUE" : "FALSE";
} }
/** @Override
* @see ghidra.program.model.data.BuiltIn#getBuiltInSettingsDefinitions() public String getRepresentation(BigInteger bigInt, Settings settings, int bitLength) {
*/ return BigInteger.ZERO.equals(bigInt) ? "FALSE" : "TRUE";
}
@Override @Override
protected SettingsDefinition[] getBuiltInSettingsDefinitions() { protected SettingsDefinition[] getBuiltInSettingsDefinitions() {
return SETTINGS_DEFS; return SETTINGS_DEFS;
@ -112,4 +121,10 @@ public class BooleanDataType extends BuiltIn {
return "BOOL"; return "BOOL";
} }
@Override
public AbstractIntegerDataType getOppositeSignednessDataType() {
// TODO: only unsigned supported
return this;
}
} }

View file

@ -40,8 +40,8 @@ public class HighConstant extends HighVariable {
* @param func the associated high function * @param func the associated high function
* @throws InvalidInputException * @throws InvalidInputException
*/ */
public HighConstant(String name, DataType type, Varnode vn, Address pc, public HighConstant(String name, DataType type, Varnode vn, Address pc, HighFunction func)
HighFunction func) throws InvalidInputException { throws InvalidInputException {
super(name, type, vn, null, func); super(name, type, vn, null, func);
pcaddr = pc; pcaddr = pc;
} }
@ -55,8 +55,8 @@ public class HighConstant extends HighVariable {
* @param sym associated dynamic symbol * @param sym associated dynamic symbol
* @throws InvalidInputException * @throws InvalidInputException
*/ */
public HighConstant(String name, DataType type, Varnode vn, Address pc, public HighConstant(String name, DataType type, Varnode vn, Address pc, DynamicSymbol sym)
DynamicSymbol sym) throws InvalidInputException { throws InvalidInputException {
this(name, type, vn, pc, sym.getHighFunction()); this(name, type, vn, pc, sym.getHighFunction());
symbol = sym; symbol = sym;
} }
@ -76,7 +76,7 @@ public class HighConstant extends HighVariable {
} }
/** /**
* Returns constant as a scalar object * @return constant as a scalar object
*/ */
public Scalar getScalar() { public Scalar getScalar() {
boolean signed = false; boolean signed = false;

View file

@ -493,7 +493,12 @@ public class PcodeDataTypeManager {
FunctionPrototype fproto = new FunctionPrototype(fdef, cspec, voidInputIsVarargs); FunctionPrototype fproto = new FunctionPrototype(fdef, cspec, voidInputIsVarargs);
fproto.buildPrototypeXML(resBuf, this); fproto.buildPrototypeXML(resBuf, this);
} }
else if (type instanceof AbstractIntegerDataType) { else if (type instanceof BooleanDataType) {
SpecXmlUtils.encodeStringAttribute(resBuf, "metatype", "bool");
SpecXmlUtils.encodeSignedIntegerAttribute(resBuf, "size", type.getLength());
resBuf.append('>');
}
else if (type instanceof AbstractIntegerDataType) { // must handle char and bool above
boolean signed = ((AbstractIntegerDataType) type).isSigned(); boolean signed = ((AbstractIntegerDataType) type).isSigned();
int sz = type.getLength(); int sz = type.getLength();
if (sz <= 0) { if (sz <= 0) {
@ -503,11 +508,6 @@ public class PcodeDataTypeManager {
SpecXmlUtils.encodeSignedIntegerAttribute(resBuf, "size", sz); SpecXmlUtils.encodeSignedIntegerAttribute(resBuf, "size", sz);
resBuf.append('>'); resBuf.append('>');
} }
else if (type instanceof BooleanDataType) {
SpecXmlUtils.encodeStringAttribute(resBuf, "metatype", "bool");
SpecXmlUtils.encodeSignedIntegerAttribute(resBuf, "size", type.getLength());
resBuf.append('>');
}
else if (type instanceof AbstractFloatDataType) { else if (type instanceof AbstractFloatDataType) {
SpecXmlUtils.encodeStringAttribute(resBuf, "metatype", "float"); SpecXmlUtils.encodeStringAttribute(resBuf, "metatype", "float");
SpecXmlUtils.encodeSignedIntegerAttribute(resBuf, "size", type.getLength()); SpecXmlUtils.encodeSignedIntegerAttribute(resBuf, "size", type.getLength());