Package ghidra.program.model.block

# Class CodeBlockImpl

java.lang.Object
ghidra.program.model.block.CodeBlockImpl

All Implemented Interfaces:
  `AddressSetView`, `CodeBlock`, `Iterable<AddressRange>`

public class CodeBlockImpl extends Object implements CodeBlock
CodeBlockImpl is an implementation of a CodeBlock. These are produced by a particular CodeBlockModel and are associated with only that model. Most methods simply delegate any work that is specific to a particular CodeBlockModel to that model.

See Also:
  - `CodeBlock`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `CodeBlockImpl(CodeBlockModel model, Address[] starts, AddressSetView body)`
  Construct a multi-entry CodeBlock associated with a CodeBlockModel.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `contains(Address a)`
  Test if the address is contained within this set.
  `boolean`
  `contains(Address start, Address end)`
  Test if the given address range is contained in this set.
  `boolean`
  `contains(AddressSetView rangeSet)`
  Test if the given address set is a subset of this set.
  `boolean`
  `equals(Object obj)`
  `Address`
  `findFirstAddressInCommon(AddressSetView otherSet)`
  Finds the first address in this collection that is also in the given addressSet.
  `AddressIterator`
  `getAddresses(boolean forward)`
  Returns an iterator over all addresses in this set.
  `AddressIterator`
  `getAddresses(Address start, boolean forward)`
  Returns an iterator over the addresses in this address set starting at the start address
  `AddressRangeIterator`
  `getAddressRanges()`
  `AddressRangeIterator`
  `getAddressRanges(boolean startAtFront)`
  Returns an iterator over the ranges in the specified order
  `AddressRangeIterator`
  `getAddressRanges(Address start, boolean forward)`
  Returns an iterator of address ranges starting with the range that contains the given address.
  `CodeBlockReferenceIterator`
  `getDestinations(TaskMonitor monitor)`
  Get an Iterator over the CodeBlocks that are flowed to from this CodeBlock.
  `AddressRange`
  `getFirstRange()`
  Returns the first range in this set or null if the set is empty
  `Address`
  `getFirstStartAddress()`
  Return the first start address of the CodeBlock.
  `FlowType`
  `getFlowType()`
  Return, in theory, how things flow out of this node.
  `AddressRange`
  `getLastRange()`
  Returns the last range in this set or null if the set is empty
  `Address`
  `getMaxAddress()`
  Get the maximum address for this address set.
  `Address`
  `getMinAddress()`
  Get the minimum address for this address set.
  `CodeBlockModel`
  `getModel()`
  Get the model instance which was used to generate this block.
  `String`
  `getName()`
  Return the name of the block.
  `long`
  `getNumAddresses()`
  `int`
  `getNumAddressRanges()`
  `int`
  `getNumDestinations(TaskMonitor monitor)`
  Get the number of CodeBlocks this block flows to.
  `int`
  `getNumSources(TaskMonitor monitor)`
  Get the number of CodeBlocks that flow into this CodeBlock.
  `AddressRange`
  `getRangeContaining(Address address)`
  Returns the range that contains the given address
  `CodeBlockReferenceIterator`
  `getSources(TaskMonitor monitor)`
  Get an Iterator over the CodeBlocks that flow into this CodeBlock.
  `Address[]`
  `getStartAddresses()`
  Get all the entry points to this block.
  `int`
  `hashCode()`
  `boolean`
  `hasSameAddresses(AddressSetView view)`
  Returns true if the given address set contains the same set of addresses as this set.
  `AddressSet`
  `intersect(AddressSetView view)`
  Computes the intersection of this address set with the given address set.
  `AddressSet`
  `intersectRange(Address start, Address end)`
  Computes the intersection of this address set with the given address range.
  `boolean`
  `intersects(Address start, Address end)`
  Determine if the start and end range intersects with the specified address set.
  `boolean`
  `intersects(AddressSetView addrSet)`
  Determine if this address set intersects with the specified address set.
  `boolean`
  `isEmpty()`
  `Iterator<AddressRange>`
  `iterator()`
  Returns an iterator over the address ranges in this address set.
  `Iterator<AddressRange>`
  `iterator(boolean forward)`
  Returns an iterator over the ranges in the specified order
  `Iterator<AddressRange>`
  `iterator(Address start, boolean forward)`
  Returns an iterator of address ranges starting with the range that contains the given address.
  `AddressSet`
  `subtract(AddressSetView addrSet)`
  Computes the difference of this address set with the given address set (this - set).
  `String`
  `toString()`
  `AddressSet`
  `union(AddressSetView addrSet)`
  Computes the union of this address set with the given address set.
  `AddressSet`
  `xor(AddressSetView addrSet)`
  Computes the exclusive-or of this address set with the given set.

  ### Methods inherited from class java.lang.Object

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

  ### Methods inherited from interface ghidra.program.model.address.AddressSetView

  `getAddressCountBefore, spliterator, spliterator, spliterator, stream, stream, stream`

  ### Methods inherited from interface java.lang.Iterable

  `forEach`

- ## Constructor Details

  - ### CodeBlockImpl

    public CodeBlockImpl(CodeBlockModel model, Address[] starts, AddressSetView body)
    Construct a multi-entry CodeBlock associated with a CodeBlockModel. The significance of the start Addresses is model dependent.
    Parameters:
      `model` - the model instance which produced this block.
      `starts` - the entry points for the block. Any of these addresses may be used to identify this block within the model that produced it.
      `body` - the address set which makes-up the body of this block.

- ## Method Details

  - ### getFirstStartAddress

    public Address getFirstStartAddress()
    Description copied from interface: `CodeBlock`
    Return the first start address of the CodeBlock. Depending on the model used to generate the CodeBlock, there may be multiple entry points to the block. This will return the first start address for the block. It should always return the same address for a given block if there is more than one entry point.
    Specified by:
      `getFirstStartAddress` in interface `CodeBlock`
    Returns:
      the first start address of the block.
    See Also:
      - `CodeBlock.getFirstStartAddress()`

  - ### getStartAddresses

    public Address[] getStartAddresses()
    Description copied from interface: `CodeBlock`
    Get all the entry points to this block. Depending on the model, there may be more than one entry point. Entry points will be returned in natural sorted order.
    Specified by:
      `getStartAddresses` in interface `CodeBlock`
    Returns:
      an array of entry points to this block. a zero length array if there are no entry points.
    See Also:
      - `CodeBlock.getStartAddresses()`

  - ### getName

    public String getName()
    Description copied from interface: `CodeBlock`
    Return the name of the block.
    Specified by:
      `getName` in interface `CodeBlock`
    Returns:
      name of block, normally the symbol at the starting address
    See Also:
      - `CodeBlock.getName()`

  - ### getFlowType

    public FlowType getFlowType()
    Description copied from interface: `CodeBlock`
    Return, in theory, how things flow out of this node. If there are any abnormal ways to flow out of this node, (ie: jump, call, etc...) then the flow type of the node takes on that type. If there are multiple unique ways out of the node, then we should return FlowType.UNKNOWN. Fallthrough is returned if that is the only way out.
    Specified by:
      `getFlowType` in interface `CodeBlock`
    Returns:
      flow type of this node
    See Also:
      - `CodeBlock.getFlowType()`

  - ### getNumSources

    public int getNumSources(TaskMonitor monitor) throws CancelledException
    Description copied from interface: `CodeBlock`
    Get the number of CodeBlocks that flow into this CodeBlock. Note that this is almost as much work as getting the actual source references.
    Specified by:
      `getNumSources` in interface `CodeBlock`
    Parameters:
      `monitor` - task monitor which allows user to cancel operation.
    Returns:
      number of source CodeBlocks.
    Throws:
      `CancelledException` - if the monitor cancels the operation.
    See Also:
      - `CodeBlock.getNumSources(ghidra.util.task.TaskMonitor)`

  - ### getSources

    public CodeBlockReferenceIterator getSources(TaskMonitor monitor) throws CancelledException
    Description copied from interface: `CodeBlock`
    Get an Iterator over the CodeBlocks that flow into this CodeBlock.
    Specified by:
      `getSources` in interface `CodeBlock`
    Parameters:
      `monitor` - task monitor which allows user to cancel operation.
    Returns:
      An iterator over CodeBlocks referencing this Block.
    Throws:
      `CancelledException` - if the monitor cancels the operation.
    See Also:
      - `CodeBlock.getSources(ghidra.util.task.TaskMonitor)`

  - ### getNumDestinations

    public int getNumDestinations(TaskMonitor monitor) throws CancelledException
    Description copied from interface: `CodeBlock`
    Get the number of CodeBlocks this block flows to. Note that this is almost as much work as getting the actual destination references.
    Specified by:
      `getNumDestinations` in interface `CodeBlock`
    Parameters:
      `monitor` - task monitor which allows user to cancel operation.
    Returns:
      number of destination CodeBlocks.
    Throws:
      `CancelledException` - if the monitor cancels the operation.
    See Also:
      - `CodeBlock.getNumDestinations(ghidra.util.task.TaskMonitor)`

  - ### getDestinations

    public CodeBlockReferenceIterator getDestinations(TaskMonitor monitor) throws CancelledException
    Description copied from interface: `CodeBlock`
    Get an Iterator over the CodeBlocks that are flowed to from this CodeBlock.
    Specified by:
      `getDestinations` in interface `CodeBlock`
    Parameters:
      `monitor` - task monitor which allows user to cancel operation.
    Returns:
      An iterator over CodeBlocks referred to by this Block.
    Throws:
      `CancelledException` - if the monitor cancels the operation.
    See Also:
      - `CodeBlock.getDestinations(ghidra.util.task.TaskMonitor)`

  - ### getModel

    public CodeBlockModel getModel()
    Description copied from interface: `CodeBlock`
    Get the model instance which was used to generate this block.
    Specified by:
      `getModel` in interface `CodeBlock`
    Returns:
      the model used to build this CodeBlock
    See Also:
      - `CodeBlock.getModel()`

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`
    See Also:
      - `Object.toString()`

  - ### contains

    public boolean contains(Address a)
    Description copied from interface: `AddressSetView`
    Test if the address is contained within this set.
    Specified by:
      `contains` in interface `AddressSetView`
    Parameters:
      `a` - address to test.
    Returns:
      true if addr exists in the set, false otherwise.
    See Also:
      - `AddressSetView.contains(ghidra.program.model.address.Address)`

  - ### contains

    public boolean contains(Address start, Address end)
    Description copied from interface: `AddressSetView`
    Test if the given address range is contained in this set.

    The specified start and end addresses must form a valid range within a single `AddressSpace`.

    Specified by:
      `contains` in interface `AddressSetView`
    Parameters:
      `start` - the first address in the range.
      `end` - the last address in the range.
    Returns:
      true if entire range is contained within the set, false otherwise.
    See Also:
      - `AddressSetView.contains(ghidra.program.model.address.Address, ghidra.program.model.address.Address)`

  - ### contains

    public boolean contains(AddressSetView rangeSet)
    Description copied from interface: `AddressSetView`
    Test if the given address set is a subset of this set.
    Specified by:
      `contains` in interface `AddressSetView`
    Parameters:
      `rangeSet` - the set to test.
    Returns:
      true if the entire set is contained within this set, false otherwise.
    See Also:
      - `AddressSetView.contains(ghidra.program.model.address.AddressSetView)`

  - ### intersects

    public boolean intersects(Address start, Address end)
    Description copied from interface: `AddressSetView`
    Determine if the start and end range intersects with the specified address set.

    The specified start and end addresses must form a valid range within a single `AddressSpace`.

    Specified by:
      `intersects` in interface `AddressSetView`
    Parameters:
      `start` - start of range
      `end` - end of range
    Returns:
      true if the given range intersects this address set.
    See Also:
      - `AddressSetView.intersects(ghidra.program.model.address.Address, ghidra.program.model.address.Address)`

  - ### intersects

    public boolean intersects(AddressSetView addrSet)
    Description copied from interface: `AddressSetView`
    Determine if this address set intersects with the specified address set.
    Specified by:
      `intersects` in interface `AddressSetView`
    Parameters:
      `addrSet` - address set to check intersection with.
    Returns:
      true if this set intersects the specified addrSet else false
    See Also:
      - `AddressSetView.intersects(ghidra.program.model.address.AddressSetView)`

  - ### intersect

    public AddressSet intersect(AddressSetView view)
    Description copied from interface: `AddressSetView`
    Computes the intersection of this address set with the given address set.

    This method does not modify this address set.

    Specified by:
      `intersect` in interface `AddressSetView`
    Parameters:
      `view` - the address set to intersect with.
    Returns:
      AddressSet a new address set that contains all addresses that are contained in both this set and the given set.
    See Also:
      - `AddressSetView.intersect(ghidra.program.model.address.AddressSetView)`

  - ### intersectRange

    public AddressSet intersectRange(Address start, Address end)
    Description copied from interface: `AddressSetView`
    Computes the intersection of this address set with the given address range.

    This method does not modify this address set. The specified start and end addresses must form a valid range within a single `AddressSpace`.

    Specified by:
      `intersectRange` in interface `AddressSetView`
    Parameters:
      `start` - start of range
      `end` - end of range
    Returns:
      AddressSet a new address set that contains all addresses that are contained in both this set and the given range.
    See Also:
      - `AddressSetView.intersectRange(ghidra.program.model.address.Address, ghidra.program.model.address.Address)`

  - ### union

    public AddressSet union(AddressSetView addrSet)
    Description copied from interface: `AddressSetView`
    Computes the union of this address set with the given address set.

    This method does not change this address set.

    Specified by:
      `union` in interface `AddressSetView`
    Parameters:
      `addrSet` - The address set to be unioned with this address set.
    Returns:
      AddressSet A new address set which contains all the addresses from both this set and the given set.
    See Also:
      - `AddressSetView.union(ghidra.program.model.address.AddressSetView)`

  - ### xor

    public AddressSet xor(AddressSetView addrSet)
    Description copied from interface: `AddressSetView`
    Computes the exclusive-or of this address set with the given set.

    This method does not modify this address set.

    Specified by:
      `xor` in interface `AddressSetView`
    Parameters:
      `addrSet` - address set to exclusive-or with.
    Returns:
      AddressSet a new address set containing all addresses that are in either this set or the given set, but not in both sets
    See Also:
      - `AddressSetView.xor(ghidra.program.model.address.AddressSetView)`

  - ### subtract

    public AddressSet subtract(AddressSetView addrSet)
    Description copied from interface: `AddressSetView`
    Computes the difference of this address set with the given address set (this - set).

    Note that this is not the same as (set - this). This method does not change this address set.

    Specified by:
      `subtract` in interface `AddressSetView`
    Parameters:
      `addrSet` - the set to subtract from this set.
    Returns:
      AddressSet a new address set which contains all the addresses that are in this set, but not in the given set.
    See Also:
      - `AddressSetView.subtract(ghidra.program.model.address.AddressSetView)`

  - ### isEmpty

    public boolean isEmpty()
    Specified by:
      `isEmpty` in interface `AddressSetView`
    Returns:
      true if this set is empty.
    See Also:
      - `AddressSetView.isEmpty()`

  - ### getMinAddress

    public Address getMinAddress()
    Description copied from interface: `AddressSetView`
    Get the minimum address for this address set.

    NOTE: An `AddressRange` should generally not be formed using this address and `AddressSetView.getMaxAddress()` since it may span multiple `AddressSpace`s.

    Specified by:
      `getMinAddress` in interface `AddressSetView`
    Returns:
      the minimum address for this set. Returns null if the set is empty.
    See Also:
      - `AddressSetView.getMinAddress()`

  - ### getMaxAddress

    public Address getMaxAddress()
    Description copied from interface: `AddressSetView`
    Get the maximum address for this address set.

    NOTE: An `AddressRange` should generally not be formed using this address and `AddressSetView.getMaxAddress()` since it may span multiple `AddressSpace`s.

    Specified by:
      `getMaxAddress` in interface `AddressSetView`
    Returns:
      the maximum address for this set. Returns null if the set is empty.
    See Also:
      - `AddressSetView.getMaxAddress()`

  - ### getNumAddressRanges

    public int getNumAddressRanges()
    Specified by:
      `getNumAddressRanges` in interface `AddressSetView`
    Returns:
      the number of address ranges in this set.
    See Also:
      - `AddressSetView.getNumAddressRanges()`

  - ### getAddressRanges

    public AddressRangeIterator getAddressRanges()
    Specified by:
      `getAddressRanges` in interface `AddressSetView`
    Returns:
      an iterator over the address ranges in this address set.
    See Also:
      - `AddressSetView.getAddressRanges()`

  - ### iterator

    public Iterator<AddressRange> iterator()
    Description copied from interface: `AddressSetView`
    Returns an iterator over the address ranges in this address set.
    Specified by:
      `iterator` in interface `AddressSetView`
    Specified by:
      `iterator` in interface `Iterable<AddressRange>`

  - ### getNumAddresses

    public long getNumAddresses()
    Specified by:
      `getNumAddresses` in interface `AddressSetView`
    Returns:
      the number of addresses in this set.
    See Also:
      - `AddressSetView.getNumAddresses()`

  - ### getAddresses

    public AddressIterator getAddresses(boolean forward)
    Description copied from interface: `AddressSetView`
    Returns an iterator over all addresses in this set.
    Specified by:
      `getAddresses` in interface `AddressSetView`
    Parameters:
      `forward` - if true the address are return in increasing order, otherwise in decreasing order.
    Returns:
      an iterator over all addresses in this set.
    See Also:
      - `AddressSetView.getAddresses(boolean)`

  - ### getAddresses

    public AddressIterator getAddresses(Address start, boolean forward)
    Description copied from interface: `AddressSetView`
    Returns an iterator over the addresses in this address set starting at the start address
    Specified by:
      `getAddresses` in interface `AddressSetView`
    Parameters:
      `start` - address to start iterating at in the address set
      `forward` - if true address are return from lowest to highest, else from highest to lowest
    Returns:
      an iterator over the addresses in this address set starting at the start address
    See Also:
      - `AddressSetView.getAddresses(ghidra.program.model.address.Address, boolean)`

  - ### hasSameAddresses

    public boolean hasSameAddresses(AddressSetView view)
    Description copied from interface: `AddressSetView`
    Returns true if the given address set contains the same set of addresses as this set.
    Specified by:
      `hasSameAddresses` in interface `AddressSetView`
    Parameters:
      `view` - the address set to compare.
    Returns:
      true if the given set contains the same addresses as this set.
    See Also:
      - `AddressSetView.hasSameAddresses(ghidra.program.model.address.AddressSetView)`

  - ### equals

    public boolean equals(Object obj)
    Overrides:
      `equals` in class `Object`
    See Also:
      - `Object.equals(java.lang.Object)`

  - ### getAddressRanges

    public AddressRangeIterator getAddressRanges(boolean startAtFront)
    Description copied from interface: `AddressSetView`
    Returns an iterator over the ranges in the specified order
    Specified by:
      `getAddressRanges` in interface `AddressSetView`
    Parameters:
      `startAtFront` - the ranges are returned from lowest to highest, otherwise from highest to lowest
    Returns:
      an iterator over all the addresse ranges in the set.
    See Also:
      - `AddressSetView.getAddressRanges(boolean)`

  - ### hashCode

    public int hashCode()
    Overrides:
      `hashCode` in class `Object`
    See Also:
      - `Object.hashCode()`

  - ### getAddressRanges

    public AddressRangeIterator getAddressRanges(Address start, boolean forward)
    Description copied from interface: `AddressSetView`
    Returns an iterator of address ranges starting with the range that contains the given address.

    If there is no range containing the start address, then the first range will be the next range greater than the start address if going forward, otherwise the range less than the start address

    Specified by:
      `getAddressRanges` in interface `AddressSetView`
    Parameters:
      `start` - the address the first range should contain.
      `forward` - true iterators forward, false backwards
    Returns:
      the AddressRange iterator

  - ### getFirstRange

    public AddressRange getFirstRange()
    Description copied from interface: `AddressSetView`
    Returns the first range in this set or null if the set is empty
    Specified by:
      `getFirstRange` in interface `AddressSetView`
    Returns:
      the first range in this set or null if the set is empty

  - ### getLastRange

    public AddressRange getLastRange()
    Description copied from interface: `AddressSetView`
    Returns the last range in this set or null if the set is empty
    Specified by:
      `getLastRange` in interface `AddressSetView`
    Returns:
      the last range in this set or null if the set is empty

  - ### getRangeContaining

    public AddressRange getRangeContaining(Address address)
    Description copied from interface: `AddressSetView`
    Returns the range that contains the given address
    Specified by:
      `getRangeContaining` in interface `AddressSetView`
    Parameters:
      `address` - the address for which to find a range.
    Returns:
      the range that contains the given address.

  - ### iterator

    public Iterator<AddressRange> iterator(boolean forward)
    Description copied from interface: `AddressSetView`
    Returns an iterator over the ranges in the specified order
    Specified by:
      `iterator` in interface `AddressSetView`
    Parameters:
      `forward` - the ranges are returned from lowest to highest, otherwise from highest to lowest
    Returns:
      an iterator over all the address ranges in the set.

  - ### iterator

    public Iterator<AddressRange> iterator(Address start, boolean forward)
    Description copied from interface: `AddressSetView`
    Returns an iterator of address ranges starting with the range that contains the given address.

    If there is no range containing the start address, then the first range will be the next range greater than the start address if going forward, otherwise the range less than the start address

    Specified by:
      `iterator` in interface `AddressSetView`
    Parameters:
      `start` - the address that the first range should contain.
      `forward` - true iterators forward, false backwards
    Returns:
      the AddressRange iterator

  - ### findFirstAddressInCommon

    public Address findFirstAddressInCommon(AddressSetView otherSet)
    Description copied from interface: `AddressSetView`
    Finds the first address in this collection that is also in the given addressSet.
    Specified by:
      `findFirstAddressInCommon` in interface `AddressSetView`
    Parameters:
      `otherSet` - the addressSet to search for the first (lowest) common address.
    Returns:
      the first address that is contained in this set and the given set.