Package ghidra.test

Class AbstractGhidraHeadlessIntegrationTest

Direct Known Subclasses:
AbstractGhidraHeadedIntegrationTest

public abstract class AbstractGhidraHeadlessIntegrationTest extends AbstractDockingTest
  • Field Details

    • PROJECT_NAME

      public static final String PROJECT_NAME
  • Constructor Details

    • AbstractGhidraHeadlessIntegrationTest

      public AbstractGhidraHeadlessIntegrationTest()
  • Method Details

    • createApplicationLayout

      protected ApplicationLayout createApplicationLayout() throws IOException
      Overrides:
      createApplicationLayout in class AbstractDockingTest
      Throws:
      IOException
    • createApplicationConfiguration

      protected ApplicationConfiguration createApplicationConfiguration()
      Overrides:
      createApplicationConfiguration in class AbstractDockingTest
    • initializeSystemProperties

      protected void initializeSystemProperties()
      Description copied from class: AbstractGenericTest
      A place to initialize and needed static properties
      Overrides:
      initializeSystemProperties in class AbstractGenericTest
    • cleanDbTestDir

      public static void cleanDbTestDir()
    • deleteProject

      public static boolean deleteProject(String directory, String name)
    • getLanguageCompilerSpecPair

      public static LanguageCompilerSpecPair getLanguageCompilerSpecPair(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(String name, String languageString, Object consumer) throws 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:
      Exception - if there is any issue creating the language
    • createDefaultProgram

      public static ProgramDB createDefaultProgram(String name, String languageString, String compilerSpecID, Object consumer) throws 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:
      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 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
      See Also:
    • tx

      public static <T, E extends Exception> T tx(Program p, ExceptionalSupplier<T,E> s)
      Provides a convenient method for modifying the current program, handling the transaction logic and returning a result.
      Type Parameters:
      T - the return type
      E - the exception type
      Parameters:
      p - the program
      s - the code to execute
      Returns:
      the supplier's return value
      See Also:
    • modifyProgram

      public static <E extends 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
      See Also:
    • modifyProgram

      public <R, E extends 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
      See Also:
    • undo

      public static void undo(DomainObject 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(DomainObject 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(DomainObject dobj, String name)
      Undo the last transaction on the domain object and wait for all events to be flushed. This method takes the undo item name, which is used to find the undo item. Once found, all items before and including that undo item will be undone.
      Parameters:
      dobj - The domain object upon which to perform the undo.
      name - the name of the undo item on the stack.
    • undo

      public static void undo(DomainObject 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(DomainObject 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(DomainObject 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(DomainObject 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, Class<T> c)
    • toAddressSet

      public AddressSet toAddressSet(List<Address> addrs)
    • toAddressSet

      public AddressSet toAddressSet(Address start, Address end)
    • toAddressSet

      public AddressSet toAddressSet(AddressRange... ranges)
    • goTo

      public void goTo(PluginTool tool, Program p, Address addr)
    • goTo

      public void goTo(PluginTool tool, Program p, String addrString)
    • makeSelection

      public void makeSelection(PluginTool tool, Program p, List<Address> addrs)
    • makeSelection

      public void makeSelection(PluginTool tool, Program p, Address from, Address to)
    • makeSelection

      public void makeSelection(PluginTool tool, Program p, AddressRange... ranges)
    • makeSelection

      public void makeSelection(PluginTool tool, Program p, AddressSetView addresses)
    • getUniqueSymbol

      public Symbol getUniqueSymbol(Program program, 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, 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, String address) throws 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:
      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, 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()