Class AddressMapDB

  • All Implemented Interfaces:
    AddressMap

    public class AddressMapDB
    extends java.lang.Object
    implements AddressMap
    Class used to map addresses to longs and longs to addresses. Several different encodings are depending on the nature of the address to be converted. The upper 4 bits in the long are used to specify the encoding used. Currently the encoding are: 0 - use the original ghidra encoding - used for backwards compatibility. 1 - absolute encoding - ignores the image base - used only by the memory map. 2 - relocatable - most common encoding - allows address to move with the image base. 3 - register - used to encode register addresses 4 - stack - used to encode stack addresses (includes namespace information to make them unique between functions) 5 - external - used to encode addresses in another program 15 - no address - used to represent the null address or a meaningless address.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Address decodeAddress​(long value)
      Returns the address that was used to generate the given long key.
      Address decodeAddress​(long value, boolean useMemorySegmentation)
      Returns the address that was used to generate the given long key.
      void deleteOverlaySpace​(java.lang.String name)
      Delete the specified overlay space from this address map.
      int findKeyRange​(java.util.List<KeyRange> keyRangeList, Address addr)
      Search for addr within the "sorted" keyRangeList and return the index of the keyRange which contains the specified addr.
      long getAbsoluteEncoding​(Address addr, boolean create)
      Get the database key associated with the given absolute address.
      AddressFactory getAddressFactory()
      Returns the address factory associated with this map.
      Address getImageBase()
      Returns the current image base setting.
      long getKey​(Address addr, boolean create)
      Get the database key associated with the given relative address.
      java.util.List<KeyRange> getKeyRanges​(Address start, Address end, boolean create)
      Generates a properly ordered list of database key ranges for a a specified address range.
      java.util.List<KeyRange> getKeyRanges​(Address start, Address end, boolean absolute, boolean create)
      Generates a properly ordered list of database key ranges for a a specified address range.
      java.util.List<KeyRange> getKeyRanges​(AddressSetView set, boolean create)
      Generates a properly ordered list of database key ranges for a a specified address set.
      java.util.List<KeyRange> getKeyRanges​(AddressSetView set, boolean absolute, boolean create)
      Generates a properly ordered list of database key ranges for a a specified address set.
      int getModCount()
      Returns a modification number that always increases when the address map base table has changed.
      AddressMap getOldAddressMap()
      Returns an address map which may be used during the upgrade of old address encodings.
      boolean hasSameKeyBase​(long addrKey1, long addrKey2)
      Returns true if the two address keys share a common key base and can be used within a single key-range.
      void invalidateCache()
      Clears any cached values.
      boolean isKeyRangeMax​(long addrKey)
      Returns true if the specified addrKey is the maximum key within its key-range.
      boolean isKeyRangeMin​(long addrKey)
      Returns true if the specified addrKey is the minimum key within its key-range.
      boolean isUpgraded()
      Returns true if this address map has been upgraded.
      void memoryMapChanged​(MemoryMapDB mem)
      Notification when the memory map changes.
      void renameOverlaySpace​(java.lang.String oldName, java.lang.String newName)
      Rename an existing overlay space.
      void setImageBase​(Address base)
      Sets the image base, effectively changing the mapping between addresses and longs.
      void setLanguage​(Language newLanguage, AddressFactory addrFactory, LanguageTranslator translator)
      Converts the current base addresses to addresses compatible with the new language.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AddressMapDB

        public AddressMapDB​(DBHandle handle,
                            int openMode,
                            AddressFactory factory,
                            long baseImageOffset,
                            TaskMonitor monitor)
                     throws java.io.IOException,
                            VersionException
        Constructs a new AddressMapDB object
        Parameters:
        handle - the handle to the database
        openMode - the mode that program was opened.
        factory - the address factory containing all the address spaces for the program.
        baseImageOffset - the current image base offset.
        monitor - the progress monitory used for upgrading.
        Throws:
        java.io.IOException - thrown if a dabase io error occurs.
        VersionException - if the database version does not match the expected version.
    • Method Detail

      • memoryMapChanged

        public void memoryMapChanged​(MemoryMapDB mem)
        Notification when the memory map changes. If we are segemented, we need to update our list of address ranges used for address normalization.
        Parameters:
        memory -
      • invalidateCache

        public void invalidateCache()
                             throws java.io.IOException
        Description copied from interface: AddressMap
        Clears any cached values.
        Specified by:
        invalidateCache in interface AddressMap
        Throws:
        java.io.IOException
      • getOldAddressMap

        public AddressMap getOldAddressMap()
        Returns an address map which may be used during the upgrade of old address encodings. If the address map is up-to-date, then this method will return this instance of AddressMapDB.
        Specified by:
        getOldAddressMap in interface AddressMap
      • getKey

        public long getKey​(Address addr,
                           boolean create)
        Description copied from interface: AddressMap
        Get the database key associated with the given relative address. This key uniquely identifies a relative location within the program. If the program's image base is moved to another address, this key will map to a new address that is the same distance to the new base as the old address was to the old base. If the requested key does not exist and create is false, INVALID_ADDRESS_KEY will be returned. Note that nothing should ever be stored using the returned key unless create is true.
        Specified by:
        getKey in interface AddressMap
        Parameters:
        addr - the address for which to get a database key.
        create - true if a new key may be generated
        Returns:
        the database key for the given address or INVALID_ADDRESS_KEY if create is false and one does not exist for the specified addr.
        See Also:
        AddressMap.getKey(ghidra.program.model.address.Address, boolean)
      • getAbsoluteEncoding

        public long getAbsoluteEncoding​(Address addr,
                                        boolean create)
        Description copied from interface: AddressMap
        Get the database key associated with the given absolute address. This key uniquely identifies an absolute location within the program. If the requested key does not exist and create is false, INVALID_ADDRESS_KEY will be returned. Note that nothing should ever be stored using the returned key unless create is true.
        Specified by:
        getAbsoluteEncoding in interface AddressMap
        Parameters:
        addr - the address for which to get a database key.
        create - true if a new key may be generated
        Returns:
        the database key for the given address or INVALID_ADDRESS_KEY if create is false and one does not exist for the specified addr.
        See Also:
        AddressMap.getAbsoluteEncoding(ghidra.program.model.address.Address, boolean)
      • decodeAddress

        public Address decodeAddress​(long value)
        Description copied from interface: AddressMap
        Returns the address that was used to generate the given long key. (If the image base was moved, then a different address is returned unless the value was encoded using the "absoluteEncoding" method. If the program's default address space is segmented (i.e., SegmentedAddressSpace). the address returned will be always be normalized to defined segmented memory blocks if possible.
        Specified by:
        decodeAddress in interface AddressMap
        Parameters:
        value - the long value to convert to an address.
        See Also:
        ghidra.program.model.address.AddressMap#decodeAddress(long)
      • decodeAddress

        public Address decodeAddress​(long value,
                                     boolean useMemorySegmentation)
        Returns the address that was used to generate the given long key. (If the image base was moved, then a different address is returned unless the value was encoded using the "absoluteEncoding" method
        Parameters:
        value - the long value to convert to an address.
        useMemorySegmentation - if true and the program's default address space is segmented (i.e., SegmentedAddressSpace). the address returned will be normalized to defined segmented memory blocks if possible. This parameter should generally always be true except when used by the Memory map objects to avoid recursion problems.
      • hasSameKeyBase

        public boolean hasSameKeyBase​(long addrKey1,
                                      long addrKey2)
        Description copied from interface: AddressMap
        Returns true if the two address keys share a common key base and can be used within a single key-range.
        Specified by:
        hasSameKeyBase in interface AddressMap
      • isKeyRangeMax

        public boolean isKeyRangeMax​(long addrKey)
        Description copied from interface: AddressMap
        Returns true if the specified addrKey is the maximum key within its key-range.
        Specified by:
        isKeyRangeMax in interface AddressMap
      • isKeyRangeMin

        public boolean isKeyRangeMin​(long addrKey)
        Description copied from interface: AddressMap
        Returns true if the specified addrKey is the minimum key within its key-range.
        Specified by:
        isKeyRangeMin in interface AddressMap
      • getAddressFactory

        public AddressFactory getAddressFactory()
        Description copied from interface: AddressMap
        Returns the address factory associated with this map. Null may be returned if map not associated with a specific address factory.
        Specified by:
        getAddressFactory in interface AddressMap
        See Also:
        ghidra.program.model.address.AddressMap#getAddressFactory()
      • findKeyRange

        public int findKeyRange​(java.util.List<KeyRange> keyRangeList,
                                Address addr)
        Description copied from interface: AddressMap
        Search for addr within the "sorted" keyRangeList and return the index of the keyRange which contains the specified addr.
        Specified by:
        findKeyRange in interface AddressMap
        addr - address or null
        Returns:
        index of the keyRange within the keyRangeList which contains addr if it is contained in the list; otherwise, (-(insertion point) - 1). The insertion point is defined as the point at which the addr would be inserted into the list: the index of the first keyRange greater than addr, or keyRangeList.size(), if all keyRanges in the list are less than the specified addr. Note that this guarantees that the return value will be >= 0 if and only if the addr is found within a keyRange. An addr of null will always result in a returned index of -1.
        See Also:
        ghidra.program.model.address.AddressMap#findKeyRange(java.util.List, ghidra.program.model.address.Address)
      • getKeyRanges

        public java.util.List<KeyRange> getKeyRanges​(Address start,
                                                     Address end,
                                                     boolean create)
        Description copied from interface: AddressMap
        Generates a properly ordered list of database key ranges for a a specified address range. If absolute encodings are requested, only memory addresses will be included. Returned key ranges are generally intended for read-only operations since new keys will never be generated. The returned key ranges will correspond to those key ranges which have previously been created within the specified address range and may represent a much smaller subset of addresses within the specified range.
        Specified by:
        getKeyRanges in interface AddressMap
        Parameters:
        start - minimum address of range
        end - maximum address of range
        create - true if a new keys may be generated, otherwise returned key-ranges will be limited to those already defined.
        Returns:
        "sorted" list of KeyRange objects
        See Also:
        AddressMap.getKeyRanges(ghidra.program.model.address.Address, ghidra.program.model.address.Address, boolean)
      • getKeyRanges

        public java.util.List<KeyRange> getKeyRanges​(AddressSetView set,
                                                     boolean create)
        Description copied from interface: AddressMap
        Generates a properly ordered list of database key ranges for a a specified address set. If absolute encodings are requested, only memory addresses will be included.
        Specified by:
        getKeyRanges in interface AddressMap
        Parameters:
        set - address set or null for all real address.
        create - true if a new keys may be generated, otherwise returned key-ranges will be limited to those already defined.
        Returns:
        "sorted" list of KeyRange objects
        See Also:
        AddressMap.getKeyRanges(ghidra.program.model.address.AddressSetView, boolean)
      • getKeyRanges

        public java.util.List<KeyRange> getKeyRanges​(Address start,
                                                     Address end,
                                                     boolean absolute,
                                                     boolean create)
        Description copied from interface: AddressMap
        Generates a properly ordered list of database key ranges for a a specified address range. If absolute encodings are requested, only memory addresses will be included.
        Specified by:
        getKeyRanges in interface AddressMap
        Parameters:
        start - minimum address of range
        end - maximum address of range
        absolute - if true, absolute key encodings are returned, otherwise standard/relocatable address key encodings are returned.
        create - true if a new keys may be generated, otherwise returned key-ranges will be limited to those already defined.
        Returns:
        "sorted" list of KeyRange objects
        See Also:
        AddressMap.getKeyRanges(ghidra.program.model.address.Address, ghidra.program.model.address.Address, boolean, boolean)
      • getKeyRanges

        public java.util.List<KeyRange> getKeyRanges​(AddressSetView set,
                                                     boolean absolute,
                                                     boolean create)
        Description copied from interface: AddressMap
        Generates a properly ordered list of database key ranges for a a specified address set. If absolute encodings are requested, only memory addresses will be included.
        Specified by:
        getKeyRanges in interface AddressMap
        Parameters:
        set - address set or null for all real address.
        absolute - if true, absolute key encodings are returned, otherwise standard/relocatable address key encodings are returned.
        create - true if a new keys may be generated, otherwise returned key-ranges will be limited to those already defined.
        Returns:
        "sorted" list of KeyRange objects
        See Also:
        AddressMap.getKeyRanges(ghidra.program.model.address.AddressSetView, boolean, boolean)
      • setLanguage

        public void setLanguage​(Language newLanguage,
                                AddressFactory addrFactory,
                                LanguageTranslator translator)
                         throws java.io.IOException
        Description copied from interface: AddressMap
        Converts the current base addresses to addresses compatible with the new language.
        Specified by:
        setLanguage in interface AddressMap
        Parameters:
        newLanguage - the new language to use.
        addrFactory - the new AddressFactory.
        translator - translates address spaces from the old language to the new language.
        Throws:
        java.io.IOException
      • renameOverlaySpace

        public void renameOverlaySpace​(java.lang.String oldName,
                                       java.lang.String newName)
                                throws java.io.IOException
        Description copied from interface: AddressMap
        Rename an existing overlay space.
        Specified by:
        renameOverlaySpace in interface AddressMap
        Parameters:
        oldName - old overlay name
        newName - new overlay name (must be unique among all space names within this map)
        Throws:
        java.io.IOException
      • deleteOverlaySpace

        public void deleteOverlaySpace​(java.lang.String name)
                                throws java.io.IOException
        Description copied from interface: AddressMap
        Delete the specified overlay space from this address map.
        Specified by:
        deleteOverlaySpace in interface AddressMap
        Parameters:
        name - overlay space name (must be unique among all space names within this map)
        Throws:
        java.io.IOException