Class ByteInterval

  • All Implemented Interfaces:
    TreeListItem

    public final class ByteInterval
    extends Node
    implements TreeListItem
    A ByteInterval represents a piece of runtime memory. The ByteInterval class has a size and can store contents as a byte array, Not having a byte array, or having one with a size smaller than the ByteInterval size is allowed, generally this would represent uninitialized memory. The byte blocks (code blocks and data blocks) and symbolic expressions attached to a byte interval reference the memory range it contains, and it may or may not have an assigned address at any one time.
    • Constructor Detail

      • ByteInterval

        public ByteInterval​(byte[] bytes,
                            long address)
        Class Constructor.
        Parameters:
        bytes - The array of bytes to be stored in the ByteInterval.
        address - The address of the ByteInterval.
      • ByteInterval

        public ByteInterval​(long size)
        Class Constructor.
        Parameters:
        size - The size of the new ByteInterval.
      • ByteInterval

        public ByteInterval()
        Class Constructor.
    • Method Detail

      • getAddress

        public java.util.OptionalLong getAddress()
        Get the address of this ByteInterval.
        Returns:
        An OptionalLong that either is empty or holds a valid address.
      • setAddress

        public void setAddress​(long address)
        Set the address of this ByteInterval.
        Parameters:
        address - The new address to give to this ByteInterval
      • clearAddress

        public void clearAddress()
        Clears the address of this ByteInterval.
      • hasAddress

        public boolean hasAddress()
        Check that this ByteInterval has an address.
        Returns:
        true if this ByteInterval has an address; false otherwise.
      • getBlockList

        public java.util.List<ByteBlock> getBlockList()
        Get the blocks of this ByteInterval.
        Returns:
        An unmodifiable ByteBlock list of all the blocks in this ByteInterval.
      • getSize

        public long getSize()
        Get the size of this ByteBlock.
        Specified by:
        getSize in interface TreeListItem
        Returns:
        The number of bytes assigned to this ByteInterval.
      • setSize

        public void setSize​(long size)
        Set the size of this ByteInterval. If the new size is less than the actual bytes, the byte array will be truncated to the new length.
        Parameters:
        size - The new size to give to this ByteInterval.
      • getBytes

        public byte[] getBytes()
        Get the byte array of this ByteInterval.
        Returns:
        The array of bytes belonging to this ByteInterval.
      • setBytes

        public void setBytes​(byte[] bytes)
        Set the byte array of this ByteInterval.
        Parameters:
        bytes - The new byte array to give to this ByteInterval.
      • getInitializedSize

        public long getInitializedSize()
        Get the size of this ByteBlock.
        Returns:
        The number of bytes actually stored in this ByteInterval.
      • getSection

        public java.util.Optional<Section> getSection()
        Get the section this ByteInterval belongs to.
        Returns:
        The Section that this ByteInterval belongs to, or null if it does not belong to any section.
      • getIndex

        public long getIndex()
        Get the index to manage this ByteInterval with. This is the index is used for storing and retrieving the ByteInterval, as required by the TreeListItem interface. ByteIntervals are ordered by address, so this method just returns the address.
        Specified by:
        getIndex in interface TreeListItem
        Returns:
        The ByteInterval index, which is it's address.
      • insertByteBlock

        public java.util.List<ByteBlock> insertByteBlock​(ByteBlock block)
        Insert a block into this ByteInterval. The Block must already have an offset. This will be used to determine where to insert it.
        Parameters:
        block - The ByteBlock to add to this ByteInterval.
        Returns:
        An updated list of blocks at this offset, or null if the insert fails.
      • removeByteBlock

        public boolean removeByteBlock​(ByteBlock block)
        Remove a block from this ByteInterval.
        Parameters:
        block - The ByteBlock to add to this ByteInterval.
        Returns:
        boolean true if the byte interval contained the block, and it was removed.
      • findBlocksAtOffset

        public java.util.List<ByteBlock> findBlocksAtOffset​(long offset)
        Get all ByteBlocks at an offset.
        Parameters:
        offset - The offset of this ByteBlock from the beginning of the ByteInterval.
        Returns:
        A list of blocks at this offset, or null if none.
      • byteBlockIterator

        public java.util.Iterator<ByteBlock> byteBlockIterator()
        Get a ByteBlock iterator.
        Returns:
        An iterator for iterating through all the blocks in this ByteInterval.
      • findCodeBlocksOn

        public java.util.List<CodeBlock> findCodeBlocksOn​(long address)
        Find all the blocks that have bytes that lie within the address specified.
        Parameters:
        address - The address to look for.
        Returns:
        A list of Code Blocks that intersect this address, or null if none.
      • findCodeBlocksOn

        public java.util.List<CodeBlock> findCodeBlocksOn​(long startAddress,
                                                          long endAddress)
        Find all the code blocks that have bytes that lie within the addresses specified.
        Parameters:
        startAddress - The beginning of the address range to look for. (inclusive)
        endAddress - The last address of the address range to look for. (exclusive)
        Returns:
        A list of Code Blocks that intersect this address range, or null if none.
      • findCodeBlocksAt

        public java.util.List<CodeBlock> findCodeBlocksAt​(long address)
        Find all the code blocks that start at an address.
        Parameters:
        address - The address to look for.
        Returns:
        A list of Code Blocks that that start at this address, or null if none.
      • findCodeBlocksAt

        public java.util.List<CodeBlock> findCodeBlocksAt​(long startAddress,
                                                          long endAddress)
        Find all the code blocks that start between a range of addresses.
        Parameters:
        startAddress - The beginning of the address range to look for. (inclusive)
        endAddress - The last address in the address range to look for. (exclusive)
        Returns:
        A list of Code Blocks that that start at this address, or null if none.
      • findDataBlocksOn

        public java.util.List<DataBlock> findDataBlocksOn​(long address)
        Find all the data blocks that have bytes that lie within the address specified
        Parameters:
        address - The address to look for.
        Returns:
        A list of Data Blocks that intersect this address, or null if none.
      • findDataBlocksOn

        public java.util.List<DataBlock> findDataBlocksOn​(long startAddress,
                                                          long endAddress)
        Find all the data blocks that have bytes that lie within the address range specified
        Parameters:
        startAddress - The beginning of the address range to look for. (inclusive)
        endAddress - The last address of the address range to look for. (exclusive)
        Returns:
        A list of Data Blocks that intersect this address range, or null if none.
      • findDataBlocksAt

        public java.util.List<DataBlock> findDataBlocksAt​(long address)
        Find all the data blocks that start at an address.
        Parameters:
        address - The address to look for.
        Returns:
        A list of Data Blocks that that start at this address, or null if none.
      • findDataBlocksAt

        public java.util.List<DataBlock> findDataBlocksAt​(long startAddress,
                                                          long endAddress)
        Find all the data blocks that start between a range of addresses.
        Parameters:
        startAddress - The beginning of the address range to look for. (inclusive)
        endAddress - The last address in the address to look for. (exclusive)
        Returns:
        A list of Data Blocks that that start at this address, or null if none.
      • insertSymbolicExpression

        public void insertSymbolicExpression​(long offset,
                                             SymbolicExpression symbolicExpression)
        Insert a symbolic expression into this ByteInterval.
        Parameters:
        offset - The offset within this ByteInterval at which the address described by this Symbolic Expression belongs; not to be confused with the symbol-relative offset that may be part of a SymAddrConst.
        symbolicExpression - The SymbolicExpression to add to this ByteInterval.
      • removeSymbolicExpression

        public boolean removeSymbolicExpression​(long offset)
        Remove a symbolic expression from this byte interval.
        Parameters:
        offset - The offset within this ByteInterval of the SymbolicExpression.
        Returns:
        boolean true if the byte interval contained the symbolic expression, and it was removed.
      • symbolicExpressionIterator

        public java.util.Iterator<java.util.Map.Entry<java.lang.Long,​SymbolicExpression>> symbolicExpressionIterator()
        Get a SymbolicExpression iterator.
        Returns:
        An iterator for iterating through the symbolic expressions in this ByteInterval. Each value returned by the iterator is a of type Map.Entry<Long, SymbolicExpression>, where the key is the offset of the SymbolicExpression in the ByteInterval.
      • findSymbolicExpressionAt

        public SymbolicExpression findSymbolicExpressionAt​(long address)
        Find all the symbolic expressions that start at an address. Note that only one symbolic expression can be at any given offset, so this will return at most one SymbolicExpression.
        Parameters:
        address - The address to look for.
        Returns:
        A Symbolic Expression at this address, or null if none.
      • findSymbolicExpressionsAt

        public java.util.Iterator<java.util.Map.Entry<java.lang.Long,​SymbolicExpression>> findSymbolicExpressionsAt​(long startAddress,
                                                                                                                          long endAddress)
        Find all the symbolic expressions that start between a range of addresses.
        Parameters:
        startAddress - The beginning of the address range to look for. (inclusive)
        endAddress - The last address in the address to look for. (exlusive)
        Returns:
        An iterator of the set of SymbolicExpressions found, if any, as Map entries, where the key is the offset of the SymbolicExpression in the ByteInterval.
      • toProtobuf

        public com.grammatech.gtirb.proto.ByteIntervalOuterClass.ByteInterval.Builder toProtobuf()
        Serialize this ByteInterval into a protobuf .
        Returns:
        ByteInterval protocol buffer.