Package ghidra.app.script

# Class JavaScriptProvider

java.lang.Object
ghidra.app.script.GhidraScriptProvider
ghidra.app.script.JavaScriptProvider

All Implemented Interfaces:
  `ExtensionPoint`, `Comparable<GhidraScriptProvider>`

public class JavaScriptProvider extends GhidraScriptProvider
The provider for Ghidra Scripts written in Java

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `JavaScriptProvider()`
  Create a new `JavaScriptProvider` associated with the current bundle host used by scripting.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `createNewScript(ResourceFile newScript, String category)`
  Creates a new script using the specified file.
  `boolean`
  `deleteScript(ResourceFile sourceFile)`
  Deletes the script file and unloads the script from the script manager.
  `protected String`
  `fixupName(String scriptName)`
  Fixup a script name for searching in script directories.
  `Pattern`
  `getBlockCommentEnd()`
  Returns a Pattern that matches block comment closings.
  `Pattern`
  `getBlockCommentStart()`
  Returns a Pattern that matches block comment openings.
  `ghidra.app.plugin.core.osgi.GhidraSourceBundle`
  `getBundleForSource(ResourceFile sourceFile)`
  Get the `GhidraSourceBundle` containing the given source file, assuming it already exists.
  `protected String`
  `getCertificationBodyPrefix()`
  Return the prefix for each certification header body line if this file is subject to certification.
  `protected String`
  `getCertifyHeaderEnd()`
  Return the end of certification header line if this file type is subject to certification.
  `protected String`
  `getCertifyHeaderStart()`
  Return the start of certification header line if this file type is subject to certification.
  `String`
  `getCommentCharacter()`
  Returns the comment character.
  `String`
  `getDescription()`
  Returns a description for this type of script.
  `String`
  `getExtension()`
  Returns the file extension for this type of script.
  `GhidraScript`
  `getScriptInstance(ResourceFile sourceFile, PrintWriter writer)`
  Returns a GhidraScript instance for the specified source file.
  `Class<?>`
  `loadClass(ResourceFile sourceFile, PrintWriter writer)`
  Activate and build the `GhidraSourceBundle` containing `sourceFile` then load the script's class from its class loader.

  ### Methods inherited from class ghidra.app.script.GhidraScriptProvider

  `compareTo, equals, hashCode, toString, writeBody, writeHeader`

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

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### JavaScriptProvider

    public JavaScriptProvider()
    Create a new `JavaScriptProvider` associated with the current bundle host used by scripting.

