Package ghidra.app.script
Class JavaScriptProvider
- java.lang.Object
-
- ghidra.app.script.GhidraScriptProvider
-
- ghidra.app.script.JavaScriptProvider
-
- All Implemented Interfaces:
ExtensionPoint
,java.lang.Comparable<GhidraScriptProvider>
public class JavaScriptProvider extends GhidraScriptProvider
-
-
Constructor Summary
Constructors Constructor Description JavaScriptProvider()
Create a newJavaScriptProvider
associated with the current bundle host used by scripting.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
createNewScript(ResourceFile newScript, java.lang.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 java.lang.String
fixupName(java.lang.String scriptName)
Fix script name for search in script directories, such as Java package parts in the name and inner class names.java.util.regex.Pattern
getBlockCommentEnd()
Returns a Pattern that matches block comment closings.java.util.regex.Pattern
getBlockCommentStart()
Returns a Pattern that matches block comment openings.ghidra.app.plugin.core.osgi.GhidraSourceBundle
getBundleForSource(ResourceFile sourceFile)
Get theGhidraSourceBundle
containing the given source file, assuming it already exists.protected java.lang.String
getCertificationBodyPrefix()
Return the prefix for each certification header body line if this file is subject to certification.protected java.lang.String
getCertifyHeaderEnd()
Return the end of certification header line if this file type is subject to certification.protected java.lang.String
getCertifyHeaderStart()
Return the start of certification header line if this file type is subject to certification.java.lang.String
getCommentCharacter()
Returns the comment character.java.lang.String
getDescription()
Returns a description for this type of script.java.lang.String
getExtension()
Returns the file extension for this type of script.GhidraScript
getScriptInstance(ResourceFile sourceFile, java.io.PrintWriter writer)
Returns a GhidraScript instance for the specified source file.java.lang.Class<?>
loadClass(ResourceFile sourceFile, java.io.PrintWriter writer)
Activate and build theGhidraSourceBundle
containingsourceFile
then load the script's class from its class loader.-
Methods inherited from class ghidra.app.script.GhidraScriptProvider
compareTo, equals, hashCode, toString, writeBody, writeHeader
-
-
-
-
Constructor Detail
-
JavaScriptProvider
public JavaScriptProvider()
Create a newJavaScriptProvider
associated with the current bundle host used by scripting.
-
-
Method Detail
-
getBundleForSource
public ghidra.app.plugin.core.osgi.GhidraSourceBundle getBundleForSource(ResourceFile sourceFile)
Get theGhidraSourceBundle
containing the given source file, assuming it already exists.- Parameters:
sourceFile
- the source file- Returns:
- the bundle
-
getDescription
public java.lang.String getDescription()
Description copied from class:GhidraScriptProvider
Returns a description for this type of script.- Specified by:
getDescription
in classGhidraScriptProvider
- Returns:
- a description for this type of script
-
getExtension
public java.lang.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 classGhidraScriptProvider
- 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 classGhidraScriptProvider
- Parameters:
sourceFile
- the script source file- Returns:
- true if the script was completely deleted and cleaned up
-
getScriptInstance
public GhidraScript getScriptInstance(ResourceFile sourceFile, java.io.PrintWriter writer) throws java.lang.ClassNotFoundException, java.lang.InstantiationException, java.lang.IllegalAccessException
Description copied from class:GhidraScriptProvider
Returns a GhidraScript instance for the specified source file.- Specified by:
getScriptInstance
in classGhidraScriptProvider
- Parameters:
sourceFile
- the source filewriter
- the print writer to write warning/error messages- Returns:
- a GhidraScript instance for the specified source file
- Throws:
java.lang.ClassNotFoundException
- if the script class cannot be foundjava.lang.InstantiationException
- if the construction of the script fails for some reasonjava.lang.IllegalAccessException
- if the class constructor is not accessible
-
loadClass
public java.lang.Class<?> loadClass(ResourceFile sourceFile, java.io.PrintWriter writer) throws java.lang.Exception
Activate and build theGhidraSourceBundle
containingsourceFile
then load the script's class from its class loader.- Parameters:
sourceFile
- the source filewriter
- the target for build messages- Returns:
- the loaded
Class
object - Throws:
java.lang.Exception
- if build, activation, or class loading fail
-
createNewScript
public void createNewScript(ResourceFile newScript, java.lang.String category) throws java.io.IOException
Description copied from class:GhidraScriptProvider
Creates a new script using the specified file.- Specified by:
createNewScript
in classGhidraScriptProvider
- Parameters:
newScript
- the new script filecategory
- the script category- Throws:
java.io.IOException
- if an error occurs writing the file
-
getBlockCommentStart
public java.util.regex.Pattern getBlockCommentStart()
Returns a Pattern that matches block comment openings. For Java this is "/*".- Overrides:
getBlockCommentStart
in classGhidraScriptProvider
- Returns:
- the Pattern for Java block comment openings
-
getBlockCommentEnd
public java.util.regex.Pattern getBlockCommentEnd()
Returns a Pattern that matches block comment closings. In Java this is an asterisk followed by a forward slash.- Overrides:
getBlockCommentEnd
in classGhidraScriptProvider
- Returns:
- the Pattern for Java block comment closings
-
getCommentCharacter
public java.lang.String getCommentCharacter()
Description copied from class:GhidraScriptProvider
Returns the comment character. For example, "//" or "#".- Specified by:
getCommentCharacter
in classGhidraScriptProvider
- Returns:
- the comment character
-
getCertifyHeaderStart
protected java.lang.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 classGhidraScriptProvider
- Returns:
- start of certification header or null if not supported
-
getCertifyHeaderEnd
protected java.lang.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 classGhidraScriptProvider
- Returns:
- end of certification header or null if not supported
-
getCertificationBodyPrefix
protected java.lang.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 classGhidraScriptProvider
- Returns:
- certification header body prefix or null if not supported
-
fixupName
protected java.lang.String fixupName(java.lang.String scriptName)
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 classGhidraScriptProvider
- Parameters:
scriptName
- the name of the script- Returns:
- the name as a '.java' file path (with '/'s and not '.'s)
-
-