Package ghidra.test

Class AbstractProgramBasedTest


public abstract class AbstractProgramBasedTest extends AbstractGhidraHeadedIntegrationTest
A convenience base class for creating tests that use the default tool and open a program. This class will create for you a tool, a TestEnv and will open the program specified by getProgramName().

To use this class, you must call initialize() from your test or setUp method.

Note: if you are loading a pre-existing program, then simply override getProgramName(). Alternatively, if you are building a program, then override getProgram() and return it there.

  • Field Details

    • env

      protected TestEnv env
    • tool

      protected PluginTool tool
    • program

      protected Program program
    • codeBrowser

      protected ghidra.app.plugin.core.codebrowser.CodeBrowserPlugin codeBrowser
  • Constructor Details

    • AbstractProgramBasedTest

      public AbstractProgramBasedTest()
  • Method Details

    • getProgramName

      protected String getProgramName()
    • initialize

      protected void initialize() throws Exception
      Throws:
      Exception
    • getProgram

      protected Program getProgram() throws Exception
      Override this method if you need to build your own program.
      Returns:
      the program to use for this test.
      Throws:
      Exception - if an exception is thrown opening the program
    • tearDown

      public void tearDown() throws Exception
      Throws:
      Exception
    • assertCurrentAddress

      public void assertCurrentAddress(Address expected)
    • addr

      public Address addr(long offset)
    • addr

      public Address addr(String offset)
    • addr

      public Address addr(Program p, long offset)
    • addr

      public Address addr(Program p, String offset)
    • goTo

      public void goTo(long offset)
    • goTo

      public void goTo(String offset)
    • range

      public AddressRange range(long from, long to)
    • showProvider

      public void showProvider(String name)
    • function

      public Function function(Address addr)
    • addrs

      public List<Address> addrs(long... offsets)
    • toAddressSet

      public AddressSet toAddressSet(long... offsets)
    • addrs

      public List<Address> addrs(Address... addrs)
    • goTo

      public void goTo(Address a)
    • modifyProgram

      public <E extends Exception> void modifyProgram(ExceptionalConsumer<Program,E> callback)
      Provides a convenient method for modifying the current program, handling the transaction logic.
      Parameters:
      callback - the code to execute
    • createInProgram

      public <R, E extends Exception> R createInProgram(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:
      f - the function for modifying the program and creating the desired result
      Returns:
      the result
    • getField

      protected ListingField getField(Address a, String fieldName)
      Returns a field by the given name at the given address. Clients can use the convention that field factory classes specify a public static field named 'FIELD_NAME' to choose the desired field name.

      Note: you will have to perform a goTo() to trigger the view to load the given field.

      Parameters:
      a - the address
      fieldName - the field name
      Returns:
      the field
    • getField

      protected ListingField getField(String fieldName, int occurrence, BigInteger index, FieldPanel fieldPanel)