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

pwndbg import fails when not using virtual environment and not running gdb from pwndbg directory #1866

Closed
fidgetingbits opened this issue Aug 16, 2023 · 7 comments
Labels
Milestone

Comments

@fidgetingbits
Copy link
Contributor

Description

If you don't want to use the virtual environment you now have to tell gdbinit.py to skip it by setting an environment variable:

 venv_path = os.environ.get("PWNDBG_VENV_PATH")
 if venv_path == "PWNDBG_PLEASE_SKIP_VENV":
     pass

This will then skip the stuff requiring setup.sh and then import pwndbg. I found while doing this I was getting an error about not finding pwndbg:

Traceback (most recent call last):
  File "/home/aa/source/pwndbg/gdbinit.py", line 74, in <module>
    import pwndbg  # noqa: F401
    ^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'pwndbg'

The solution for me was to just add the following in the if venv_path == "PWNDBG_PLEASE_SKIP_VENV": condition block

+    module_path = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))
+    if module_path not in sys.path:
+        sys.path.insert(0, module_path)

But I'm not really sure this is what you would want so I'm not sending it as a pull request, but it seems useful to be able to source gdbinit.py without having to be in the pwndbg directory. I believe this used to work on earlier versions...

Steps to reproduce

source <path_to_pwndbg>/gdbinit.py from gdb, when cwd is not the pwndbg directory

My setup

pwndbg> version
Gdb:      13.2
Python:   3.11.3 (main, Jun  5 2023, 09:32:32) [GCC 13.1.1 20230429]
Pwndbg:   2023.07.17 build: 3d6f864
Capstone: 5.0.1280
Unicorn:  2.0.1
@disconnect3d
Copy link
Member

The PWNDBG_PLEASE_SKIP_VENV part is there mostly when you install Pwndbg via Nix or/and via self-contained linux distro packages that we will be deploying in the future (haven't released them yet, since I still need to double check them). Fwiw the idea beyond those packages is to allow installation of GDB+Pwndbg+all deps for environments where you have old machine and can only install .deb/.rpm/etc packages or a machine without internet.

@disconnect3d
Copy link
Member

@fidgetingbits Is there a reason you don't want to use virtual environment? Is this related to the issue we discussed on Discord where Pwndbg sources gets installed into virtualenv? This is something we may not want it to be doing.

@fidgetingbits
Copy link
Contributor Author

Ya it's the same issue, which I didnt look into closer. I just stopped using venv as I didn't want to deal with recopying the files into the venv, or rebuilding the venv every time. Better to fix the venv I guess, but in the mean time while not using it I couldn't use a bunch of my other scripts, so decided to file this anyway. Fine to close if you think not worth fixing.

@disconnect3d
Copy link
Member

This must be caused by this change: https://github.com/pwndbg/pwndbg/pull/1843/files#diff-4209d788ad32c40cbda3c66b3de47eefb929308ca703bb77a6382625986add17R192

This made it so that instead of installing just the requirements we install the whole description from pyproject.toml as a whole pwndbg package. Hmm...

@disconnect3d
Copy link
Member

@fidgetingbits
Copy link
Contributor Author

So that seems to work if I replace -U with -e. If I use both -e and -U it doesn't. I'm not sure how much it matters if we don't use -U. By using -e, we end up with something like:

❯ ls -l .venv/lib/python3.11/site-packages/pwndbg.pth
.rw-r----- 23 aa 16 Aug 18:58  .venv/lib/python3.11/site-packages/pwndbg.pth
❯ cat  .venv/lib/python3.11/site-packages/pwndbg.pth
/home/aa/source/pwndbg

I'll send a PR tomorrow.

@disconnect3d
Copy link
Member

@fidgetingbits this has been fixed in #1877 right? Closing this for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants