diff --git a/.github/workflows/releases.yml b/.github/workflows/releases.yml index 8eb67bf56..608e74ee6 100644 --- a/.github/workflows/releases.yml +++ b/.github/workflows/releases.yml @@ -18,18 +18,18 @@ jobs: nix_path: nixpkgs=channel:nixos-unstable - name: build pwndbg - run: nix build '.?submodules=1#pwndbg' -o result-pwndbg + run: nix build '.#pwndbg' -o result-pwndbg - name: build rpm - run: nix build '.?submodules=1#rpm' -o dist-rpm + run: nix build '.#rpm' -o dist-rpm - name: build deb - run: nix build '.?submodules=1#deb' -o dist-deb + run: nix build '.#deb' -o dist-deb - name: build apk - run: nix build '.?submodules=1#apk' -o dist-apk + run: nix build '.#apk' -o dist-apk - name: build archlinux - run: nix build '.?submodules=1#archlinux' -o dist-archlinux + run: nix build '.#archlinux' -o dist-archlinux - name: build tarball - run: nix build '.?submodules=1#tarball' -o dist-tarball + run: nix build '.#tarball' -o dist-tarball - name: release uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 # @v1 diff --git a/Dockerfile b/Dockerfile index e290ba687..97b782f3b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -33,15 +33,12 @@ ADD ./pyproject.toml /pwndbg/ ADD ./dev-requirements.txt /pwndbg/ # pyproject.toml requires these files, pip install would fail -RUN touch README.md && mkdir pwndbg && touch pwndbg/empty.py && mkdir gdb-pt-dump && touch gdb-pt-dump/empty.py +RUN touch README.md && mkdir pwndbg && touch pwndbg/empty.py -# The `git submodule` is commented because it refreshes all the sub-modules in the project -# but at this time we only need the essentials for the set up. It will execute at the end. -RUN sed -i "s/^git submodule/#git submodule/" ./setup.sh && \ - DEBIAN_FRONTEND=noninteractive ./setup.sh +RUN DEBIAN_FRONTEND=noninteractive ./setup.sh # Cleanup dummy files -RUN rm README.md && rm -rf pwndbg && rm -rf gdb-pt-dump +RUN rm README.md && rm -rf pwndbg # Comment these lines if you won't run the tests. ADD ./setup-dev.sh /pwndbg/ @@ -50,5 +47,3 @@ RUN ./setup-dev.sh RUN echo "source /pwndbg/gdbinit.py" >> ~/.gdbinit.py ADD . /pwndbg/ - -RUN git submodule update --init --recursive diff --git a/Dockerfile.arch b/Dockerfile.arch index 602871ed7..5d8a0fcd6 100644 --- a/Dockerfile.arch +++ b/Dockerfile.arch @@ -30,16 +30,13 @@ ADD ./poetry.lock /pwndbg/ ADD ./dev-requirements.txt /pwndbg/ # pyproject.toml requires these files, pip install would fail -RUN touch README.md && mkdir pwndbg && touch pwndbg/empty.py && mkdir gdb-pt-dump && touch gdb-pt-dump/empty.py +RUN touch README.md && mkdir pwndbg && touch pwndbg/empty.py -# The `git submodule` is commented because it refreshes all the sub-modules in the project -# but at this time we only need the essentials for the set up. It will execute at the end. -RUN sed -i "s/^git submodule/#git submodule/" ./setup.sh && \ - sed -i 's/read -p "Do you want to do a full system update?/#read/' ./setup.sh && \ +RUN sed -i 's/read -p "Do you want to do a full system update?/#read/' ./setup.sh && \ ./setup.sh # Cleanup dummy files -RUN rm README.md && rm -rf pwndbg && rm -rf gdb-pt-dump +RUN rm README.md && rm -rf pwndbg # Comment these lines if you won't run the tests. ADD ./setup-dev.sh /pwndbg/ @@ -51,5 +48,3 @@ RUN echo "source /pwndbg/gdbinit.py" >> ~/.gdbinit.py && \ echo "export PATH=$PATH:$PYTHON_PATH" >> /root/.bashrc ADD . /pwndbg/ - -RUN git submodule update --init --recursive diff --git a/README.md b/README.md index 4839bbcaa..bbe58ca8b 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,12 @@ cd pwndbg ./setup.sh ``` +Or install via the Nix package manager (you can use Nix on any distribution): +```shell +nix shell github:pwndbg/pwndbg +pwndbg ./your-binnary +``` + Pwndbg is supported on Ubuntu 20.04, and 22.04 with GDB 9.2 and later. We do not test on any older versions of Ubuntu, so `pwndbg` may not work on these versions (for Ubuntu 18.04 use the [2023.07.17: ubuntu18.04-final release](https://github.com/pwndbg/pwndbg/releases/tag/2023.07.17)). We may accept pull requests fixing issues in older versions on a case by case basis, please discuss this with us on [Discord](https://discord.gg/x47DssnGwm) first. You can also always checkout an older version of `pwndbg` from around the time the Ubuntu version you're interested in was still supported by Canonical, or you can attempt to build a newer version of GDB from source. Other Linux distributions are also supported via `setup.sh`, including: diff --git a/flake.lock b/flake.lock index 5e08da20a..b8727703c 100644 --- a/flake.lock +++ b/flake.lock @@ -5,11 +5,11 @@ "systems": "systems" }, "locked": { - "lastModified": 1689068808, - "narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=", + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", "owner": "numtide", "repo": "flake-utils", - "rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", "type": "github" }, "original": { @@ -26,11 +26,11 @@ ] }, "locked": { - "lastModified": 1688870561, - "narHash": "sha256-4UYkifnPEw1nAzqqPOTL2MvWtm3sNGw1UTYTalkTcGY=", + "lastModified": 1693660503, + "narHash": "sha256-B/g2V4v6gjirFmy+I5mwB2bCYc0l3j5scVfwgl6WOl8=", "owner": "nix-community", "repo": "nix-github-actions", - "rev": "165b1650b753316aa7f1787f3005a8d2da0f5301", + "rev": "bd5bdbb52350e145c526108f4ef192eb8e554fa0", "type": "github" }, "original": { @@ -41,11 +41,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1691313029, - "narHash": "sha256-JCdafAmmuOkcRGFEUkXckRZ3Q/PBBtcm1Mq0GBA3XEY=", + "lastModified": 1698855203, + "narHash": "sha256-I9Vrh2ZXBZciGjgIXVhlHNc9XxRt0+bGlUGLGDXQ2r8=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "0bab81e6319eb418e1509fe4b88401a022f3bf99", + "rev": "39d2f0847ebbb57beb8fe3b992b043ad39afa0af", "type": "github" }, "original": { @@ -61,14 +61,16 @@ "nix-github-actions": "nix-github-actions", "nixpkgs": [ "nixpkgs" - ] + ], + "systems": "systems_2", + "treefmt-nix": "treefmt-nix" }, "locked": { - "lastModified": 1691333779, - "narHash": "sha256-sCPemHLepJxZwYpAIs6RfgYVO8SlutWq2yc3lZgXvko=", + "lastModified": 1698873888, + "narHash": "sha256-ZIJ7IS38DQ52JL6Zxbs7F6iXardwEAAz1PQrZfyFmTU=", "owner": "nix-community", "repo": "poetry2nix", - "rev": "a2e7c3522d79ec28a2d41bf8ea19ced88f882a05", + "rev": "566e2cdc8c90969f5a165aa6c4e863df2c3fefd7", "type": "github" }, "original": { @@ -97,6 +99,41 @@ "repo": "default", "type": "github" } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "id": "systems", + "type": "indirect" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "poetry2nix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1697388351, + "narHash": "sha256-63N2eBpKaziIy4R44vjpUu8Nz5fCJY7okKrkixvDQmY=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "aae39f64f5ecbe89792d05eacea5cb241891292a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 6f3f26005..3aded7e10 100644 --- a/flake.nix +++ b/flake.nix @@ -15,7 +15,7 @@ pkgsBySystem = forAllSystems (system: import nixpkgs { inherit system; - overlays = [ poetry2nix.overlay ]; + overlays = [ poetry2nix.overlays.default ]; }); pkgUtil = forAllSystems (system: import ./nix/bundle/pkg.nix { pkgs = pkgsBySystem.${system}; diff --git a/gdbinit.py b/gdbinit.py index b379c8fbc..520e6e4ca 100644 --- a/gdbinit.py +++ b/gdbinit.py @@ -48,14 +48,12 @@ else: bin_path = os.path.join(venv_path, "bin") os.environ["PATH"] = bin_path + os.pathsep + os.environ.get("PATH") - # Add gdb-pt-dump directory to sys.path so it can be imported - gdbpt = path.join(directory, "gdb-pt-dump") + # Add pwndbg directory to sys.path so it can be imported sys.path.insert(0, directory) - sys.path.insert(1, gdbpt) # Push virtualenv's site-packages to the front sys.path.remove(site_pkgs_path) - sys.path.insert(2, site_pkgs_path) + sys.path.insert(1, site_pkgs_path) # warn if the user has different encoding than utf-8 diff --git a/nix/portable.nix b/nix/portable.nix index b3e3bfdf1..f3b34ac56 100644 --- a/nix/portable.nix +++ b/nix/portable.nix @@ -20,7 +20,7 @@ dir="$(cd -- "$(dirname "$(dirname "$(realpath "$0")")")" >/dev/null 2>&1 ; pwd export PYTHONHOME="$dir" export PYTHONPYCACHEPREFIX="$dir/cache/" export PWNDBG_VENV_PATH="PWNDBG_PLEASE_SKIP_VENV" -exec "$dir/lib/${ldName}" "$dir/exe/gdb" --quiet --eval-command="set charset UTF-8" --eval-command="set auto-load safe-path /" --command=$dir/exe/gdbinit.py "$@" +exec "$dir/lib/${ldName}" "$dir/exe/gdb" --quiet --early-init-eval-command="set charset UTF-8" --early-init-eval-command="set auto-load safe-path /" --command=$dir/exe/gdbinit.py "$@" ''; # for cache: pwndbg --eval-command="py import compileall; compileall.compile_dir('/usr/lib/pwndbg/'); exit()" @@ -47,10 +47,12 @@ exec "$dir/lib/${ldName}" "$dir/exe/gdb" --quiet --eval-command="set charset UTF chmod -R +w $out cp -rf ${pwndbg.src}/pwndbg $out/pwndbg/lib/${python3.libPrefix}/site-packages/ - cp -rf ${pwndbg.src}/gdb-pt-dump $out/pwndbg/lib/${python3.libPrefix}/site-packages/ cp ${pwndbg.src}/gdbinit.py $out/pwndbg/exe/ cp ${pwndbgBundleBin} $out/pwndbg/bin/pwndbg + + # fix python "subprocess.py" to use "/bin/sh" and not the nix'ed version, otherwise "gdb-pt-dump" is broken + substituteInPlace $out/pwndbg/lib/${python3.libPrefix}/subprocess.py --replace "'${pkgs.bash}/bin/sh'" "'/bin/sh'" ''; in portable diff --git a/nix/pwndbg.nix b/nix/pwndbg.nix index d16775aaa..a3d56dec2 100644 --- a/nix/pwndbg.nix +++ b/nix/pwndbg.nix @@ -18,6 +18,9 @@ let overrides = pkgs.poetry2nix.overrides.withDefaults (self: super: { pip = python3.pkgs.pip; # fix infinite loop in nix, look here: https://github.com/nix-community/poetry2nix/issues/1184#issuecomment-1644878841 unicorn = python3.pkgs.unicorn; # fix build for aarch64 (but it will use same version like in nixpkgs) + pt = super.pt.overridePythonAttrs (old: { + buildInputs = (old.buildInputs or [ ]) ++ [ super.poetry-core ]; + }); capstone = super.capstone.overridePythonAttrs (old: { # fix darwin preBuild = pkgs.lib.optionalString pkgs.stdenv.isDarwin '' @@ -47,8 +50,6 @@ let src = pkgs.lib.sourceByRegex inputs.pwndbg [ "pwndbg" "pwndbg/.*" - "gdb-pt-dump" - "gdb-pt-dump/.*" "gdbinit.py" ]; @@ -57,14 +58,14 @@ let installPhase = '' mkdir -p $out/share/pwndbg - cp -r gdbinit.py pwndbg gdb-pt-dump $out/share/pwndbg + cp -r gdbinit.py pwndbg $out/share/pwndbg ln -s ${pyEnv} $out/share/pwndbg/.venv makeWrapper ${gdb}/bin/gdb $out/bin/pwndbg \ - --add-flags "--quiet --eval-command=\"set charset UTF-8\" --eval-command=\"set auto-load safe-path /\" --command=$out/share/pwndbg/gdbinit.py" \ + --add-flags "--quiet --early-init-eval-command=\"set charset UTF-8\" --early-init-eval-command=\"set auto-load safe-path /\" --command=$out/share/pwndbg/gdbinit.py" \ --prefix PATH : ${binPath} \ - --set LC_CTYPE C.UTF-8 + --set LC_CTYPE C.UTF-8 ''; meta = { diff --git a/poetry.lock b/poetry.lock index 666894a6d..578f559f2 100644 --- a/poetry.lock +++ b/poetry.lock @@ -484,6 +484,21 @@ files = [ [package.extras] test = ["enum34", "ipaddress", "mock", "pywin32", "wmi"] +[[package]] +name = "pt" +version = "1.0.0" +description = "`gdb-pt-dump` is a gdb script to examine the address space of a QEMU-based virtual machine." +optional = false +python-versions = "^3.8" +files = [] +develop = false + +[package.source] +type = "git" +url = "https://github.com/patryk4815/gdb-pt-dump" +reference = "a5e363316adb977d2c3a12fae3697ce20bece898" +resolved_reference = "a5e363316adb977d2c3a12fae3697ce20bece898" + [[package]] name = "pwntools" version = "4.11.0" @@ -776,4 +791,4 @@ zstd = ["zstandard (>=0.18.0)"] [metadata] lock-version = "2.0" python-versions = "^3.8" -content-hash = "bcbb1f8025aab6dd658b42dca35f538619945d0a5fdeb826b289aec75425c0db" +content-hash = "2fbe1e759f4fb2b01443c788c30672cae00b0954b0713b1b9f38bbc217a0a333" diff --git a/pyproject.toml b/pyproject.toml index 75f7ec06d..eb079a65c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,9 +1,7 @@ [tool.black] line-length = 100 -extend-exclude = "gdb-pt-dump" [tool.ruff] -exclude = ["gdb-pt-dump"] ignore = [ "A003", "E402", @@ -84,7 +82,6 @@ ignore_missing_imports = true profile = "black" force_single_line = true known_third_party = ["capstone", "unicorn", "psutil", "pycparser", "gdb"] -extend_skip_glob = ["gdb-pt-dump/*"] add_imports = "from __future__ import annotations" [tool.coverage.run] @@ -171,7 +168,7 @@ disable = [ # Files or directories to be skipped. They should be base names, not paths. -ignore = ["tests", "gdb-pt-dump", ".git"] +ignore = ["tests", ".git"] # List of module names for which member attributes should not be checked (useful # for modules/projects where namespaces are manipulated during runtime and thus @@ -255,7 +252,6 @@ authors = ["Dominik 'disconnect3d' Czarnota "] readme = "README.md" packages = [ { include = "pwndbg" }, - { include = "gdb-pt-dump" } ] [tool.poetry.dependencies] @@ -271,6 +267,7 @@ tabulate = "0.9.0" typing-extensions = "4.6.1" unicorn = "2.0.1.post1" requests = "2.31.0" +pt = {git = "https://github.com/patryk4815/gdb-pt-dump", rev = "a5e363316adb977d2c3a12fae3697ce20bece898"} [build-system] requires = ["poetry-core"] diff --git a/setup.sh b/setup.sh index 2de6b0ee3..8820b3b53 100755 --- a/setup.sh +++ b/setup.sh @@ -170,9 +170,6 @@ if ! hash gdb; then exit fi -# Update all submodules -git submodule update --init --recursive - # Find the Python version used by GDB. PYVER=$(gdb -batch -q --nx -ex 'pi import platform; print(".".join(platform.python_version_tuple()[:2]))') PYTHON+=$(gdb -batch -q --nx -ex 'pi import sys; print(sys.executable)') @@ -196,17 +193,6 @@ ${PYTHON} -m pip install --upgrade pip # Create Python virtual environment and install dependencies in it ${PWNDBG_VENV_PATH}/bin/pip install -e . -# pyproject.toml install itself "pwndbg"/"gdb-pt-dump" into site-packages, for "caching" dockerfile we need remove it -PYTHON_VERSION=$(ls "${PWNDBG_VENV_PATH}/lib/") -CHECK_PATH="${PWNDBG_VENV_PATH}/lib/${PYTHON_VERSION}/site-packages/pwndbg/empty.py" -if [ -f "$CHECK_PATH" ]; then - rm -rf "$(dirname "$CHECK_PATH")" -fi -CHECK_PATH="${PWNDBG_VENV_PATH}/lib/${PYTHON_VERSION}/site-packages/gdb-pt-dump/empty.py" -if [ -f "$CHECK_PATH" ]; then - rm -rf "$(dirname "$CHECK_PATH")" -fi - if [ -z "$UPDATE_MODE" ]; then # Comment old configs out if grep -q '^[^#]*source.*pwndbg/gdbinit.py' ~/.gdbinit; then