Package ghidra.program.model.data

# Class EnumDataType

java.lang.Object
ghidra.program.model.data.AbstractDataType
ghidra.program.model.data.DataTypeImpl
ghidra.program.model.data.GenericDataType
ghidra.program.model.data.EnumDataType

All Implemented Interfaces:
  `DataType`, `Enum`

Direct Known Subclasses:
  `CliAbstractSig.CliTypeCodeDataType`, `CliBlobMarshalSpec.CliNativeTypeDataType`, `CliBlobMarshalSpec.CliSafeArrayElemTypeDataType`, `CliFlags.CliEnumAssemblyFlags`, `CliFlags.CliEnumAssemblyHashAlgorithm`, `CliFlags.CliEnumEventAttributes`, `CliFlags.CliEnumFieldAttributes`, `CliFlags.CliEnumFileAttributes`, `CliFlags.CliEnumGenericParamAttributes`, `CliFlags.CliEnumManifestResourceAttributes`, `CliFlags.CliEnumMethodAttributes`, `CliFlags.CliEnumMethodImplAttributes`, `CliFlags.CliEnumMethodSemanticsAttributes`, `CliFlags.CliEnumParamAttributes`, `CliFlags.CliEnumPInvokeAttributes`, `CliFlags.CliEnumPropertyAttributes`, `CliFlags.CliEnumTypeAttributes`, `ImageCor20Header.ImageCor20Flags`

public class EnumDataType extends GenericDataType implements Enum

