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

@ -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();

View file

@ -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;
}
}

View file

@ -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;

View file

@ -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());