Skip to content

Commit

Permalink
init add portable pwndbg using nix, package for rpm,deb,arch,alpine
Browse files Browse the repository at this point in the history
Signed-off-by: Patryk Sondej <patryk.sondej@gmail.com>
  • Loading branch information
patryk4815 authored and disconnect3d committed Aug 6, 2023
1 parent dbdce5d commit f3914e2
Show file tree
Hide file tree
Showing 21 changed files with 1,674 additions and 58 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/releases.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Releases

on:
push:
branches:
- dev
tags:
- '*'

jobs:
releases:
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # @v3
- uses: cachix/install-nix-action@6ed004b9ccb68dbc28e7c85bee15fa93dbd214ac # @v22
with:
nix_path: nixpkgs=channel:nixos-unstable

- name: build pwndbg
run: nix build '.?submodules=1#pwndbg' -o result-pwndbg

- name: build rpm
run: nix build '.?submodules=1#rpm' -o dist-rpm
- name: build deb
run: nix build '.?submodules=1#deb' -o dist-deb
- name: build apk
run: nix build '.?submodules=1#apk' -o dist-apk
- name: build archlinux
run: nix build '.?submodules=1#archlinux' -o dist-archlinux
- name: build tarball
run: nix build '.?submodules=1#tarball' -o dist-tarball

- name: release
uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 # @v1
with:
files: |
./dist-rpm/*
./dist-deb/*
./dist-apk/*
./dist-archlinux/*
./dist-tarball/*
draft: true
token: ${{ secrets.TOKEN }}
12 changes: 4 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && \
rm -rf /var/lib/apt/lists/* && \
localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 && \
apt-get update && \
apt-get install -y vim
apt-get install -y vim git

ADD . /pwndbg/
RUN git submodule update --init --recursive

ADD ./setup.sh /pwndbg/
ADD ./requirements.txt /pwndbg/
ADD ./dev-requirements.txt /pwndbg/
# 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 && \
Expand All @@ -40,7 +40,3 @@ ADD ./setup-dev.sh /pwndbg/
RUN ./setup-dev.sh

RUN echo "source /pwndbg/gdbinit.py" >> ~/.gdbinit.py

ADD . /pwndbg/

RUN git submodule update --init --recursive
12 changes: 4 additions & 8 deletions Dockerfile.arch
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && \
echo $TZ > /etc/timezone && \
pacman -Syu --noconfirm && \
localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 && \
pacman -S --noconfirm vim && \
pacman -S --noconfirm vim git && \
pacman -Scc --noconfirm

ADD ./setup.sh /pwndbg/
ADD ./requirements.txt /pwndbg/
ADD ./dev-requirements.txt /pwndbg/
ADD . /pwndbg/
RUN git submodule update --init --recursive

# 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 && \
Expand All @@ -40,7 +40,3 @@ RUN echo "source /pwndbg/gdbinit.py" >> ~/.gdbinit.py && \
echo "PYTHON_MINOR=$(python3 -c "import sys;print(sys.version_info.minor)")" >> /root/.bashrc && \
echo "PYTHON_PATH=\"/usr/local/lib/python3.${PYTHON_MINOR}/dist-packages/bin\"" >> /root/.bashrc && \
echo "export PATH=$PATH:$PYTHON_PATH" >> /root/.bashrc

ADD . /pwndbg/

RUN git submodule update --init --recursive
104 changes: 104 additions & 0 deletions flake.lock

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

53 changes: 53 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
description = "pwndbg";

inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
inputs.poetry2nix = {
url = "github:nix-community/poetry2nix";
inputs.nixpkgs.follows = "nixpkgs";
};

outputs = { self, nixpkgs, poetry2nix }:
let
forAllSystems = nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed;
forPortables = nixpkgs.lib.genAttrs [ "deb" "rpm" "apk" "archlinux" ];

pkgsBySystem = forAllSystems (system: import nixpkgs {
inherit system;
overlays = [ poetry2nix.overlay ];
});
pkgUtil = forAllSystems (system: import ./nix/bundle/pkg.nix {
pkgs = pkgsBySystem.${system};
});

portableDrv = system: import ./nix/portable.nix {
pkgs = pkgsBySystem.${system};
pwndbg = self.packages.${system}.pwndbg;
};
portableDrvs = system: forPortables (packager: pkgUtil.${system}.buildPackagePFPM {
inherit packager;
drv = portableDrv system;
config = ./nix/bundle/nfpm.yaml;
preremove = ./nix/bundle/preremove.sh;
});
tarballDrv = system: {
tarball = pkgUtil.${system}.buildPackageTarball {
drv = portableDrv system;
};
};
in
{
packages = forAllSystems (system: {
pwndbg = import ./nix/pwndbg.nix {
pkgs = pkgsBySystem.${system};
python3 = pkgsBySystem.${system}.python3;
gdb = pkgsBySystem.${system}.gdb;
inputs.pwndbg = self;
};
default = self.packages.${system}.pwndbg;
}
// (portableDrvs system)
// (tarballDrv system)
);
};
}
61 changes: 32 additions & 29 deletions gdbinit.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,40 @@
_start_time = time.time()
_profiler.enable()

directory, file = path.split(__file__)
directory = path.expanduser(directory)
directory = path.abspath(directory)

# Get virtualenv's site-packages path
venv_path = os.environ.get("PWNDBG_VENV_PATH")
if not venv_path:
venv_path = os.path.join(directory, ".venv")

if not os.path.exists(venv_path):
print(f"Cannot find Pwndbg virtualenv directory: {venv_path}: please re-run setup.sh")
sys.exit(1)

site_pkgs_path = glob(os.path.join(venv_path, "lib/*/site-packages"))[0]

# add virtualenv's site-packages to sys.path and run .pth files
site.addsitedir(site_pkgs_path)

# remove existing, system-level site-packages from sys.path
for site_packages in site.getsitepackages():
if site_packages in sys.path:
sys.path.remove(site_packages)

# Set virtualenv's bin path (needed for utility tools like ropper, pwntools etc)
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")
sys.path.append(directory)
sys.path.append(gdbpt)
if venv_path == "PWNDBG_PLEASE_SKIP_VENV":
pass
else:
directory, file = path.split(__file__)
directory = path.expanduser(directory)
directory = path.abspath(directory)

if not venv_path:
venv_path = os.path.join(directory, ".venv")

if not os.path.exists(venv_path):
print(f"Cannot find Pwndbg virtualenv directory: {venv_path}: please re-run setup.sh")
sys.exit(1)

site_pkgs_path = glob(os.path.join(venv_path, "lib/*/site-packages"))[0]

# add virtualenv's site-packages to sys.path and run .pth files
site.addsitedir(site_pkgs_path)

# remove existing, system-level site-packages from sys.path
for site_packages in site.getsitepackages():
if site_packages in sys.path:
sys.path.remove(site_packages)

# Set virtualenv's bin path (needed for utility tools like ropper, pwntools etc)
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")
sys.path.append(directory)
sys.path.append(gdbpt)

# warn if the user has different encoding than utf-8
encoding = locale.getpreferredencoding()
Expand Down

0 comments on commit f3914e2

Please sign in to comment.