Package ghidra.app.script
Class GhidraScriptUtil
java.lang.Object
ghidra.app.script.GhidraScriptUtil
A utility class for managing script directories and ScriptInfo objects.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ghidra.app.plugin.core.osgi.BundleHostWhen running the GUI,GhidraScriptUtilmanages a singleBundleHostinstance.static ResourceFilecreateNewScript(GhidraScriptProvider provider, ResourceFile parentDirectory, List<ResourceFile> scriptDirectories) Creates a new script with a unique name using the specified provider in the specified directory.static ResourceFilefindScriptByName(String scriptName) Search the currently managed scripts for one with the given name.static ResourceFilefindSourceDirectoryContaining(ResourceFile sourceFile) Search the currently managed source directories for the given script file.static StringgetBaseName(ResourceFile script) Returns the base name give a script file.static ghidra.app.plugin.core.osgi.BundleHoststatic List<ResourceFile> Returns a list of the current enabled script directories.static List<ResourceFile> Deprecated.accessing class file directly precludes OSGi wiring according to requirements and capabilitiesstatic GhidraScriptProvidergetProvider(ResourceFile scriptFile) Returns the corresponding Ghidra script provider for the specified script file.static List<GhidraScriptProvider> Returns a list of all supported Ghidra script providers.static List<ResourceFile> Returns a list of the current script directories.static List<ResourceFile> Returns a list of the default script directories.static ResourceFilestatic booleanhasScriptProvider(ResourceFile scriptFile) Returns true if a provider exists that can process the specified file.static booleanisSystemScript(ResourceFile file) Determine if the specified file is contained within the Ghidra installation.static ScriptInfonewScriptInfo(ResourceFile file) static voidrelease the reference the BundleHost reference.
-
Field Details
-
USER_SCRIPTS_DIR
User's home scripts directory
-
-
Constructor Details
-
GhidraScriptUtil
public GhidraScriptUtil()
-
-
Method Details
-
getBundleHost
public static ghidra.app.plugin.core.osgi.BundleHost getBundleHost()- Returns:
- the bundle host used for scripting
-
getScriptSourceDirectories
Returns a list of the current script directories.- Returns:
- a list of the current script directories
-
getEnabledScriptSourceDirectories
Returns a list of the current enabled script directories.- Returns:
- a list of the current enabled script directories
-
findSourceDirectoryContaining
Search the currently managed source directories for the given script file.- Parameters:
sourceFile- the source file- Returns:
- the source directory if found, or null if not
-
findScriptByName
Search the currently managed scripts for one with the given name.- Parameters:
scriptName- the name- Returns:
- the first file found or null if none are found
-
getSystemScriptDirectories
Returns a list of the default script directories.- Returns:
- a list of the default script directories
-
getUserScriptDirectory
-
isSystemScript
Determine if the specified file is contained within the Ghidra installation.- Parameters:
file- script file or directory- Returns:
- true if file contained within Ghidra installation area
-
getExplodedCompiledSourceBundlePaths
Deprecated.accessing class file directly precludes OSGi wiring according to requirements and capabilitiesReturns the list of exploded bundle directories- Returns:
- the list
-
getBaseName
Returns the base name give a script file. For example, given "C:\Temp\SomeClass.java", it will return "SomeClass".- Parameters:
script- the script- Returns:
- the base name
-
getProviders
Returns a list of all supported Ghidra script providers.NOTE: The list is
priority-sorted- Returns:
- a list of all supported Ghidra script providers
- API Notes:
- this method is synchronized so that two threads do not try to create the list when null
-
getProvider
Returns the corresponding Ghidra script provider for the specified script file.- Parameters:
scriptFile- the script file- Returns:
- the Ghidra script provider or
UnsupportedScriptProviderif the script file does not exist or no provider matches
-
hasScriptProvider
Returns true if a provider exists that can process the specified file.- Parameters:
scriptFile- the script file- Returns:
- true if a provider exists that can process the specified file
-
createNewScript
public static ResourceFile createNewScript(GhidraScriptProvider provider, ResourceFile parentDirectory, List<ResourceFile> scriptDirectories) throws IOException Creates a new script with a unique name using the specified provider in the specified directory.- Parameters:
provider- the Ghidra script providerparentDirectory- the directory where the new script will be created.scriptDirectories- The list of directories containing scripts (used to find a unique name).- Returns:
- the newly created script file
- Throws:
IOException- if an i/o error occurs
-
newScriptInfo
-
acquireBundleHostReference
public static ghidra.app.plugin.core.osgi.BundleHost acquireBundleHostReference()When running the GUI,GhidraScriptUtilmanages a singleBundleHostinstance.- Returns:
- the BundleHost singleton
-
releaseBundleHostReference
public static void releaseBundleHostReference()release the reference the BundleHost reference. When no references remain,dispose()is called.
-