Package ghidra.app.util.viewer.util
Class AddressIndexMap
- java.lang.Object
-
- ghidra.app.util.viewer.util.AddressIndexMap
-
- Direct Known Subclasses:
AddressIndexMapConverter
public class AddressIndexMap extends java.lang.Object
This class maps a set of address ranges into a contiguous set of indexes from 0 to the total size of the address set. This is used primarily by the listing panel to simplify the display and scrolling logic. Because of the nature of the listing display, not all addresses have displayable content. For example, a closed data structure can consume thousands of addresses where only the first address has anything to display while the structure is closed. This can cause poor scrollbar behavior. To fix this, a new methodremoveUnviewableAddressRanges(AddressSet)
was added that removes those ranges from the index mapping, but the original addresses are also maintained for purposes of determining "gap" addresses (an address is a gap address if the original address set does not include its immediate predecessor.) The original addresses are also used so that this index mapping can be reset and then given a different set of address ranges to remove as not viewable. (Useful for when data is open/closed or created/deleted)
-
-
Field Summary
Fields Modifier and Type Field Description static java.math.BigInteger
DEFAULT_UNVIEWABLE_GAP_SIZE
static java.math.BigInteger
PERCENT_DIVIDER
-
Constructor Summary
Constructors Constructor Description AddressIndexMap()
Constructs an empty AddressIndexMapAddressIndexMap(AddressSetView addrSet)
Constructs an AddressIndexMap for the given address set.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Address
getAddress(java.math.BigInteger index)
Returns the i'th address in the set.AddressSet
getAddressSet(FieldSelection sel)
Returns the Address set corresponding to the set of indexesFieldSelection
getFieldSelection(AddressSetView set)
Returns a FieldSelection containing the set of indexes represented by the given address setjava.math.BigInteger
getIndex(Address addr)
Returns the index for the given address.java.math.BigInteger
getIndexAtOrAfter(Address addr)
Returns the index for the given address.java.math.BigInteger
getIndexCount()
Returns the total number of addressesAddressSetView
getIndexedAddressSet()
Returns the total set of addresses in this index mapping (not including those that have been closed)java.math.BigInteger
getMaxIndex(Address addr)
Returns the the maximum address for the range containing the given address.java.math.BigInteger
getMinIndex(Address addr)
Returns the the minimum address for the range containing the given address.java.math.BigInteger
getMiniumUnviewableGapSize()
Returns the suggested minimum size of address ranges that contain no viewable code units (i.e.AddressSetView
getOriginalAddressSet()
Returns the total set of addresses in this map include addresses that have been closedboolean
isGapAddress(Address address)
Returns true if the given address is the first address after gap of missing addresses.boolean
isGapIndex(java.math.BigInteger index)
Returns true if address of the given index is not the successor of the previous index's address.void
removeUnviewableAddressRanges(AddressSet addressSet)
Removes the given addresses from the set of addresses that get mapped into indexes.AddressIndexMap
reset()
Resets the mapping to the entire original address set.
-
-
-
Constructor Detail
-
AddressIndexMap
public AddressIndexMap()
Constructs an empty AddressIndexMap
-
AddressIndexMap
public AddressIndexMap(AddressSetView addrSet)
Constructs an AddressIndexMap for the given address set.- Parameters:
addrSet
- the address set to index.
-
-
Method Detail
-
getIndexCount
public java.math.BigInteger getIndexCount()
Returns the total number of addresses- Returns:
- the number of addresses in the view
-
isGapIndex
public boolean isGapIndex(java.math.BigInteger index)
Returns true if address of the given index is not the successor of the previous index's address.- Parameters:
index
- the index to test for gap in the address set.- Returns:
- true if the given index represents the first address after a gap in the address set.
-
isGapAddress
public boolean isGapAddress(Address address)
Returns true if the given address is the first address after gap of missing addresses.- Parameters:
address
- the address to check for being a gap address- Returns:
- true if the given address is the first address after gap of missing addresses.
-
getAddress
public Address getAddress(java.math.BigInteger index)
Returns the i'th address in the set.- Parameters:
index
- the index of the address to retrieve.- Returns:
- the address associated with the given index
-
getIndex
public java.math.BigInteger getIndex(Address addr)
Returns the index for the given address. If the address is not mapped, null will be returned- Parameters:
addr
- the address for which to retrieve the index.- Returns:
- the index associated with the given address.
-
getIndexAtOrAfter
public java.math.BigInteger getIndexAtOrAfter(Address addr)
Returns the index for the given address. If the address is not mapped, the result is defined as follows: if the address is less than the smallest address in the map, then null is returned if the address is greater the the largest address in the map, then a value one bigger than the index of the largest address in the map. if the address is in a "gap", then the index of the next largest address that is in the map is returned.- Parameters:
addr
- the address for which to retrieve the index.- Returns:
- the associated index for the given address or if there is none, then the index of then next address greater than the given address or null if there is none.
-
getAddressSet
public AddressSet getAddressSet(FieldSelection sel)
Returns the Address set corresponding to the set of indexes- Parameters:
sel
- the FieldSelection containing the set of indexes to include.- Returns:
- the AddressSet for the given field selection.
-
getFieldSelection
public FieldSelection getFieldSelection(AddressSetView set)
Returns a FieldSelection containing the set of indexes represented by the given address set- Parameters:
set
- the set of addresses to convert into a set of indexes.- Returns:
- a FieldSelection for the given address set.
-
getOriginalAddressSet
public AddressSetView getOriginalAddressSet()
Returns the total set of addresses in this map include addresses that have been closed- Returns:
- the total set of addresses in the map including addresses that have been closed
-
getIndexedAddressSet
public AddressSetView getIndexedAddressSet()
Returns the total set of addresses in this index mapping (not including those that have been closed)- Returns:
- the total set of addresses in this index mapping (not including those that have been closed)
-
getMaxIndex
public java.math.BigInteger getMaxIndex(Address addr)
Returns the the maximum address for the range containing the given address.- Parameters:
addr
- the address to find its containing range's max address.- Returns:
- the the maximum address for the range containing the given address.
-
getMinIndex
public java.math.BigInteger getMinIndex(Address addr)
Returns the the minimum address for the range containing the given address.- Parameters:
addr
- the address to find its containing range's min address.- Returns:
- the the minimum address for the range containing the given address.
-
removeUnviewableAddressRanges
public void removeUnviewableAddressRanges(AddressSet addressSet)
Removes the given addresses from the set of addresses that get mapped into indexes. This is used to remove large number of addresses that are contained in closed data in order to make scrollbars scroll smoothly.The original address set is maintained to determine the gap addresses and also for resetting the index map to the entire set of addresses
- Parameters:
addressSet
- the set of addresses to remove from the set of addresses that get mapped.
-
getMiniumUnviewableGapSize
public java.math.BigInteger getMiniumUnviewableGapSize()
Returns the suggested minimum size of address ranges that contain no viewable code units (i.e. collapsed data). Ranges larger that this should be removed from the index mapping to get better scrollbar behavior. Currently this is 1% of the total viewed address space.- Returns:
- the suggested minimum size for a range of addresses with no viewable content.
-
reset
public AddressIndexMap reset()
Resets the mapping to the entire original address set.
-
-