From 0caf175699a1d2f627512d3dbe46674611cc181e Mon Sep 17 00:00:00 2001 From: patryk4815 Date: Mon, 18 Nov 2024 14:06:23 +0100 Subject: [PATCH] Fix terminfo (#2532) * Fix proper check symlink path * Fix #2531 terminfo issues in portable build * Remove useless line this should be remove in #2459 PR * Fix terminfo for portable on darwin * test ci TERM=xterm-256color * portable: Disable user site packages `-s` (same as PYTHONNOUSERSITE=1) * portable: fix bundling on darwin * portable: Disable user site packages (same as PYTHONNOUSERSITE=1) * portable: Disable user site packages --- .github/workflows/lock.yml | 4 ++-- lldbinit.py | 2 -- nix/bundle/bundle.py | 6 +++--- nix/portable.nix | 33 +++++++++++++++++++++++---------- 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/.github/workflows/lock.yml b/.github/workflows/lock.yml index de9264b51..7f249a829 100644 --- a/.github/workflows/lock.yml +++ b/.github/workflows/lock.yml @@ -37,7 +37,7 @@ jobs: run: nix build '.#pwndbg' --accept-flake-config -o result - name: simple run pwndbg - run: ./result/bin/pwndbg <<< 'exit' + run: TERM=xterm-256color ./result/bin/pwndbg <<< 'exit' - name: configure cache if: github.ref == 'refs/heads/dev' @@ -75,7 +75,7 @@ jobs: run: nix build '.#pwndbg-lldb' --accept-flake-config -o result - name: simple run pwndbg - run: ./result/bin/pwndbg-lldb <<< 'exit' + run: TERM=xterm-256color ./result/bin/pwndbg-lldb <<< 'exit' - name: configure cache if: github.ref == 'refs/heads/dev' diff --git a/lldbinit.py b/lldbinit.py index e2100fae2..d46321195 100644 --- a/lldbinit.py +++ b/lldbinit.py @@ -142,8 +142,6 @@ def main(debugger: lldb.SBDebugger, major: int, minor: int, debug: bool = False) update_deps(src_root, venv_path) fixup_paths(src_root, venv_path) - os.environ["PWNLIB_NOTERM"] = "1" - import pwndbg # noqa: F811 import pwndbg.dbg.lldb diff --git a/nix/bundle/bundle.py b/nix/bundle/bundle.py index ac401b399..5a3746333 100755 --- a/nix/bundle/bundle.py +++ b/nix/bundle/bundle.py @@ -274,14 +274,14 @@ def copy_with_symlink_normal(src_file_path: Path, root_dir_src: Path, root_dst_d file_resolved = src_file_path.resolve() is_allowed_symlink = file_resolved.is_relative_to(root_dir_src) - if is_so and is_allowed_symlink: - # For .so / .dylib files, symlinks are only allowed within the same directory. + if is_so and is_allowed_symlink and sys.platform != 'darwin': + # For .so files, symlinks are only allowed within the same directory. # This is because $ORIGIN in the runpath cannot resolve symlinks. # This issue was specifically encountered with the file: # lib/python3.12/site-packages/lldb/_lldb.cpython-312-aarch64-linux-gnu.so -> ../../../liblldb.so.19.1.1 # To avoid such issues, we check if the resolved file's parent directory # matches the parent directory of the source file. - if file_resolved.relative_to(root_dir_src).parent != src_file_path.parent: + if file_resolved.parent != src_file_path.parent: is_allowed_symlink = False if is_allowed_symlink: diff --git a/nix/portable.nix b/nix/portable.nix index b9189b76c..14297d256 100644 --- a/nix/portable.nix +++ b/nix/portable.nix @@ -16,32 +16,45 @@ let echo -n $(basename $(patchelf --print-interpreter "${gdb}/bin/gdb")) > $out '' ); - ldLoader = if pkgs.stdenv.isDarwin then "" else "\"$dir/lib/${ldName}\""; + ldLoader = if pkgs.stdenv.isLinux then "\"$dir/lib/${ldName}\"" else ""; - linuxLldbEnvs = pkgs.lib.optionalString (pkgs.stdenv.isLinux && isLLDB) '' + commonEnvs = pkgs.lib.optionalString (pkgs.stdenv.isLinux && isLLDB) '' export LLDB_DEBUGSERVER_PATH="$dir/bin/lldb-server" + '' + pkgs.lib.optionalString pkgs.stdenv.isLinux '' + export TERMINFO_DIRS=${pkgs.lib.concatStringsSep ":" [ + # Fix issue Linux https://github.com/pwndbg/pwndbg/issues/2531 + "/etc/terminfo" # Debian, Fedora, Gentoo + "/lib/terminfo" # Debian + "/usr/share/terminfo" # upstream default, probably all FHS-based distros + "/run/current-system/sw/share/terminfo" # NixOS + ]} + '' + pkgs.lib.optionalString pkgs.stdenv.isDarwin '' + export TERMINFO_DIRS=${pkgs.lib.concatStringsSep ":" [ + # Fix issue Darwin https://github.com/pwndbg/pwndbg/issues/2531 + "/usr/share/terminfo" # upstream default, probably all FHS-based distros + ]} + '' + '' + export PYTHONNOUSERSITE=1 + export PYTHONHOME="$dir" + export PATH="$dir/bin/:$PATH" ''; + wrapperBinPwndbgGdbinit = pkgs.writeScript "pwndbg-wrapper-bin-gdbinit" '' #!/bin/sh dir="$(cd -- "$(dirname "$(dirname "$(realpath "$0")")")" >/dev/null 2>&1 ; pwd -P)" - export PYTHONHOME="$dir" - export PATH="$dir/bin/:$PATH" + ${commonEnvs} exec ${ldLoader} "$dir/exe/gdb" --quiet --early-init-eval-command="set auto-load safe-path /" --command=$dir/exe/gdbinit.py "$@" ''; wrapperBinPy = file: pkgs.writeScript "pwndbg-wrapper-bin-py" '' #!/bin/sh dir="$(cd -- "$(dirname "$(dirname "$(realpath "$0")")")" >/dev/null 2>&1 ; pwd -P)" - export PYTHONHOME="$dir" - export PATH="$dir/bin/:$PATH" - ${linuxLldbEnvs} + ${commonEnvs} exec ${ldLoader} "$dir/exe/python3" "$dir/${file}" "$@" ''; wrapperBin = file: pkgs.writeScript "pwndbg-wrapper-bin" '' #!/bin/sh dir="$(cd -- "$(dirname "$(dirname "$(realpath "$0")")")" >/dev/null 2>&1 ; pwd -P)" - export PATH="$dir/bin/:$PATH" - export PYTHONHOME="$dir" - ${linuxLldbEnvs} + ${commonEnvs} exec ${ldLoader} "$dir/${file}" "$@" ''; skipVenv = pkgs.writeScript "pwndbg-skip-venv" "";