Class ProgramDB

    • Field Detail

      • ANALYSIS_OPTIONS_MOVED_VERSION

        public static final int ANALYSIS_OPTIONS_MOVED_VERSION
        Key version numbers which require special upgrade handling
        See Also:
        Constant Field Values
      • ADDED_VARIABLE_STORAGE_MANAGER_VERSION

        public static final int ADDED_VARIABLE_STORAGE_MANAGER_VERSION
        See Also:
        Constant Field Values
      • EXTERNAL_FUNCTIONS_ADDED_VERSION

        public static final int EXTERNAL_FUNCTIONS_ADDED_VERSION
        See Also:
        Constant Field Values
      • COMPOUND_VARIABLE_STORAGE_ADDED_VERSION

        public static final int COMPOUND_VARIABLE_STORAGE_ADDED_VERSION
        See Also:
        Constant Field Values
      • AUTO_PARAMETERS_ADDED_VERSION

        public static final int AUTO_PARAMETERS_ADDED_VERSION
        See Also:
        Constant Field Values
    • Constructor Detail

      • ProgramDB

        public ProgramDB​(java.lang.String name,
                         Language language,
                         CompilerSpec compilerSpec,
                         java.lang.Object consumer)
                  throws java.io.IOException
        Constructs a new ProgramDB
        Parameters:
        name - the name of the program
        languageSuperFacade - the Language used by this program
        consumer - the object that is using this program.
        Throws:
        java.io.IOException - if there is an error accessing the database.
      • ProgramDB

        public ProgramDB​(DBHandle dbh,
                         int openMode,
                         TaskMonitor monitor,
                         java.lang.Object consumer)
                  throws java.io.IOException,
                         VersionException,
                         LanguageNotFoundException,
                         CancelledException
        Constructs a new ProgramDB
        Parameters:
        dbh - a handle to an open program database.
        userDbh - a handle to the associated user data
        service - the LanguageService that will provide that language object once the name of the language is retrieved from the database.
        openMode - one of: READ_ONLY: the original database will not be modified UPDATE: the database can be written to. UPGRADE: the database is upgraded to the latest schema as it is opened.
        monitor - TaskMonitor that allows the open to be canceled.
        consumer - the object that keeping the program open.
        Throws:
        java.io.IOException - if an error accessing the database occurs.
        VersionException - if database version does not match implementation, UPGRADE may be possible.
        CancelledException - if instantiation is canceled by monitor
        LanguageNotFoundException
    • Method Detail

      • getNamespaceManager

        public NamespaceManager getNamespaceManager()
        returns the namespace manager
      • getCodeManager

        public CodeManager getCodeManager()
        Returns the CodeManager
      • getTreeManager

        public TreeManager getTreeManager()
        Returns the TreeManager
      • getCompiler

        public java.lang.String getCompiler()
        Description copied from interface: Program
        Gets the name of the compiler believed to have been used to create this program. If the compiler hasn't been determined then "unknown" is returned.
        Specified by:
        getCompiler in interface Program
        Returns:
        name of the compiler or "unknown".
        See Also:
        Program.getCompiler()
      • setCompiler

        public void setCompiler​(java.lang.String compiler)
        Description copied from interface: Program
        Sets the name of the compiler which created this program.
        Specified by:
        setCompiler in interface Program
        Parameters:
        compiler - the name
      • getExecutablePath

        public java.lang.String getExecutablePath()
        Description copied from interface: Program
        Gets the path to the program's executable file. For example, C:\Temp\test.exe. This will allow plugins to execute the program.
        Specified by:
        getExecutablePath in interface Program
        Returns:
        String path to program's exe file
        See Also:
        Program.getExecutablePath()
      • getExecutableMD5

        public java.lang.String getExecutableMD5()
        Description copied from interface: Program
        Returns a value corresponding to the original binary file MD5 hash. May be null if program source did not correspond to a binary file.
        Specified by:
        getExecutableMD5 in interface Program
        See Also:
        Program.getExecutableMD5()
      • getExecutableSHA256

        public java.lang.String getExecutableSHA256()
        Description copied from interface: Program
        Returns a value corresponding to the original binary file SHA256 hash. May be null if program source did not correspond to a binary file.
        Specified by:
        getExecutableSHA256 in interface Program
        See Also:
        Program.getExecutableSHA256()
      • getCreationDate

        public java.util.Date getCreationDate()
        Description copied from interface: Program
        Returns the creation date of this program. If the program was created before this property existed, then Jan 1, 1970 is returned.
        Specified by:
        getCreationDate in interface Program
        Returns:
        the creation date of this program
        See Also:
        Program.getCreationDate()
      • getDefaultPointerSize

        public int getDefaultPointerSize()
        Description copied from interface: Program
        Gets the default pointer size in bytes as it may be stored within the program listing.
        Specified by:
        getDefaultPointerSize in interface Program
        Returns:
        default pointer size.
        See Also:
        ghidra.program.model.listing.Program#getDefaultStoredPointerSize()
      • getUsrPropertyManager

        public PropertyMapManager getUsrPropertyManager()
        Description copied from interface: Program
        Get the user propertyMangager stored with this program. The user property manager is used to store arbitrary address indexed information associated with the program.
        Specified by:
        getUsrPropertyManager in interface Program
        Returns:
        the user property manager.
        See Also:
        Program.getUsrPropertyManager()
      • getMinAddress

        public Address getMinAddress()
        Description copied from interface: Program
        get the program's minimum address.
        Specified by:
        getMinAddress in interface Program
        Returns:
        the program's minimum address or null if no memory blocks have been defined in the program.
        See Also:
        Program.getMinAddress()
      • getMaxAddress

        public Address getMaxAddress()
        Description copied from interface: Program
        Get the programs maximum address.
        Specified by:
        getMaxAddress in interface Program
        Returns:
        the program's maximum address or null if no memory blocks have been defined in the program.
        See Also:
        Program.getMaxAddress()
      • getAddressMap

        public AddressMap getAddressMap()
        Returns this programs address map. NOTE: This method has been dropped from the Program interface to help discourage the use of the program's address map since bad assumptions are frequently made about address keys which may not be ordered or sequential across an entire address space.
        Specified by:
        getAddressMap in interface Program
      • parseAddress

        public Address[] parseAddress​(java.lang.String addrStr)
        Description copied from interface: Program
        Return an array of Addresses that could represent the given string.
        Specified by:
        parseAddress in interface Program
        Parameters:
        addrStr - the string to parse.
        Returns:
        zero length array if addrStr is properly formatted but no matching addresses were found or if the address is improperly formatted.
        See Also:
        Program.parseAddress(java.lang.String)
      • parseAddress

        public Address[] parseAddress​(java.lang.String addrStr,
                                      boolean caseSensitive)
        Description copied from interface: Program
        Return an array of Addresses that could represent the given string.
        Specified by:
        parseAddress in interface Program
        Parameters:
        addrStr - the string to parse.
        caseSensitive - whether or not to process any addressSpace names as case sensitive.
        Returns:
        zero length array if addrStr is properly formatted but no matching addresses were found or if the address is improperly formatted.
      • dataTypeChanged

        public void dataTypeChanged​(long dataTypeID,
                                    int type,
                                    java.lang.Object oldValue,
                                    java.lang.Object newValue)
        notification the a datatype has changed
        Parameters:
        dataTypeID - the id of the datatype that changed.
        type - the type of the change (moved, renamed, etc.)
        oldValue - the old datatype.
        newValue - the new datatype.
      • dataTypeAdded

        public void dataTypeAdded​(long dataTypeID,
                                  int type,
                                  java.lang.Object oldValue,
                                  java.lang.Object newValue)
        Notification that a datatype was added.
        Parameters:
        dataTypeID - the id if the datatype that was added.
        type - should always be DATATYPE_ADDED
        oldValue - always null
        newValue - the datatype added.
      • categoryChanged

        public void categoryChanged​(long categoryID,
                                    int type,
                                    java.lang.Object oldValue,
                                    java.lang.Object newValue)
        Notification that a category was changed.
        Parameters:
        categoryID - the id of the datatype that was added.
        type - the type of changed
        oldValue - old value depends on the type.
        newValue - new value depends on the type.
      • categoryAdded

        public void categoryAdded​(long categoryID,
                                  int type,
                                  java.lang.Object oldValue,
                                  java.lang.Object newValue)
        Notification that a category was added.
        Parameters:
        categoryID - the id of the datatype that was added.
        type - the type of changed (should always be CATEGORY_ADDED)
        oldValue - always null
        newValue - new value depends on the type.
      • sourceArchiveAdded

        public void sourceArchiveAdded​(UniversalID sourceArchiveID,
                                       int type)
      • sourceArchiveChanged

        public void sourceArchiveChanged​(UniversalID sourceArchiveID,
                                         int type)
      • programTreeAdded

        public void programTreeAdded​(long id,
                                     int type,
                                     java.lang.Object oldValue,
                                     java.lang.Object newValue)
        Notification that a program tree was added.
        Parameters:
        id - the id of the program tree that was added.
        type - the type of changed
        oldValue - old value is null
        newValue - new value depends the tree that was added.
      • programTreeChanged

        public void programTreeChanged​(long id,
                                       int type,
                                       java.lang.Object affectedObj,
                                       java.lang.Object oldValue,
                                       java.lang.Object newValue)
        Notification that a program tree was changed.
        Parameters:
        id - the id of the program tree that was changed.
        type - the type of change
        oldValue - old value depends on the type of the change
        newValue - old value depends on the type of the change
      • tagChanged

        public void tagChanged​(FunctionTag tag,
                               int type,
                               java.lang.Object oldValue,
                               java.lang.Object newValue)
        Notification that a FunctionTag was changed. This can be either an edit or a delete.
        Parameters:
        tag - the tag that was changed.
        type - the type of change
        oldValue - old value
        newValue - new value
      • tagCreated

        public void tagCreated​(FunctionTag tag,
                               int type)
        Notification that a new FunctionTag was created.
        Parameters:
        tag - the tag that was created.
        type - the type of change
      • symbolChanged

        public void symbolChanged​(Symbol symbol,
                                  int type,
                                  Address addr,
                                  java.lang.Object affectedObj,
                                  java.lang.Object oldValue,
                                  java.lang.Object newValue)
        Notification that a symbol was changed.
        Parameters:
        symbol - the symbol that was changed.
        type - the type of change
        addr - the address of the symbol that changed
        affectedObj -
        oldValue - old value depends on the type of the change
        newValue - old value depends on the type of the change
      • symbolAdded

        public void symbolAdded​(Symbol symbol,
                                int type,
                                Address addr,
                                java.lang.Object oldValue,
                                java.lang.Object newValue)
        Notification that a symbol was added.
        Parameters:
        symbol - the symbol that was added.
        type - the type of change
        addr - the address of the symbol that added
        oldValue - old value depends on the type of the change
        newValue - old value depends on the type of the change
      • getChangedFunctionTagIDs

        public java.util.HashSet<java.lang.Long> getChangedFunctionTagIDs()
      • setRegisterValuesChanged

        public void setRegisterValuesChanged​(Register register,
                                             Address start,
                                             Address end)
        Description copied from interface: ChangeManager
        Notifies that register values have changed over the indicated address range.
        Specified by:
        setRegisterValuesChanged in interface ChangeManager
        Parameters:
        register - register value which was modified (a value of null indicates all registers affected or unknown)
        start - the start address for the range where values changed
        end - the end address (inclusive) for the range where values changed
      • setChanged

        public void setChanged​(int type,
                               java.lang.Object oldValue,
                               java.lang.Object newValue)
        Mark the state this Program as having changed and generate the event. Any or all parameters may be null.
        Specified by:
        setChanged in interface ChangeManager
        Parameters:
        type - event type
        oldValue - original value
        newValue - new value
      • setChanged

        public void setChanged​(int type,
                               Address start,
                               Address end,
                               java.lang.Object oldValue,
                               java.lang.Object newValue)
        Mark the state this Program as having changed and generate the event. Any or all parameters may be null.
        Specified by:
        setChanged in interface ChangeManager
        Parameters:
        type - event type
        start - starting address that is affected by the event
        end - ending address that is affected by the event
        oldValue - original value
        newValue - new value
      • setObjChanged

        public void setObjChanged​(int type,
                                  java.lang.Object affectedObj,
                                  java.lang.Object oldValue,
                                  java.lang.Object newValue)
        Mark the state of a Program as having changed and generate the event. Any or all parameters may be null. NOTE: ChangeSet data will not be updated since this a very generic change not related to a specific address.
        Specified by:
        setObjChanged in interface ChangeManager
        Parameters:
        type - event type
        affectedObj - object that is the subject of the event
        oldValue - original value or an Object that is related to the event
        newValue - new value or an Object that is related to the the event
      • setObjChanged

        public void setObjChanged​(int type,
                                  int subType,
                                  java.lang.Object affectedObj,
                                  java.lang.Object oldValue,
                                  java.lang.Object newValue)
        Mark the state of a Program as having changed and generate the event. Any or all parameters may be null. NOTE: ChangeSet data will not be updated since this a very generic change not related to a specific address.
        Specified by:
        setObjChanged in interface ChangeManager
        Parameters:
        type - event type
        subType - event sub-type
        affectedObj - object that is the subject of the event
        oldValue - original value or an Object that is related to the event
        newValue - new value or an Object that is related to the the event
      • setObjChanged

        public void setObjChanged​(int type,
                                  Address addr,
                                  java.lang.Object affectedObj,
                                  java.lang.Object oldValue,
                                  java.lang.Object newValue)
        Mark the state of a Program as having changed and generate the event. Any or all parameters may be null.
        Specified by:
        setObjChanged in interface ChangeManager
        Parameters:
        type - event type
        addr - program address affected
        affectedObj - object that is the subject of the event
        oldValue - original value or an Object that is related to the event
        newValue - new value or an Object that is related to the the event
      • setObjChanged

        public void setObjChanged​(int type,
                                  int subType,
                                  Address addr,
                                  java.lang.Object affectedObj,
                                  java.lang.Object oldValue,
                                  java.lang.Object newValue)
        Mark the state of a Program as having changed and generate the event. Any or all parameters may be null.
        Specified by:
        setObjChanged in interface ChangeManager
        Parameters:
        type - event type
        subType - event sub-type
        addr - program address affected
        affectedObj - object that is the subject of the event
        oldValue - original value or an Object that is related to the event
        newValue - new value or an Object that is related to the the event
      • setObjChanged

        public void setObjChanged​(int type,
                                  AddressSetView addrSet,
                                  java.lang.Object affectedObj,
                                  java.lang.Object oldValue,
                                  java.lang.Object newValue)
        Mark the state of a Program as having changed and generate the event. Any or all parameters may be null.
        Specified by:
        setObjChanged in interface ChangeManager
        Parameters:
        type - event type
        addrSet - set of program addresses affected
        affectedObj - object that is the subject of the event
        oldValue - original value or an Object that is related to the event
        newValue - new value or an Object that is related to the the event
      • setPropertyChanged

        public void setPropertyChanged​(java.lang.String propertyName,
                                       Address codeUnitAddr,
                                       java.lang.Object oldValue,
                                       java.lang.Object newValue)
        Mark the state of a Program as having changed and generate the DOCR_CODE_UNIT_PROPERTY_CHANGED event.
        Specified by:
        setPropertyChanged in interface ChangeManager
        Parameters:
        propertyName -
        codeUnitAddr - address of the code unit with the property change
        oldValue - old value for the property
        newValue - new value for the property
      • setPropertyRangeRemoved

        public void setPropertyRangeRemoved​(java.lang.String propertyName,
                                            Address start,
                                            Address end)
        Mark the state of a Program as having changed and generate the DOCR_CODE_UNIT_PROPERTY_RANGE_REMOVED event.
        Specified by:
        setPropertyRangeRemoved in interface ChangeManager
        Parameters:
        propertyName - name of the property
        start - start of range of the property being removed
        end - end of the range of the property being removed
      • userDataChanged

        protected void userDataChanged​(java.lang.String propertyName,
                                       java.lang.Object oldValue,
                                       java.lang.Object newValue)
        Notification of property change
        Parameters:
        propertyName -
        oldValue -
        newValue -
      • setImageBase

        public void setImageBase​(Address base,
                                 boolean commit)
                          throws AddressOverflowException,
                                 LockException,
                                 java.lang.IllegalStateException
        Description copied from interface: Program
        Sets the program's image base address.
        Specified by:
        setImageBase in interface Program
        Parameters:
        base - the new image base address;
        commit - if false, then the image base change is temporary and does not really change the program and will be lost once the program is closed. If true, the change is permanent and marks the program as "changed" (needs saving).
        Throws:
        AddressOverflowException - if the new image would cause a memory block to end past the the address space.
        LockException - if the program is shared and the user does not have an exclusive checkout. This will never be thrown if commit is false.
        java.lang.IllegalStateException - if the program state is not suitable for setting the image base.
        See Also:
        Program.setImageBase(ghidra.program.model.address.Address, boolean)
      • getStoredVersion

        public int getStoredVersion()
                             throws java.io.IOException
        Throws:
        java.io.IOException
      • clearCache

        protected void clearCache​(boolean all)
        Overrides:
        clearCache in class DomainObjectAdapterDB
        See Also:
        ghidra.framework.data.DomainObjectAdapterDB#clearCache()
      • invalidate

        public void invalidate()
        Description copied from interface: Program
        Invalidates any caching in a program. NOTE: Over-using this method can adversely affect system performance.
        Specified by:
        invalidate in interface Program
        See Also:
        Program.invalidate()
      • getRegister

        public Register getRegister​(Address addr)
        Description copied from interface: Program
        Returns the largest register located at the specified address
        Specified by:
        getRegister in interface Program
        Returns:
        largest register or null
        See Also:
        ghidra.program.model.listing.Program#getRegister(int, int)
      • getRegister

        public Register getRegister​(Varnode varnode)
        Description copied from interface: Program
        Returns the register which corresponds to the specified varnode
        Specified by:
        getRegister in interface Program
        Returns:
        register or null
      • deleteAddressRange

        public void deleteAddressRange​(Address startAddr,
                                       Address endAddr,
                                       TaskMonitor monitor)
                                throws RollbackException
        Deletes given range from the program.
        Parameters:
        startAddr - the first address in the range.
        endAddr - the last address in the range.
        monitor - the task monitor to use while deleting information in the given range.
        Throws:
        RollbackException - if the user cancelled the operation via the task monitor.
      • moveAddressRange

        public void moveAddressRange​(Address fromAddr,
                                     Address toAddr,
                                     long length,
                                     TaskMonitor monitor)
                              throws AddressOverflowException,
                                     RollbackException
        Moves all information stored in the given range to the new location.
        Parameters:
        fromAddr - the first address in the range to be moved.
        toAddr - the address to move to.
        length - the number of addresses to move.
        monitor - the task monitor to use while deleting information in the given range.
        Throws:
        RollbackException - if the user cancelled the operation via the task monitor.
        AddressOverflowException
      • setLanguage

        public void setLanguage​(Language newLanguage,
                                CompilerSpecID newCompilerSpecID,
                                boolean forceRedisassembly,
                                TaskMonitor monitor)
                         throws java.lang.IllegalStateException,
                                IncompatibleLanguageException,
                                LockException
        Description copied from interface: Program
        Sets the language for the program. If the new language is "compatible" with the old language, the addressMap is adjusted then the program is "re-disassembled".
        Specified by:
        setLanguage in interface Program
        Parameters:
        newLanguage - the new language to use.
        forceRedisassembly - if true a redisassembly will be forced. This should always be false.
        monitor - the task monitor
        Throws:
        java.lang.IllegalStateException - thrown if any error occurs, including a cancelled monitor, which leaves this program object in an unusable state. The current transaction should be aborted and the program instance discarded.
        IncompatibleLanguageException - thrown if the new language is too different from the existing language.
        LockException - if the program is shared and not checked out exclusively.
      • setLanguage

        public void setLanguage​(LanguageTranslator translator,
                                CompilerSpecID newCompilerSpecID,
                                boolean forceRedisassembly,
                                TaskMonitor monitor)
                         throws LockException
        Translate language
        Parameters:
        translator - language translator, if null only re-disassembly will occur.
        newCompilerSpecID - new compiler specification which corresponds to new language, may be null.
        monitor -
        Throws:
        LockException
      • getAddressSetPropertyMap

        public AddressSetPropertyMap getAddressSetPropertyMap​(java.lang.String mapName)
        Description copied from interface: Program
        Get the property map with the given name.
        Specified by:
        getAddressSetPropertyMap in interface Program
        Parameters:
        mapName - name of the property map
        Returns:
        null if no property map exist with the given name
      • deleteAddressSetPropertyMap

        public void deleteAddressSetPropertyMap​(java.lang.String mapName)
        Description copied from interface: Program
        Remove the property map from the program.
        Specified by:
        deleteAddressSetPropertyMap in interface Program
        Parameters:
        mapName - name of the property map to remove
      • createIntRangeMap

        public IntRangeMapDB createIntRangeMap​(java.lang.String mapName)
                                        throws DuplicateNameException
        Description copied from interface: Program
        Create a new IntRangeMap with the specified name.
        Specified by:
        createIntRangeMap in interface Program
        Parameters:
        mapName - name of the property map.
        Returns:
        the newly created property map.
        Throws:
        DuplicateNameException - if a property map already exists with the given name.
      • getIntRangeMap

        public IntRangeMap getIntRangeMap​(java.lang.String mapName)
        Description copied from interface: Program
        Get the property map with the given name.
        Specified by:
        getIntRangeMap in interface Program
        Parameters:
        mapName - name of the property map
        Returns:
        null if no property map exist with the given name
      • deleteIntRangeMap

        public void deleteIntRangeMap​(java.lang.String mapName)
        Description copied from interface: Program
        Remove the property map from the program.
        Specified by:
        deleteIntRangeMap in interface Program
        Parameters:
        mapName - name of the property map to remove
      • getMetadata

        public java.util.Map<java.lang.String,​java.lang.String> getMetadata()
        Description copied from interface: DomainObject
        Returns a map containing all the stored metadata associated with this domain object. The map contains key,value pairs and are ordered by their insertion order.
        Specified by:
        getMetadata in interface DomainObject
        Overrides:
        getMetadata in class DomainObjectAdapter
        Returns:
        a map containing all the stored metadata associated with this domain object.
      • updateMetadata

        protected void updateMetadata()
                               throws java.io.IOException
        Description copied from class: DomainObjectAdapterDB
        This method is called before a save, saveAs, or saveToPackedFile to update common meta data
        Overrides:
        updateMetadata in class DomainObjectAdapterDB
        Throws:
        java.io.IOException
      • lock

        public boolean lock​(java.lang.String reason)
        Description copied from interface: DomainObject
        Attempt to obtain a modification lock on the domain object. Multiple locks may be granted on this domain object, although all lock owners must release their lock in a timely fashion.
        Specified by:
        lock in interface DomainObject
        Overrides:
        lock in class DomainObjectAdapterDB
        Parameters:
        reason - very short reason for requesting lock
        Returns:
        true if lock obtained successfully, else false which indicates that a modification is in process.
        See Also:
        DomainObject.lock(String)
      • getUniqueProgramID

        public long getUniqueProgramID()
        Description copied from interface: Program
        Returns an ID that is unique for this program. This provides an easy way to store references to a program across client persistence.
        Specified by:
        getUniqueProgramID in interface Program
      • invalidateWriteCache

        public void invalidateWriteCache()
        Description copied from class: DomainObjectAdapterDB
        Invalidate (i.e., clear) any pending database changes not yet written. This method will be invoked by the transaction manager prior to aborting a transaction.
        Overrides:
        invalidateWriteCache in class DomainObjectAdapterDB
      • flushWriteCache

        public void flushWriteCache()
        Description copied from class: DomainObjectAdapterDB
        Flush any pending database changes. This method will be invoked by the transaction manager prior to closing a transaction.
        Overrides:
        flushWriteCache in class DomainObjectAdapterDB