- ## Method Details

  - ### getBundleForSource

    public ghidra.app.plugin.core.osgi.GhidraSourceBundle getBundleForSource(ResourceFile sourceFile)
    Get the `GhidraSourceBundle` containing the given source file, assuming it already exists.
    Parameters:
      `sourceFile` - the source file
    Returns:
      the bundle

  - ### getDescription

    public String getDescription()
    Description copied from class: `GhidraScriptProvider`
    Returns a description for this type of script.
    Specified by:
      `getDescription` in class `GhidraScriptProvider`
    Returns:
      a description for this type of script

  - ### getExtension

    public String getExtension()
    Description copied from class: `GhidraScriptProvider`
    Returns the file extension for this type of script.

    For example, ".java" or ".py".

    Specified by:
      `getExtension` in class `GhidraScriptProvider`
    Returns:
      the file extension for this type of script

  - ### deleteScript

    public boolean deleteScript(ResourceFile sourceFile)
    Description copied from class: `GhidraScriptProvider`
    Deletes the script file and unloads the script from the script manager.
    Overrides:
      `deleteScript` in class `GhidraScriptProvider`
    Parameters:
      `sourceFile` - the script source file
    Returns:
      true if the script was completely deleted and cleaned up

  - ### getScriptInstance

    public GhidraScript getScriptInstance(ResourceFile sourceFile, PrintWriter writer) throws GhidraScriptLoadException
    Description copied from class: `GhidraScriptProvider`
    Returns a GhidraScript instance for the specified source file.
    Specified by:
      `getScriptInstance` in class `GhidraScriptProvider`
    Parameters:
      `sourceFile` - the source file
      `writer` - the print writer to write warning/error messages. If the error prevents success, throw an exception instead. The caller will print the error.
    Returns:
      a GhidraScript instance for the specified source file
    Throws:
      `GhidraScriptLoadException` - when the script instance cannot be created

  - ### loadClass

    public Class<?> loadClass(ResourceFile sourceFile, PrintWriter writer) throws Exception
    Activate and build the `GhidraSourceBundle` containing `sourceFile` then load the script's class from its class loader.
    Parameters:
      `sourceFile` - the source file
      `writer` - the target for build messages
    Returns:
      the loaded `Class` object
    Throws:
      `Exception` - if build, activation, or class loading fail

  - ### createNewScript

    public void createNewScript(ResourceFile newScript, String category) throws IOException
    Description copied from class: `GhidraScriptProvider`
    Creates a new script using the specified file.
    Specified by:
      `createNewScript` in class `GhidraScriptProvider`
    Parameters:
      `newScript` - the new script file
      `category` - the script category
    Throws:
      `IOException` - if an error occurs writing the file

  - ### getBlockCommentStart

    public Pattern getBlockCommentStart()
    Returns a Pattern that matches block comment openings.

    If block comments are not supported by this provider, then this returns null.

    For Java this is "/*".

    Overrides:
      `getBlockCommentStart` in class `GhidraScriptProvider`
    Returns:
      the Pattern for block comment openings, null if block comments are not supported

  - ### getBlockCommentEnd

    public Pattern getBlockCommentEnd()
    Returns a Pattern that matches block comment closings.

    If block comments are not supported by this provider, then this returns null.

    In Java this is an asterisk followed by a forward slash.

    Overrides:
      `getBlockCommentEnd` in class `GhidraScriptProvider`
    Returns:
      the Pattern for block comment closings, null if block comments are not supported

  - ### getCommentCharacter

    public String getCommentCharacter()
    Description copied from class: `GhidraScriptProvider`
    Returns the comment character.

    For example, "//" or "#".

    Specified by:
      `getCommentCharacter` in class `GhidraScriptProvider`
    Returns:
      the comment character

  - ### getCertifyHeaderStart

    protected String getCertifyHeaderStart()
    Description copied from class: `GhidraScriptProvider`
    Return the start of certification header line if this file type is subject to certification.
    Overrides:
      `getCertifyHeaderStart` in class `GhidraScriptProvider`
    Returns:
      start of certification header or null if not supported

  - ### getCertifyHeaderEnd

    protected String getCertifyHeaderEnd()
    Description copied from class: `GhidraScriptProvider`
    Return the end of certification header line if this file type is subject to certification.
    Overrides:
      `getCertifyHeaderEnd` in class `GhidraScriptProvider`
    Returns:
      end of certification header or null if not supported

  - ### getCertificationBodyPrefix

    protected String getCertificationBodyPrefix()
    Description copied from class: `GhidraScriptProvider`
    Return the prefix for each certification header body line if this file is subject to certification.
    Overrides:
      `getCertificationBodyPrefix` in class `GhidraScriptProvider`
    Returns:
      certification header body prefix or null if not supported

  - ### fixupName

    protected String fixupName(String scriptName)
    Fixup a script name for searching in script directories.

    This method is part of a poorly specified behavior that is due for future amendment, see `GhidraScriptUtil.fixupName(String)`.

    Fix script name for search in script directories, such as Java package parts in the name and inner class names.

    This method can handle names with '$' (inner classes) and names with '.' characters for package separators

    It is part of a poorly specified behavior that is due for future amendment, see `GhidraScriptUtil.fixupName(String)`.

    Overrides:
      `fixupName` in class `GhidraScriptProvider`
    Parameters:
      `scriptName` - the name of the script
    Returns:
      the name as a '.java' file path (with '/'s and not '.'s)