Class HeadlessAnalyzer


  • public class HeadlessAnalyzer
    extends java.lang.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

      All Methods Static Methods Instance Methods Concrete Methods 
      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​(java.io.File logFile, java.io.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​(java.lang.String projectLocation, java.lang.String projectName, java.lang.String rootFolderPath, java.util.List<java.io.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​(java.net.URL ghidraURL, java.util.List<java.io.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 Detail

      • getLoggableInstance

        public static HeadlessAnalyzer getLoggableInstance​(java.io.File logFile,
                                                           java.io.File scriptLogFile,
                                                           boolean useLog4j)
                                                    throws java.lang.IllegalStateException,
                                                           java.io.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, no application logging will take place.
        scriptLogFile - The desired scripting log file. If null, no script logging will take place.
        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:
        java.lang.IllegalStateException - if an application or headless analyzer instance has already been initialized.
        java.io.IOException - if there was a problem reading the application.properties file.
      • getInstance

        public static HeadlessAnalyzer getInstance()
                                            throws java.io.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:
        java.io.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​(java.net.URL ghidraURL,
                               java.util.List<java.io.File> filesToImport)
                        throws java.io.IOException,
                               java.net.MalformedURLException
        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:
        java.io.IOException - if there was an IO-related problem
        java.net.MalformedURLException - specified URL is invalid
      • processLocal

        public void processLocal​(java.lang.String projectLocation,
                                 java.lang.String projectName,
                                 java.lang.String rootFolderPath,
                                 java.util.List<java.io.File> filesToImport)
                          throws java.io.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:
        java.io.IOException - if there was an IO-related problem
      • 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.