java.lang.Object
com.pnfsoftware.jeb.core.units.code.asm.analyzer.MemoryRanges

@Ser public class MemoryRanges extends Object
A collection of byte-addressable memory ranges. The final addressable byte (e.g., @ 0xFFFFFFFF in a 32-bit address space) cannot be part of any range.

This class is not thread-safe.

  • Constructor Details

    • MemoryRanges

      public MemoryRanges(int spaceBits)
      Create memory ranges for an address space width.
      Parameters:
      spaceBits - number of bits in the address space
    • MemoryRanges

      public MemoryRanges()
      Create memory ranges for a 64-bit address space.
    • MemoryRanges

      public MemoryRanges(IVirtualMemory mem)
      Create memory ranges from the allocated pages of a virtual memory object.
      Parameters:
      mem - virtual memory
  • Method Details

    • add

      public void add(long begin0, long end0)
      Add a memory range.
      Parameters:
      begin0 - start address, inclusive
      end0 - end address, exclusive
    • remove

      public void remove(long begin0, long end0)
      Remove a memory range.
      Parameters:
      begin0 - start address, inclusive
      end0 - end address, exclusive
    • clear

      public void clear()
      Remove all ranges.
    • min

      public Long min()
      Get the lowest range start address.
      Returns:
      lowest address, or null if no range is recorded
    • max

      public Long max()
      Get the highest range end address.
      Returns:
      highest exclusive end address, or null if no range is recorded
    • count

      public int count()
      Get the number of recorded ranges.
      Returns:
      range count
    • asList

      public List<Couple<Long,Long>> asList()
      Convert the MemoryRanges to a List of ranges (stored as Couple.
      Returns:
      the list of MemoryRanges
    • contains

      public boolean contains(long address)
      Indicate if an address is defined in this MemoryRanges
      Parameters:
      address - address to test
      Returns:
      true if MemoryRanges contains this address
    • intersects

      public boolean intersects(long addressStart, long addressEnd)
      Indicate if an element from range [addressStart:addressEnd[ is defined in this MemoryRanges.
      Parameters:
      addressStart - start address (inclusive)
      addressEnd - end address (exclusive)
      Returns:
      true if MemoryRanges contains at least one address from the given range
    • getLocalBegin

      public Long getLocalBegin(long address0)
      Get the start of the range containing an address.
      Parameters:
      address0 - address to look up
      Returns:
      range start address, or null if the address is not contained in a range
    • getLocalEnd

      public Long getLocalEnd(long address0)
      Get the end of the range containing an address.
      Parameters:
      address0 - address to look up
      Returns:
      range exclusive end address, or null if the address is not contained in a range
    • getNextRange

      public Couple<Long,Long> getNextRange(long address0)
      Get the first range after an address.
      Parameters:
      address0 - address to look up
      Returns:
      next range as a start/end pair, or null if none exists
    • getPreviousRange

      public Couple<Long,Long> getPreviousRange(long address0)
      Get the first range before an address.
      Parameters:
      address0 - address to look up
      Returns:
      previous range as a start/end pair, or null if none exists
    • getLocalRange

      public Couple<Long,Long> getLocalRange(long address0)
      Get the range containing an address.
      Parameters:
      address0 - address to look up
      Returns:
      containing range as a start/end pair, or null if none exists
    • spanSize

      public long spanSize()
      Get the size spanned by all ranges.
      Returns:
      distance between the lowest start and highest end, or 0 if no range is recorded
    • aggregatedRangesSize

      public long aggregatedRangesSize()
      Get the sum of all range sizes.
      Returns:
      aggregate size of all ranges
    • toString

      public String toString()
      Overrides:
      toString in class Object