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

Implementing listening classes don't trigger in seperate threads #41

Open
mahaloz opened this issue Jun 7, 2024 · 1 comment
Open

Comments

@mahaloz
Copy link

mahaloz commented Jun 7, 2024

Hi Pyhidra developers! I've recently been moving to reimplement our plugin system, BinSync to Pyhidra Python3. In our code, we have some code to handle events generated by users when they make changes in their decompiler.

I put the following code in the Pyhidra interpreter running in Ghidra:

from ghidra.framework.model import DomainObjectListener
from jpype import JImplements, JOverride

@JImplements(DomainObjectListener)
class DataMonitor:
    @JOverride
    def domainObjectChanged(self, ev):
        print(ev)

my_monitor = DataMonitor()
currentProgram.addListener(my_monitor)

Now, after making some changes in the normal CodeBrowser (like renaming the function), a print should appear in the Python window. However, it never does. I notice I can only get the print to trigger if I make the change to the Domain inside the Python window.

Is this intended? Or, am I doing something incorrect? Are there any workarounds?

Thank you!

@dc3-tsd
Copy link
Member

dc3-tsd commented Oct 4, 2024

Sorry for the delay in response. We did not want to recommend the usage of certain functionality until we were sure it would be carried over into PyGhidra.

The domainObjectChanged callback is being triggered in the thread that called it. The reason the print statement isn't being seen is due to how stdout and stderr are redirected on a per-thread, best effort basis. We have overriden the builtin print function within ghidra script context to ensure print will always work as expected.

While you can't extend a Java class from Python, we have created a mechanism to assist in situations where this is required. You can create the necessary Java classes in Java and create an interface which can be implemented in Python and delegate the necessary calls to your implemented interface. You can then register this with pyhidra to create and install the Ghidra plugin for you. An example for how to register it may be found and an example of the necessary Java code may be found. When registering the entry points, please use "pyghidra.setup" and "pyghidra.pre_launch"

Ghidra uses Swing for it's GUI. Attempting to use another GUI framework is not recommended and may not work at all on some operating systems.

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

No branches or pull requests

2 participants