Package ghidra.test

Class AbstractGhidraHeadlessIntegrationTest

    • Field Detail

      • PROJECT_NAME

        public static final java.lang.String PROJECT_NAME
    • Constructor Detail

      • AbstractGhidraHeadlessIntegrationTest

        public AbstractGhidraHeadlessIntegrationTest()
    • Method Detail

      • deleteProject

        public static boolean deleteProject​(java.lang.String directory,
                                            java.lang.String name)
      • getLanguageCompilerSpecPair

        public static LanguageCompilerSpecPair getLanguageCompilerSpecPair​(java.lang.String oldLanguageName)
                                                                    throws LanguageNotFoundException
        Get the language and compiler spec associated with an old language name string. If the language no longer exists, and suitable replacement language will be returned if found. If no language is found, an exception will be thrown.
        Parameters:
        oldLanguageName - old language name string
        Returns:
        the language compiler and spec
        Throws:
        LanguageNotFoundException - if the language is not found
      • createDefaultProgram

        public static ProgramDB createDefaultProgram​(java.lang.String name,
                                                     java.lang.String languageString,
                                                     java.lang.Object consumer)
                                              throws java.lang.Exception
        Creates an in-memory program with the given language
        Parameters:
        name - the program name
        languageString - a language string of the format x86:LE:32:default
        consumer - a consumer for the program
        Returns:
        a new program
        Throws:
        java.lang.Exception - if there is any issue creating the language
      • createDefaultProgram

        public static ProgramDB createDefaultProgram​(java.lang.String name,
                                                     java.lang.String languageString,
                                                     java.lang.String compilerSpecID,
                                                     java.lang.Object consumer)
                                              throws java.lang.Exception
        Creates an in-memory program with the given language
        Parameters:
        name - the program name
        languageString - a language string of the format x86:LE:32:default
        compilerSpecID - the ID
        consumer - a consumer for the program
        Returns:
        a new program
        Throws:
        java.lang.Exception - if there is any issue creating the language
      • applyCmd

        public static boolean applyCmd​(Program program,
                                       Command cmd)
                                throws RollbackException
        Run a command against the specified program within a transaction. The transaction will be committed unless the command throws a RollbackException.
        Parameters:
        program - the program
        cmd - the command to apply
        Returns:
        result of command applyTo method
        Throws:
        RollbackException - thrown if thrown by command applyTo method
      • tx

        public static <E extends java.lang.Exception> void tx​(Program p,
                                                              ExceptionalCallback<E> c)
        Provides a convenient method for modifying the current program, handling the transaction logic.
        Parameters:
        p - the program
        c - the code to execute
      • modifyProgram

        public static <E extends java.lang.Exception> void modifyProgram​(Program p,
                                                                         ExceptionalCallback<E> c)
        Provides a convenient method for modifying the current program, handling the transaction logic. This method is calls tx(Program, ExceptionalCallback), but helps with semantics.
        Parameters:
        p - the program
        c - the code to execute
      • modifyProgram

        public <R,​E extends java.lang.Exception> R modifyProgram​(Program program,
                                                                       ExceptionalFunction<Program,​R,​E> f)
        Provides a convenient method for modifying the current program, handling the transaction logic and returning a new item as a result
        Parameters:
        program - the program
        f - the function for modifying the program and creating the desired result
        Returns:
        the result
      • undo

        public static void undo​(UndoableDomainObject dobj,
                                boolean wait)
        Undo the last transaction on the domain object and wait for all events to be flushed.
        Parameters:
        dobj - The domain object upon which to perform the undo.
        wait - if true, wait for undo to fully complete in Swing thread. If a modal dialog may result from this undo, wait should be set false.
      • redo

        public static void redo​(UndoableDomainObject dobj,
                                boolean wait)
        Redo the last undone transaction on the domain object and wait for all events to be flushed.
        Parameters:
        dobj - The domain object upon which to perform the redo.
        wait - if true, wait for redo to fully complete in Swing thread. If a modal dialog may result from this redo, wait should be set false.
      • undo

        public static void undo​(UndoableDomainObject dobj)
        Undo the last transaction on the domain object and wait for all events to be flushed.
        Parameters:
        dobj - The domain object upon which to perform the undo.
      • redo

        public static void redo​(UndoableDomainObject dobj)
        Redo the last undone transaction on domain object and wait for all events to be flushed.
        Parameters:
        dobj - The domain object upon which to perform the redo.
      • undo

        public static void undo​(UndoableDomainObject dobj,
                                int count)
        Undo the last 'count' transactions on the domain object and wait for all events to be flushed.
        Parameters:
        dobj - The domain object upon which to perform the undo.
        count - number of transactions to undo
      • redo

        public static void redo​(UndoableDomainObject dobj,
                                int count)
        Redo the last 'count' undone transactions on the domain object and wait for all events to be flushed.
        Parameters:
        dobj - The domain object upon which to perform the redo.
        count - number of transactions to redo
      • getPlugin

        public static <T extends Plugin> T getPlugin​(PluginTool tool,
                                                     java.lang.Class<T> c)
      • goTo

        public void goTo​(PluginTool tool,
                         Program p,
                         java.lang.String addrString)
      • getUniqueSymbol

        public Symbol getUniqueSymbol​(Program program,
                                      java.lang.String name)
        Returns the global symbol with the given name if and only if it is the only global symbol with that name.
        Parameters:
        program - the program to search.
        name - the name of the global symbol to find.
        Returns:
        the global symbol with the given name if and only if it is the only one.
      • getUniqueSymbol

        public Symbol getUniqueSymbol​(Program program,
                                      java.lang.String name,
                                      Namespace namespace)
        Returns the symbol in the given namespace with the given name if and only if it is the only symbol in that namespace with that name.
        Parameters:
        program - the program to search.
        name - the name of the symbol to find.
        namespace - the parent namespace; may be null
        Returns:
        the symbol with the given name if and only if it is the only one in that namespace
      • debugProgramInTool

        public void debugProgramInTool​(Program p,
                                       java.lang.String address)
                                throws java.lang.Exception
        A convenience method that allows you to open the given program in a default tool, navigating to the given address.

        Note: this is a blocking operation. Your test will not proceed while this method is sleeping.

        Do not leave this call in your test when committing changes.

        Parameters:
        p - the program
        address - the address
        Throws:
        java.lang.Exception - if there is an issue create a TestEnv
      • waitForScriptCompletion

        public void waitForScriptCompletion​(ScriptTaskListener listener,
                                            long timeoutMS)
        Waits for a launched script to complete by using the given listener.
        Parameters:
        listener - the listener used to track script progress
        timeoutMS - the max time to wait; failing if exceeded
      • replaceService

        public static <T> void replaceService​(PluginTool tool,
                                              java.lang.Class<? extends T> service,
                                              T replacement)
        Replaces the given implementations of the provided service class with the given class.
        Type Parameters:
        T - the service type
        Parameters:
        tool - the tool whose services to update (optional)
        service - the service to override
        replacement - the new version of the service
      • getLanguageService

        public static LanguageService getLanguageService()
        Get language service used for testing.
        Returns:
        language service.
      • getSLEIGH_X86_LANGUAGE

        public static Language getSLEIGH_X86_LANGUAGE()
      • getSLEIGH_X86_64_LANGUAGE

        public static Language getSLEIGH_X86_64_LANGUAGE()
      • getSLEIGH_8051_LANGUAGE

        public static Language getSLEIGH_8051_LANGUAGE()
      • getZ80_LANGUAGE

        public static Language getZ80_LANGUAGE()