Package ghidra.program.database.function
Class VariableDB
- java.lang.Object
- 
- ghidra.program.database.function.VariableDB
 
- 
- Direct Known Subclasses:
- LocalVariableDB,- ReturnParameterDB
 
 public abstract class VariableDB extends java.lang.Object implements Variable Database implementation of a Variable.
- 
- 
Field SummaryFields Modifier and Type Field Description protected FunctionDBfunctionprotected FunctionManagerDBfunctionMgrprotected VariableStoragestorageprotected VariableSymbolDBsymbol
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(Variable otherVar)booleanequals(java.lang.Object obj)java.lang.StringgetComment()Get the Comment for this variableDataTypegetDataType()Get the Data Type of this variableVarnodegetFirstStorageVarnode()Get the first storage varnode for this variableFunctiongetFunction()Returns the function that contains this Variable.VarnodegetLastStorageVarnode()Get the last storage varnode for this variableintgetLength()Get the length of this variableAddressgetMinAddress()java.lang.StringgetName()Get the Name of this variable or null if not assigned or not-applicableProgramgetProgram()Returns the program that contains this variable or is the intended targetRegistergetRegister()java.util.List<Register>getRegisters()SourceTypegetSource()Get the source of this variableintgetStackOffset()SymbolgetSymbol()VariableStoragegetVariableStorage()Get the variable storage associated with this variable.booleanhasAssignedStorage()inthashCode()booleanhasStackStorage()booleanisCompoundVariable()booleanisEquivalent(Variable otherVar)booleanisMemoryVariable()booleanisRegisterVariable()booleanisStackVariable()booleanisUniqueVariable()booleanisValid()Verify that the variable is valid (i.e., storage is valid and size matches variable data type size)voidsetComment(java.lang.String comment)Set the comment for this variablevoidsetDataType(DataType type, boolean alignStack, boolean force, SourceType source)Set the Data Type of this variable.voidsetDataType(DataType type, VariableStorage newStorage, boolean force, SourceType source)Set the Data Type of this variable and the associated storage whose size matches the data type length.voidsetDataType(DataType type, SourceType source)Set the Data Type of this variable using the default alignment behavior (implementation specific).voidsetName(java.lang.String name, SourceType source)Set the name of this variable.java.lang.StringtoString()- 
Methods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, wait
 - 
Methods inherited from interface ghidra.program.model.listing.VariablegetFirstUseOffset
 
- 
 
- 
- 
- 
Field Detail- 
symbolprotected VariableSymbolDB symbol 
 - 
storageprotected VariableStorage storage 
 - 
functionprotected FunctionDB function 
 - 
functionMgrprotected FunctionManagerDB functionMgr 
 
- 
 - 
Method Detail- 
isValidpublic boolean isValid() Description copied from interface:VariableVerify that the variable is valid (i.e., storage is valid and size matches variable data type size)
 - 
getProgrampublic Program getProgram() Description copied from interface:VariableReturns the program that contains this variable or is the intended target- Specified by:
- getProgramin interface- Variable
- Returns:
- the program.
 
 - 
getDataTypepublic DataType getDataType() Description copied from interface:VariableGet the Data Type of this variable- Specified by:
- getDataTypein interface- Variable
- Returns:
- the data type of the variable
 
 - 
setDataTypepublic void setDataType(DataType type, VariableStorage newStorage, boolean force, SourceType source) throws InvalidInputException, VariableSizeException Description copied from interface:VariableSet the Data Type of this variable and the associated storage whose size matches the data type length.NOTE: The storage and source are ignored if the function does not have custom storage enabled. - Specified by:
- setDataTypein interface- Variable
- Parameters:
- type- the data type
- newStorage- properly sized storage for the new data type
- force- overwrite conflicting variables
- source- variable storage source (used only for function parameters and return)
- Throws:
- InvalidInputException- if data type is not a fixed length or violates storage constraints.
- VariableSizeException- if force is false and data type size causes a conflict with other variables
 
 - 
