Class MemoryBlockStub

java.lang.Object
ghidra.program.model.mem.MemoryBlockStub
All Implemented Interfaces:
MemoryBlock, Serializable, Comparable<MemoryBlock>

public class MemoryBlockStub extends Object implements MemoryBlock
MemoryBlockStub can be extended for use by tests. It throws an UnsupportedOperationException for all methods in the MemoryBlock interface. Any method that is needed for your test can then be overridden so it can provide its own test implementation and return value.
See Also:
  • Constructor Details Link icon

    • MemoryBlockStub Link icon

      public MemoryBlockStub()
    • MemoryBlockStub Link icon

      public MemoryBlockStub(Address start, Address end)
  • Method Details Link icon

    • compareTo Link icon

      public int compareTo(MemoryBlock o)
      Specified by:
      compareTo in interface Comparable<MemoryBlock>
    • getFlags Link icon

      public int getFlags()
      Description copied from interface: MemoryBlock
      Returns block flags (i.e., permissions and attributes) as a bit mask. These bits defined as MemoryBlock.READ, MemoryBlock.WRITE, MemoryBlock.EXECUTE, MemoryBlock.VOLATILE, MemoryBlock.ARTIFICIAL.
      Specified by:
      getFlags in interface MemoryBlock
      Returns:
      block flag bits
    • getData Link icon

      public InputStream getData()
      Description copied from interface: MemoryBlock
      Get memory data in the form of an InputStream. Null is returned for thos memory blocks which have no data.
      Specified by:
      getData in interface MemoryBlock
    • contains Link icon

      public boolean contains(Address addr)
      Description copied from interface: MemoryBlock
      Return whether addr is contained in this block.
      Specified by:
      contains in interface MemoryBlock
      Parameters:
      addr - address
    • getStart Link icon

      public Address getStart()
      Description copied from interface: MemoryBlock
      Return the starting address for this block.
      Specified by:
      getStart in interface MemoryBlock
      Returns:
      block's start address
    • getEnd Link icon

      public Address getEnd()
      Description copied from interface: MemoryBlock
      Return the end address of this block.
      Specified by:
      getEnd in interface MemoryBlock
      Returns:
      end address of the block
    • getAddressRange Link icon

      public AddressRange getAddressRange()
      Description copied from interface: MemoryBlock
      Get the address range that corresponds to this block.
      Specified by:
      getAddressRange in interface MemoryBlock
      Returns:
      block address range
    • getSize Link icon

      public long getSize()
      Description copied from interface: MemoryBlock
      Get the number of bytes in this block.
      Specified by:
      getSize in interface MemoryBlock
      Returns:
      number of bytes in the block
    • getSizeAsBigInteger Link icon

      public BigInteger getSizeAsBigInteger()
      Description copied from interface: MemoryBlock
      Get the number of bytes in this block.
      Specified by:
      getSizeAsBigInteger in interface MemoryBlock
      Returns:
      the number of bytes in this block as a BigInteger
    • getName Link icon

      public String getName()
      Description copied from interface: MemoryBlock
      Get the name of this block
      Specified by:
      getName in interface MemoryBlock
      Returns:
      block name
    • setName Link icon

      public void setName(String name) throws LockException
      Description copied from interface: MemoryBlock
      Set the name for this block (See NamingUtilities.isValidName(String) for naming rules). Specified name must not conflict with an address space name.
      Specified by:
      setName in interface MemoryBlock
      Parameters:
      name - the new name for this block.
      Throws:
      LockException - renaming an Overlay block without exclusive access
    • getComment Link icon

      public String getComment()
      Description copied from interface: MemoryBlock
      Get the comment associated with this block.
      Specified by:
      getComment in interface MemoryBlock
      Returns:
      block comment string
    • setComment Link icon

      public void setComment(String comment)
      Description copied from interface: MemoryBlock
      Set the comment associated with this block.
      Specified by:
      setComment in interface MemoryBlock
      Parameters:
      comment - the comment to associate with this block.
    • isRead Link icon

      public boolean isRead()
      Description copied from interface: MemoryBlock
      Returns the value of the read property associated with this block
      Specified by:
      isRead in interface MemoryBlock
      Returns:
      true if enabled else false
    • setRead Link icon

      public void setRead(boolean r)
      Description copied from interface: MemoryBlock
      Sets the read property associated with this block.
      Specified by:
      setRead in interface MemoryBlock
      Parameters:
      r - the value to set the read property to.
    • isWrite Link icon

      public boolean isWrite()
      Description copied from interface: MemoryBlock
      Returns the value of the write property associated with this block
      Specified by:
      isWrite in interface MemoryBlock
      Returns:
      true if enabled else false
    • setWrite Link icon

      public void setWrite(boolean w)
      Description copied from interface: MemoryBlock
      Sets the write property associated with this block.
      Specified by:
      setWrite in interface MemoryBlock
      Parameters:
      w - the value to set the write property to.
    • isExecute Link icon

      public boolean isExecute()
      Description copied from interface: MemoryBlock
      Returns the value of the execute property associated with this block
      Specified by:
      isExecute in interface MemoryBlock
      Returns:
      true if enabled else false
    • setExecute Link icon

      public void setExecute(boolean e)
      Description copied from interface: MemoryBlock
      Sets the execute property associated with this block.
      Specified by:
      setExecute in interface MemoryBlock
      Parameters:
      e - the value to set the execute property to.
    • setPermissions Link icon

      public void setPermissions(boolean read, boolean write, boolean execute)
      Description copied from interface: MemoryBlock
      Sets the read, write, execute permissions on this block
      Specified by:
      setPermissions in interface MemoryBlock
      Parameters:
      read - the read permission
      write - the write permission
      execute - the execute permission
    • isVolatile Link icon

      public boolean isVolatile()
      Description copied from interface: MemoryBlock
      Returns the volatile attribute state of this block. This attribute is generally associated with block of I/O regions of memory.
      Specified by:
      isVolatile in interface MemoryBlock
      Returns:
      true if enabled else false
    • setVolatile Link icon

      public void setVolatile(boolean v)
      Description copied from interface: MemoryBlock
      Sets the volatile attribute state associated of this block. This attribute is generally associated with block of I/O regions of memory.
      Specified by:
      setVolatile in interface MemoryBlock
      Parameters:
      v - the volatile attribute state.
    • isArtificial Link icon

      public boolean isArtificial()
      Description copied from interface: MemoryBlock
      Returns the artificial attribute state of this block. This attribute is generally associated with blocks which have been fabricated to facilitate analysis but do not exist in the same form within a running/loaded process state.
      Specified by:
      isArtificial in interface MemoryBlock
      Returns:
      true if enabled else false
    • setArtificial Link icon

      public void setArtificial(boolean a)
      Description copied from interface: MemoryBlock
      Sets the artificial attribute state associated with this block. This attribute is generally associated with blocks which have been fabricated to facilitate analysis but do not exist in the same form within a running/loaded process state.
      Specified by:
      setArtificial in interface MemoryBlock
      Parameters:
      a - the artificial attribute state.
    • isOverlay Link icon

      public boolean isOverlay()
      Description copied from interface: MemoryBlock
      Returns true if this is an overlay block (i.e., contained within overlay space).
      Specified by:
      isOverlay in interface MemoryBlock
      Returns:
      true if this is an overlay block
    • getSourceName Link icon

      public String getSourceName()
      Description copied from interface: MemoryBlock
      Get the name of the source of this memory block.
      Specified by:
      getSourceName in interface MemoryBlock
      Returns:
      source name
    • setSourceName Link icon

      public void setSourceName(String sourceName)
      Description copied from interface: MemoryBlock
      Sets the name of the source file that provided the data.
      Specified by:
      setSourceName in interface MemoryBlock
      Parameters:
      sourceName - the name of the source file.
    • getByte Link icon

      public byte getByte(Address addr) throws MemoryAccessException
      Description copied from interface: MemoryBlock
      Returns the byte at the given address in this block.
      Specified by:
      getByte in interface MemoryBlock
      Parameters:
      addr - the address.
      Returns:
      byte value from this block and specified address
      Throws:
      MemoryAccessException - if any of the requested bytes are uninitialized.
    • getBytes Link icon

      public int getBytes(Address addr, byte[] b) throws MemoryAccessException
      Description copied from interface: MemoryBlock
      Tries to get b.length bytes from this block at the given address. May return fewer bytes if the requested length is beyond the end of the block.
      Specified by:
      getBytes in interface MemoryBlock
      Parameters:
      addr - the address from which to get the bytes.
      b - the byte array to populate.
      Returns:
      the number of bytes actually populated.
      Throws:
      MemoryAccessException - if any of the requested bytes are uninitialized.
    • getBytes Link icon

      public int getBytes(Address addr, byte[] b, int off, int len) throws MemoryAccessException
      Description copied from interface: MemoryBlock
      Tries to get len bytes from this block at the given address and put them into the given byte array at the specified offet. May return fewer bytes if the requested length is beyond the end of the block.
      Specified by:
      getBytes in interface MemoryBlock
      Parameters:
      addr - the address from which to get the bytes.
      b - the byte array to populate.
      off - the offset into the byte array.
      len - the number of bytes to get.
      Returns:
      the number of bytes actually populated.
      Throws:
      MemoryAccessException - if any of the requested bytes are uninitialized.
    • putByte Link icon

      public void putByte(Address addr, byte b) throws MemoryAccessException
      Description copied from interface: MemoryBlock
      Puts the given byte at the given address in this block.
      Specified by:
      putByte in interface MemoryBlock
      Parameters:
      addr - the address.
      b - byte value
      Throws:
      MemoryAccessException - if the block is uninitialized
    • putBytes Link icon

      public int putBytes(Address addr, byte[] b) throws MemoryAccessException
      Description copied from interface: MemoryBlock
      Tries to put b.length bytes from the specified byte array to this block. All the bytes may not be put if the requested length is beyond the end of the block.
      Specified by:
      putBytes in interface MemoryBlock
      Parameters:
      addr - the address of where to put the bytes.
      b - the byte array containing the bytes to write.
      Returns:
      the number of bytes actually written.
      Throws:
      MemoryAccessException - if the block is uninitialized
    • putBytes Link icon

      public int putBytes(Address addr, byte[] b, int off, int len) throws MemoryAccessException
      Description copied from interface: MemoryBlock
      Tries to put len bytes from the specified byte array to this block. All the bytes may not be written if the requested length is beyond the end of the block.
      Specified by:
      putBytes in interface MemoryBlock
      Parameters:
      addr - the address of where to put the bytes.
      b - the byte array containing the bytes to write.
      off - the offset into the byte array.
      len - the number of bytes to write.
      Returns:
      the number of bytes actually written.
      Throws:
      MemoryAccessException - if the block is uninitialized
    • getType Link icon

      public MemoryBlockType getType()
      Description copied from interface: MemoryBlock
      Get the type for this block: DEFAULT, BIT_MAPPED, or BYTE_MAPPED (see MemoryBlockType).
      Specified by:
      getType in interface MemoryBlock
      Returns:
      memory block type
    • isInitialized Link icon

      public boolean isInitialized()
      Description copied from interface: MemoryBlock
      Return whether this block has been initialized.

      WARNING: A mapped memory block may have a mix of intialized, uninitialized, and undefined regions. The value returned by this method for a mapped memory block is always false even if some regions are initialized.

      Specified by:
      isInitialized in interface MemoryBlock
      Returns:
      true if block is fully initialized and not a memory-mapped-block, else false
    • isMapped Link icon

      public boolean isMapped()
      Description copied from interface: MemoryBlock
      Returns true if this is either a bit-mapped or byte-mapped block
      Specified by:
      isMapped in interface MemoryBlock
      Returns:
      true if this is either a bit-mapped or byte-mapped block
    • isLoaded Link icon

      public boolean isLoaded()
      Description copied from interface: MemoryBlock
      Returns true if this memory block is a real loaded block (i.e. RAM) and not a special block containing file header data such as debug sections.
      Specified by:
      isLoaded in interface MemoryBlock
      Returns:
      true if this is a loaded block and not a "special" block such as a file header.
    • getSourceInfos Link icon

      public List<MemoryBlockSourceInfo> getSourceInfos()
      Description copied from interface: MemoryBlock
      Returns a list of MemoryBlockSourceInfo objects for this block. A block may consist of multiple sequences of bytes from different sources. Each such source of bytes is described by its respective SourceInfo object. Blocks may have multiple sources after two or more memory blocks have been joined together and the underlying byte sources can't be joined.
      Specified by:
      getSourceInfos in interface MemoryBlock
      Returns:
      a list of SourceInfo objects, one for each different source of bytes in this block.