- ## Field Summary

  ### Fields inherited from class ghidra.program.model.data.DataTypeImpl

  `defaultSettings`

  ### Fields inherited from class ghidra.program.model.data.AbstractDataType

  `categoryPath, dataMgr, name`

  ### Fields inherited from interface ghidra.program.model.data.DataType

  `CONFLICT_SUFFIX, DEFAULT, NO_LAST_CHANGE_TIME, NO_SOURCE_SYNC_TIME, TYPEDEF_ATTRIBUTE_PREFIX, TYPEDEF_ATTRIBUTE_SUFFIX, VOID`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `EnumDataType(CategoryPath path, String name, int length)`
  `EnumDataType(CategoryPath path, String name, int length, DataTypeManager dtm)`
  `EnumDataType(CategoryPath path, String name, int length, UniversalID universalID, SourceArchive sourceArchive, long lastChangeTime, long lastChangeTimeInSourceArchive, DataTypeManager dtm)`
  `EnumDataType(String name, int length)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `add(String valueName, long value)`
  Add a enum entry.
  `void`
  `add(String valueName, long value, String comment)`
  Add a enum entry.
  `DataType`
  `clone(DataTypeManager dtm)`
  Returns an instance of this DataType using the specified `DataTypeManager` to allow its use of the corresponding `DataOrganization` while retaining its unique identity (see `DataType.getUniversalID()` and archive association (see `DataType.getSourceArchive()`) if applicable.
  `boolean`
  `contains(long value)`
  Returns true if this enum has an entry with the given value.
  `boolean`
  `contains(String entryName)`
  Returns true if this enum has an entry with the given name.
  `DataType`
  `copy(DataTypeManager dtm)`
  Returns a new instance (shallow copy) of this DataType with a new identity and no source archive association.
  `int`
  `getAlignedLength()`
  Get the aligned-length of this datatype as a number of 8-bit bytes.
  `String`
  `getComment(String valueName)`
  Get the comment for the given name.
  `int`
  `getCount()`
  Get the number of entries in this Enum.
  `String`
  `getDefaultLabelPrefix()`
  Returns the appropriate string to use as the default label prefix in the absence of any data.
  `String`
  `getDescription()`
  Get a String briefly describing this DataType.
  `int`
  `getLength()`
  Get the length of this DataType as a number of 8-bit bytes.
  `long`
  `getMaxPossibleValue()`
  Returns the maximum value that this enum can represent based on its size and signedness.
  `int`
  `getMinimumPossibleLength()`
  Returns the smallest length (size in bytes) this enum can be and still represent all of it's current values.
  `long`
  `getMinPossibleValue()`
  Returns the maximum value that this enum can represent based on its size and signedness.
  `String`
  `getMnemonic(Settings settings)`
  Get the mnemonic for this DataType.
  `String`
  `getName(long value)`
  Get the name for the given value.
  `String[]`
  `getNames()`
  Get the names of the enum entries.
  `String[]`
  `getNames(long value)`
  Returns all names that map to the given value.
  `String`
  `getRepresentation(MemBuffer buf, Settings settings, int valueLength)`
  Get bytes from memory in a printable format for this type.
  `String`
  `getRepresentation(BigInteger bigInt, Settings settings, int bitLength)`
  Get enum representation of the big-endian value.
  `SettingsDefinition[]`
  `getSettingsDefinitions()`
  Get the list of settings definitions available for use with this datatype.
  `EnumSignedState`
  `getSignedState()`
  Returns the signed state.
  `Object`
  `getValue(MemBuffer buf, Settings settings, int valueLength)`
  Returns the interpreted data value as an instance of the `advertised value class`.
  `long`
  `getValue(String valueName)`
  Get the value for the given name.
  `Class<?>`
  `getValueClass(Settings settings)`
  Get the Class of the value Object to be returned by this datatype (see `DataType.getValue(MemBuffer, Settings, int)`).
  `long[]`
  `getValues()`
  Get the values of the enum entries.
  `boolean`
  `isEquivalent(DataType dt)`
  Check if the given datatype is equivalent to this datatype.
  `boolean`
  `isSigned()`
  Returns true if the enum contains at least one negative value.
  `void`
  `pack()`
  Sets this enum to it smallest (power of 2) size that it can be and still represent all its current values.
  `void`
  `remove(String valueName)`
  Remove the enum entry with the given name.
  `void`
  `replaceWith(DataType dataType)`
  For datatypes that support change, this method replaces the internals of this datatype with the internals of the given datatype.
  `void`
  `setDescription(String description)`
  Sets a String briefly describing this DataType.
  `void`
  `setLength(int newLength)`

  ### Methods inherited from class ghidra.program.model.data.GenericDataType

  `setCategoryPath, setName, setNameAndCategory`

  ### Methods inherited from class ghidra.program.model.data.DataTypeImpl

  `addParent, equals, getAlignment, getDefaultSettings, getLastChangeTime, getLastChangeTimeInSourceArchive, getParents, getPathName, getSourceArchive, getUniversalID, hashCode, notifyAlignmentChanged, notifyDeleted, notifyNameChanged, notifyParents, notifyReplaced, notifySizeChanged, removeParent, setLastChangeTime, setLastChangeTimeInSourceArchive, setSourceArchive`

  ### Methods inherited from class ghidra.program.model.data.AbstractDataType

  `dataTypeAlignmentChanged, dataTypeDeleted, dataTypeNameChanged, dataTypeReplaced, dataTypeSizeChanged, dependsOn, encodeRepresentation, encodeValue, getCategoryPath, getDataOrganization, getDataOrganization, getDataTypeManager, getDataTypePath, getDefaultAbbreviatedLabelPrefix, getDefaultLabelPrefix, getDefaultOffcutLabelPrefix, getDisplayName, getDocs, getName, getTypeDefSettingsDefinitions, hasLanguageDependantLength, isDeleted, isEncodable, isNotYetDefined, isZeroLength, toString`

  ### Methods inherited from class java.lang.Object

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

  ### Methods inherited from interface ghidra.program.model.data.DataType

  `addParent, dataTypeAlignmentChanged, dataTypeDeleted, dataTypeNameChanged, dataTypeReplaced, dataTypeSizeChanged, dependsOn, encodeRepresentation, encodeValue, getAlignment, getCategoryPath, getDataOrganization, getDataTypeManager, getDataTypePath, getDefaultAbbreviatedLabelPrefix, getDefaultLabelPrefix, getDefaultOffcutLabelPrefix, getDefaultSettings, getDisplayName, getDocs, getLastChangeTime, getLastChangeTimeInSourceArchive, getName, getParents, getPathName, getSourceArchive, getTypeDefSettingsDefinitions, getUniversalID, hasLanguageDependantLength, isDeleted, isEncodable, isNotYetDefined, isZeroLength, removeParent, setCategoryPath, setLastChangeTime, setLastChangeTimeInSourceArchive, setName, setNameAndCategory, setSourceArchive`

- ## Constructor Details

  - ### EnumDataType

    public EnumDataType(String name, int length)

  - ### EnumDataType

    public EnumDataType(CategoryPath path, String name, int length)

  - ### EnumDataType

    public EnumDataType(CategoryPath path, String name, int length, DataTypeManager dtm)

  - ### EnumDataType

    public EnumDataType(CategoryPath path, String name, int length, UniversalID universalID, SourceArchive sourceArchive, long lastChangeTime, long lastChangeTimeInSourceArchive, DataTypeManager dtm)

- ## Method Details

  - ### getSettingsDefinitions

    public SettingsDefinition[] getSettingsDefinitions()
    Description copied from interface: `DataType`
    Get the list of settings definitions available for use with this datatype.

    In the case of a `TypeDef`, the return list will include the `TypeDefSettingsDefinition` list from the associated base data type.

    Unlike `TypeDefSettingsDefinition` standard settings definitions generally support default, component-default and data-instance use. In addition, standard settings definitions are never considered during `DataType.isEquivalent(DataType)` checking or during the resolve process.

    Specified by:
      `getSettingsDefinitions` in interface `DataType`
    Overrides:
      `getSettingsDefinitions` in class `DataTypeImpl`
    Returns:
      list of the settings definitions for this datatype.

  - ### getValue

    public long getValue(String valueName) throws NoSuchElementException
    Description copied from interface: `Enum`
    Get the value for the given name.
    Specified by:
      `getValue` in interface `Enum`
    Parameters:
      `valueName` - name of the entry.
    Returns:
      the value.
    Throws:
      `NoSuchElementException` - if the name does not exist in this Enum.

  - ### getName

    public String getName(long value)
    Description copied from interface: `Enum`
    Get the name for the given value.
    Specified by:
      `getName` in interface `Enum`
    Parameters:
      `value` - value of the enum entry.
    Returns:
      null if the name with the given value was not found.

  - ### getNames

    public String[] getNames(long value)
    Description copied from interface: `Enum`
    Returns all names that map to the given value.
    Specified by:
      `getNames` in interface `Enum`
    Parameters:
      `value` - value for the enum entries.
    Returns:
      all names; null if there is not name for the given value.

  - ### getComment

    public String getComment(String valueName)
    Description copied from interface: `Enum`
    Get the comment for the given name.
    Specified by:
      `getComment` in interface `Enum`
    Parameters:
      `valueName` - name of the entry.
    Returns:
      the comment or the empty string if the name does not exist in this enum or if no comment is set.

  - ### getValues

    public long[] getValues()
    Description copied from interface: `Enum`
    Get the values of the enum entries.
    Specified by:
      `getValues` in interface `Enum`
    Returns:
      values sorted in ascending order

  - ### getNames

    public String[] getNames()
    Description copied from interface: `Enum`
    Get the names of the enum entries. The returned names are first sorted by the enum int value, then sub-sorted by name value where there are multiple name values per int value.
    Specified by:
      `getNames` in interface `Enum`
    Returns:
      the names of the enum entries.

  - ### getCount

    public int getCount()
    Description copied from interface: `Enum`
    Get the number of entries in this Enum.
    Specified by:
      `getCount` in interface `Enum`
    Returns:
      the number of entries in this Enum.

  - ### add

    public void add(String valueName, long value)
    Description copied from interface: `Enum`
    Add a enum entry.
    Specified by:
      `add` in interface `Enum`
    Parameters:
      `valueName` - name of the new entry
      `value` - value of the new entry

  - ### add

    public void add(String valueName, long value, String comment)
    Description copied from interface: `Enum`
    Add a enum entry.
    Specified by:
      `add` in interface `Enum`
    Parameters:
      `valueName` - name of the new entry
      `value` - value of the new entry
      `comment` - comment of the new entry

  - ### remove

    public void remove(String valueName)
    Description copied from interface: `Enum`
    Remove the enum entry with the given name.
    Specified by:
      `remove` in interface `Enum`
    Parameters:
      `valueName` - name of entry to remove.

  - ### copy

    public DataType copy(DataTypeManager dtm)
    Description copied from interface: `DataType`
    Returns a new instance (shallow copy) of this DataType with a new identity and no source archive association.

    Any reference to other datatypes will use `DataType.clone(DataTypeManager)`.

    Specified by:
      `copy` in interface `DataType`
    Parameters:
      `dtm` - the data-type manager instance whose data-organization should apply.
    Returns:
      new instanceof of this datatype

  - ### clone

    public DataType clone(DataTypeManager dtm)
    Description copied from interface: `DataType`
    Returns an instance of this DataType using the specified `DataTypeManager` to allow its use of the corresponding `DataOrganization` while retaining its unique identity (see `DataType.getUniversalID()` and archive association (see `DataType.getSourceArchive()`) if applicable.

    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 `DataTypeManager` matches the specified dtm and simply use the existing datatype instance.

    NOTE: In general, this method should not be used to obtain an instance to be modified. In most cases changes may be made directly to this instance if supported or to a `DataType.copy(DataTypeManager)` of this type.

    Specified by:
      `clone` in interface `DataType`
    Parameters:
      `dtm` - the data-type manager instance whose data-organization should apply.
    Returns:
      cloned instance which may be the same as this instance

  - ### getMnemonic

    public String getMnemonic(Settings settings)
    Description copied from interface: `DataType`
    Get the mnemonic for this DataType.
    Specified by:
      `getMnemonic` in interface `DataType`
    Overrides:
      `getMnemonic` in class `AbstractDataType`
    Parameters:
      `settings` - settings which may influence the result or null
    Returns:
      the mnemonic for this DataType.

  - ### getLength

    public int getLength()
    Description copied from interface: `DataType`
    Get the length of this DataType as a number of 8-bit bytes.

    For primitive datatypes this reflects the smallest varnode which can be used to contain its value (i.e., raw data length).

    Example: For x86 32-bit gcc an 80-bit `long double` `raw data length` of 10-bytes will fit within a floating point register while its `aligned-length` of 12-bytes is used by the gcc compiler for data/array/component allocations to maintain alignment (i.e., `sizeof(long double)` ).

    NOTE: Other than the `VoidDataType`, no datatype should ever return 0, even if `DataType.isZeroLength()`, and only `Dynamic`/`FactoryDataType` datatypes should return -1. If `DataType.isZeroLength()` is true a length of 1 should be returned. Where a zero-length datatype can be handled (e.g., `Composite`) the `DataType.isZeroLength()` method should be used.

    Specified by:
      `getLength` in interface `DataType`
    Returns:
      the length of this DataType

  - ### getAlignedLength

    public int getAlignedLength()
    Description copied from interface: `DataType`
    Get the aligned-length of this datatype as a number of 8-bit bytes.

    For primitive datatypes this is equivalent to the C/C++ "sizeof" operation within source code and should be used when determining `Array` element length or component sizing for a `Composite`. For `Pointer`, `Composite` and `Array` types this will return the same value as `DataType.getLength()`.

    Example: For x86 32-bit gcc an 80-bit `long double` `raw data length` of 10-bytes will fit within a floating point register while its `aligned-length` of 12-bytes is used by the gcc compiler for data/array/component allocations to maintain alignment (i.e., `sizeof(long double)` ).

    NOTE: Other than the `VoidDataType`, no datatype should ever return 0, even if `DataType.isZeroLength()`, and only `Dynamic` / `FactoryDataType` / `FunctionDefinition` datatypes should return -1. If `DataType.isZeroLength()` is true a length of 1 should be returned.

    Specified by:
      `getAlignedLength` in interface `DataType`
    Overrides:
      `getAlignedLength` in class `DataTypeImpl`
    Returns:
      byte length of binary encoding.

  - ### setLength

    public void setLength(int newLength)

  - ### isSigned

    public boolean isSigned()
    Description copied from interface: `Enum`
    Returns true if the enum contains at least one negative value. Internally, enums have three states, signed, unsigned, and none (can't tell from the values). If any of the values are negative, the enum is considered signed. If any of the values are large unsigned values (upper bit set), then it is considered unsigned. This method will return true if the enum is signed, and false if it is either unsigned or none (meaning that it doesn't matter for the values that are contained in the enum.
    Specified by:
      `isSigned` in interface `Enum`
    Returns:
      true if the enum contains at least one negative value

  - ### getSignedState

    public EnumSignedState getSignedState()
    Description copied from interface: `Enum`
    Returns the signed state.
    Specified by:
      `getSignedState` in interface `Enum`
    Returns:
      the signed state.

  - ### getMinPossibleValue

    public long getMinPossibleValue()
    Description copied from interface: `Enum`
    Returns the maximum value that this enum can represent based on its size and signedness.
    Specified by:
      `getMinPossibleValue` in interface `Enum`
    Returns:
      the maximum value that this enum can represent based on its size and signedness.

  - ### getMaxPossibleValue

    public long getMaxPossibleValue()
    Description copied from interface: `Enum`
    Returns the maximum value that this enum can represent based on its size and signedness.
    Specified by:
      `getMaxPossibleValue` in interface `Enum`
    Returns:
      the maximum value that this enum can represent based on its size and signedness.

  - ### getMinimumPossibleLength

    public int getMinimumPossibleLength()
    Description copied from interface: `Enum`
    Returns the smallest length (size in bytes) this enum can be and still represent all of it's current values. Note that that this will only return powers of 2 (1,2,4, or 8)
    Specified by:
      `getMinimumPossibleLength` in interface `Enum`
    Returns:
      the smallest length (size in bytes) this enum can be and still represent all of it's current values

  - ### getDescription

    public String getDescription()
    Description copied from interface: `DataType`
    Get a String briefly describing this DataType.
    Specified by:
      `getDescription` in interface `DataType`
    Returns:
      a one-liner describing this DataType.

  - ### setDescription

    public void setDescription(String description)
    Description copied from class: `DataTypeImpl`
    Sets a String briefly describing this DataType.
    If a data type that extends this class wants to allow the description to be changed, then it must override this method.
    Specified by:
      `setDescription` in interface `DataType`
    Specified by:
      `setDescription` in interface `Enum`
    Overrides:
      `setDescription` in class `DataTypeImpl`
    Parameters:
      `description` - a one-liner describing this DataType.

  - ### getValue

    public Object getValue(MemBuffer buf, Settings settings, int valueLength)
    Description copied from interface: `DataType`
    Returns the interpreted data value as an instance of the `advertised value class`.

    For instance, `Pointer` data types should return an Address object (or null), or integer data types should return a `Scalar` object.

    Specified by:
      `getValue` in interface `DataType`
    Parameters:
      `buf` - the data buffer
      `settings` - the settings to use.
      `valueLength` - indicates the maximum number of bytes that may be consumed by a `Dynamic` datatype, otherwise this value is ignored. A value of -1 may be specified to allow a Dynamic datatype to determine the length based upon the actual data bytes
    Returns:
      the data object, or null if data is invalid

  - ### getValueClass

    public Class<?> getValueClass(Settings settings)
    Description copied from interface: `DataType`
    Get the Class of the value Object to be returned by this datatype (see `DataType.getValue(MemBuffer, Settings, int)`).
    Specified by:
      `getValueClass` in interface `DataType`
    Overrides:
      `getValueClass` in class `DataTypeImpl`
    Parameters:
      `settings` - the relevant settings to use or null for default.
    Returns:
      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 class.

  - ### getRepresentation

    public String getRepresentation(MemBuffer buf, Settings settings, int valueLength)
    Description copied from interface: `DataType`
    Get bytes from memory in a printable format for this type.
    Specified by:
      `getRepresentation` in interface `DataType`
    Parameters:
      `buf` - the data.
      `settings` - the settings to use for the representation.
      `valueLength` - the number of bytes to represent.
    Returns:
      the representation of the data in this format, never null.

  - ### getRepresentation

    public String getRepresentation(BigInteger bigInt, Settings settings, int bitLength)
    Description copied from interface: `Enum`
    Get enum representation of the big-endian value.
    Specified by:
      `getRepresentation` in interface `Enum`
    Parameters:
      `bigInt` - BigInteger value with the appropriate sign
      `settings` - integer format settings (PADDING, FORMAT, etc.)
      `bitLength` - the bit length
    Returns:
      formatted integer string

  - ### isEquivalent

    public boolean isEquivalent(DataType dt)
    Description copied from interface: `DataType`
    Check if the given datatype is equivalent to this datatype.

    The precise meaning of "equivalent" is datatype dependent.
    NOTE: if invoked by a DB object or manager it should be invoked on the DataTypeDB object passing the other datatype as the argument.

    Specified by:
      `isEquivalent` in interface `DataType`
    Parameters:
      `dt` - the datatype being tested for equivalence.
    Returns:
      true if the if the given datatype is equivalent to this datatype.

  - ### replaceWith

    public void replaceWith(DataType dataType)
    Description copied from interface: `DataType`
    For datatypes that support change, this method replaces the internals of this datatype with the internals of the given datatype.

    The datatypes must be of the same "type" (i.e. structure can only be replacedWith another structure.

    Specified by:
      `replaceWith` in interface `DataType`
    Overrides:
      `replaceWith` in class `DataTypeImpl`
    Parameters:
      `dataType` - the datatype that contains the internals to upgrade to.

  - ### getDefaultLabelPrefix

    public String getDefaultLabelPrefix()
    Description copied from interface: `DataType`
    Returns the appropriate string to use as the default label prefix in the absence of any data.
    Specified by:
      `getDefaultLabelPrefix` in interface `DataType`
    Overrides:
      `getDefaultLabelPrefix` in class `AbstractDataType`
    Returns:
      the default label prefix or null if none specified.

  - ### contains

    public boolean contains(String entryName)
    Description copied from interface: `Enum`
    Returns true if this enum has an entry with the given name.
    Specified by:
      `contains` in interface `Enum`
    Parameters:
      `entryName` - the name to check for an entry
    Returns:
      true if this enum has an entry with the given name

  - ### contains

    public boolean contains(long value)
    Description copied from interface: `Enum`
    Returns true if this enum has an entry with the given value.
    Specified by:
      `contains` in interface `Enum`
    Parameters:
      `value` - the value to check for an entry
    Returns:
      true if this enum has an entry with the given value

  - ### pack

    public void pack()
    Sets this enum to it smallest (power of 2) size that it can be and still represent all its current values.