setDataTypepublic void setDataType(DataType type, boolean alignStack, boolean force, SourceType source) throws InvalidInputException Description copied from interface:VariableSet the Data Type of this variable. The given dataType must have a fixed length.- Specified by:
- setDataTypein interface- Variable
- Parameters:
- type- the data type
- force- overwrite conflicting variables
- source- signature source
- Throws:
- InvalidInputException- if data type is not a fixed length or violates storage constraints.
- VariableSizeException- if force is false and data type size causes a conflict with other variables
 
 - 
setDataTypepublic void setDataType(DataType type, SourceType source) throws InvalidInputException Description copied from interface:VariableSet the Data Type of this variable using the default alignment behavior (implementation specific). The given dataType must have a fixed length. If contained within a stack-frame, data-type size will be constrained by existing variables (e.g., equivalent to force=false) Note: stack offset will be maintained for stack variables.- Specified by:
- setDataTypein interface- Variable
- Parameters:
- type- the data type
- source- signature source
- Throws:
- InvalidInputException- if data type is not a fixed length or violates storage constraints.
- VariableSizeException- if data type size causes a conflict with other variables
- See Also:
- #setDataType(DataType, boolean)
 
 - 
getNamepublic java.lang.String getName() Description copied from interface:VariableGet the Name of this variable or null if not assigned or not-applicable
 - 
getLengthpublic int getLength() Description copied from interface:VariableGet the length of this variable
 - 
setNamepublic void setName(java.lang.String name, SourceType source) throws DuplicateNameException, InvalidInputExceptionDescription copied from interface:VariableSet the name of this variable.- Specified by:
- setNamein interface- Variable
- Parameters:
- name- the name
- source- the source of this variable name
- Throws:
- DuplicateNameException- if the name collides with the name of another variable.
- InvalidInputException- if name contains blank characters, is zero length, or is null
 
 - 
getCommentpublic java.lang.String getComment() Description copied from interface:VariableGet the Comment for this variable- Specified by:
- getCommentin interface- Variable
- Returns:
- the comment
 
 - 
setCommentpublic void setComment(java.lang.String comment) Description copied from interface:VariableSet the comment for this variable- Specified by:
- setCommentin interface- Variable
- Parameters:
- comment- the comment
 
 - 
getFunctionpublic Function getFunction() Description copied from interface:VariableReturns the function that contains this Variable. May be null if the variable is not in a function.- Specified by:
- getFunctionin interface- Variable
 
 - 
getSymbolpublic Symbol getSymbol() 
 - 
toStringpublic java.lang.String toString() - Overrides:
- toStringin class- java.lang.Object
 
 - 
getSourcepublic SourceType getSource() Description copied from interface:VariableGet the source of this variable
 - 
hasAssignedStoragepublic boolean hasAssignedStorage() - Specified by:
- hasAssignedStoragein interface- Variable
- Returns:
- true if this variable has been assigned storage.  This is equivalent to 
 Variable.getVariableStorage()!= null
 
 - 
getVariableStoragepublic VariableStorage getVariableStorage() Description copied from interface:VariableGet the variable storage associated with this variable.- Specified by:
- getVariableStoragein interface- Variable
- Returns:
- the variable storage for this variable
 
 - 
getFirstStorageVarnodepublic Varnode getFirstStorageVarnode() Description copied from interface:VariableGet the first storage varnode for this variable- Specified by:
- getFirstStorageVarnodein interface- Variable
- Returns:
- the first storage varnode associated with this variable
- See Also:
- #getStorageElements()
 
 - 
getLastStorageVarnodepublic Varnode getLastStorageVarnode() Description copied from interface:VariableGet the last storage varnode for this variable- Specified by:
- getLastStorageVarnodein interface- Variable
- Returns:
- the last storage varnode associated with this variable
- See Also:
- #getStorageElements()
 
 - 
isStackVariablepublic boolean isStackVariable() - Specified by:
- isStackVariablein interface- Variable
- Returns:
- true if this is a simple variable consisting of a single stack varnode
 which will be returned by either the Variable.getFirstStorageVarnode()orVariable.getLastStorageVarnode()methods. The stack offset can be obtained using:getFirstStorageVarnode().getOffset()
 
 - 
hasStackStoragepublic boolean hasStackStorage() - Specified by:
- hasStackStoragein interface- Variable
- Returns:
- true if this variable uses simple or compound storage which contains a stack element. If true, the last storage varnode will always be the stack element.
- See Also:
- Variable.getLastStorageVarnode()
 
 - 
isRegisterVariablepublic boolean isRegisterVariable() - Specified by:
- isRegisterVariablein interface- Variable
- Returns:
- true if this is a simple variable consisting of a single register varnode
 which will be returned by either the Variable.getFirstStorageVarnode()orVariable.getLastStorageVarnode()methods. The register can be obtained using theVariable.getRegister()method.
 
 - 
getRegisterpublic Register getRegister() - Specified by:
- getRegisterin interface- Variable
- Returns:
- first storage register associated with this variable, else null is returned. A variable with compound storage may have more than one register or other storage in addition to the register returned by this method.
- See Also:
- Variable.isRegisterVariable()
 
 - 
getRegisterspublic java.util.List<Register> getRegisters() - Specified by:
- getRegistersin interface- Variable
- Returns:
- all storage register(s) associated with this variable, else null is returned if no registers are used. A variable with compound storage may have more than one register or other storage in addition to the register(s) returned by this method.
- See Also:
- Variable.isRegisterVariable(),- Variable.isCompoundVariable()
 
 - 
getMinAddresspublic Address getMinAddress() - Specified by:
- getMinAddressin interface- Variable
- Returns:
- the minimum address corresponding to the first varnode of this storage
 or null if this is a special empty storage: #BAD_STORAGE,#UNASSIGNED_STORAGE,#VOID_STORAGE
 
 - 
getStackOffsetpublic int getStackOffset() - Specified by:
- getStackOffsetin interface- Variable
- Returns:
- the stack offset associated with simple stack variable (i.e., Variable.isStackVariable()returns true).
 
 - 
isMemoryVariablepublic boolean isMemoryVariable() - Specified by:
- isMemoryVariablein interface- Variable
- Returns:
- true if this is a simple variable consisting of a single storage memory element
 which will be returned by either the Variable.getFirstStorageVarnode()orgetStorageElements()methods.
 
 - 
isUniqueVariablepublic boolean isUniqueVariable() - Specified by:
- isUniqueVariablein interface- Variable
- Returns:
- true if this is a simple variable consisting of a single storage unique/hash element
 which will be returned by either the Variable.getFirstStorageVarnode()orgetStorageElements()methods. The unique hash can be obtained from the storage address offset corresponding to the single storage element.
 
 - 
isCompoundVariablepublic boolean isCompoundVariable() - Specified by:
- isCompoundVariablein interface- Variable
- Returns:
- true if this variable uses compound storage consisting of two or more storage elements
 which will be returned by the getStorageElements()method. Compound variables will always use a register(s) optionally followed by other storage (i.e., stack).
 
 - 
hashCodepublic int hashCode() - Overrides:
- hashCodein class- java.lang.Object
 
 - 
equalspublic boolean equals(java.lang.Object obj) - Overrides:
- equalsin class- java.lang.Object
 
 - 
compareTopublic int compareTo(Variable otherVar) - Specified by:
- compareToin interface- java.lang.Comparable<Variable>
 
 - 
isEquivalentpublic boolean isEquivalent(Variable otherVar) - Specified by:
- isEquivalentin interface- Variable
- Returns:
- true if the specified variable is equivalent to this variable
 
 
- 
 
-