Class GhidraProject

    • Method Detail

      • openProject

        public static GhidraProject openProject​(java.lang.String projectsDir,
                                                java.lang.String projectName)
                                         throws java.io.IOException
        Returns an instance of an open Ghidra Project that can be used to open/save programs.
        Parameters:
        projectsDir - the directory containing the Ghidra project.
        projectName - the name of the ghidra project.
        Returns:
        an open ghidra project.
        Throws:
        java.io.IOException - if there was a problem accessing the project
      • openProject

        public static GhidraProject openProject​(java.lang.String projectsDir,
                                                java.lang.String projectName,
                                                boolean restoreProject)
                                         throws java.io.IOException
        Returns an instance of an open Ghidra Project that can be used to open/save programs.
        Parameters:
        projectsDir - the directory containing the Ghidra project.
        projectName - the name of the ghidra project.
        restoreProject - if true the project tool state is restored
        Returns:
        an open ghidra project.
        Throws:
        java.io.IOException - if there was a problem accessing the project
      • createProject

        public static GhidraProject createProject​(java.lang.String projectDirPath,
                                                  java.lang.String projectName,
                                                  boolean temporary)
                                           throws java.io.IOException
        Creates a new non-shared Ghidra project to be used for storing programs.

        Note: Calling this method will delete any existing project files on disk that match the given project name.

        Parameters:
        projectDirPath - the directory path to contain the new Ghidra project.
        projectName - the name of the project to be created.
        temporary - if true, deletes the the project when it is closed - useful for testing.
        Returns:
        an open ghidra project.
        Throws:
        java.io.IOException - if there was a problem accessing the project
      • getServerRepository

        public static RepositoryAdapter getServerRepository​(java.lang.String host,
                                                            int port,
                                                            java.lang.String repositoryName,
                                                            boolean createIfNeeded)
                                                     throws DuplicateNameException
        Get/Create shared repository.
        Parameters:
        host - Ghidra Server host
        port - Ghidra Server port (0 = use default port)
        repositoryName -
        createIfNeeded - if true repository will be created if it does not exist
        Throws:
        DuplicateNameException
      • getProjectManager

        public DefaultProjectManager getProjectManager()
        Returns the project manager
        Returns:
        the project manager
      • getProject

        public Project getProject()
        Returns the underlying Project instance or null if project was opened for READ access only.
      • close

        public void close()
        Closes the ghidra project, closing (without saving!) any open programs in that project. Also deletes the project if created as a temporary project.
      • setDeleteOnClose

        public void setDeleteOnClose​(boolean toDelete)
        Updates the flag passed to this project at construction time.
        Parameters:
        toDelete - true to delete on close; false in the opposite condition
      • close

        public void close​(Program program)
        Closes the given program. Any changes in the program will be lost.
        Parameters:
        program - the program to close.
      • openProgram

        public Program openProgram​(java.lang.String folderPath,
                                   java.lang.String programName,
                                   boolean readOnly)
                            throws java.io.IOException
        Opens a program.
        Parameters:
        folderPath - the path of the program within the project. ("\" is root)
        programName - the name of the program to open.
        readOnly - flag if the program will only be read and not written.
        Returns:
        an open program.
        Throws:
        java.io.IOException - if there was a problem accessing the program
      • save

        public void save​(Program program)
                  throws java.io.IOException
        Saves any changes in the program back to its file. If the program does not have an associated file (it was created), then it is an error to call this method, use saveAs instead. Any open transaction will be terminated.
        Parameters:
        program - the program to be saved.
        Throws:
        java.io.IOException - if there was a problem accessing the program
      • getRootFolder

        public DomainFolder getRootFolder()
        Get the root folder for the Ghidra project.
      • saveAs

        public void saveAs​(Program program,
                           java.lang.String folderPath,
                           java.lang.String name,
                           boolean overWrite)
                    throws InvalidNameException,
                           java.io.IOException
        Saves the given program to the project with the given name.
        Parameters:
        program - the program to be saved
        folderPath - the path where to save the program.
        name - the name to save the program as.
        overWrite - if true, any existing program with that name will be over-written.
        Throws:
        DuplicateFileException - if a file exists with that name and overwrite is false or overwrite failed
        InvalidNameException - the name is null or has invalid characters.
        java.io.IOException - if there was a problem accessing the program
      • saveAsPackedFile

        public void saveAsPackedFile​(Program program,
                                     java.io.File file,
                                     boolean overWrite)
                              throws InvalidNameException,
                                     java.io.IOException
        Saves the given program to as a packed file.
        Parameters:
        program - the program to be saved
        file - the packed file destination.
        overWrite - if true, any existing program with that name will be over-written.
        Throws:
        InvalidNameException - the name is null or has invalid characters.
        java.io.IOException - if there was a problem accessing the program
      • checkPoint

        public void checkPoint​(Program program)
        Creates a checkpoint in the program. Any changes since the last checkpoint can be instantly undone by calling the rollback command.
        Parameters:
        program - the program to be checkpointed.
      • rollback

        public void rollback​(Program program)
        Rolls back any changes to the program since the last checkpoint.
        Parameters:
        program - the program to be rolled back.
      • analyze

        public static void analyze​(Program program)
        Invokes the auto-analyzer on the program. Depending on which analyzers are in the classpath, generally will disassemble at entry points, and create and analyze functions that are called.
        Parameters:
        program - the program to analyze.
      • analyze

        public void analyze​(Program program,
                            boolean debug)
        Debug version of the auto_analyzer. Same as regular analyzer except that any stack traces are not trapped.
        Parameters:
        program - the program to be analyzed
        debug - true to allow stack traces to propagate out.
      • getAnalysisOptions

        public Options getAnalysisOptions​(Program program)
        Returns a PropertList containing all the analysis option properties that can be set. Changing the value of the analysis properties will affect what happens when the analyze call is made.
        Parameters:
        program - the program whose analysis options are to be set.
      • execute

        public void execute​(Command cmd,
                            Program program)
        Executes the give command on the program.
        Parameters:
        cmd - the command to be applied to the program.
        program - the program on which the command is to be applied.