Class DWARFDataTypeManager
- java.lang.Object
-
- ghidra.app.util.bin.format.dwarf4.next.DWARFDataTypeManager
-
public class DWARFDataTypeManager extends java.lang.ObjectManages mappings between DWARF DIEs and Ghidra DataTypes.
-
-
Constructor Summary
Constructors Constructor Description DWARFDataTypeManager(DWARFProgram prog, DataTypeManager dataTypeManager, DataTypeManager builtInDTM, DWARFImportSummary importSummary)Creates a newDWARFDataTypeManagerinstance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddDataType(long offset, DataType dataType, DWARFSourceInfo dsi)DataTypedoGetDataType(DIEAggregate diea)java.lang.Iterable<DataType>forAllConflicts(DataTypePath dtp)Iterate allDataTypes that match the CategoryPath / name given in theDataTypePathparameter, including "conflict" datatypes that have a ".CONFLICTxx" suffix.DataTypegetBaseType(java.lang.String name)Returns a DWARF base data type based on its name, or null if it does not exist.DataTypegetBaseType(java.lang.String name, int dwarfSize, int dwarfEncoding, boolean isBigEndian)Returns a Ghidradatatypethat corresponds to the DWARF named type.DataTypegetDataType(long dieOffset, DataType defaultValue)Returns a GhidraDataTypecorresponding to the specified DIE (based on its offset), or the specified defaultValue if the DIE does not map to a defined datatype (registered with#addType(long, DataType, DWARFImportSummary)).DataTypegetDataType(DIEAggregate diea, DataType defaultValue)Returns a GhidraDataTypecorresponding to the specifiedDIEAggregate, or the specified defaultValue if the DIEA param is null or does not map to an already defined datatype (registered with#addType(long, DataType, DWARFImportSummary)).FunctionDefinitiongetFunctionSignature(DIEAggregate diea)Construct a temporary 'impl'FunctionDefinitionDataType using the information found in the specifiedDIEAggregate.java.util.List<DataTypePath>getImportedTypes()DataTypegetOffsetType(int size)Returns a Ghidradatatypethat corresponds to a type that can be used to represent an offset.DataTypegetPtrTo(DataType dt)Returns a pointer to the specified data type.DWARFSourceInfogetSourceInfo(DataType dataType)<T extends DataType>
TgetSpecificDataType(DIEAggregate diea, java.lang.Class<T> dataTypeClazz)DataTypegetStorageDataType(DIEAggregate diea, DataType defaultValue)DataTypegetUndefined1Type()Returns datatype to hold a 1 byte undefined value.DataTypegetVoidType()Returns the void type.voidimportAllDataTypes(TaskMonitor monitor)Does the actual import work.booleanisCharType(DataType dataType)Returns true if the data type is one of the standard character types.voidsetAsStringType(long dieOffset)Marks the DWARF DIE at the specified offset as a string.
-
-
-
Constructor Detail
-
DWARFDataTypeManager
public DWARFDataTypeManager(DWARFProgram prog, DataTypeManager dataTypeManager, DataTypeManager builtInDTM, DWARFImportSummary importSummary)
Creates a newDWARFDataTypeManagerinstance.- Parameters:
prog-DWARFProgramthat holds the GhidraProgrambeing imported.dataTypeManager-DataTypeManagerof the Ghidra Program.builtInDTM-DataTypeManagerwith built-in data types.importSummary-DWARFImportSummarywhere summary information will be stored during the import session.
-
-
Method Detail
-
doGetDataType
public DataType doGetDataType(DIEAggregate diea) throws java.io.IOException, DWARFExpressionException
Creates aDataTypefrom the DWARFDIEA, or returns a pre-existingDataTypecreated by the specified DIEA previously.Creating a new DataType happens in two stages, where the DataType is created as an 'impl' DataType first (possibly representing a large graph of referred-to datatypes), and then it is submitted to the
DataTypeManagerto be added to the database and converted to a 'db' object.Mapping from the DIEA's offset to the resultant 'db' DataType object is a two step process.
A
DataTypeGraphComparatoris used to walk the 'impl' DataType object graph in lock-step with the resultant 'db' DataType object graph, and the mapping between the 'impl' object and its creator DIEA (held in#currentImplDataTypeToDIE) is used to create a mapping to the resultant 'db' DataType's path.- Parameters:
diea- DWARFDIEAggregatewith datatype information that needs to be converted to a Ghidra DataType.- Returns:
DataTypethat is ready to use.- Throws:
java.io.IOException- if problemDWARFExpressionException- if problem
-
addDataType
public void addDataType(long offset, DataType dataType, DWARFSourceInfo dsi)
-
getImportedTypes
public java.util.List<DataTypePath> getImportedTypes()
-
getSourceInfo
public DWARFSourceInfo getSourceInfo(DataType dataType)
-
setAsStringType
public void setAsStringType(long dieOffset)
Marks the DWARF DIE at the specified offset as a string.- Parameters:
dieOffset- the DWARF DIE offset.
-
getDataType
public DataType getDataType(DIEAggregate diea, DataType defaultValue)
Returns a GhidraDataTypecorresponding to the specifiedDIEAggregate, or the specified defaultValue if the DIEA param is null or does not map to an already defined datatype (registered with#addType(long, DataType, DWARFImportSummary)).- Parameters:
diea-DIEAggregatethat defines a data typedefaultValue- GhidraDataTypeto return if the specified DIEA is null or not already defined.- Returns:
- Ghidra
DataType - Throws:
DWARFExpressionExceptionjava.io.IOException
-
getDataType
public DataType getDataType(long dieOffset, DataType defaultValue)
Returns a GhidraDataTypecorresponding to the specified DIE (based on its offset), or the specified defaultValue if the DIE does not map to a defined datatype (registered with#addType(long, DataType, DWARFImportSummary)).
-
getSpecificDataType
public <T extends DataType> T getSpecificDataType(DIEAggregate diea, java.lang.Class<T> dataTypeClazz)
-
getStorageDataType
public DataType getStorageDataType(DIEAggregate diea, DataType defaultValue)
Returns theDataTypethat the passed-inDIEAdefines, except when it was a char array of undefined length, then it returns a StringDataType that can be used to detect the size of the null-terminated string in memory.- Parameters:
diea-defaultValue-- Returns:
- Throws:
DWARFExpressionExceptionjava.io.IOException
-
forAllConflicts
public java.lang.Iterable<DataType> forAllConflicts(DataTypePath dtp)
Iterate allDataTypes that match the CategoryPath / name given in theDataTypePathparameter, including "conflict" datatypes that have a ".CONFLICTxx" suffix.- Parameters:
dtp-- Returns:
-
getOffsetType
public DataType getOffsetType(int size)
Returns a Ghidradatatypethat corresponds to a type that can be used to represent an offset.- Parameters:
size-- Returns:
-
isCharType
public boolean isCharType(DataType dataType)
Returns true if the data type is one of the standard character types.- Parameters:
dataType-DataTypeto check- Returns:
- true if the specified datatype is one of the many char data types.
-
getUndefined1Type
public DataType getUndefined1Type()
Returns datatype to hold a 1 byte undefined value.- Returns:
- undefined 1 byte
DataType.
-
getBaseType
public DataType getBaseType(java.lang.String name)
Returns a DWARF base data type based on its name, or null if it does not exist.- Parameters:
name- base type name- Returns:
DataTypeor null if base type does not exist
-
getBaseType
public DataType getBaseType(java.lang.String name, int dwarfSize, int dwarfEncoding, boolean isBigEndian)
Returns a Ghidradatatypethat corresponds to the DWARF named type.If there is no direct matching named Ghidra type, generic types of matching size will be returned for integer and floating numeric dwarf encoding types, boolean, and character types. Failing that, generic storage types of matching size (word, dword, etc) will be returned, and failing that, an array of the correct size will be returned.
If the returned data type is not a direct named match, the returned data type will be wrapped in a Ghdira typedef using the dwarf type's name.
Any newly created Ghidra data types will be cached and the same instance will be returned if the same DWARF named base type is requested again.
- Parameters:
name-dwarfSize-dwarfEncoding-isBigEndian-- Returns:
-
importAllDataTypes
public void importAllDataTypes(TaskMonitor monitor) throws java.io.IOException, DWARFException, CancelledException
Does the actual import work. Updates thesummaryobject with information about the types imported and errors encountered.- Parameters:
TaskMonitor- monitor to watch for cancel- Throws:
java.io.IOException- if errors are encountered reading dataDWARFException- if errors are encountered processingCancelledException- if theTaskMonitoris canceled by the user.
-
getFunctionSignature
public FunctionDefinition getFunctionSignature(DIEAggregate diea)
Construct a temporary 'impl'FunctionDefinitionDataType using the information found in the specifiedDIEAggregate.- Parameters:
diea-DIEAggregateof a subprogram, callsite, etc.- Returns:
FunctionDefinitionimpl (not saved to the DB) or null if not a valid DIEA.
-
-