Ghidra: [Scripting] Subpackages in scripts

Created on 6 Jul 2020  路  5Comments  路  Source: NationalSecurityAgency/ghidra

Hi everyone !

I have been playing with the ghidra script API for a few days, and my script file keep growing bigger as I add more features to it. To make my code cleaner and more readable, I have been splitting my script into subpackages (as a sane person would do).

But right now I am stumbling upon a big issue: whenever I modify one of my subpackages that are included by my main script (the class that extends GhidraScript), ghidra does not recognize the changes I made to it and uses an old cached version of my subpackage. To be able to use a modified subpackage, I need to restart ghidra which is not really optimal.

Is there a way to force ghidra to always use updated versions of subpackages when scripting ?

Thanks for any help ! :)

Most helpful comment

I attempt to address this in #1941. Other than using that branch, you should be able to blow away your ~/.ghidra/.ghidra-<version>/dev/ghidra_scripts directory to force the recompile. Another hack is to make your utility class a parent class of your GhidraScript, because it is currently smart enough to detect changes in parent classes.

All 5 comments

I attempt to address this in #1941. Other than using that branch, you should be able to blow away your ~/.ghidra/.ghidra-<version>/dev/ghidra_scripts directory to force the recompile. Another hack is to make your utility class a parent class of your GhidraScript, because it is currently smart enough to detect changes in parent classes.

Thanks for your answer !
I tried to clean my ~/.ghidra/.... directory and now I have the following message when I run my script again:
Successfully compiled: MyScript.java
Unable to locate script class: MyScript

Any idea on how to solve this issue ?

After investigating a little bit, I found that this was caused because MyScript.java was located in its own package myscript. Putting it out of a package makes it work.

I believe this issue is caused by the method getScriptClass() in ghidra.app.script.JavaScriptProvider.java, as its uses only the base name of a script an not a fully qualified name as it is specified in the java.lang.Class.forName documentation.
I don't know if this is worth to open another issue ...

There is an intentional requirement that scripts intended to run be in the default package, so I wouldn't consider that a bug.

That's what I thought !

Thanks for your help !

Was this page helpful?
0 / 5 - 0 ratings

Related issues

awsaba picture awsaba  路  3Comments

huettenhain picture huettenhain  路  3Comments

pd0wm picture pd0wm  路  3Comments

Kerilk picture Kerilk  路  3Comments

chibicitiberiu picture chibicitiberiu  路  3Comments