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

Add ghidra.app.script.GhidraScript println, printf, printerr methods to Python built-in scope #97

Open
hoanghai27 opened this issue Mar 25, 2024 · 2 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@hoanghai27
Copy link

I need to use the println function to log messages when running headless mode but I see that Ghidrathon is ignoring it. Why is that? Can you support it?

>>> println
Traceback (most recent call last):
  File "/home/user/.ghidra/.ghidra_11.0.1_PUBLIC/Extensions/Ghidrathon/data/python/jepeval.py", line 74, in jepeval
    more_input_needed = _jepeval(line)
                        ^^^^^^^^^^^^^^
  File "/home/user/.ghidra/.ghidra_11.0.1_PUBLIC/Extensions/Ghidrathon/data/python/jepeval.py", line 49, in _jepeval
    exec(compile(line, "<string>", "single"), globals(), globals())
  File "<string>", line 1, in <module>
NameError: name 'println' is not defined

https://github.com/mandiant/Ghidrathon/blob/91c0cab3ecdd01ec3327d577cc5e0b4e31a384ae/data/python/jepwrappers.py#L285C29-L285C34

@mike-hunhoff
Copy link
Collaborator

Thanks for reaching out @hoanghai27 . This specific line of code prevents overwriting Python's print function but you're correct that we should, if possible, add ghidra.app.script.GhidraScript's print* methods (println, printf, printerr). I limited these methods initially because Ghidrathon has to wire the Python interpreter's stdout, stderr to the JVM's stdout, stderr and additional testing would be needed to ensure the additional methods function as expected after the wiring is configured.

In the mean time, are you able to use the print method for your needs here?

@mike-hunhoff mike-hunhoff added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers labels Mar 25, 2024
@mike-hunhoff mike-hunhoff changed the title Why did Ghidrathon omit the println function? Add ghidra.app.script.GhidraScript println, printf, printerr methods to Python built-in scope Mar 25, 2024
@hoanghai27
Copy link
Author

Thanks for your feedback, I tried removing those two lines and found that both python's print function and Ghidra's println function work fine on both Ghidrathon console and scripts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants