Print a warning for users if they don't have ipython

This commit is contained in:
lebr0nli 2022-09-29 10:04:18 +08:00 committed by Disconnect3d
parent 8d184a9e8e
commit 3f3746beb2
1 changed files with 15 additions and 6 deletions

View File

@ -6,6 +6,7 @@ from contextlib import contextmanager
import gdb
import pwndbg.color.message as M
import pwndbg.commands
@ -33,12 +34,20 @@ def switch_to_ipython_env():
def ipi():
with switch_to_ipython_env():
# Use `gdb.execute` to embed IPython into GDB's variable scope
code4ipython = """import IPython
import jedi
try:
gdb.execute("pi import IPython")
except gdb.error:
print(
M.warn(
"Cannot import IPython.\n"
"You need to install IPython if you want to use this command.\n"
"Maybe you can try `pip install ipython` first."
)
)
return
code4ipython = """import jedi
import pwn
jedi.Interpreter._allow_descriptor_getattr_default = False
IPython.embed(colors='neutral',banner1='',confirm_exit=False,simple_prompt=False)
""".strip().replace(
"\n", ";"
)
gdb.execute(f"pi {code4ipython}")
"""
gdb.execute(f"py\n{code4ipython}")