Package ghidra.program.model.listing
Class VariableStorage
java.lang.Object
ghidra.program.model.listing.VariableStorage
- All Implemented Interfaces:
Comparable<VariableStorage>
- Direct Known Subclasses:
DynamicVariableStorage
encapsulates the ordered list of storage varnodes which correspond to a
function parameter or local variable. For big-endian the first element corresponds
to the most-significant varnode, while for little-endian the first element
corresponds to the least-significant varnode.-
Field Summary
Modifier and TypeFieldDescriptionstatic final VariableStorage
BAD_STORAGE
used to identify variable storage which is no longer valid.protected final ProgramArchitecture
static final VariableStorage
UNASSIGNED_STORAGE
used to identify parameter storage which is "unmapped" or could not be determined.protected final Varnode[]
static final VariableStorage
VOID_STORAGE
used to identify parameter/return storage which is "mapped" with a data-type of void. -
Constructor Summary
ModifierConstructorDescriptionprotected
Construct an empty variable storage for reserved usage (i.e., BAD_STORAGE, UNMAPPED_STORAGE)VariableStorage
(ProgramArchitecture programArch, int stackOffset, int size) Construct stack variable storageVariableStorage
(ProgramArchitecture programArch, Address address, int size) Construct variable storageVariableStorage
(ProgramArchitecture programArch, Register... registers) Construct register variable storageVariableStorage
(ProgramArchitecture programArch, Varnode... varnodes) Construct variable storageVariableStorage
(ProgramArchitecture programArch, List<Varnode> varnodes) Construct variable storage -
Method Summary
Modifier and TypeMethodDescriptionclone
(ProgramArchitecture newProgramArch) Attempt to clone variable storage for use in a different program.int
compareTo
(VariableStorage otherStorage) Compare this variable storage with another.boolean
Determine if the specified address is contained within this storagestatic VariableStorage
deserialize
(ProgramArchitecture programArch, String serialization) Construct variable storageboolean
This storage is considered equal if it consists of the same storage varnodes.If this storage corresponds to a auto-parameter, return the type associated with the auto-parameter.long
Return a serialization form of this variable storage.static String
getSerializationString
(Varnode... varnodes) Generate VariableStorage serialization stringint
int
Varnode[]
getVarnodes
(AddressFactory addrFactory, String serialization) Parse a storage serialization string to produce an array or varnodesint
hashCode()
boolean
boolean
intersects
(AddressSetView set) Determine if this storage intersects the specified address setboolean
intersects
(Register reg) Determine if this storage intersects the specified registerboolean
intersects
(VariableStorage variableStorage) Determine if this variable storage intersects the specified variable storageboolean
Associated with auto-parameters.boolean
boolean
boolean
boolean
If this storage corresponds to parameter which was forced by the associated calling convention to be passed as a pointer instead of its raw type.boolean
boolean
boolean
boolean
boolean
boolean
boolean
isValid()
boolean
int
size()
toString()
static String
translateSerialization
(LanguageTranslator translator, String serialization) Perform language translations on VariableStorage serialization string
-
Field Details
-
BAD_STORAGE
BAD_STORAGE
used to identify variable storage which is no longer valid. This can be caused by various events such as significant language/processor changes or software bugs which prevent variable storage to be properly decoded. -
UNASSIGNED_STORAGE
UNASSIGNED_STORAGE
used to identify parameter storage which is "unmapped" or could not be determined. -
VOID_STORAGE
VOID_STORAGE
used to identify parameter/return storage which is "mapped" with a data-type of void. -
varnodes
-
programArch
-
-
Constructor Details
-
VariableStorage
protected VariableStorage()Construct an empty variable storage for reserved usage (i.e., BAD_STORAGE, UNMAPPED_STORAGE) -
VariableStorage
public VariableStorage(ProgramArchitecture programArch, Varnode... varnodes) throws InvalidInputException Construct variable storage- Parameters:
programArch
- program architecture detailsvarnodes
- one or more ordered storage varnodes- Throws:
InvalidInputException
- if specified varnodes violate storage restrictions
-
VariableStorage
public VariableStorage(ProgramArchitecture programArch, Register... registers) throws InvalidInputException Construct register variable storage- Parameters:
programArch
- program architecture detailsregisters
- one or more ordered registers- Throws:
InvalidInputException
- if specified registers violate storage restrictions
-
VariableStorage
public VariableStorage(ProgramArchitecture programArch, int stackOffset, int size) throws InvalidInputException Construct stack variable storage- Parameters:
programArch
- program architecture detailsstackOffset
- stack offsetsize
- stack element size- Throws:
InvalidInputException
- if specified registers violate storage restrictions
-
VariableStorage
public VariableStorage(ProgramArchitecture programArch, List<Varnode> varnodes) throws InvalidInputException Construct variable storage- Parameters:
programArch
- program architecture detailsvarnodes
- one or more ordered storage varnodes- Throws:
InvalidInputException
- if specified varnodes violate storage restrictions
-
VariableStorage
public VariableStorage(ProgramArchitecture programArch, Address address, int size) throws InvalidInputException Construct variable storage- Parameters:
programArch
- program architecture detailsaddress
- varnode addresssize
- varnode size- Throws:
InvalidInputException
- if specified varnodes violate storage restrictions
-
-
Method Details
-
deserialize
public static VariableStorage deserialize(ProgramArchitecture programArch, String serialization) throws InvalidInputException Construct variable storage- Parameters:
programArch
- program architecture detailsserialization
- storage serialization string- Returns:
- deserialized variable storage.
BAD_STORAGE
may be returned on failure. - Throws:
InvalidInputException
- if specified varnodes violate storage restrictions
-
getProgramArchitecture
- Returns:
- program for which this storage is associated
-
size
public int size()- Returns:
- the total size of corresponding storage varnodes
-
clone
Attempt to clone variable storage for use in a different program. Dynamic storage characteristics will not be preserved.- Parameters:
newProgramArch
- target program architecture details- Returns:
- cloned storage
- Throws:
InvalidInputException
- if specified varnodes violate storage restrictions
-
toString
-
getVarnodeCount
public int getVarnodeCount()- Returns:
- the number of varnodes associated with this variable storage
-
getVarnodes
- Returns:
- ordered varnodes associated with this variable storage
-
isAutoStorage
public boolean isAutoStorage()Associated with auto-parameters. Parameters whose existence is dictated by a calling-convention may automatically inject additional hidden parameters. If this storage is associated with a auto-parameter, this method will return true.- Returns:
- true if this storage is associated with an auto-parameter, else false
-
getAutoParameterType
If this storage corresponds to a auto-parameter, return the type associated with the auto-parameter.- Returns:
- auto-parameter type or null if not applicable
-
isForcedIndirect
public boolean isForcedIndirect()If this storage corresponds to parameter which was forced by the associated calling convention to be passed as a pointer instead of its raw type.- Returns:
- true if this parameter was forced to be passed as a pointer instead of its raw type
-
isBadStorage
public boolean isBadStorage()- Returns:
- true if this storage is bad (could not be resolved)
-
isUnassignedStorage
public boolean isUnassignedStorage()- Returns:
- true if storage has not been assigned (no varnodes)
-
isValid
public boolean isValid()- Returns:
- true if storage is assigned and is not BAD
-
isVoidStorage
public boolean isVoidStorage()- Returns:
- true if storage corresponds to the VOID_STORAGE instance
- See Also:
-
getFirstVarnode
- Returns:
- first varnode within the ordered list of varnodes
-
getLastVarnode
- Returns:
- last varnode within the ordered list of varnodes
-
isStackStorage
public boolean isStackStorage()- Returns:
- true if storage consists of a single stack varnode
-
hasStackStorage
public boolean hasStackStorage()- Returns:
- true if the last varnode for simple or compound storage is a stack varnode
-
isRegisterStorage
public boolean isRegisterStorage()- 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 thegetRegister()
method. Keep in mind that registers may exist in a memory space or the register space.
-
getRegister
- Returns:
- first storage register associated with this register or compound storage, else null is returned.
- See Also:
-
getRegisters
- Returns:
- storage register(s) associated with this register or compound storage, else null is returned.
- See Also:
-
getStackOffset
public int getStackOffset()- Returns:
- the stack offset associated with simple stack storage or compound
storage where the last varnode is stack, see
hasStackStorage()
. - Throws:
UnsupportedOperationException
- if storage does not have a stack varnode
-
getMinAddress
- Returns:
- the minimum address corresponding to the first varnode of this storage
or null if this is a special empty storage:
isBadStorage()
,isUnassignedStorage()
,isVoidStorage()
-
isMemoryStorage
public boolean isMemoryStorage()- Returns:
- true if storage consists of a single memory varnode which does not correspond to a register.
-
isConstantStorage
public boolean isConstantStorage()- Returns:
- true if storage consists of a single constant-space varnode which is used when storing local function constants.
-
isHashStorage
public boolean isHashStorage()- Returns:
- true if storage consists of a single hash-space varnode which is used when storing local unique function variables.
-
isUniqueStorage
public boolean isUniqueStorage()- Returns:
- true if storage consists of a single unique-space varnode which is used during function analysis. This type of storage is not suitable for database-stored function variables. This type of storage must be properly converted to Hash storage when storing unique function variables.
-
isCompoundStorage
public boolean isCompoundStorage()- Returns:
- true if storage consists of two or more storage varnodes
-
getLongHash
public long getLongHash() -
hashCode
public int hashCode() -
equals
This storage is considered equal if it consists of the same storage varnodes. -
intersects
Determine if this variable storage intersects the specified variable storage- Parameters:
variableStorage
- other variable storage- Returns:
- true if any intersection exists between this storage and the specified variable storage
-
intersects
Determine if this storage intersects the specified address set- Parameters:
set
- address set- Returns:
- true if this storage intersects the specified address set
-
intersects
Determine if this storage intersects the specified register- Parameters:
reg
- the register- Returns:
- true if this storage intersects the specified register
-
contains
Determine if the specified address is contained within this storage- Parameters:
address
- address- Returns:
- true if this storage varnode(s) contain specified address
-
compareTo
Compare this variable storage with another. A value of 0 indicates that the two objects are equal- Specified by:
compareTo
in interfaceComparable<VariableStorage>
- See Also:
-
getSerializationString
Return a serialization form of this variable storage.- Returns:
- storage serialization string useful for subsequent reconstruction
-
getSerializationString
Generate VariableStorage serialization string- Parameters:
varnodes
- one or more storage varnodes- Returns:
- storage serialization string useful for subsequent reconstruction of a VariableStorage object
-
getVarnodes
public static List<Varnode> getVarnodes(AddressFactory addrFactory, String serialization) throws InvalidInputException Parse a storage serialization string to produce an array or varnodes- Parameters:
addrFactory
- address factoryserialization
- serialized variable storage string (seegetSerializationString()
).- Returns:
- array of varnodes or null if invalid
- Throws:
InvalidInputException
- if specified registers violate storage restrictions
-
translateSerialization
public static String translateSerialization(LanguageTranslator translator, String serialization) throws InvalidInputException Perform language translations on VariableStorage serialization string- Parameters:
translator
- language translatorserialization
- VariableStorage serialization string- Returns:
- translated serialization string
- Throws:
InvalidInputException
- if serialization has invalid format
-