Class SleighLanguageFile

java.lang.Object
ghidra.app.plugin.processors.sleigh.SleighLanguageFile

public class SleighLanguageFile extends Object
Represents a Sleigh .sla and .slaspec file, and a way to lock them to ensure exclusive access while checking / updating the files.
  • Field Details

  • Method Details

    • getLanguageResourceFile

      public static ResourceFile getLanguageResourceFile(ResourceFile dir, String filename, String expectedExtension) throws SleighFileException
      Finds a sleigh language file, using search rules specific to sleigh.

      If file is not found in the specific base directory, the entire app install will be searched for a matching file.

      Parameters:
      dir - base directory where files are typically located
      filename - name of file, with or without the extension
      expectedExtension - extension of the specific type of sleigh file, leading dot required. Typically ".sla", ".slaspec", ".pspec", etc.
      Returns:
      ResourceFile that exists, never null
      Throws:
      SleighFileException - if file is not found or has bad case matching
    • fromSlaFilename

      public static SleighLanguageFile fromSlaFilename(ResourceFile dir, String slaFilename) throws SleighFileException
      Creates a SleighLanguageFile instance using the language directory and sla filename to bootstrap the information about the sla file, slaspec file and lock file.

      NOTE: if the sla/slaspec are not found in the specified language directory, the entire application will be searched for the slaspec.

      Parameters:
      dir - ResourceFile language directory that should contain the sla or slaspec file
      slaFilename - name of the sla file (typically from the ldefs xml value), with optional .sla file extension
      Returns:
      SleighLanguageFile, never null
      Throws:
      SleighFileException - if sla and slaspec file can not be found
    • fromSlaFilename_UserDir

      public static SleighLanguageFile fromSlaFilename_UserDir(ResourceFile dir, String slaFilename) throws SleighFileException
      Creates a SleighLanguageFile instance using the language directory and Sleigh language file name to bootstrap the information about the slaspec file and lock file.

      The .slaspec file will be found in the location indicated by the slaFilename.

      The actual .sla file will be private to the user and located under the user's .ghidra config directory. (or if single-jar mode, .sla will remain in the jar)

      Parameters:
      dir - ResourceFile language directory containing the slaspec file
      slaFilename - name of the sla file (typically from the ldefs xml value), with optional .sla file extension
      Returns:
      SleighLanguageFile, never null
      Throws:
      SleighFileException - if slaspec is not found
    • getSlaFile

      public ResourceFile getSlaFile()
      Returns the path of this language's .sla file.
      Returns:
      path of the .sla file
    • getSlaSpecFile

      public ResourceFile getSlaSpecFile()
      Returns the path of the .slaspec file.
      Returns:
      .slaspec file
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • canLock

      public boolean canLock()
      Returns true if this language's files can be locked, or false if they can't be locked (embedded in a .jar file).
      Returns:
      true if this language's files can be locked
    • getLockFile

      public File getLockFile()
    • needsCompilation

      public boolean needsCompilation(int requiredSlaFormatVersion)
      Checks if the sla file needs to be compiled/re-compiled.

      Conditions: missing .sla, .sla is older than the .slaspec, or the sla format version value inside the existing .sla file does not match the current sla format version.

      NOTE: this should only be called when holding the lock with withLock(Duration, TaskMonitor, CheckedRunnable)

      Parameters:
      requiredSlaFormatVersion - required sla format version
      Returns:
      true if the .sla file needs to be compiled/recompiled
    • isSlaFileStale

      public boolean isSlaFileStale()
      Returns true if the slaspec file (or any included sinc files) is newer than the current sla file, indicating that the sla file should be recompiled.

      Returns false if the slaspec or sla files are embedded in a jar (eg. single-jar mode).

      NOTE: call this when holding the lock using withLock(Duration, TaskMonitor, CheckedRunnable)

      Returns:
      true if slaspec file is newer than the sla file
    • getSlaVersion

      public int getSlaVersion()
      Returns the format version number embedded in the compiled sla file.

      NOTE: this should only be called when holding the lock with withLock(Duration, TaskMonitor, CheckedRunnable)

      Returns:
      format version number embedded in the sla file, or -1 if error reading or file doesn't exist
    • compileSlaFile

      public void compileSlaFile(TaskMonitor monitor) throws SleighException
      Compiles the slaspec file and replaces the sla file with the newly compiled sleigh output.

      NOTE: this should only be called when holding the lock with withLock(Duration, TaskMonitor, CheckedRunnable)

      Parameters:
      monitor - TaskMonitor
      Throws:
      SleighException - if error occurs during compilation