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)
|
2022-10-26 08:46:53 +08:00
|
|
|
if ! hash sudo 2> /dev/null && whoami | grep 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() {
|
2022-10-26 08:46:53 +08:00
|
|
|
uname | grep -i Linux &> /dev/null
|
2017-04-06 10:27:42 +08:00
|
|
|
}
|
|
|
|
osx() {
|
2022-10-26 08:46:53 +08:00
|
|
|
uname | grep -i Darwin &> /dev/null
|
2017-04-06 10:27:42 +08:00
|
|
|
}
|
|
|
|
|
2018-10-18 00:33:15 +08:00
|
|
|
install_apt() {
|
|
|
|
sudo apt-get update || true
|
2023-07-05 19:11:59 +08:00
|
|
|
sudo apt-get install -y git gdb gdbserver python3-dev python3-venv python3-pip python3-setuptools libglib2.0-dev libc6-dbg
|
2018-10-18 00:33:15 +08:00
|
|
|
|
2022-10-26 08:46:53 +08:00
|
|
|
if uname -m | grep x86_64 > /dev/null; 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
|
2019-10-08 06:54:59 +08:00
|
|
|
sudo dnf -y install gdb gdb-gdbserver python-devel python3-devel python-pip python3-pip glib2-devel make
|
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
|
|
|
|
sudo xbps-install -Sy gdb gcc python-devel python3-devel python-pip python3-pip glibc-devel make
|
|
|
|
sudo xbps-install -Sy glibc-dbg
|
|
|
|
}
|
|
|
|
|
2019-12-13 01:07:27 +08:00
|
|
|
install_swupd() {
|
|
|
|
sudo swupd update || true
|
|
|
|
sudo swupd bundle-add gdb python3-basic make c-basic
|
|
|
|
}
|
|
|
|
|
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-07 19:59:03 +08:00
|
|
|
sudo zypper install -y gdb gdbserver python-devel python3-devel python3-pip glib2-devel make glibc-debuginfo
|
|
|
|
sudo zypper install -y python2-pip || true # skip py2 installation if it doesn't exist
|
2020-03-28 23:16:24 +08:00
|
|
|
|
2022-10-26 08:46:53 +08:00
|
|
|
if uname -m | grep x86_64 > /dev/null; 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-03-12 00:39:47 +08:00
|
|
|
sudo emerge --oneshot --deep --newuse --changed-use --changed-deps dev-lang/python dev-python/pip dev-debug/gdb
|
2020-09-17 20:24:06 +08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
# user want to perfom a full system upgrade
|
|
|
|
answer=${answer:-n} # n is default
|
|
|
|
if [[ "$answer" == "y" ]]; then
|
|
|
|
sudo pacman -Syu || true
|
|
|
|
fi
|
2023-09-29 05:18:06 +08:00
|
|
|
sudo pacman -S --noconfirm --needed git gdb python python-pip python-capstone python-unicorn python-pycparser python-psutil python-ptrace python-pyelftools python-six python-pygments which debuginfod
|
2023-03-16 03:30:24 +08:00
|
|
|
if ! grep -q "^set debuginfod enabled on" ~/.gdbinit; then
|
|
|
|
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() {
|
|
|
|
sudo pkg install git gdb python py39-pip cmake gmake
|
|
|
|
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
|
2023-04-06 17:02:36 +08:00
|
|
|
if [ -z "$UPDATE_MODE" ] && grep -q '^[^#]*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-03-23 07:54:47 +08:00
|
|
|
"arch" | "archarm" | "endeavouros" | "manjaro" | "garuda" | "cachyos" | "archcraft")
|
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
|
|
|
|
;;
|
2018-10-12 05:51:49 +08:00
|
|
|
*) # we can add more install command for each distros.
|
2018-10-18 00:33:15 +08:00
|
|
|
echo "\"$distro\" is not supported distro. Will search for 'apt' or 'dnf' package managers."
|
|
|
|
if hash apt; then
|
|
|
|
install_apt
|
|
|
|
elif hash dnf; then
|
|
|
|
install_dnf
|
|
|
|
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
|
|
|
|
2023-07-05 19:11:59 +08:00
|
|
|
# Create Python virtualenv
|
|
|
|
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}
|
|
|
|
PYTHON=${PWNDBG_VENV_PATH}/bin/python
|
2017-04-06 03:04:45 +08:00
|
|
|
|
|
|
|
# Upgrade pip itself
|
2023-07-05 19:11:59 +08:00
|
|
|
${PYTHON} -m pip install --upgrade pip
|
2017-04-06 03:04:45 +08:00
|
|
|
|
2023-07-05 19:11:59 +08:00
|
|
|
# Create Python virtual environment and install dependencies in it
|
2023-08-17 10:58:43 +08:00
|
|
|
${PWNDBG_VENV_PATH}/bin/pip install -e .
|
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-02-15 02:50:03 +08:00
|
|
|
if grep -q '^[^#]*source.*pwndbg/gdbinit.py' ~/.gdbinit 2> /dev/null; 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
|