Package ghidra.app.util.headless

# Class HeadlessAnalyzer

java.lang.Object
ghidra.app.util.headless.HeadlessAnalyzer

public class HeadlessAnalyzer extends Object
The class used kick-off and interact with headless processing. All headless options have been broken out into their own class: `HeadlessOptions`. This class is intended to be used one of two ways:

- Used by `AnalyzeHeadless` to perform headless analysis based on arguments specified on the command line.
- Used by another tool as a library to perform headless analysis.

Note: This class is not thread safe.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `checkAnalysisTimedOut()`
  Checks to see if the most recent analysis timed out.
  `static HeadlessAnalyzer`
  `getInstance()`
  Gets a headless analyzer instance, with the assumption that the application has already been initialized.
  `static HeadlessAnalyzer`
  `getLoggableInstance(File logFile, File scriptLogFile, boolean useLog4j)`
  Gets a headless analyzer, initializing the application if necessary with the specified logging parameters.
  `HeadlessOptions`
  `getOptions()`
  Gets the headless analyzer's options.
  `void`
  `processLocal(String projectLocation, String projectName, String rootFolderPath, List<File> filesToImport)`
  Process the optional import file/directory list and process each imported file: execute ordered list of pre-scripts perform auto-analysis if not disabled execute ordered list of post-scripts If no import files or directories have been specified the ordered list of pre/post scripts will be executed once.
  `void`
  `processURL(URL ghidraURL, List<File> filesToImport)`
  Process the optional import file/directory list and process each imported file: execute ordered list of pre-scripts perform auto-analysis if not disabled execute ordered list of post-scripts If no import files or directories have been specified the ordered list of pre/post scripts will be executed once.
  `void`
  `reset()`
  Resets the state of the headless analyzer to the default settings.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### getLoggableInstance

    public static HeadlessAnalyzer getLoggableInstance(File logFile, File scriptLogFile, boolean useLog4j) throws IllegalStateException, IOException
    Gets a headless analyzer, initializing the application if necessary with the specified logging parameters. An `IllegalStateException` will be thrown if the application has already been initialized or a headless analyzer has already been retrieved. In these cases, the headless analyzer should be gotten with `getInstance()`.
    Parameters:
      `logFile` - The desired application log file. If null, the default application log file will be used (see `Application.initializeLogging()`).
      `scriptLogFile` - The desired scripting log file. If null, the default scripting log file will be used (see `Application.initializeLogging()`).
      `useLog4j` - true if log4j is to be used; otherwise, false. If this class is being used by another tool as a library, using log4j might interfere with that tool.
    Returns:
      An instance of a new headless analyzer.
    Throws:
      `IllegalStateException` - if an application or headless analyzer instance has already been initialized.
      `IOException` - if there was a problem reading the application.properties file.

  - ### getInstance

    public static HeadlessAnalyzer getInstance() throws IOException
    Gets a headless analyzer instance, with the assumption that the application has already been initialized. If this is called before the application has been initialized, it will initialize the application with no logging.
    Returns:
      An instance of a new headless analyzer.
    Throws:
      `IOException` - if there was a problem reading the application.properties file (only possible if the application had not be initialized).

  - ### reset

    public void reset()
    Resets the state of the headless analyzer to the default settings.

  - ### getOptions

    public HeadlessOptions getOptions()
    Gets the headless analyzer's options.
    Returns:
      The headless analyer's options.

  - ### processURL

    public void processURL(URL ghidraURL, List<File> filesToImport) throws IOException, MalformedURLException, URISyntaxException
    Process the optional import file/directory list and process each imported file:
    1. execute ordered list of pre-scripts
    2. perform auto-analysis if not disabled
    3. execute ordered list of post-scripts
    If no import files or directories have been specified the ordered list of pre/post scripts will be executed once.
    Parameters:
      `ghidraURL` - ghidra URL for existing server repository and optional folder path
      `filesToImport` - directories and files to be imported (null or empty is acceptable if we are in -process mode)
    Throws:
      `IOException` - if there was an IO-related problem
      `MalformedURLException` - specified URL is invalid
      `URISyntaxException` - specified URL is invalid

  - ### processLocal

    public void processLocal(String projectLocation, String projectName, String rootFolderPath, List<File> filesToImport) throws IOException
    Process the optional import file/directory list and process each imported file:
    1. execute ordered list of pre-scripts
    2. perform auto-analysis if not disabled
    3. execute ordered list of post-scripts
    If no import files or directories have been specified the ordered list of pre/post scripts will be executed once.
    Parameters:
      `projectLocation` - directory path of project If project exists it will be opened, otherwise it will be created.
      `projectName` - project name
      `rootFolderPath` - root folder for imports
      `filesToImport` - directories and files to be imported (null or empty is acceptable if we are in -process mode)
    Throws:
      `IOException` - if there was an IO-related problem. If caused by a failure to obtain a write-lock on the project the exception cause will a `LockException`.

  - ### checkAnalysisTimedOut

    public boolean checkAnalysisTimedOut()
    Checks to see if the most recent analysis timed out.
    Returns:
      true if the most recent analysis timed out; otherwise, false.