Package ghidra.program.model.listing
Class LocalVariableImpl
java.lang.Object
ghidra.program.model.listing.LocalVariableImpl
- All Implemented Interfaces:
LocalVariable
,Variable
,Comparable<Variable>
-
Constructor Summary
ConstructorDescriptionLocalVariableImpl
(String name, int firstUseOffset, DataType dataType, Address storageAddr, Program program) Construct a variable with a single storage element at the specified address.LocalVariableImpl
(String name, int firstUseOffset, DataType dataType, Address storageAddr, Program program, SourceType sourceType) Construct a variable with a single storage element at the specified address.LocalVariableImpl
(String name, int firstUseOffset, DataType dataType, Register register, Program program) Construct a register variable with the specified register storage.LocalVariableImpl
(String name, int firstUseOffset, DataType dataType, Register register, Program program, SourceType sourceType) Construct a variable with one or more associated storage elements.LocalVariableImpl
(String name, int firstUseOffset, DataType dataType, VariableStorage storage, boolean force, Program program) Construct a variable with one or more associated storage elements.LocalVariableImpl
(String name, int firstUseOffset, DataType dataType, VariableStorage storage, boolean force, Program program, SourceType sourceType) Construct a variable with one or more associated storage elements.LocalVariableImpl
(String name, int firstUseOffset, DataType dataType, VariableStorage storage, Program program) Construct a variable with one or more associated storage elements.LocalVariableImpl
(String name, DataType dataType, int stackOffset, Program program) Construct a stack variable at the specified stack offset with a first-use offset of 0.LocalVariableImpl
(String name, DataType dataType, int stackOffset, Program program, SourceType sourceType) Construct a stack variable at the specified stack offset with a first-use offset of 0. -
Method Summary
Modifier and TypeMethodDescriptionfinal int
final boolean
final String
Get the Comment for this variableGet the Data Type of this variablefinal Varnode
Get the first storage varnode for this variableint
Returns the function that contains this Variable.final Varnode
Get the last storage varnode for this variablefinal int
Get the length of this variablefinal Address
final String
getName()
Get the Name of this variable or null if not assigned or not-applicablefinal Program
Returns the program that contains this variable or is the intended targetfinal Register
final SourceType
Get the source of this variablefinal int
final Symbol
final VariableStorage
Get the variable storage associated with this variable.final boolean
protected boolean
Determine if current name is a default name.int
hashCode()
final boolean
final boolean
final boolean
isEquivalent
(Variable otherVar) Determine is another variable is equivalent to this variable.final boolean
final boolean
final boolean
final boolean
final boolean
isValid()
Verify that the variable is valid (i.e., storage is valid and size matches variable data type size)protected boolean
void
setComment
(String comment) Set the comment for this variablefinal void
setDataType
(DataType type, boolean align, boolean force, SourceType source) Set the Data Type of this variable.void
setDataType
(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.void
setDataType
(DataType type, SourceType source) Set the Data Type of this variable using the default alignment behavior (implementation specific).boolean
setFirstUseOffset
(int firstUseOffset) Set the first use offset.void
setName
(String name, SourceType source) Set the name of this variable.toString()
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Comparable
compareTo
Methods inherited from interface ghidra.program.model.listing.Variable
getComment, getDataType, 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 Details
-
LocalVariableImpl
public LocalVariableImpl(String name, DataType dataType, int stackOffset, Program program) throws InvalidInputException Construct a stack variable at the specified stack offset with a first-use offset of 0.- Parameters:
name
- variable name or null for default namingdataType
- a fixed-length datatype. (NOTE: Should be cloned to program datatype manager prior to determining storage elements since their length may change)stackOffset
- signed stack offsetprogram
- 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
-
LocalVariableImpl
public LocalVariableImpl(String name, DataType dataType, int stackOffset, Program program, SourceType sourceType) throws InvalidInputException Construct a stack variable at the specified stack offset with a first-use offset of 0.- Parameters:
name
- variable 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
-
LocalVariableImpl
public LocalVariableImpl(String name, int firstUseOffset, DataType dataType, Register register, Program program) throws InvalidInputException Construct a register variable with the specified register storage.- Parameters:
name
- variable name or null for default namingfirstUseOffset
- first use function-relative offset (i.e., start of scope).dataType
- a fixed-length datatype. (NOTE: Should be cloned to program datatype manager prior to determining storage elements since their length may change)register
- the register used for the storage.program
- target program- Throws:
InvalidInputException
- if dataType restrictions are violated, an invalid storage element is specified, or error while resolving storage element for specified datatype
-
LocalVariableImpl
public LocalVariableImpl(String name, int firstUseOffset, DataType dataType, Register register, Program program, SourceType sourceType) throws InvalidInputException Construct a variable with one or more associated storage elements. Storage elements may get slightly modified to adjust for the resolved datatype size.- Parameters:
name
- variable namefirstUseOffset
- first use function-relative offset (i.e., start of scope).dataType
- a fixed-length datatype. (NOTE: Should be cloned to program datatype manager prior to determining storage elements since their length may change)register
- the register used for the storage.program
- 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
-
LocalVariableImpl
public LocalVariableImpl(String name, int firstUseOffset, DataType dataType, Address storageAddr, Program program) throws InvalidInputException Construct a variable 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.- Parameters:
name
- variable name or null for default namingfirstUseOffset
- first use function-relative offset (i.e., start of scope).dataType
- 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
-
LocalVariableImpl
public LocalVariableImpl(String name, int firstUseOffset, DataType dataType, Address storageAddr, Program program, SourceType sourceType) throws InvalidInputException Construct a variable 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.- Parameters:
name
- variable namefirstUseOffset
- first use function-relative offset (i.e., start of scope).dataType
- 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
-
LocalVariableImpl
public LocalVariableImpl(String name, int firstUseOffset, DataType dataType, VariableStorage storage, Program program) throws InvalidInputException Construct a variable 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 namingfirstUseOffset
- first use function-relative offset (i.e., start of scope).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 (may not be null)program
- target program- Throws:
InvalidInputException
- if dataType restrictions are violated, an invalid storage element is specified, or error while resolving storage element for specified datatype
-
LocalVariableImpl
public LocalVariableImpl(String name, int firstUseOffset, DataType dataType, VariableStorage storage, boolean force, Program program) throws InvalidInputException Construct a variable 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 namingfirstUseOffset
- first use function-relative offset (i.e., start of scope).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 (may not be null)force
- if true storage will be forced even if incorrect sizeprogram
- target program- Throws:
InvalidInputException
- if dataType restrictions are violated, an invalid storage element is specified, or error while resolving storage element for specified datatype
-
LocalVariableImpl
public LocalVariableImpl(String name, int firstUseOffset, DataType dataType, VariableStorage storage, boolean force, Program program, SourceType sourceType) throws InvalidInputException Construct a variable with one or more associated storage elements. Storage elements may get slightly modified to adjust for the resolved datatype size.- Parameters:
name
- variable namefirstUseOffset
- first use function-relative offset (i.e., start of scope).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 (may not be null)force
- 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 Details
-
getFirstUseOffset
public int getFirstUseOffset()- Specified by:
getFirstUseOffset
in interfaceVariable
- Returns:
- the first use offset relative to the function entry point.
-
setFirstUseOffset
public boolean setFirstUseOffset(int firstUseOffset) Description copied from interface:LocalVariable
Set the first use offset.- Specified by:
setFirstUseOffset
in interfaceLocalVariable
- Parameters:
firstUseOffset
-- Returns:
- true if successful, else false
-
hasDefaultName
protected 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
-
isVoidAllowed
protected boolean isVoidAllowed()- Returns:
- true if a zero-sized void type is permitted
-
isValid
public final boolean isValid()Description copied from interface:Variable
Verify that the variable is valid (i.e., storage is valid and size matches variable data type size) -
getComment
Description copied from interface:Variable
Get the Comment for this variable- Specified by:
getComment
in interfaceVariable
- Returns:
- the comment
-
getDataType
Description copied from interface:Variable
Get the Data Type of this variable- Specified by:
getDataType
in interfaceVariable
- Returns:
- the data type of the variable
-
setDataType
public void setDataType(DataType type, VariableStorage storage, boolean force, SourceType source) throws InvalidInputException Description copied from interface:Variable
Set 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:
setDataType
in 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.
-
setDataType
public final void setDataType(DataType type, boolean align, boolean force, SourceType source) throws InvalidInputException Description copied from interface:Variable
Set the Data Type of this variable. The given dataType must have a fixed length.- Specified by:
setDataType
in 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.
-
setDataType
Description copied from interface:Variable
Set 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:
setDataType
in interfaceVariable
- Parameters:
type
- the data typesource
- signature source- Throws:
InvalidInputException
- if data type is not a fixed length or violates storage constraints.- See Also:
-
getFunction
Description copied from interface:Variable
Returns the function that contains this Variable. May be null if the variable is not in a function.- Specified by:
getFunction
in interfaceVariable
- Returns:
- containing function or null
-
getProgram
Description copied from interface:Variable
Returns the program that contains this variable or is the intended target- Specified by:
getProgram
in interfaceVariable
- Returns:
- the program.
-
getLength
public final int getLength()Description copied from interface:Variable
Get the length of this variable -
getName
Description copied from interface:Variable
Get the Name of this variable or null if not assigned or not-applicable -
getSource
Description copied from interface:Variable
Get the source of this variable -
getSymbol
-
setComment
Description copied from interface:Variable
Set the comment for this variable- Specified by:
setComment
in interfaceVariable
- Parameters:
comment
- the comment
-
setName
Description copied from interface:Variable
Set the name of this variable.- Specified by:
setName
in 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:
hasAssignedStorage
in interfaceVariable
- Returns:
- true if this variable has been assigned storage. This is equivalent to
Variable.getVariableStorage()
!= null
-
getVariableStorage
Description copied from interface:Variable
Get the variable storage associated with this variable.- Specified by:
getVariableStorage
in interfaceVariable
- Returns:
- the variable storage for this variable
-
getFirstStorageVarnode
Description copied from interface:Variable
Get the first storage varnode for this variable- Specified by:
getFirstStorageVarnode
in interfaceVariable
- Returns:
- the first storage varnode associated with this variable
- See Also:
-
getLastStorageVarnode
Description copied from interface:Variable
Get the last storage varnode for this variable- Specified by:
getLastStorageVarnode
in interfaceVariable
- Returns:
- the last storage varnode associated with this variable
- See Also:
-
isStackVariable
public final boolean isStackVariable()- Specified by:
isStackVariable
in 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:
hasStackStorage
in 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:
-
isRegisterVariable
public final boolean isRegisterVariable()- Specified by:
isRegisterVariable
in 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
- Specified by:
getRegister
in 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:
-
getRegisters
- Specified by:
getRegisters
in 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:
-
getMinAddress
- Specified by:
getMinAddress
in 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:
getStackOffset
in interfaceVariable
- Returns:
- the stack offset associated with simple stack variable (i.e.,
Variable.isStackVariable()
returns true).
-
isMemoryVariable
public final boolean isMemoryVariable()- Specified by:
isMemoryVariable
in 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:
isUniqueVariable
in 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:
isCompoundVariable
in 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
-
equals
-
hashCode
public int hashCode() -
compareTo
- Specified by:
compareTo
in interfaceComparable<Variable>
-
isEquivalent
Description copied from interface:Variable
Determine is another variable is equivalent to this variable.- Specified by:
isEquivalent
in interfaceVariable
- Parameters:
otherVar
- other variable- Returns:
- true if the specified variable is equivalent to this variable
-