mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2024-11-28 23:21:46 +00:00
Merge remote-tracking branch 'origin/GT-3170_ghidra1_BoolBitFields' into Ghidra_9.1
This commit is contained in:
commit
ef7809d9f2
@ -1313,7 +1313,7 @@
|
||||
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.
|
||||
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
|
||||
assistance or via full access to a datatype tree chooser by clicking the '...' button.</P>
|
||||
|
||||
|
@ -23,7 +23,9 @@ import javax.swing.JMenuItem;
|
||||
import docking.action.MenuData;
|
||||
import ghidra.app.context.ListingActionContext;
|
||||
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.scalar.Scalar;
|
||||
import ghidra.program.util.OperandFieldLocation;
|
||||
@ -65,7 +67,11 @@ public abstract class AbstractConvertAction extends ListingContextAction {
|
||||
// unsupported data action
|
||||
return false;
|
||||
}
|
||||
DataType dataType = ((Data) cu).getBaseDataType();
|
||||
Data data = (Data) cu;
|
||||
if (!data.isDefined()) {
|
||||
return false;
|
||||
}
|
||||
DataType dataType = data.getBaseDataType();
|
||||
if (!(dataType instanceof AbstractIntegerDataType)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ public class ConvertCommand extends BackgroundCommand {
|
||||
DataType dt = data.getBaseDataType();
|
||||
Settings settings = data;
|
||||
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();
|
||||
return false;
|
||||
}
|
||||
|
@ -36,8 +36,7 @@ import ghidra.framework.cmd.CompoundBackgroundCommand;
|
||||
import ghidra.framework.plugintool.*;
|
||||
import ghidra.framework.plugintool.util.PluginStatus;
|
||||
import ghidra.program.model.address.*;
|
||||
import ghidra.program.model.data.DataType;
|
||||
import ghidra.program.model.data.DataTypeManager;
|
||||
import ghidra.program.model.data.*;
|
||||
import ghidra.program.model.data.Enum;
|
||||
import ghidra.program.model.listing.*;
|
||||
import ghidra.program.model.scalar.Scalar;
|
||||
@ -165,6 +164,10 @@ public class EquatePlugin extends Plugin {
|
||||
if (!data.isDefined()) {
|
||||
return false;
|
||||
}
|
||||
DataType dataType = data.getBaseDataType();
|
||||
if (!(dataType instanceof AbstractIntegerDataType)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Equate equate = getEquate(context);
|
||||
|
@ -710,6 +710,9 @@ public class DWARFFunctionImporter {
|
||||
if (!(dataDT instanceof Enum || dataDT instanceof AbstractIntegerDataType)) {
|
||||
return false;
|
||||
}
|
||||
if (dataDT instanceof BooleanDataType) {
|
||||
return false;
|
||||
}
|
||||
if (dataDT.getLength() != enumDT.getLength()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -56,6 +56,8 @@ public class RenameConstantTask extends RenameTask {
|
||||
*/
|
||||
@Override
|
||||
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.setHelpLocation(new HelpLocation("EquatesPlugin", "Set_Equate"));
|
||||
|
||||
|
@ -33,8 +33,6 @@ import ghidra.util.StringFormat;
|
||||
*/
|
||||
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_UNSIGNED_CHAR = "unsigned char";
|
||||
static final String C_SIGNED_SHORT = "short";
|
||||
@ -59,7 +57,7 @@ public abstract class AbstractIntegerDataType extends BuiltIn implements ArraySt
|
||||
/**
|
||||
* Constructor
|
||||
* @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
|
||||
*/
|
||||
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() {
|
||||
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.
|
||||
*/
|
||||
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.
|
||||
* 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
|
||||
* no appropriate declaration exists.
|
||||
*/
|
||||
@ -162,28 +160,6 @@ public abstract class AbstractIntegerDataType extends BuiltIn implements ArraySt
|
||||
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
|
||||
public Object getValue(MemBuffer buf, Settings settings, int length) {
|
||||
|
||||
@ -233,9 +209,6 @@ public abstract class AbstractIntegerDataType extends BuiltIn implements ArraySt
|
||||
return Scalar.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ghidra.program.model.data.DataType#getRepresentation(ghidra.program.model.mem.MemBuffer, ghidra.docking.settings.Settings, int)
|
||||
*/
|
||||
@Override
|
||||
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.
|
||||
* @param bigInt BigInteger value with the appropriate sign
|
||||
* @param settings integer format settings (PADDING, FORMAT, etc.)
|
||||
* @param bitLength number of value bits to be used from bigInt
|
||||
* @return formatted integer string
|
||||
*/
|
||||
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>,
|
||||
* 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() {
|
||||
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>,
|
||||
* 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() {
|
||||
if (unsignedTypes == null) {
|
||||
@ -455,6 +429,7 @@ public abstract class AbstractIntegerDataType extends BuiltIn implements ArraySt
|
||||
* Returns all built-in signed integer data-types.
|
||||
* @param dtm optional program data-type manager, if specified
|
||||
* 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) {
|
||||
AbstractIntegerDataType[] dataTypes = getSignedTypes().clone();
|
||||
@ -524,6 +499,7 @@ public abstract class AbstractIntegerDataType extends BuiltIn implements ArraySt
|
||||
* Returns all built-in unsigned integer data-types
|
||||
* @param dtm optional program data-type manager, if specified
|
||||
* 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) {
|
||||
AbstractIntegerDataType[] dataTypes = getUnsignedTypes().clone();
|
||||
|
@ -15,6 +15,8 @@
|
||||
*/
|
||||
package ghidra.program.model.data;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
import ghidra.docking.settings.Settings;
|
||||
import ghidra.docking.settings.SettingsDefinition;
|
||||
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.
|
||||
*/
|
||||
public class BooleanDataType extends BuiltIn {
|
||||
public class BooleanDataType extends AbstractIntegerDataType {
|
||||
|
||||
private final static long serialVersionUID = 1;
|
||||
|
||||
@ -40,7 +42,7 @@ public class BooleanDataType extends BuiltIn {
|
||||
}
|
||||
|
||||
public BooleanDataType(DataTypeManager dtm) {
|
||||
super(null, "bool", dtm);
|
||||
super("bool", false, dtm);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -55,6 +57,11 @@ public class BooleanDataType extends BuiltIn {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCDeclaration() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLength() {
|
||||
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";
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ghidra.program.model.data.BuiltIn#getBuiltInSettingsDefinitions()
|
||||
*/
|
||||
@Override
|
||||
public String getRepresentation(BigInteger bigInt, Settings settings, int bitLength) {
|
||||
return BigInteger.ZERO.equals(bigInt) ? "FALSE" : "TRUE";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SettingsDefinition[] getBuiltInSettingsDefinitions() {
|
||||
return SETTINGS_DEFS;
|
||||
@ -112,4 +121,10 @@ public class BooleanDataType extends BuiltIn {
|
||||
return "BOOL";
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractIntegerDataType getOppositeSignednessDataType() {
|
||||
// TODO: only unsigned supported
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -40,8 +40,8 @@ public class HighConstant extends HighVariable {
|
||||
* @param func the associated high function
|
||||
* @throws InvalidInputException
|
||||
*/
|
||||
public HighConstant(String name, DataType type, Varnode vn, Address pc,
|
||||
HighFunction func) throws InvalidInputException {
|
||||
public HighConstant(String name, DataType type, Varnode vn, Address pc, HighFunction func)
|
||||
throws InvalidInputException {
|
||||
super(name, type, vn, null, func);
|
||||
pcaddr = pc;
|
||||
}
|
||||
@ -55,8 +55,8 @@ public class HighConstant extends HighVariable {
|
||||
* @param sym associated dynamic symbol
|
||||
* @throws InvalidInputException
|
||||
*/
|
||||
public HighConstant(String name, DataType type, Varnode vn, Address pc,
|
||||
DynamicSymbol sym) throws InvalidInputException {
|
||||
public HighConstant(String name, DataType type, Varnode vn, Address pc, DynamicSymbol sym)
|
||||
throws InvalidInputException {
|
||||
this(name, type, vn, pc, sym.getHighFunction());
|
||||
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() {
|
||||
boolean signed = false;
|
||||
|
@ -493,7 +493,12 @@ public class PcodeDataTypeManager {
|
||||
FunctionPrototype fproto = new FunctionPrototype(fdef, cspec, voidInputIsVarargs);
|
||||
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();
|
||||
int sz = type.getLength();
|
||||
if (sz <= 0) {
|
||||
@ -503,11 +508,6 @@ public class PcodeDataTypeManager {
|
||||
SpecXmlUtils.encodeSignedIntegerAttribute(resBuf, "size", sz);
|
||||
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) {
|
||||
SpecXmlUtils.encodeStringAttribute(resBuf, "metatype", "float");
|
||||
SpecXmlUtils.encodeSignedIntegerAttribute(resBuf, "size", type.getLength());
|
||||
|
Loading…
Reference in New Issue
Block a user