2016-06-11 02:48:58 +08:00
|
|
|
#!/bin/bash
|
|
|
|
set -ex
|
2016-05-13 03:35:35 +08:00
|
|
|
|
2018-10-18 00:33:15 +08:00
|
|
|
# If we are a root in a Docker container and `sudo` doesn't exist
|
|
|
|
# lets overwrite it with a function that just executes things passed to sudo
|
|
|
|
# (yeah it won't work for sudo executed with flags)
|
|
|
|
if [ -f /.dockerenv ] && ! hash sudo 2>/dev/null && whoami | grep root; then
|
|
|
|
sudo() {
|
|
|
|
$*
|
|
|
|
}
|
|
|
|
fi
|
2017-04-06 10:27:42 +08:00
|
|
|
|
|
|
|
# Helper functions
|
|
|
|
linux() {
|
|
|
|
uname | grep -i Linux &>/dev/null
|
|
|
|
}
|
|
|
|
osx() {
|
|
|
|
uname | grep -i Darwin &>/dev/null
|
|
|
|
}
|
|
|
|
|
2018-10-18 00:33:15 +08:00
|
|
|
install_apt() {
|
|
|
|
sudo apt-get update || true
|
|
|
|
sudo apt-get -y install gdb python-dev python3-dev python-pip python3-pip libglib2.0-dev libc6-dbg
|
|
|
|
|
|
|
|
if uname -m | grep x86_64 > /dev/null; then
|
2019-10-26 00:43:59 +08:00
|
|
|
sudo apt-get -y install libc6-dbg: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
|
|
|
|
|
|
|
PYTHON=''
|
|
|
|
INSTALLFLAGS=''
|
|
|
|
|
|
|
|
if osx || [ "$1" == "--user" ]; then
|
|
|
|
INSTALLFLAGS="--user"
|
|
|
|
else
|
|
|
|
PYTHON="sudo "
|
|
|
|
fi
|
|
|
|
|
|
|
|
if linux; then
|
2018-10-12 05:51:49 +08:00
|
|
|
distro=$(cat /etc/os-release | grep "^ID=" | 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
|
|
|
|
;;
|
|
|
|
"arch")
|
|
|
|
echo "Install Arch linux using a community package. See:"
|
|
|
|
echo " - https://www.archlinux.org/packages/community/any/pwndbg/"
|
|
|
|
echo " - https://aur.archlinux.org/packages/pwndbg-git/"
|
|
|
|
exit 1
|
2018-10-12 05:51:49 +08:00
|
|
|
;;
|
2019-04-01 15:43:37 +08:00
|
|
|
"manjaro")
|
|
|
|
echo "Pwndbg is not avaiable on Manjaro's repositories."
|
|
|
|
echo "But it can be installed using Arch's AUR community package. See:"
|
|
|
|
echo " - https://www.archlinux.org/packages/community/any/pwndbg/"
|
|
|
|
echo " - https://aur.archlinux.org/packages/pwndbg-git/"
|
|
|
|
exit 1
|
|
|
|
;;
|
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
|
|
|
|
echo "\"$distro\" is not supported and your distro don't have apt or dnf 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
|
|
|
|
echo 'Could not find gdb in $PATH'
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2016-05-12 10:36:26 +08:00
|
|
|
# Update all submodules
|
|
|
|
git submodule update --init --recursive
|
|
|
|
|
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)')
|
|
|
|
PYTHON+="${PYVER}"
|
2016-05-28 08:15:34 +08:00
|
|
|
|
2017-04-06 03:04:45 +08:00
|
|
|
# Find the Python site-packages that we need to use so that
|
|
|
|
# GDB can find the files once we've installed them.
|
2017-04-06 10:27:42 +08:00
|
|
|
if linux && [ -z "$INSTALLFLAGS" ]; then
|
|
|
|
SITE_PACKAGES=$(gdb -batch -q --nx -ex 'pi import site; print(site.getsitepackages()[0])')
|
|
|
|
INSTALLFLAGS="--target ${SITE_PACKAGES}"
|
|
|
|
fi
|
2017-04-06 03:04:45 +08:00
|
|
|
|
|
|
|
# Make sure that pip is available
|
|
|
|
if ! ${PYTHON} -m pip -V; then
|
2017-04-06 10:27:42 +08:00
|
|
|
${PYTHON} -m ensurepip ${INSTALLFLAGS} --upgrade
|
2017-04-06 03:04:45 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Upgrade pip itself
|
2017-04-06 10:27:42 +08:00
|
|
|
${PYTHON} -m pip install ${INSTALLFLAGS} --upgrade pip
|
2017-04-06 03:04:45 +08:00
|
|
|
|
2016-05-13 03:35:35 +08:00
|
|
|
# Install Python dependencies
|
2017-04-06 10:27:42 +08:00
|
|
|
${PYTHON} -m pip install ${INSTALLFLAGS} -Ur requirements.txt
|
2016-05-12 10:36:26 +08:00
|
|
|
|
2016-05-12 10:42:13 +08:00
|
|
|
# Load Pwndbg into GDB on every launch.
|
2016-05-12 10:36:26 +08:00
|
|
|
if ! grep pwndbg ~/.gdbinit &>/dev/null; then
|
2016-05-27 09:49:19 +08:00
|
|
|
echo "source $PWD/gdbinit.py" >> ~/.gdbinit
|
2016-05-12 10:36:26 +08:00
|
|
|
fi
|