2023-07-25 04:59:11 +08:00
|
|
|
#!/usr/bin/env bash
|
2024-02-15 02:50:03 +08:00
|
|
|
set -e
|
2016-05-13 03:35:35 +08:00
|
|
|
|
2021-07-31 04:12:36 +08:00
|
|
|
# If we are a root in a container and `sudo` doesn't exist
|
2018-10-18 00:33:15 +08:00
|
|
|
# lets overwrite it with a function that just executes things passed to sudo
|
|
|
|
# (yeah it won't work for sudo executed with flags)
|
2024-06-25 02:22:46 +08:00
|
|
|
if ! hash sudo 2> /dev/null && whoami | grep -q root; then
|
2018-10-18 00:33:15 +08:00
|
|
|
sudo() {
|
2020-12-31 11:35:52 +08:00
|
|
|
${*}
|
2018-10-18 00:33:15 +08:00
|
|
|
}
|
|
|
|
fi
|
2017-04-06 10:27:42 +08:00
|
|
|
|
|
|
|
# Helper functions
|
|
|
|
linux() {
|
2024-06-25 02:22:46 +08:00
|
|
|
uname | grep -iqs Linux
|
2017-04-06 10:27:42 +08:00
|
|
|
}
|
|
|
|
osx() {
|
2024-06-25 02:22:46 +08:00
|
|
|
uname | grep -iqs Darwin
|
2017-04-06 10:27:42 +08:00
|
|
|
}
|
|
|
|
|
2018-10-18 00:33:15 +08:00
|
|
|
install_apt() {
|
|
|
|
sudo apt-get update || true
|
2024-06-11 23:15:16 +08:00
|
|
|
sudo apt-get install -y git gdb gdbserver python3-dev python3-venv python3-setuptools libglib2.0-dev libc6-dbg curl
|
2018-10-18 00:33:15 +08:00
|
|
|
|
2024-06-25 02:22:46 +08:00
|
|
|
if uname -m | grep -q x86_64; then
|
2020-12-02 22:14:15 +08:00
|
|
|
sudo dpkg --add-architecture i386 || true
|
|
|
|
sudo apt-get update || true
|
2023-05-18 09:29:39 +08:00
|
|
|
sudo apt-get install -y libc6-dbg:i386 libgcc-s1:i386 || true
|
2018-10-18 00:33:15 +08:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
install_dnf() {
|
|
|
|
sudo dnf update || true
|
2024-06-11 23:15:16 +08:00
|
|
|
sudo dnf -y install gdb gdb-gdbserver python-devel python3-devel glib2-devel make curl
|
2018-10-18 00:33:15 +08:00
|
|
|
sudo dnf -y debuginfo-install glibc
|
|
|
|
}
|
2017-04-06 10:27:42 +08:00
|
|
|
|
2020-05-11 03:23:59 +08:00
|
|
|
install_xbps() {
|
|
|
|
sudo xbps-install -Su
|
2024-06-11 23:15:16 +08:00
|
|
|
sudo xbps-install -Sy gdb gcc python-devel python3-devel glibc-devel make curl
|
2020-05-11 03:23:59 +08:00
|
|
|
sudo xbps-install -Sy glibc-dbg
|
|
|
|
}
|
|
|
|
|
2019-12-13 01:07:27 +08:00
|
|
|
install_swupd() {
|
|
|
|
sudo swupd update || true
|
2024-06-11 23:15:16 +08:00
|
|
|
sudo swupd bundle-add gdb python3-basic make c-basic curl
|
2019-12-13 01:07:27 +08:00
|
|
|
}
|
|
|
|
|
2020-03-28 23:16:24 +08:00
|
|
|
install_zypper() {
|
2024-01-09 20:20:14 +08:00
|
|
|
sudo zypper mr -e repo-oss-debug || sudo zypper mr -e repo-debug
|
2020-03-28 23:16:24 +08:00
|
|
|
sudo zypper refresh || true
|
2024-06-11 23:15:16 +08:00
|
|
|
sudo zypper install -y gdb gdbserver python-devel python3-devel glib2-devel make glibc-debuginfo curl
|
2024-06-07 23:37:27 +08:00
|
|
|
sudo zypper install -y python2-pip || true # skip py2 installation if it doesn't exist
|
2020-03-28 23:16:24 +08:00
|
|
|
|
2024-06-25 02:22:46 +08:00
|
|
|
if uname -m | grep -q x86_64; then
|
2020-03-28 23:16:24 +08:00
|
|
|
sudo zypper install -y glibc-32bit-debuginfo || true
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-09-17 20:24:06 +08:00
|
|
|
install_emerge() {
|
2024-06-11 23:15:16 +08:00
|
|
|
sudo emerge --oneshot --deep --newuse --changed-use --changed-deps dev-lang/python dev-debug/gdb
|
2020-09-17 20:24:06 +08:00
|
|
|
}
|
|
|
|
|
2024-08-26 20:28:21 +08:00
|
|
|
install_oma() {
|
|
|
|
sudo oma refresh || true
|
|
|
|
sudo oma install -y gdb gdbserver python-3 glib make glibc-dbg curl
|
|
|
|
|
|
|
|
if uname -m | grep -q x86_64; then
|
|
|
|
sudo oma install -y glibc+32-dbg || true
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-10-27 07:22:58 +08:00
|
|
|
install_pacman() {
|
2023-09-05 17:33:05 +08:00
|
|
|
read -p "Do you want to do a full system update? (y/n) [n] " answer
|
2024-06-11 23:15:16 +08:00
|
|
|
# user want to perform a full system upgrade
|
2023-09-05 17:33:05 +08:00
|
|
|
answer=${answer:-n} # n is default
|
|
|
|
if [[ "$answer" == "y" ]]; then
|
|
|
|
sudo pacman -Syu || true
|
|
|
|
fi
|
2024-06-11 23:15:16 +08:00
|
|
|
sudo pacman -S --noconfirm --needed git gdb python python-capstone python-unicorn python-pycparser python-psutil python-ptrace python-pyelftools python-six python-pygments which debuginfod curl
|
2024-06-25 02:22:46 +08:00
|
|
|
if ! grep -qs "^set debuginfod enabled on" ~/.gdbinit; then
|
2023-03-16 03:30:24 +08:00
|
|
|
echo "set debuginfod enabled on" >> ~/.gdbinit
|
|
|
|
fi
|
2022-10-27 07:22:58 +08:00
|
|
|
}
|
|
|
|
|
2023-07-25 04:59:11 +08:00
|
|
|
install_freebsd() {
|
2024-06-11 23:15:16 +08:00
|
|
|
sudo pkg install git gdb python py39-pip cmake gmake curl
|
2023-07-25 04:59:11 +08:00
|
|
|
which rustc || sudo pkg install rust
|
|
|
|
}
|
|
|
|
|
2023-04-06 17:02:36 +08:00
|
|
|
usage() {
|
Fix codecov (#1792)
* Fix coverage combine toml issue
This commit should fix this issue:
```
Run coverage combine
coverage combine
coverage xml
shell: /usr/bin/bash -e {0}
Can't read 'pyproject.toml' without TOML support. Install with [toml] extra
Error: Process completed with exit code 1.
```
* setup.sh: cleanup the --user flag since we use venv now
Cleans up the --user flag from setup.sh since it is unused after we changed setup.sh to install Python dependencies in a virtual environment
* Remove --user flag from CI workflows
* Fix codecov problem
We need to run the python `coverage` library to collect coverage.
However, gdb was failing to find it.
Recently, pwndbg moved to using venvs. When pwndbg is initialized
it setups the venv "manually", that is, no "source .venv/bin/activate"
is needed. When we run gdb tests, we pass the `gdbinit.py` of pwndbg as a
command to gdb to be executed like this:
`gdb --silent --nx --nh -ex 'py import coverage;coverage.process_startup()' --command PATH_TO_gdbinit.py`
The problem is that *order* matters. This means that *first* coverage
is imported (by `-ex py ...`) and only *then* the init script is executed.
When `coverage` is first imported, it's library search path only looks
in system libraries of python, and not the venv that gdbinit.py would load.
So we would try to import an old version of coverage and fail.
One solution would be to move around the commands, but this would be an
ugly hack IMHO. **Instead**, we should just tell gdb that this is an **init**
command that has to be executed before other commands.
Previously, the order did not matter. All of pwndbg's dependencies were
installed directly as system libraries to python. So the library search path
was the same before and after loading `gdbinit.py`.
---------
Co-authored-by: disconnect3d <dominik.b.czarnota@gmail.com>
Co-authored-by: intrigus <abc123zeus@live.de>
2023-07-12 02:27:25 +08:00
|
|
|
echo "Usage: $0 [--update]"
|
2023-04-06 17:02:36 +08:00
|
|
|
echo " --update: Install/update dependencies without checking ~/.gdbinit"
|
|
|
|
}
|
|
|
|
|
|
|
|
UPDATE_MODE=
|
|
|
|
for arg in "$@"; do
|
|
|
|
case $arg in
|
|
|
|
--update)
|
|
|
|
UPDATE_MODE=1
|
|
|
|
;;
|
|
|
|
-h | --help)
|
|
|
|
set +x
|
|
|
|
usage
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
set +x
|
|
|
|
echo "Unknown argument: $arg"
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2017-04-06 10:27:42 +08:00
|
|
|
PYTHON=''
|
|
|
|
|
2023-03-16 03:30:24 +08:00
|
|
|
# Check for the presence of the initializer line in the user's ~/.gdbinit file
|
2024-06-25 02:22:46 +08:00
|
|
|
if [ -z "$UPDATE_MODE" ] && grep -qs '^[^#]*source.*pwndbg/gdbinit.py' ~/.gdbinit; then
|
2023-03-16 03:30:24 +08:00
|
|
|
# Ask the user if they want to proceed and override the initializer line
|
2024-02-15 02:50:03 +08:00
|
|
|
read -p "A Pwndbg initializer line was found in your ~/.gdbinit file. Do you want to proceed and override it? (y/n) " answer
|
2023-03-16 03:30:24 +08:00
|
|
|
|
|
|
|
# If the user does not want to proceed, exit the script
|
|
|
|
if [[ "$answer" != "y" ]]; then
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2017-04-06 10:27:42 +08:00
|
|
|
if linux; then
|
2020-03-08 21:10:19 +08:00
|
|
|
distro=$(grep "^ID=" /etc/os-release | cut -d'=' -f2 | sed -e 's/"//g')
|
2019-10-08 06:54:59 +08:00
|
|
|
|
2018-10-12 05:51:49 +08:00
|
|
|
case $distro in
|
|
|
|
"ubuntu")
|
2018-10-18 00:33:15 +08:00
|
|
|
install_apt
|
2018-10-12 05:51:49 +08:00
|
|
|
;;
|
|
|
|
"fedora")
|
2018-10-18 00:33:15 +08:00
|
|
|
install_dnf
|
|
|
|
;;
|
2020-03-28 23:16:24 +08:00
|
|
|
"clear-linux-os")
|
|
|
|
install_swupd
|
|
|
|
;;
|
2023-05-17 06:12:16 +08:00
|
|
|
"opensuse-leap" | "opensuse-tumbleweed")
|
2020-03-28 23:16:24 +08:00
|
|
|
install_zypper
|
|
|
|
;;
|
2024-06-12 20:36:25 +08:00
|
|
|
"arch" | "archarm" | "endeavouros" | "manjaro" | "garuda" | "cachyos" | "archcraft" | "artix")
|
2022-10-31 04:51:00 +08:00
|
|
|
install_pacman
|
|
|
|
echo "Logging off and in or conducting a power cycle is required to get debuginfod to work."
|
|
|
|
echo "Alternatively you can manually set the environment variable: DEBUGINFOD_URLS=https://debuginfod.archlinux.org"
|
2019-04-01 15:43:37 +08:00
|
|
|
;;
|
2020-05-11 03:23:59 +08:00
|
|
|
"void")
|
|
|
|
install_xbps
|
|
|
|
;;
|
2020-09-17 20:24:06 +08:00
|
|
|
"gentoo")
|
|
|
|
install_emerge
|
2022-10-26 08:46:53 +08:00
|
|
|
if ! hash sudo 2> /dev/null && whoami | grep root; then
|
2020-09-17 20:24:06 +08:00
|
|
|
sudo() {
|
2020-12-31 11:35:52 +08:00
|
|
|
${*}
|
2020-09-17 20:24:06 +08:00
|
|
|
}
|
|
|
|
fi
|
|
|
|
;;
|
2023-07-25 04:59:11 +08:00
|
|
|
"freebsd")
|
|
|
|
install_freebsd
|
|
|
|
;;
|
2024-08-26 20:28:21 +08:00
|
|
|
"aosc")
|
|
|
|
install_oma
|
|
|
|
;;
|
2018-10-12 05:51:49 +08:00
|
|
|
*) # we can add more install command for each distros.
|
2024-06-13 04:14:56 +08:00
|
|
|
echo "\"$distro\" is not supported distro. Will search for 'apt', 'dnf' or 'pacman' package managers."
|
2018-10-18 00:33:15 +08:00
|
|
|
if hash apt; then
|
|
|
|
install_apt
|
|
|
|
elif hash dnf; then
|
|
|
|
install_dnf
|
2024-06-13 04:14:56 +08:00
|
|
|
elif hash pacman; then
|
|
|
|
install_pacman
|
2018-10-18 00:33:15 +08:00
|
|
|
else
|
2023-04-19 01:36:06 +08:00
|
|
|
echo "\"$distro\" is not supported and your distro don't have a package manager that we support currently."
|
2018-10-23 05:20:40 +08:00
|
|
|
exit
|
2018-10-18 00:33:15 +08:00
|
|
|
fi
|
2018-10-12 05:51:49 +08:00
|
|
|
;;
|
|
|
|
esac
|
2016-05-13 03:35:35 +08:00
|
|
|
fi
|
2016-05-12 10:36:26 +08:00
|
|
|
|
2017-04-06 03:04:45 +08:00
|
|
|
if ! hash gdb; then
|
2020-12-31 11:35:52 +08:00
|
|
|
echo "Could not find gdb in $PATH"
|
2017-04-06 03:04:45 +08:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2016-05-28 08:15:34 +08:00
|
|
|
# Find the Python version used by GDB.
|
|
|
|
PYVER=$(gdb -batch -q --nx -ex 'pi import platform; print(".".join(platform.python_version_tuple()[:2]))')
|
2017-04-06 10:27:42 +08:00
|
|
|
PYTHON+=$(gdb -batch -q --nx -ex 'pi import sys; print(sys.executable)')
|
2023-07-25 04:59:11 +08:00
|
|
|
|
2022-04-28 20:50:37 +08:00
|
|
|
if ! osx; then
|
2022-09-05 19:24:52 +08:00
|
|
|
PYTHON+="${PYVER}"
|
2022-04-28 20:50:37 +08:00
|
|
|
fi
|
2016-05-28 08:15:34 +08:00
|
|
|
|
2024-06-11 23:15:16 +08:00
|
|
|
# Install Poetry
|
|
|
|
if ! command -v poetry &> /dev/null; then
|
|
|
|
echo "Poetry not found. Installing Poetry..."
|
|
|
|
curl -sSL https://install.python-poetry.org | python3 -
|
|
|
|
export PATH="$HOME/.local/bin:$PATH"
|
|
|
|
else
|
|
|
|
echo "Poetry is already installed."
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Create the Python virtual environment and install dependencies using poetry
|
2023-07-05 19:11:59 +08:00
|
|
|
if [[ -z "${PWNDBG_VENV_PATH}" ]]; then
|
|
|
|
PWNDBG_VENV_PATH="./.venv"
|
2017-04-06 10:27:42 +08:00
|
|
|
fi
|
2023-07-05 19:11:59 +08:00
|
|
|
echo "Creating virtualenv in path: ${PWNDBG_VENV_PATH}"
|
2017-04-06 03:04:45 +08:00
|
|
|
|
2023-07-05 19:11:59 +08:00
|
|
|
${PYTHON} -m venv -- ${PWNDBG_VENV_PATH}
|
2024-06-11 23:15:16 +08:00
|
|
|
source ${PWNDBG_VENV_PATH}/bin/activate
|
|
|
|
poetry install
|
2021-12-09 08:28:22 +08:00
|
|
|
|
2023-04-06 17:02:36 +08:00
|
|
|
if [ -z "$UPDATE_MODE" ]; then
|
|
|
|
# Comment old configs out
|
2024-06-25 02:22:46 +08:00
|
|
|
if grep -qs '^[^#]*source.*pwndbg/gdbinit.py' ~/.gdbinit; then
|
2023-04-06 17:02:36 +08:00
|
|
|
if ! osx; then
|
|
|
|
sed -i '/^[^#]*source.*pwndbg\/gdbinit.py/ s/^/# /' ~/.gdbinit
|
|
|
|
else
|
|
|
|
# In BSD sed we need to pass ' ' to indicate that no backup file should be created
|
|
|
|
sed -i ' ' '/^[^#]*source.*pwndbg\/gdbinit.py/ s/^/# /' ~/.gdbinit
|
|
|
|
fi
|
2023-03-20 07:49:01 +08:00
|
|
|
fi
|
|
|
|
|
2023-04-06 17:02:36 +08:00
|
|
|
# Load Pwndbg into GDB on every launch.
|
|
|
|
echo "source $PWD/gdbinit.py" >> ~/.gdbinit
|
2024-02-15 02:50:03 +08:00
|
|
|
echo "[*] Added 'source $PWD/gdbinit.py' to ~/.gdbinit so that Pwndbg will be loaded on every launch of GDB."
|
2021-12-09 08:28:22 +08:00
|
|
|
fi
|