You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was wondering if dropping into pdb/ipdb, or a REPL from Ghidra's headless mode would be possible using Ghidrathon.
Just naively trying ipdb results in:
[...snip...]
INFO SCRIPT: /src/checker/ghidra.py (HeadlessAnalyzer)
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/jep/java_import_hook.py", line 45, in __getattr__
return super(module, self).__getattribute__(name)
AttributeError: module 'pdb' has no attribute 'Pdb'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/root/.ghidra/.ghidra_10.2.3_PUBLIC/Extensions/ghidrathon/data/python/jeprunscript.py", line 31, in jep_runscript
exec(compile(source, path, "exec"), {**globals(), **additional_globals})
File "/src/checker/ghidra.py", line 8, in <module>
from IPython import embed
File "/usr/lib/python3/dist-packages/IPython/__init__.py", line 55, in <module>
from .core.application import Application
File "/usr/lib/python3/dist-packages/IPython/core/application.py", line 25, in <module>
from IPython.core import release, crashhandler
File "/usr/lib/python3/dist-packages/IPython/core/crashhandler.py", line 27, in <module>
from IPython.core import ultratb
File "/usr/lib/python3/dist-packages/IPython/core/ultratb.py", line 112, in <module>
from IPython.core import debugger
File "/usr/lib/python3/dist-packages/IPython/core/debugger.py", line 123, in <module>
from pdb import Pdb as OldPdb
File "/usr/local/lib/python3.10/dist-packages/jep/java_import_hook.py", line 57, in __getattr__
clazz = forName('{0}.{1}'.format(self.__name__, name))
ImportError: java.lang.ClassNotFoundException: pdb.Pdb
[...snip...]
results in a prompt, but the code is only interpreted when I leave the interactive session (e.g., CTRL+D):
[...snip...]
INFO SCRIPT: /src/checker/ghidra.py (HeadlessAnalyzer)
>>> print("foobar")
>>> Python 3.10.6 (main, Mar 10 2023, 10:55:28) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
now exiting InteractiveConsole...
foobar
[...snip...]
Is there any way to do this?
The text was updated successfully, but these errors were encountered:
Hi @0ddc0de - thank you for reaching out. TLDR; this unfortunately appears to be a bug in Ghidrathon. In theory, after fixing this bug what you are trying to do should work, although, I am uncertain without testing how dropping into a REPL may mess with headless execution flow.
Long winded explanation and notes:
Based on ImportError: java.lang.ClassNotFoundException: pdb.Pdb it appears Ghidra's ghidra.app.util.bin.format.pdb package is overshadowing Python's pdb module. This is likely due to Jep's import hook giving preference to Java over Python when resolving imports.
We should give preference to Python when executing Python code but still allow access to the overshadowed Java package. This likely requires wrapping Jep's ClassEnquirer as discussed here or modifying Jep's java_import_hook.py.
Hi,
First of all, thanks for this project!
I was wondering if dropping into pdb/ipdb, or a REPL from Ghidra's headless mode would be possible using Ghidrathon.
Just naively trying
ipdb
results in:Using
results in a prompt, but the code is only interpreted when I leave the interactive session (e.g.,
CTRL+D
):Is there any way to do this?
The text was updated successfully, but these errors were encountered: