Package ghidra.program.model.listing
Class ParameterImpl
- java.lang.Object
-
- ghidra.program.model.listing.ParameterImpl
-
- Direct Known Subclasses:
AutoParameterImpl,ReturnParameterImpl
public class ParameterImpl extends java.lang.Object implements Parameter
Generic implementation of Parameter.
-
-
Field Summary
Fields Modifier and Type Field Description protected intordinal-
Fields inherited from interface ghidra.program.model.listing.Parameter
RETURN_NAME, RETURN_ORIDINAL, UNASSIGNED_ORDINAL
-
-
Constructor Summary
Constructors Modifier Constructor Description ParameterImpl(Parameter param, Program program)Construct a parameter from another.protectedParameterImpl(java.lang.String name, int ordinal, DataType dataType, VariableStorage storage, boolean force, Program program, SourceType sourceType)Construct a parameter with one or more associated storage elements.ParameterImpl(java.lang.String name, DataType dataType, int stackOffset, Program program)Construct a stack parameter at the specified stack offset.ParameterImpl(java.lang.String name, DataType dataType, int stackOffset, Program program, SourceType sourceType)Construct a stack parameter at the specified stack offset.ParameterImpl(java.lang.String name, DataType dataType, Address storageAddr, Program program)Construct a parameter with a single storage element at the specified address.ParameterImpl(java.lang.String name, DataType dataType, Address storageAddr, Program program, SourceType sourceType)Construct a parameter with a single storage element at the specified address.ParameterImpl(java.lang.String name, DataType dataType, Register register, Program program)Construct a register parameter using the specified register.ParameterImpl(java.lang.String name, DataType dataType, Register register, Program program, SourceType sourceType)Construct a register parameter using the specified register.ParameterImpl(java.lang.String name, DataType dataType, Program program)Construct a parameter which has no specific storage specified.ParameterImpl(java.lang.String name, DataType dataType, Program program, SourceType sourceType)Construct a parameter which has no specific storage specified.ParameterImpl(java.lang.String name, DataType dataType, VariableStorage storage, Program program)Construct a parameter with one or more associated storage elements.ParameterImpl(java.lang.String name, DataType dataType, VariableStorage storage, Program program, SourceType sourceType)Construct a parameter with one or more associated storage elements.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(Variable otherVar)booleanequals(java.lang.Object obj)AutoParameterTypegetAutoParameterType()If this is an auto-parameter this method will indicate its type.java.lang.StringgetComment()Get the Comment for this variableDataTypegetDataType()Get the Data Type of this variableVarnodegetFirstStorageVarnode()Get the first storage varnode for this variableintgetFirstUseOffset()DataTypegetFormalDataType()Get the original formal signature data type before a possible forced indirect was possibly imposed by the functions calling convention.FunctiongetFunction()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-applicableintgetOrdinal()Returns the ordinal (index) of this parameter within the function signature.ProgramgetProgram()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()protected booleanhasDefaultName()Determine if current name is a default name.inthashCode()booleanhasStackStorage()booleanisAutoParameter()booleanisCompoundVariable()booleanisEquivalent(Variable otherVar)Determine is another variable is equivalent to this variable.booleanisForcedIndirect()If this parameter which was forced by the associated calling convention to be passed as a pointer instead of its original formal type.booleanisMemoryVariable()booleanisRegisterVariable()booleanisStackVariable()booleanisUniqueVariable()booleanisValid()Verify that the variable is valid (i.e., storage is valid and size matches variable data type size)protected booleanisVoidAllowed()voidsetComment(java.lang.String comment)Set the comment for this variablevoidsetDataType(DataType type, boolean align, boolean force, SourceType source)Set the Data Type of this variable.voidsetDataType(DataType type, VariableStorage storage, 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.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface ghidra.program.model.listing.Variable
getComment, getFirstStorageVarnode, getFunction, getLastStorageVarnode, getLength, getMinAddress, getName, getProgram, getRegister, getRegisters, getSource, getStackOffset, getSymbol, getVariableStorage, hasAssignedStorage, hasStackStorage, isCompoundVariable, isEquivalent, isMemoryVariable, isRegisterVariable, isStackVariable, isUniqueVariable, isValid, setComment, setDataType, setDataType, setDataType, setName
-
-
-
-
Constructor Detail
-
ParameterImpl
public ParameterImpl(Parameter param, Program program) throws InvalidInputException
Construct a parameter from another.- Parameters:
param- parameter to be copiedprogram- target program- Throws:
InvalidInputException- if dataType restrictions are violated
-
ParameterImpl
public ParameterImpl(java.lang.String name, DataType dataType, Program program) throws InvalidInputExceptionConstruct a parameter which has no specific storage specified. Ordinal assignment is not established (UNASSIGNED_ORDINAL).- Parameters:
name- variable name or null for default namedataType- a fixed-length datatype. (NOTE: Should be cloned to program datatype manager prior to determining storage elements since their length may change)program- target program- Throws:
InvalidInputException- if dataType restrictions are violated
-
ParameterImpl
public ParameterImpl(java.lang.String name, DataType dataType, Program program, SourceType sourceType) throws InvalidInputExceptionConstruct a parameter which has no specific storage specified. Ordinal assignment is not established (UNASSIGNED_ORDINAL).- Parameters:
name- variable name or null for default namedataType- a fixed-length datatype. (NOTE: Should be cloned to program datatype manager prior to determining storage elements since their length may change)program- target programsourceType- name source type- Throws:
InvalidInputException- if dataType restrictions are violated
-
ParameterImpl
public ParameterImpl(java.lang.String name, DataType dataType, int stackOffset, Program program) throws InvalidInputExceptionConstruct a stack parameter at the specified stack offset. Ordinal assignment is not established (UNASSIGNED_ORDINAL).- Parameters:
name- variable name or null for default namedataType- a fixed-length datatype. (NOTE: Should be cloned to program datatype manager prior to determining storage elements since their length may change)stackOffset-program- target program- Throws:
InvalidInputException- if dataType restrictions are violated, an invalid storage address is specified, or unable to resolve storage element for specified datatypeAddressOutOfBoundsException- if invalid stack offset specified
-
ParameterImpl
public ParameterImpl(java.lang.String name, DataType dataType, int stackOffset, Program program, SourceType sourceType) throws InvalidInputExceptionConstruct a stack parameter at the specified stack offset. Ordinal assignment is not established (UNASSIGNED_ORDINAL).- Parameters:
name- variable name or null for default namedataType- a fixed-length datatype. (NOTE: Should be cloned to program datatype manager prior to determining storage elements since their length may change)stackOffset-program- target programsourceType- name source type- Throws:
InvalidInputException- if dataType restrictions are violated, an invalid storage address is specified, or unable to resolve storage element for specified datatypeAddressOutOfBoundsException- if invalid stack offset specified
-
ParameterImpl
public ParameterImpl(java.lang.String name, DataType dataType, Register register, Program program) throws InvalidInputExceptionConstruct a register parameter using the specified register. Ordinal assignment is not established (UNASSIGNED_ORDINAL).- Parameters:
name- variable name or null for default namedataType- a fixed-length datatype. (NOTE: Should be cloned to program datatype manager prior to determining storage elements since their length may change)register-program- target program- Throws:
InvalidInputException- if dataType restrictions are violated, an invalid storage address is specified, or unable to resolve storage element for specified datatype
-
ParameterImpl
public ParameterImpl(java.lang.String name, DataType dataType, Register register, Program program, SourceType sourceType) throws InvalidInputExceptionConstruct a register parameter using the specified register. Ordinal assignment is not established (UNASSIGNED_ORDINAL).- Parameters:
name- variable name or null for default namedataType- a fixed-length datatype. (NOTE: Should be cloned to program datatype manager prior to determining storage elements since their length may change)register-program- target programsourceType- name source type- Throws:
InvalidInputException- if dataType restrictions are violated, an invalid storage address is specified, or unable to resolve storage element for specified datatype
-
ParameterImpl
public ParameterImpl(java.lang.String name, DataType dataType, Address storageAddr, Program program) throws InvalidInputExceptionConstruct a parameter with a single storage element at the specified address. If address is contained within a register it may get realigned to the register based upon the resolved datatype length. Variable storage will be aligned to the least-significant portion of the register. Ordinal assignment is not established (UNASSIGNED_ORDINAL).- Parameters:
name- variable name or null for default namedataType- a fixed-length datatype. (NOTE: Should be cloned to program datatype manager prior to determining storage elements since their length may change)storageAddr- storage address or null if no storage has been identifiedprogram- target program- Throws:
InvalidInputException- if dataType restrictions are violated, an invalid storage address is specified, or unable to resolve storage element for specified datatype
-
ParameterImpl
public ParameterImpl(java.lang.String name, DataType dataType, Address storageAddr, Program program, SourceType sourceType) throws InvalidInputExceptionConstruct a parameter with a single storage element at the specified address. If address is contained within a register it may get realigned to the register based upon the resolved datatype length. Variable storage will be aligned to the least-significant portion of the register. Ordinal assignment is not established (UNASSIGNED_ORDINAL).- Parameters:
name- variable name or null for default namedataType- a fixed-length datatype. (NOTE: Should be cloned to program datatype manager prior to determining storage elements since their length may change)storageAddr- storage address or null if no storage has been identifiedprogram- target programsourceType- name source type- Throws:
InvalidInputException- if dataType restrictions are violated, an invalid storage address is specified, or unable to resolve storage element for specified datatype
-
ParameterImpl
public ParameterImpl(java.lang.String name, DataType dataType, VariableStorage storage, Program program) throws InvalidInputExceptionConstruct a parameter with one or more associated storage elements. Storage elements may get slightly modified to adjust for the resolved datatype size. Ordinal assignment is not established (UNASSIGNED_ORDINAL).- Parameters:
name- variable name or null for default namedataType- a fixed-length datatype. (NOTE: Should be cloned to program datatype manager prior to determining storage elements since their length may change)storage- variable storage or null for unassigned storageprogram- target program- Throws:
InvalidInputException- if dataType restrictions are violated, an invalid storage element is specified, or error while resolving storage element for specified datatype
-
ParameterImpl
public ParameterImpl(java.lang.String name, DataType dataType, VariableStorage storage, Program program, SourceType sourceType) throws InvalidInputExceptionConstruct a parameter with one or more associated storage elements. Storage elements may get slightly modified to adjust for the resolved datatype size. Ordinal assignment is not established (UNASSIGNED_ORDINAL).- Parameters:
name- variable name or null for default namedataType- a fixed-length datatype. (NOTE: Should be cloned to program datatype manager prior to determining storage elements since their length may change)storage- variable storage or null for unassigned storageprogram- target programsourceType- name source type- Throws:
InvalidInputException- if dataType restrictions are violated, an invalid storage element is specified, or error while resolving storage element for specified datatype
-
ParameterImpl
protected ParameterImpl(java.lang.String name, int ordinal, DataType dataType, VariableStorage storage, boolean force, Program program, SourceType sourceType) throws InvalidInputExceptionConstruct a parameter with one or more associated storage elements. Storage elements may get slightly modified to adjust for the resolved datatype size.- Parameters:
name- variable name or null for default nameordinal- parameter ordinal (-1 for return ordinal)dataType- a fixed-length datatype. (NOTE: Should be cloned to program datatype manager prior to determining storage elements since their length may change)storage- variable storage or null for unassigned storageforce- if true storage will be forced even if incorrect sizeprogram- target programsourceType- name source type- Throws:
InvalidInputException- if dataType restrictions are violated, an invalid storage element is specified, or error while resolving storage element for specified datatype
-
-
Method Detail
-
hasDefaultName
protected final boolean hasDefaultName()
Determine if current name is a default name. This is more important for parameters so always returning false for locals is OK.- Returns:
- true if name is reserved as a default name
-
getOrdinal
public final int getOrdinal()
Description copied from interface:ParameterReturns the ordinal (index) of this parameter within the function signature.- Specified by:
getOrdinalin interfaceParameter
-
getFirstUseOffset
public final int getFirstUseOffset()
- Specified by:
getFirstUseOffsetin interfaceVariable- Returns:
- the first use offset relative to the function entry point.
-
getDataType
public DataType getDataType()
Description copied from interface:VariableGet the Data Type of this variable- Specified by:
getDataTypein interfaceVariable- Returns:
- the data type of the variable
-
getFormalDataType
public DataType getFormalDataType()
Description copied from interface:ParameterGet the original formal signature data type before a possible forced indirect was possibly imposed by the functions calling convention. TheVariable.getDataType()method will always return the effective data type which corresponds to the allocated variable storage.- Specified by:
getFormalDataTypein interfaceParameter- Returns:
- Formal data type. This type will only differ from the
Variable.getDataType()value if this parameter isForcedIndirect.
-
isForcedIndirect
public boolean isForcedIndirect()
Description copied from interface:ParameterIf this parameter which was forced by the associated calling convention to be passed as a pointer instead of its original formal type.- Specified by:
isForcedIndirectin interfaceParameter- Returns:
- true if this parameter was forced to be passed as a pointer instead of its original formal type
-
isAutoParameter
public boolean isAutoParameter()
- Specified by:
isAutoParameterin interfaceParameter- Returns:
- true if this parameter is automatically generated based upon the associated function calling convention and function signature. An example of such a parameter include the "__return_storage_ptr__" parameter.
-
getAutoParameterType
public AutoParameterType getAutoParameterType()
Description copied from interface:ParameterIf this is an auto-parameter this method will indicate its type.- Specified by:
getAutoParameterTypein interfaceParameter- Returns:
- auto-parameter type of null if not applicable.
-
isVoidAllowed
protected boolean isVoidAllowed()
- Returns:
- true if a zero-sized void type is permitted
-
isValid
public final boolean isValid()
Description copied from interface:VariableVerify that the variable is valid (i.e., storage is valid and size matches variable data type size)
-
getComment
public final java.lang.String getComment()
Description copied from interface:VariableGet the Comment for this variable- Specified by:
getCommentin interfaceVariable- Returns:
- the comment
-
setDataType
public void setDataType(DataType type, VariableStorage storage, boolean force, SourceType source) throws InvalidInputException
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 interfaceVariable- Parameters:
type- the data typestorage- properly sized storage for the new data typeforce- overwrite conflicting variablessource- 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
-
setDataType
public final void setDataType(DataType type, boolean align, 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 interfaceVariable- Parameters:
type- the data typealign- maintain proper stack alignment/justification if supported by implementation. If false and this is a stack variable, the current stack address/offset will not change. If true, the affect is implementation dependent since alignment can not be performed without access to a compiler specification.force- overwrite conflicting variablessource- 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
-
setDataType
public 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 interfaceVariable- Parameters:
type- the data typesource- 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:
Variable.setDataType(DataType, boolean, boolean, SourceType)
-
getFunction
public 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 interfaceVariable- Returns:
- containing function or null
-
getProgram
public final Program getProgram()
Description copied from interface:VariableReturns the program that contains this variable or is the intended target- Specified by:
getProgramin interfaceVariable- Returns:
- the program.
-
getLength
public final int getLength()
Description copied from interface:VariableGet the length of this variable
-
getName
public final java.lang.String getName()
Description copied from interface:VariableGet the Name of this variable or null if not assigned or not-applicable
-
getSource
public final SourceType getSource()
Description copied from interface:VariableGet the source of this variable
-
getSymbol
public final Symbol getSymbol()
-
setComment
public void setComment(java.lang.String comment)
Description copied from interface:VariableSet the comment for this variable- Specified by:
setCommentin interfaceVariable- Parameters:
comment- the comment
-
setName
public void setName(java.lang.String name, SourceType source) throws InvalidInputExceptionDescription copied from interface:VariableSet the name of this variable.- Specified by:
setNamein interfaceVariable- Parameters:
name- the namesource- the source of this variable name- Throws:
InvalidInputException- if name contains blank characters, is zero length, or is null
-
hasAssignedStorage
public final boolean hasAssignedStorage()
- Specified by:
hasAssignedStoragein interfaceVariable- Returns:
- true if this variable has been assigned storage. This is equivalent to
Variable.getVariableStorage()!= null
-
getVariableStorage
public final VariableStorage getVariableStorage()
Description copied from interface:VariableGet the variable storage associated with this variable.- Specified by:
getVariableStoragein interfaceVariable- Returns:
- the variable storage for this variable
-
getFirstStorageVarnode
public final Varnode getFirstStorageVarnode()
Description copied from interface:VariableGet the first storage varnode for this variable- Specified by:
getFirstStorageVarnodein interfaceVariable- Returns:
- the first storage varnode associated with this variable
- See Also:
Variable.getVariableStorage()
-
getLastStorageVarnode
public final Varnode getLastStorageVarnode()
Description copied from interface:VariableGet the last storage varnode for this variable- Specified by:
getLastStorageVarnodein interfaceVariable- Returns:
- the last storage varnode associated with this variable
- See Also:
Variable.getVariableStorage()
-
isStackVariable
public final boolean isStackVariable()
- Specified by:
isStackVariablein interfaceVariable- 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()
-
hasStackStorage
public final boolean hasStackStorage()
- Specified by:
hasStackStoragein interfaceVariable- 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()
-
isRegisterVariable
public final boolean isRegisterVariable()
- Specified by:
isRegisterVariablein interfaceVariable- 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.
-
getRegister
public final Register getRegister()
- Specified by:
getRegisterin interfaceVariable- 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()
-
getRegisters
public final java.util.List<Register> getRegisters()
- Specified by:
getRegistersin interfaceVariable- 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()
-
getMinAddress
public final Address getMinAddress()
- Specified by:
getMinAddressin interfaceVariable- Returns:
- the minimum address corresponding to the first varnode of this storage
or null if this is a special empty storage:
VariableStorage.BAD_STORAGE,VariableStorage.UNASSIGNED_STORAGE,VariableStorage.VOID_STORAGE
-
getStackOffset
public final int getStackOffset()
- Specified by:
getStackOffsetin interfaceVariable- Returns:
- the stack offset associated with simple stack variable (i.e.,
Variable.isStackVariable()returns true).
-
isMemoryVariable
public final boolean isMemoryVariable()
- Specified by:
isMemoryVariablein interfaceVariable- Returns:
- true if this is a simple variable consisting of a single storage memory element
which will be returned by either the
Variable.getFirstStorageVarnode()orVariable.getVariableStorage()methods.
-
isUniqueVariable
public final boolean isUniqueVariable()
- Specified by:
isUniqueVariablein interfaceVariable- 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()orVariable.getVariableStorage()methods. The unique hash can be obtained from the storage address offset corresponding to the single storage element.
-
isCompoundVariable
public final boolean isCompoundVariable()
- Specified by:
isCompoundVariablein interfaceVariable- Returns:
- true if this variable uses compound storage consisting of two or more storage elements
which will be returned by the
Variable.getVariableStorage()method. Compound variables will always use a register(s) optionally followed by other storage (i.e., stack).
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
equals
public final boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
compareTo
public final int compareTo(Variable otherVar)
- Specified by:
compareToin interfacejava.lang.Comparable<Variable>
-
isEquivalent
public final boolean isEquivalent(Variable otherVar)
Description copied from interface:VariableDetermine is another variable is equivalent to this variable.- Specified by:
isEquivalentin interfaceVariable- Parameters:
otherVar- other variable- Returns:
- true if the specified variable is equivalent to this variable
-
-