Skip to content

Commit

Permalink
- remove gdb-pt-dump from all files
Browse files Browse the repository at this point in the history
- remove submodules from all files
- bump flake.lock
- add gdb-pt-dump as dependency
- fix building Dockerfile
- fix gdb-pt-dump was broken on portable packages
  • Loading branch information
patryk4815 authored and disconnect3d committed Nov 2, 2023
1 parent 3fddf03 commit ab96e1a
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 67 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/releases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 3 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand All @@ -50,5 +47,3 @@ RUN ./setup-dev.sh
RUN echo "source /pwndbg/gdbinit.py" >> ~/.gdbinit.py

ADD . /pwndbg/

RUN git submodule update --init --recursive
11 changes: 3 additions & 8 deletions Dockerfile.arch
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand All @@ -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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
63 changes: 50 additions & 13 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
6 changes: 2 additions & 4 deletions gdbinit.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,12 @@
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
Expand Down
6 changes: 4 additions & 2 deletions nix/portable.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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()"

Expand All @@ -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
11 changes: 6 additions & 5 deletions nix/pwndbg.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 ''
Expand Down Expand Up @@ -47,8 +50,6 @@ let
src = pkgs.lib.sourceByRegex inputs.pwndbg [
"pwndbg"
"pwndbg/.*"
"gdb-pt-dump"
"gdb-pt-dump/.*"
"gdbinit.py"
];

Expand All @@ -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 = {
Expand Down
17 changes: 16 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
[tool.black]
line-length = 100
extend-exclude = "gdb-pt-dump"

[tool.ruff]
exclude = ["gdb-pt-dump"]
ignore = [
"A003",
"E402",
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -255,7 +252,6 @@ authors = ["Dominik 'disconnect3d' Czarnota <dominik.b.czarnota+dc@gmail.com>"]
readme = "README.md"
packages = [
{ include = "pwndbg" },
{ include = "gdb-pt-dump" }
]

[tool.poetry.dependencies]
Expand All @@ -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"]
Expand Down
14 changes: 0 additions & 14 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)')
Expand All @@ -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
Expand Down

0 comments on commit ab96e1a

Please sign in to comment.