Package ghidra.program.model.data
Class DataOrganizationImpl
- java.lang.Object
-
- ghidra.program.model.data.DataOrganizationImpl
-
- All Implemented Interfaces:
DataOrganization
public class DataOrganizationImpl extends java.lang.Object implements DataOrganization
DataOrganization provides a single place for determining size and alignment information for data types within an archive or a program.
-
-
Field Summary
-
Fields inherited from interface ghidra.program.model.data.DataOrganization
NO_MAXIMUM_ALIGNMENT
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearSizeAlignmentMap()Remove all entries from the size alignment mapintgetAbsoluteMaxAlignment()Gets the maximum alignment value that is allowed by this data organization.intgetAlignment(DataType dataType, int dtSize)Determines the alignment value for the indicated data type.intgetAlignmentOffset(int minimumOffset, DataType dataType, int dtSize)Determines the offset where the specified data type should be placed to be properly aligned.BitFieldPackinggetBitFieldPacking()Get the composite bitfield packing information associated with this data organization.intgetCharSize()intgetDefaultAlignment()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 DataOrganizationgetDefaultOrganization()Creates a new default DataOrganization.static DataOrganizationImplgetDefaultOrganization(Language language)Creates a new default DataOrganization.intgetDefaultPointerAlignment()Gets the default alignment to be used for a pointer that doesn't have size.intgetDoubleSize()intgetFloatSize()intgetForcedAlignment(DataType dataType)static intgetGreatestCommonDenominator(int value1, int value2)Determines the greatest common denominator of two numbers.java.lang.StringgetIntegerCTypeApproximation(int size, boolean signed)Returns the best fitting integer C-type whose size is less-than-or-equal to the specified size.intgetIntegerSize()static intgetLeastCommonMultiple(int value1, int value2)Determines the least (lowest) common multiple of two numbers.intgetLongDoubleSize()intgetLongLongSize()intgetLongSize()intgetMachineAlignment()Gets the maximum useful alignment for the target machinestatic intgetOffset(int alignment, int minimumOffset)Determines the first offset that is equal to or greater than the minimum offset which has the specified alignment.static intgetPaddingSize(int alignment, int offset)Determines the amount of padding that should be added to a structure at the indicated offset in order to get the next component (member) to be aligned with the specified alignment within the structure.intgetPointerShift()Shift amount affects interpretation of in-memory pointer values only and will also be reflected within instruction pcode.intgetPointerSize()intgetShortSize()intgetSizeAlignment(int size)Gets the alignment that is defined for a data type of the indicated size if one is defined.intgetSizeAlignmentCount()Gets the number of sizes that have an alignment specified.int[]getSizes()Gets the sizes that have an alignment specified.intgetWideCharSize()booleanisBigEndian()booleanisForcingAlignment(DataType dataType)booleanisSignedChar()voidsetAbsoluteMaxAlignment(int absoluteMaxAlignment)Sets the maximum alignment value that is allowed by this data organization.voidsetBigEndian(boolean bigEndian)Set data endianessvoidsetBitFieldPacking(BitFieldPacking bitFieldPacking)Set the bitfield packing information associated with this data organization.voidsetCharIsSigned(boolean signed)Defines the signed-ness of the "char" data typevoidsetCharSize(int charSize)Defines the size of a char (char) data type.voidsetDefaultAlignment(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.voidsetDefaultPointerAlignment(int defaultPointerAlignment)Sets the default alignment to be used for a pointer that doesn't have size.voidsetDoubleSize(int doubleSize)Defines the size of a double primitive data type.voidsetFloatSize(int floatSize)Defines the size of a float primitive data type.voidsetIntegerSize(int integerSize)Defines the size of an int primitive data type.voidsetLongDoubleSize(int longDoubleSize)Defines the size of a long double primitive data type.voidsetLongLongSize(int longLongSize)Defines the size of a long long primitive data type.voidsetLongSize(int longSize)Defines the size of a long primitive data type.voidsetMachineAlignment(int machineAlignment)Sets the maximum useful alignment for the target machinevoidsetPointerShift(int pointerShift)Defines the left shift amount for a shifted pointer data type.voidsetPointerSize(int pointerSize)Defines the size of a pointer data type.voidsetShortSize(int shortSize)Defines the size of a short primitive data type.voidsetSizeAlignment(int size, int alignment)Sets the alignment that is defined for a data type of the indicated size if one is defined.voidsetWideCharSize(int wideCharSize)Defines the size of a wide-char (wchar_t) data type.
-
-
-
Method Detail
-
getDefaultOrganization
public static 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.- Returns:
- a new default DataOrganization.
-
getDefaultOrganization
public static DataOrganizationImpl getDefaultOrganization(Language language)
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, endianess, etc.) (may be null)- Returns:
- a new default DataOrganization.
-
isBigEndian
public boolean isBigEndian()
- Specified by:
isBigEndianin interfaceDataOrganization- Returns:
- true if data stored big-endian byte order
-
getPointerSize
public int getPointerSize()
- Specified by:
getPointerSizein interfaceDataOrganization- Returns:
- the size of a pointer data type in bytes.
-
getPointerShift
public int getPointerShift()
Description copied from interface:DataOrganizationShift 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:
getPointerShiftin interfaceDataOrganization- Returns:
- the left shift amount for shifted-pointers.
-
isSignedChar
public boolean isSignedChar()
- Specified by:
isSignedCharin interfaceDataOrganization- Returns:
- true if the "char" type is signed
-
getCharSize
public int getCharSize()
- Specified by:
getCharSizein interfaceDataOrganization- Returns:
- the size of a char (char) primitive data type in bytes.
-
getWideCharSize
public int getWideCharSize()
- Specified by:
getWideCharSizein interfaceDataOrganization- Returns:
- the size of a wide-char (wchar_t) primitive data type in bytes.
-
getShortSize
public int getShortSize()
- Specified by:
getShortSizein interfaceDataOrganization- Returns:
- the size of a short primitive data type in bytes.
-
getIntegerSize
public int getIntegerSize()
- Specified by:
getIntegerSizein interfaceDataOrganization- Returns:
- the size of a int primitive data type in bytes.
-
getLongSize
public int getLongSize()
- Specified by:
getLongSizein interfaceDataOrganization- Returns:
- the size of a long primitive data type in bytes.
-
getLongLongSize
public int getLongLongSize()
- Specified by:
getLongLongSizein interfaceDataOrganization- Returns:
- the size of a long long primitive data type in bytes.
-
getFloatSize
public int getFloatSize()
- Specified by:
getFloatSizein interfaceDataOrganization- Returns:
- the size of a float primitive data type in bytes.
-
getDoubleSize
public int getDoubleSize()
- Specified by:
getDoubleSizein interfaceDataOrganization- Returns:
- the size of a double primitive data type in bytes.
-
getLongDoubleSize
public int getLongDoubleSize()
- Specified by:
getLongDoubleSizein interfaceDataOrganization- Returns:
- the size of a long double primitive data type in bytes.
-
getBitFieldPacking
public BitFieldPacking getBitFieldPacking()
Description copied from interface:DataOrganizationGet the composite bitfield packing information associated with this data organization.- Specified by:
getBitFieldPackingin interfaceDataOrganization- Returns:
- composite bitfield packing information
-
setBigEndian
public void setBigEndian(boolean bigEndian)
Set data endianess- Parameters:
bigEndian-
-
setPointerSize
public void setPointerSize(int pointerSize)
Defines the size of a pointer data type.- Parameters:
shortSize- the size of a short.
-
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:
wideCharSize- 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 size of a float primitive data type.- Parameters:
floatSize- the size of a float.
-
setDoubleSize
public void setDoubleSize(int doubleSize)
Defines the size of a double primitive data type.- Parameters:
doubleSize- the size of a double.
-
setLongDoubleSize
public void setLongDoubleSize(int longDoubleSize)
Defines the 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:
getAbsoluteMaxAlignmentin 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:
getMachineAlignmentin 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:
getDefaultAlignmentin 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:
getDefaultPointerAlignmentin 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) throws NoValueExceptionGets the alignment that is defined for a data type of the indicated size if one is defined.- Specified by:
getSizeAlignmentin interfaceDataOrganization- Parameters:
size- the size of the data type- Returns:
- the alignment of the data type.
- Throws:
NoValueException- if there isn't an alignment defined for the indicated size.
-
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
public void setBitFieldPacking(BitFieldPacking bitFieldPacking)
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- Specified by:
clearSizeAlignmentMapin interfaceDataOrganization
-
getSizeAlignmentCount
public int getSizeAlignmentCount()
Gets the number of sizes that have an alignment specified.- Specified by:
getSizeAlignmentCountin 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:
getSizesin interfaceDataOrganization- Returns:
- the sizes with alignments mapped to them.
-
getIntegerCTypeApproximation
public java.lang.String getIntegerCTypeApproximation(int size, boolean signed)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:
getIntegerCTypeApproximationin interfaceDataOrganization- Parameters:
size- integer sizesigned- if false the unsigned modifier will be prepended.- Returns:
- the best fitting
-
getAlignment
public int getAlignment(DataType dataType, int dtSize)
Description copied from interface:DataOrganizationDetermines the alignment value for the indicated data type. (i.e. how the data type gets aligned within other data types.) NOTE: the alignment of bitfields is dependent upon packing rules which must be considered at the composite level.- Specified by:
getAlignmentin interfaceDataOrganization- Parameters:
dataType- the data typedtSize- the data type's size or component size- Returns:
- the alignment
-
isForcingAlignment
public boolean isForcingAlignment(DataType dataType)
- Specified by:
isForcingAlignmentin interfaceDataOrganization
-
getForcedAlignment
public int getForcedAlignment(DataType dataType)
- Specified by:
getForcedAlignmentin interfaceDataOrganization
-
getAlignmentOffset
public int getAlignmentOffset(int minimumOffset, DataType dataType, int dtSize)Determines the offset where the specified data type should be placed to be properly aligned.- Specified by:
getAlignmentOffsetin interfaceDataOrganization- Parameters:
minimumOffset- the minimum allowable offset where the data type can be placed.dataType- the data typedtSize- the data type's size- Returns:
- the aligned offset for the data type
-
getOffset
public static int getOffset(int alignment, int minimumOffset)Determines the first offset that is equal to or greater than the minimum offset which has the specified alignment.- Parameters:
alignment- the desired alignmentminimumOffset- the minimum offset- Returns:
- the aligned offset
-
getPaddingSize
public static int getPaddingSize(int alignment, int offset)Determines the amount of padding that should be added to a structure at the indicated offset in order to get the next component (member) to be aligned with the specified alignment within the structure.- Parameters:
alignment- the desired alignmentoffset- the offset that the padding would be placed at to achieve the desired alignment.- Returns:
- the padding needed at the 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
-
-