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

doc: Python modules are imported once and exist for the lifetime of your Ghidra process #103

Open
jonschz opened this issue May 13, 2024 · 3 comments
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@jonschz
Copy link

jonschz commented May 13, 2024

Hello,

sorry if this is a beginner question, but this looks like a bug to me.

Steps to reproduce:

  1. Create a new Python 3 Ghidra script, e.g. example.py.
  2. Create a folder next to that script (e.g. ghidra_utils) and create a file in there, e.g. debugging.py.
  3. Add the following contents:
[example.py]
from ghidra_util.debugging import demo_function
demo_function()

[debugging.py]
def demo_function():
    print("Hello there")
  1. Run the script in Ghidra.
  2. Invalidate the syntax in debugging.py, e.g. by adding invalid_syntax somewhere within the file.
  3. Run the script again.

Now the script runs as if debugging.py had not changed. More annoyingly, in order to fix bugs in submodules I need to restart Ghidra every time I make a change. I have observed a more expected behaviour before I installed Ghidrathon.

Setup: Windows 10, Ghidra 11.0.3, Ghidration 4.0.0, Python 3.12

Thanks in advance for looking at this!

@mike-hunhoff
Copy link
Collaborator

Thank you for reaching out @jonschz ! This an expected behavior resulting from Ghidrathon's use of Jep's shared interpreters where Python modules are imported once and exist for the life of the Ghidra (Java) process. We are required to do this in order for Ghidrathon to properly run CPython extensions (more discussion on this topic found in Jep's documentation).

For development, where imported modules may frequently change, you can use Python's importlib.reload to force affected modules to be reloaded without needing to restart your Ghidra process. You should be able to call this from Ghidrathon's interpreter window and see the module reloaded (and changes reflected) for subsequent script executions using Ghidra's script manager.

@jonschz
Copy link
Author

jonschz commented May 20, 2024

Thank you for your response! In that case, would it make sense to update the documentation / README with a short explanation and/or example? I was mostly surprised that stock Ghidra behaves differently.

@mike-hunhoff
Copy link
Collaborator

That's a good idea @jonschz , I'll update this issue to reflect adding documentation to describe this functionality.

@mike-hunhoff mike-hunhoff changed the title Dependent files are not reloaded on changes doc: Python modules are imported once and exist for the lifetime of your Ghidra process May 21, 2024
@mike-hunhoff mike-hunhoff added documentation Improvements or additions to documentation enhancement New feature or request labels May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants