Class ProjectDataUtils

java.lang.Object
ghidra.framework.model.ProjectDataUtils

public class ProjectDataUtils extends Object
  • Constructor Details

    • ProjectDataUtils

      public ProjectDataUtils()
  • Method Details

    • descendantFiles

      public static Iterable<DomainFile> descendantFiles(DomainFolder folder)
      Returns a Iterable of DomainFiles that exist under the specified folder including all sub-folder content. All folder-links and file-links will be ignored and files of all content-types will be returned by the iterator.

      Use descendantFiles(DomainFolder, DomainFileFilter) for finer-grained control over returned files.

      Parameters:
      folder - domain folder
      Returns:
      domain file iterator
    • descendantFiles

      public static Iterable<DomainFile> descendantFiles(DomainFolder folder, DomainFileFilter filter)
      Returns a Iterable of DomainFiles that exist under the specified folder, including all sub-folder content, which satisfy the specified filter restrictions.

      NOTE: Care must be taken in the presence of folder-links and file-links since such links can result in the same files being returned by the iterator multiple times. In general it is recommended that all links (see DomainFile.isLink()) be ignored when iterating over an entire project. When restricting content-type it is highly recommended that the method DomainFile.getDomainObjectClass() since both linked and non-linked files for the same content will specify the same DomainObject class (e.g., Program.class).

      Parameters:
      folder - domain folder
      filter - the filter which determines which files should be returned by the iterator and what links should be followed.
      Returns:
      domain file iterator
    • descendantFolders

      public static Iterable<DomainFolder> descendantFolders(DomainFolder folder)
      Returns a Iterable of DomainFolders that exist under the specified folder including all sub-folders. All folder-links will be ignored.

      Use descendantFolders(DomainFolder, boolean, boolean) if folder-links should be followed.

      Parameters:
      folder - domain folder
      Returns:
      domain folder iterator
    • descendantFolders

      public static Iterable<DomainFolder> descendantFolders(DomainFolder folder, boolean ignoreFolderLinks, boolean ignoreExternalLinks)
      Returns a Iterable of DomainFolders that exist under the specified folder including all sub-folders. subject to the specified folder-link restrictions. All broken folder-links encountered will be logged and skipped.
      Parameters:
      folder - domain folder
      ignoreFolderLinks - true if all folder-links should be ignored
      ignoreExternalLinks - true if all external-links should be ignored (ignored if ignoreFolderLinks is true)
      Returns:
      domain folder iterator
    • createDomainFolderPath

      public static DomainFolder createDomainFolderPath(DomainFolder currentFolder, String path) throws InvalidNameException, IOException
      Returns a Ghidra DomainFolder with the matching path, creating any missing parent folders as needed. Broken folder-links will always be ignored.
      Parameters:
      currentFolder - starting DomainFolder.
      path - relative path to the desired DomainFolder, using forward slashes as separators. Empty string ok, multiple slashes in a row treated as single slash, trailing slashes ignored.
      Returns:
      DomainFolder that the path points to.
      Throws:
      InvalidNameException - if bad name
      ReadOnlyException - if unable to create a folder within a read-only project
      IOException - if problem when creating folder or a conflicting/broken folder/folder-link encountered.
    • getDomainFolder

      public static DomainFolder getDomainFolder(DomainFolder baseFolder, String relativePath)
      Returns a Ghidra DomainFolder with the matching path within the baseFolder's project, or null if not found. Broken and external folder-links will be ignored.
      Parameters:
      baseFolder - Base DomainFolder for relativePath
      relativePath - path relative to the specified DomainFolder, using forward slashes as separators. Empty string ok, multiple slashes in a row treated as single slash, leading and trailing slashes ignored.
      Returns:
      DomainFolder that the path points to or null if not found.
    • getDomainFolder

      public static DomainFolder getDomainFolder(DomainFolder baseFolder, String relativePath, DomainFolderFilter filter)
      Returns a Ghidra DomainFolder with the matching path, or null if not found.
      Parameters:
      baseFolder - Base DomainFolder for relativePath
      relativePath - path relative to the specified DomainFolder, using forward slashes as separators. Empty string ok, multiple slashes in a row treated as single slash, leading and trailing slashes ignored.
      filter - domain folder filter which constrains returned folder and following of folder-links. Broken links will always be ignored.
      Returns:
      DomainFolder that the path points to or null if not found or path contains a broken folder-link.
    • getUniqueName

      public static String getUniqueName(DomainFolder folder, String baseName)
      Returns a unique folder/file name within the specified folder. The specified baseName will be used as the basis for the name returned with an appended number.
      Parameters:
      folder - DomainFolder to check for child name collisions.
      baseName - String base name of the file or folder
      Returns:
      "baseName" if no collisions, or "baseNameNNN" (where NNN is an incrementing integer value) when collisions are found, or null if there are more than 1000 collisions.