Class VariableStorage

java.lang.Object
ghidra.program.model.listing.VariableStorage
All Implemented Interfaces:
Comparable<VariableStorage>
Direct Known Subclasses:
DynamicVariableStorage

public class VariableStorage extends Object implements Comparable<VariableStorage>
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 Details Link icon

    • BAD_STORAGE Link icon

      public static final VariableStorage 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 Link icon

      public static final VariableStorage UNASSIGNED_STORAGE
      UNASSIGNED_STORAGE used to identify parameter storage which is "unmapped" or could not be determined.
    • VOID_STORAGE Link icon

      public static final VariableStorage VOID_STORAGE
      VOID_STORAGE used to identify parameter/return storage which is "mapped" with a data-type of void.
    • varnodes Link icon

      protected final Varnode[] varnodes
    • programArch Link icon

      protected final ProgramArchitecture programArch
  • Constructor Details Link icon

    • VariableStorage Link icon

      protected VariableStorage()
      Construct an empty variable storage for reserved usage (i.e., BAD_STORAGE, UNMAPPED_STORAGE)
    • VariableStorage Link icon

      public VariableStorage(ProgramArchitecture programArch, Varnode... varnodes) throws InvalidInputException
      Construct variable storage
      Parameters:
      programArch - program architecture details
      varnodes - one or more ordered storage varnodes
      Throws:
      InvalidInputException - if specified varnodes violate storage restrictions
    • VariableStorage Link icon

      public VariableStorage(ProgramArchitecture programArch, Register... registers) throws InvalidInputException
      Construct register variable storage
      Parameters:
      programArch - program architecture details
      registers - one or more ordered registers
      Throws:
      InvalidInputException - if specified registers violate storage restrictions
    • VariableStorage Link icon

      public VariableStorage(ProgramArchitecture programArch, int stackOffset, int size) throws InvalidInputException
      Construct stack variable storage
      Parameters:
      programArch - program architecture details
      stackOffset - stack offset
      size - stack element size
      Throws:
      InvalidInputException - if specified registers violate storage restrictions
    • VariableStorage Link icon

      public VariableStorage(ProgramArchitecture programArch, List<Varnode> varnodes) throws InvalidInputException
      Construct variable storage
      Parameters:
      programArch - program architecture details
      varnodes - one or more ordered storage varnodes
      Throws:
      InvalidInputException - if specified varnodes violate storage restrictions
    • VariableStorage Link icon

      public VariableStorage(ProgramArchitecture programArch, Address address, int size) throws InvalidInputException
      Construct variable storage
      Parameters:
      programArch - program architecture details
      address - varnode address
      size - varnode size
      Throws:
      InvalidInputException - if specified varnodes violate storage restrictions
  • Method Details Link icon

    • deserialize Link icon

      public static VariableStorage deserialize(ProgramArchitecture programArch, String serialization) throws InvalidInputException
      Construct variable storage
      Parameters:
      programArch - program architecture details
      serialization - storage serialization string
      Returns:
      deserialized variable storage. BAD_STORAGE may be returned on failure.
      Throws:
      InvalidInputException - if specified varnodes violate storage restrictions
    • getProgramArchitecture Link icon

      public ProgramArchitecture getProgramArchitecture()
      Returns:
      program for which this storage is associated
    • size Link icon

      public int size()
      Returns:
      the total size of corresponding storage varnodes
    • clone Link icon

      public VariableStorage clone(ProgramArchitecture newProgramArch) throws InvalidInputException
      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 Link icon

      public String toString()
      Overrides:
      toString in class Object
    • getVarnodeCount Link icon

      public int getVarnodeCount()
      Returns:
      the number of varnodes associated with this variable storage
    • getVarnodes Link icon

      public Varnode[] getVarnodes()
      Returns:
      ordered varnodes associated with this variable storage
    • isAutoStorage Link icon

      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 Link icon

      public AutoParameterType 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 Link icon

      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 Link icon

      public boolean isBadStorage()
      Returns:
      true if this storage is bad (could not be resolved)
    • isUnassignedStorage Link icon

      public boolean isUnassignedStorage()
      Returns:
      true if storage has not been assigned (no varnodes)
    • isValid Link icon

      public boolean isValid()
      Returns:
      true if storage is assigned and is not BAD
    • isVoidStorage Link icon

      public boolean isVoidStorage()
      Returns:
      true if storage corresponds to the VOID_STORAGE instance
      See Also:
    • getFirstVarnode Link icon

      public Varnode getFirstVarnode()
      Returns:
      first varnode within the ordered list of varnodes
    • getLastVarnode Link icon

      public Varnode getLastVarnode()
      Returns:
      last varnode within the ordered list of varnodes
    • isStackStorage Link icon

      public boolean isStackStorage()
      Returns:
      true if storage consists of a single stack varnode
    • hasStackStorage Link icon

      public boolean hasStackStorage()
      Returns:
      true if the last varnode for simple or compound storage is a stack varnode
    • isRegisterStorage Link icon

      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() or Variable.getLastStorageVarnode() methods. The register can be obtained using the getRegister() method. Keep in mind that registers may exist in a memory space or the register space.
    • getRegister Link icon

      public Register getRegister()
      Returns:
      first storage register associated with this register or compound storage, else null is returned.
      See Also:
    • getRegisters Link icon

      public List<Register> getRegisters()
      Returns:
      storage register(s) associated with this register or compound storage, else null is returned.
      See Also:
    • getStackOffset Link icon

      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 Link icon

      public Address 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 Link icon

      public boolean isMemoryStorage()
      Returns:
      true if storage consists of a single memory varnode which does not correspond to a register.
    • isConstantStorage Link icon

      public boolean isConstantStorage()
      Returns:
      true if storage consists of a single constant-space varnode which is used when storing local function constants.
    • isHashStorage Link icon

      public boolean isHashStorage()
      Returns:
      true if storage consists of a single hash-space varnode which is used when storing local unique function variables.
    • isUniqueStorage Link icon

      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 Link icon

      public boolean isCompoundStorage()
      Returns:
      true if storage consists of two or more storage varnodes
    • getLongHash Link icon

      public long getLongHash()
    • hashCode Link icon

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals Link icon

      public boolean equals(Object obj)
      This storage is considered equal if it consists of the same storage varnodes.
      Overrides:
      equals in class Object
    • intersects Link icon

      public boolean intersects(VariableStorage variableStorage)
      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 Link icon

      public boolean intersects(AddressSetView set)
      Determine if this storage intersects the specified address set
      Parameters:
      set - address set
      Returns:
      true if this storage intersects the specified address set
    • intersects Link icon

      public boolean intersects(Register reg)
      Determine if this storage intersects the specified register
      Parameters:
      reg - the register
      Returns:
      true if this storage intersects the specified register
    • contains Link icon

      public boolean contains(Address address)
      Determine if the specified address is contained within this storage
      Parameters:
      address - address
      Returns:
      true if this storage varnode(s) contain specified address
    • compareTo Link icon

      public int compareTo(VariableStorage otherStorage)
      Compare this variable storage with another. A value of 0 indicates that the two objects are equal
      Specified by:
      compareTo in interface Comparable<VariableStorage>
      See Also:
    • getSerializationString Link icon

      public String getSerializationString()
      Return a serialization form of this variable storage.
      Returns:
      storage serialization string useful for subsequent reconstruction
    • getSerializationString Link icon

      public static String getSerializationString(Varnode... varnodes)
      Generate VariableStorage serialization string
      Parameters:
      varnodes - one or more storage varnodes
      Returns:
      storage serialization string useful for subsequent reconstruction of a VariableStorage object
    • getVarnodes Link icon

      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 factory
      serialization - serialized variable storage string (see getSerializationString()).
      Returns:
      array of varnodes or null if invalid
      Throws:
      InvalidInputException - if specified registers violate storage restrictions
    • translateSerialization Link icon

      public static String translateSerialization(LanguageTranslator translator, String serialization) throws InvalidInputException
      Perform language translations on VariableStorage serialization string
      Parameters:
      translator - language translator
      serialization - VariableStorage serialization string
      Returns:
      translated serialization string
      Throws:
      InvalidInputException - if serialization has invalid format