Package ghidra.program.model.data
Class DataOrganizationImpl
java.lang.Object
ghidra.program.model.data.DataOrganizationImpl
- All Implemented Interfaces:
DataOrganization
DataOrganization provides a single place for determining size and alignment information
for data types within an archive or a program.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final boolean
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
Fields inherited from interface ghidra.program.model.data.DataOrganization
NO_MAXIMUM_ALIGNMENT
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Remove all entries from the size alignment mapvoid
Output the details of this data organization to a encoded document formatter.boolean
int
Gets the maximum alignment value that is allowed by this data organization.static int
getAlignedOffset
(int alignment, int minimumOffset) Determines the first offset that is equal to or greater than the minimum offset which has the specified alignment.int
getAlignment
(DataType dataType) Determines the alignment value for the indicated data type.Get the composite bitfield packing information associated with this data organization.int
int
Gets the default alignment to be used for any data type that isn't a structure, union, array, pointer, type definition, and whose size isn't in the size/alignment map.static DataOrganization
Creates a new default DataOrganization.static DataOrganizationImpl
getDefaultOrganization
(Language language) Creates a new default DataOrganization.int
Gets the default alignment to be used for a pointer that doesn't have size.int
int
static int
getGreatestCommonDenominator
(int value1, int value2) Determines the greatest common denominator of two numbers.getIntegerCTypeApproximation
(int size, boolean signed) Returns the best fitting integer C-type whose size is less-than-or-equal to the specified size.int
static int
getLeastCommonMultiple
(int value1, int value2) Determines the least (lowest) common multiple of two numbers.int
int
int
int
Gets the maximum useful alignment for the target machineint
Shift amount affects interpretation of in-memory pointer values only and will also be reflected within instruction pcode.int
int
int
getSizeAlignment
(int size) Gets the primitive data alignment that is defined for the specified size.int
Gets the number of sizes that have an alignment specified.int[]
getSizes()
Gets the sizes that have an alignment specified.int
int
hashCode()
boolean
boolean
static DataOrganizationImpl
restore
(DBStringMapAdapter dataMap, String keyPrefix) Restore a data organization from the specified DB data map.void
restoreXml
(XmlPullParser parser) Restore settings from an XML stream.static void
save
(DataOrganization dataOrg, DBStringMapAdapter dataMap, String keyPrefix) Save the specified data organization to the specified DB data map.void
setAbsoluteMaxAlignment
(int absoluteMaxAlignment) Sets the maximum alignment value that is allowed by this data organization.void
setBigEndian
(boolean bigEndian) Set data endiannessvoid
setBitFieldPacking
(BitFieldPackingImpl bitFieldPacking) Set the bitfield packing information associated with this data organization.void
setCharIsSigned
(boolean signed) Defines the signed-ness of the "char" data typevoid
setCharSize
(int charSize) Defines the size of a char (char) data type.void
setDefaultAlignment
(int defaultAlignment) Sets the default alignment to be used for any data type that isn't a structure, union, array, pointer, type definition, and whose size isn't in the size/alignment map.void
setDefaultPointerAlignment
(int defaultPointerAlignment) Sets the default alignment to be used for a pointer that doesn't have size.void
setDoubleSize
(int doubleSize) Defines the encoding size of a double primitive data type.void
setFloatSize
(int floatSize) Defines the encoding size of a float primitive data type.void
setIntegerSize
(int integerSize) Defines the size of an int primitive data type.void
setLongDoubleSize
(int longDoubleSize) Defines the encoding size of a long double primitive data type.void
setLongLongSize
(int longLongSize) Defines the size of a long long primitive data type.void
setLongSize
(int longSize) Defines the size of a long primitive data type.void
setMachineAlignment
(int machineAlignment) Sets the maximum useful alignment for the target machinevoid
setPointerShift
(int pointerShift) Defines the left shift amount for a shifted pointer data type.void
setPointerSize
(int pointerSize) Defines the size of a pointer data type.void
setShortSize
(int shortSize) Defines the size of a short primitive data type.void
setSizeAlignment
(int size, int alignment) Sets the alignment that is defined for a data type of the indicated size if one is defined.void
setWideCharSize
(int wideCharSize) Defines the size of a wide-char (wchar_t) data type.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface ghidra.program.model.data.DataOrganization
isEquivalent
-
Field Details
-
DEFAULT_MACHINE_ALIGNMENT
public static final int DEFAULT_MACHINE_ALIGNMENT- See Also:
-
DEFAULT_DEFAULT_ALIGNMENT
public static final int DEFAULT_DEFAULT_ALIGNMENT- See Also:
-
DEFAULT_DEFAULT_POINTER_ALIGNMENT
public static final int DEFAULT_DEFAULT_POINTER_ALIGNMENT- See Also:
-
DEFAULT_POINTER_SHIFT
public static final int DEFAULT_POINTER_SHIFT- See Also:
-
DEFAULT_POINTER_SIZE
public static final int DEFAULT_POINTER_SIZE- See Also:
-
DEFAULT_CHAR_SIZE
public static final int DEFAULT_CHAR_SIZE- See Also:
-
DEFAULT_CHAR_IS_SIGNED
public static final boolean DEFAULT_CHAR_IS_SIGNED- See Also:
-
DEFAULT_WIDE_CHAR_SIZE
public static final int DEFAULT_WIDE_CHAR_SIZE- See Also:
-
DEFAULT_SHORT_SIZE
public static final int DEFAULT_SHORT_SIZE- See Also:
-
DEFAULT_INT_SIZE
public static final int DEFAULT_INT_SIZE- See Also:
-
DEFAULT_LONG_SIZE
public static final int DEFAULT_LONG_SIZE- See Also:
-
DEFAULT_LONG_LONG_SIZE
public static final int DEFAULT_LONG_LONG_SIZE- See Also:
-
DEFAULT_FLOAT_SIZE
public static final int DEFAULT_FLOAT_SIZE- See Also:
-
DEFAULT_DOUBLE_SIZE
public static final int DEFAULT_DOUBLE_SIZE- See Also:
-
DEFAULT_LONG_DOUBLE_SIZE
public static final int DEFAULT_LONG_DOUBLE_SIZE- See Also:
-
-
Method Details
-
getDefaultOrganization
Creates a new default DataOrganization. This has a mapping which defines the alignment of a data type based on its size. The map defines pairs for data types that are 1, 2, 4, and 8 bytes in length.- Returns:
- a new default DataOrganization.
-
getDefaultOrganization
Creates a new default DataOrganization. This has a mapping which defines the alignment of a data type based on its size. The map defines pairs for data types that are 1, 2, 4, and 8 bytes in length.- Parameters:
language
- optional language used to initialize defaults (pointer size, endianness, etc.) (may be null)- Returns:
- a new default DataOrganization.
-
isBigEndian
public boolean isBigEndian()- Specified by:
isBigEndian
in interfaceDataOrganization
- Returns:
- true if data stored big-endian byte order
-
getPointerSize
public int getPointerSize()- Specified by:
getPointerSize
in interfaceDataOrganization
- Returns:
- the size of a pointer data type in bytes.
-
getPointerShift
public int getPointerShift()Description copied from interface:DataOrganization
Shift amount affects interpretation of in-memory pointer values only and will also be reflected within instruction pcode. A value of zero indicates that shifted-pointers are not supported.- Specified by:
getPointerShift
in interfaceDataOrganization
- Returns:
- the left shift amount for shifted-pointers.
-
isSignedChar
public boolean isSignedChar()- Specified by:
isSignedChar
in interfaceDataOrganization
- Returns:
- true if the "char" type is signed
-
getCharSize
public int getCharSize()- Specified by:
getCharSize
in interfaceDataOrganization
- Returns:
- the size of a char (char) primitive data type in bytes.
-
getWideCharSize
public int getWideCharSize()- Specified by:
getWideCharSize
in interfaceDataOrganization
- Returns:
- the size of a wide-char (wchar_t) primitive data type in bytes.
-
getShortSize
public int getShortSize()- Specified by:
getShortSize
in interfaceDataOrganization
- Returns:
- the size of a short primitive data type in bytes.
-
getIntegerSize
public int getIntegerSize()- Specified by:
getIntegerSize
in interfaceDataOrganization
- Returns:
- the size of a int primitive data type in bytes.
-
getLongSize
public int getLongSize()- Specified by:
getLongSize
in interfaceDataOrganization
- Returns:
- the size of a long primitive data type in bytes.
-
getLongLongSize
public int getLongLongSize()- Specified by:
getLongLongSize
in interfaceDataOrganization
- Returns:
- the size of a long long primitive data type in bytes.
-
getFloatSize
public int getFloatSize()- Specified by:
getFloatSize
in interfaceDataOrganization
- Returns:
- the encoding size of a float primitive data type in bytes.
-
getDoubleSize
public int getDoubleSize()- Specified by:
getDoubleSize
in interfaceDataOrganization
- Returns:
- the encoding size of a double primitive data type in bytes.
-
getLongDoubleSize
public int getLongDoubleSize()- Specified by:
getLongDoubleSize
in interfaceDataOrganization
- Returns:
- the encoding size of a long double primitive data type in bytes.
-
getBitFieldPacking
Description copied from interface:DataOrganization
Get the composite bitfield packing information associated with this data organization.- Specified by:
getBitFieldPacking
in interfaceDataOrganization
- Returns:
- composite bitfield packing information
-
setBigEndian
public void setBigEndian(boolean bigEndian) Set data endianness- Parameters:
bigEndian
- true if big-endian, false if little-endian
-
setPointerSize
public void setPointerSize(int pointerSize) Defines the size of a pointer data type.- Parameters:
pointerSize
- the size of a pointer.
-
setPointerShift
public void setPointerShift(int pointerShift) Defines the left shift amount for a shifted pointer data type. Shift amount affects interpretation of in-memory pointer values only and will also be reflected within instruction pcode.- Parameters:
pointerShift
- left shift amount for in-memory pointer values
-
setCharIsSigned
public void setCharIsSigned(boolean signed) Defines the signed-ness of the "char" data type- Parameters:
signed
- true if "char" type is signed
-
setCharSize
public void setCharSize(int charSize) Defines the size of a char (char) data type.- Parameters:
charSize
- the size of a char (char).
-
setWideCharSize
public void setWideCharSize(int wideCharSize) Defines the size of a wide-char (wchar_t) data type.- Parameters:
wideCharSize
- the size of a wide-char (wchar_t).
-
setShortSize
public void setShortSize(int shortSize) Defines the size of a short primitive data type.- Parameters:
shortSize
- the size of a short.
-
setIntegerSize
public void setIntegerSize(int integerSize) Defines the size of an int primitive data type.- Parameters:
integerSize
- the size of an int.
-
setLongSize
public void setLongSize(int longSize) Defines the size of a long primitive data type.- Parameters:
longSize
- the size of a long.
-
setLongLongSize
public void setLongLongSize(int longLongSize) Defines the size of a long long primitive data type.- Parameters:
longLongSize
- the size of a long long.
-
setFloatSize
public void setFloatSize(int floatSize) Defines the encoding size of a float primitive data type.- Parameters:
floatSize
- the size of a float.
-
setDoubleSize
public void setDoubleSize(int doubleSize) Defines the encoding size of a double primitive data type.- Parameters:
doubleSize
- the size of a double.
-
setLongDoubleSize
public void setLongDoubleSize(int longDoubleSize) Defines the encoding size of a long double primitive data type.- Parameters:
longDoubleSize
- the size of a long double.
-
getAbsoluteMaxAlignment
public int getAbsoluteMaxAlignment()Gets the maximum alignment value that is allowed by this data organization. When getting an alignment for any data type it will not exceed this value. If NO_MAXIMUM_ALIGNMENT is returned, the data organization isn't specifically limited.- Specified by:
getAbsoluteMaxAlignment
in interfaceDataOrganization
- Returns:
- the absolute maximum alignment or NO_MAXIMUM_ALIGNMENT
-
getMachineAlignment
public int getMachineAlignment()Gets the maximum useful alignment for the target machine- Specified by:
getMachineAlignment
in interfaceDataOrganization
- Returns:
- the machine alignment
-
getDefaultAlignment
public int getDefaultAlignment()Gets the default alignment to be used for any data type that isn't a structure, union, array, pointer, type definition, and whose size isn't in the size/alignment map.- Specified by:
getDefaultAlignment
in interfaceDataOrganization
- Returns:
- the default alignment to be used if no other alignment can be determined for a data type.
-
getDefaultPointerAlignment
public int getDefaultPointerAlignment()Gets the default alignment to be used for a pointer that doesn't have size.- Specified by:
getDefaultPointerAlignment
in interfaceDataOrganization
- Returns:
- the default alignment for a pointer
-
setAbsoluteMaxAlignment
public void setAbsoluteMaxAlignment(int absoluteMaxAlignment) Sets the maximum alignment value that is allowed by this data organization. When getting an alignment for any data type it will not exceed this value. If NO_MAXIMUM_ALIGNMENT is returned, the data organization isn't specifically limited.- Parameters:
absoluteMaxAlignment
- the absolute maximum alignment or NO_MAXIMUM_ALIGNMENT
-
setMachineAlignment
public void setMachineAlignment(int machineAlignment) Sets the maximum useful alignment for the target machine- Parameters:
machineAlignment
- the machine alignment
-
setDefaultAlignment
public void setDefaultAlignment(int defaultAlignment) Sets the default alignment to be used for any data type that isn't a structure, union, array, pointer, type definition, and whose size isn't in the size/alignment map.- Parameters:
defaultAlignment
- the default alignment to be used if no other alignment can be determined for a data type.
-
setDefaultPointerAlignment
public void setDefaultPointerAlignment(int defaultPointerAlignment) Sets the default alignment to be used for a pointer that doesn't have size.- Parameters:
defaultPointerAlignment
- the default alignment for a pointer
-
getSizeAlignment
public int getSizeAlignment(int size) Description copied from interface:DataOrganization
Gets the primitive data alignment that is defined for the specified size. If no entry has been defined for the specified size alignment of the next smaller map entry will be returned. If the map is empty thedefault alignment
. The returned value will not exceed thedefined maximum alignment
.- Specified by:
getSizeAlignment
in interfaceDataOrganization
- Parameters:
size
- the primitive data size- Returns:
- the alignment of the data type.
-
setSizeAlignment
public void setSizeAlignment(int size, int alignment) Sets the alignment that is defined for a data type of the indicated size if one is defined.- Parameters:
size
- the size of the data typealignment
- the alignment of the data type.
-
setBitFieldPacking
Set the bitfield packing information associated with this data organization.- Parameters:
bitFieldPacking
- bitfield packing information
-
clearSizeAlignmentMap
public void clearSizeAlignmentMap()Remove all entries from the size alignment map -
getSizeAlignmentCount
public int getSizeAlignmentCount()Gets the number of sizes that have an alignment specified.- Specified by:
getSizeAlignmentCount
in interfaceDataOrganization
- Returns:
- the number of sizes with an alignment mapped to them.
-
getSizes
public int[] getSizes()Gets the sizes that have an alignment specified.- Specified by:
getSizes
in interfaceDataOrganization
- Returns:
- the sizes with alignments mapped to them.
-
getIntegerCTypeApproximation
Returns the best fitting integer C-type whose size is less-than-or-equal to the specified size. "long long" will be returned for any size larger than "long long";- Specified by:
getIntegerCTypeApproximation
in interfaceDataOrganization
- Parameters:
size
- integer sizesigned
- if false the unsigned modifier will be prepended.- Returns:
- the best fitting
-
getAlignment
Description copied from interface:DataOrganization
Determines the alignment value for the indicated data type. (i.e. how the data type gets aligned within other data types.) NOTE: this method should not be used for bitfields which are highly dependent upon packing for a composite. This method will always return 1 for Dynamic and FactoryDataTypes.- Specified by:
getAlignment
in interfaceDataOrganization
- Parameters:
dataType
- the data type- Returns:
- the datatype alignment
-
getAlignedOffset
public static int getAlignedOffset(int alignment, int minimumOffset) Determines the first offset that is equal to or greater than the minimum offset which has the specified alignment. If a non-positive alignment is specified the origina minimumOffset will be return.- Parameters:
alignment
- the desired alignment (positive value)minimumOffset
- the minimum offset- Returns:
- the aligned offset
-
getLeastCommonMultiple
public static int getLeastCommonMultiple(int value1, int value2) Determines the least (lowest) common multiple of two numbers.- Parameters:
value1
- the first numbervalue2
- the second number- Returns:
- the least common multiple
-
getGreatestCommonDenominator
public static int getGreatestCommonDenominator(int value1, int value2) Determines the greatest common denominator of two numbers.- Parameters:
value1
- the first numbervalue2
- the second number- Returns:
- the greatest common denominator
-
save
public static void save(DataOrganization dataOrg, DBStringMapAdapter dataMap, String keyPrefix) throws IOException Save the specified data organization to the specified DB data map. All existing map entries starting with keyPrefix will be removed prior to ading the new map entries.- Parameters:
dataOrg
- data organizationdataMap
- DB data mapkeyPrefix
- key prefix for all map entries- Throws:
IOException
- if an IO error occurs
-
restore
public static DataOrganizationImpl restore(DBStringMapAdapter dataMap, String keyPrefix) throws IOException Restore a data organization from the specified DB data map.- Parameters:
dataMap
- DB data mapkeyPrefix
- key prefix for all map entries- Returns:
- stored data organization or null if not stored
- Throws:
IOException
- if an IO error occurs
-
encode
Output the details of this data organization to a encoded document formatter.- Parameters:
encoder
- the output document encoder.- Throws:
IOException
- if an IO error occurs while encoding/writing output
-
restoreXml
Restore settings from an XML stream. This expects to see parser positioned on the <data_organization> start tag. The XML is designed to override existing language-specific default settings which are pre-populated withgetDefaultOrganization(Language)
. This will will ensure that the endianness setting is properly established since it is not included in the XML.- Parameters:
parser
- is the XML stream
-
hashCode
public int hashCode() -
equals
-