Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use .py3 extension to avoid clashes with built-in script provider. #44

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

nneonneo
Copy link

There are actually useful scripts written in Jython with Python 2 syntax. It's very inconvenient to be unable to run these scripts with Ghidrathon installed. Upgrading existing scripts isn't completely straightforward either: for example, Jython supports shortcut syntax like obj.property instead of obj.getProperty() while JEP does not; never mind all of the little incompatibilities between Py2 and Py3.

This patch makes Ghidrathon only handle scripts with the .py3 extension. This only affects the script entry point; imported modules still use the .py extension as usual. Thus, the practical impact should be quite minimal. .py3 also serves to explicitly document that a script requires Ghidrathon to run.

With this patch, it is no longer necessary to disable the default script provider, and in fact you can use both Python 2 (Jython) scripts and Python 3 (Ghidrathon/JEP) scripts without any issues.

It's fairly straightforward to configure an editor to support .py3 just like .py. An alternative design would be to handle a double extension like .3.py, but that solution is uglier and will still require some kind of hack to prevent the existing script provider from handling them.

There are actually useful plugins written in Jython with Python 2 syntax. It's
very inconvenient to be unable to run these scripts. Upgrading isn't completely
straightforward either: for example, Jython supports shortcut syntax like
`obj.property` instead of `obj.getProperty()` while JEP does not.

This patch makes Ghidrathon only handle scripts with the .py3 extension. This
only affects the script entry point; imported modules should still use the .py
extension as usual. Thus, the practical impact should be quite minimal. .py3
also serves to explicitly document that a script requires Ghidrathon to run.

With this patch, it is no longer necessary to disable the default script
provider, and in fact you can use both Python 2 (Jython) scripts and Python 3
(Ghidrathon/JEP) scripts without any issues.
@nneonneo
Copy link
Author

I'm aware this is an obvious breaking change, but I'm hoping that you're open to the change. The alternative is that Python 2 (Jython) scripts are simply unusable with the Ghidrathon extension installed, which isn't great. I imagine that even if Ghidra ever gains a Python 3 interpreter, there will still need to be some mechanism to distinguish Python 2 scripts from Python 3 scripts for compatibility with existing scripts.

@ryanmkurtz
Copy link

ryanmkurtz commented Oct 8, 2024

As of Ghidra 11.2, the proper way to avoid clashes is to extend AbstractPythonScriptProvider, override getRuntimeEnvironmentName() to return something like Ghidrathon, and use the @runtime Ghidrathon tag in your scripts. This allows multiple providers to share the same file extension.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants