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

    • BAD_STORAGE

      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

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

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

      protected final Varnode[] varnodes
    • programArch

      protected final ProgramArchitecture 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 details
      varnodes - 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 details
      registers - 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 details
      stackOffset - stack offset
      size - 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 details
      varnodes - 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 details
      address - varnode address
      size - 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 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

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

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

      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

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

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

      public Varnode[] 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

      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

      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

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

      public Varnode 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() 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

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

      public List<Register> 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

      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

      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()
      Overrides:
      hashCode in class Object
    • equals

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

      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

      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

      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

      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

      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

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

      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

      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

      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