2016-08-20 12:46:10 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# Install Voltron for whichever debuggers are detected (only GDB and LLDB so
|
|
|
|
# far).
|
|
|
|
#
|
|
|
|
# Adapted from pwndbg's install script.
|
|
|
|
#
|
|
|
|
# Usage: ./install.sh [ -u -d ]
|
|
|
|
# -u Install to user's site-packages directory
|
|
|
|
# -d Install in developer mode (-e flag passed to pip)
|
|
|
|
#
|
|
|
|
SUDO='sudo'
|
|
|
|
GDB=$(command -v gdb)
|
|
|
|
LLDB=$(command -v lldb)
|
2016-11-25 22:34:55 +00:00
|
|
|
APT_GET=$(command -v apt-get)
|
2016-08-20 12:46:10 +00:00
|
|
|
|
2016-10-14 10:35:49 +00:00
|
|
|
set -x
|
2016-08-20 12:46:10 +00:00
|
|
|
|
2016-09-24 11:32:10 +00:00
|
|
|
if [ -z "${LLDB}" ]; then
|
2016-11-09 00:31:38 +00:00
|
|
|
for i in `seq 6 8`; do
|
2016-09-24 11:32:10 +00:00
|
|
|
LLDB=$(command -v lldb-3.$i)
|
|
|
|
if [ -n "${LLDB}" ]; then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2016-11-09 00:31:38 +00:00
|
|
|
while getopts ":uds" opt; do
|
2016-08-20 12:46:10 +00:00
|
|
|
case $opt in
|
|
|
|
u)
|
|
|
|
USER_MODE='--user'
|
|
|
|
SUDO=''
|
|
|
|
;;
|
|
|
|
d)
|
|
|
|
DEV_MODE="-e"
|
|
|
|
;;
|
2016-11-09 00:31:38 +00:00
|
|
|
s)
|
|
|
|
SKIP_UPDATE='-s'
|
|
|
|
;;
|
2016-08-20 12:46:10 +00:00
|
|
|
\?)
|
|
|
|
echo "Invalid option: -$OPTARG" >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2016-11-09 00:31:38 +00:00
|
|
|
set -e
|
|
|
|
|
2016-08-20 12:46:10 +00:00
|
|
|
function install_apt {
|
2016-11-25 22:34:55 +00:00
|
|
|
if [ -n "${APT_GET}" ]; then
|
2016-11-09 00:31:38 +00:00
|
|
|
if [ -z "${SKIP_UPDATE}" ]; then
|
|
|
|
sudo apt-get update
|
|
|
|
fi
|
2016-08-20 12:46:10 +00:00
|
|
|
if echo $PYVER|grep "3\."; then
|
2016-09-14 22:59:03 +00:00
|
|
|
sudo apt-get -y install libreadline6-dev python3-dev python3-setuptools python3-yaml python3-pip
|
2016-08-20 12:46:10 +00:00
|
|
|
else
|
2016-09-14 22:59:03 +00:00
|
|
|
sudo apt-get -y install libreadline6-dev python-dev python-setuptools python-yaml python-pip
|
2016-08-20 12:46:10 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ -n "${GDB}" ]; then
|
|
|
|
# Find the Python version used by GDB
|
2016-10-14 10:35:49 +00:00
|
|
|
GDB_PYVER=$(${GDB} -batch -q --nx -ex 'pi import platform; print(".".join(platform.python_version_tuple()[:2]))')
|
|
|
|
GDB_PYTHON=$(${GDB} -batch -q --nx -ex 'pi import sys; print(sys.executable)')
|
|
|
|
GDB_PYTHON="${GDB_PYTHON}${GDB_PYVER}"
|
2016-08-20 12:46:10 +00:00
|
|
|
|
|
|
|
install_apt
|
|
|
|
|
|
|
|
if [ -z $USER_MODE ]; then
|
2016-09-24 11:32:10 +00:00
|
|
|
GDB_SITE_PACKAGES=$(${GDB} -batch -q --nx -ex 'pi import site; print(site.getsitepackages()[0])')
|
2016-08-20 12:46:10 +00:00
|
|
|
else
|
2016-09-24 11:32:10 +00:00
|
|
|
GDB_SITE_PACKAGES=$(${GDB} -batch -q --nx -ex 'pi import site; print(site.getusersitepackages())')
|
2016-08-20 12:46:10 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Install Voltron and dependencies
|
2016-11-09 00:31:38 +00:00
|
|
|
${SUDO} ${GDB_PYTHON} -m pip install -U $USER_MODE $DEV_MODE .
|
2016-08-20 12:46:10 +00:00
|
|
|
|
|
|
|
# Add Voltron to gdbinit
|
2016-11-08 04:41:04 +00:00
|
|
|
GDB_INIT_FILE="${HOME}/.gdbinit"
|
2016-11-09 00:31:38 +00:00
|
|
|
sed -i.bak '/voltron/d' ${GDB_INIT_FILE}
|
|
|
|
if [ -z $DEV_MODE ]; then
|
|
|
|
GDB_ENTRY_FILE="$GDB_SITE_PACKAGES/voltron/entry.py"
|
|
|
|
else
|
|
|
|
GDB_ENTRY_FILE="$(pwd)/voltron/entry.py"
|
2016-08-20 12:46:10 +00:00
|
|
|
fi
|
2016-11-09 00:31:38 +00:00
|
|
|
echo "source $GDB_ENTRY_FILE" >> ${GDB_INIT_FILE}
|
2016-08-20 12:46:10 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "${LLDB}" ]; then
|
|
|
|
# Find the Python version used by LLDB
|
2016-10-14 10:35:49 +00:00
|
|
|
LLDB_PYVER=$(${LLDB} -Qxb --one-line 'script import platform; print(".".join(platform.python_version_tuple()[:2]))'|tail -1)
|
|
|
|
LLDB_PYTHON=$(${LLDB} -Qxb --one-line 'script import sys; print(sys.executable)'|tail -1)
|
|
|
|
LLDB_PYTHON="${LLDB_PYTHON}${LLDB_PYVER}"
|
2016-08-20 12:46:10 +00:00
|
|
|
if [ -z $USER_MODE ]; then
|
2016-09-24 11:32:10 +00:00
|
|
|
LLDB_SITE_PACKAGES=$(${LLDB} -Qxb --one-line 'script import site; print(site.getsitepackages()[0])'|tail -1)
|
2016-08-20 12:46:10 +00:00
|
|
|
else
|
2016-09-24 11:32:10 +00:00
|
|
|
LLDB_SITE_PACKAGES=$(${LLDB} -Qxb --one-line 'script import site; print(site.getusersitepackages())'|tail -1)
|
2016-08-20 12:46:10 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
install_apt
|
|
|
|
|
|
|
|
if [ "$LLDB_SITE_PACKAGES" == "$GDB_SITE_PACKAGES" ]; then
|
|
|
|
echo "Skipping installation for LLDB - same site-packages directory"
|
|
|
|
else
|
|
|
|
# Install Voltron and dependencies
|
2016-11-09 00:31:38 +00:00
|
|
|
${SUDO} ${LLDB_PYTHON} -m pip install -U $USER_MODE $DEV_MODE .
|
2016-08-20 12:46:10 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Add Voltron to lldbinit
|
2016-11-08 04:41:04 +00:00
|
|
|
LLDB_INIT_FILE="${HOME}/.lldbinit"
|
2016-11-09 00:31:38 +00:00
|
|
|
sed -i.bak '/voltron/d' ${LLDB_INIT_FILE}
|
|
|
|
if [ -z $DEV_MODE ]; then
|
|
|
|
LLDB_ENTRY_FILE="$LLDB_SITE_PACKAGES/voltron/entry.py"
|
|
|
|
else
|
|
|
|
LLDB_ENTRY_FILE="$(pwd)/voltron/entry.py"
|
2016-08-20 12:46:10 +00:00
|
|
|
fi
|
2016-11-09 00:31:38 +00:00
|
|
|
echo "command script import $LLDB_ENTRY_FILE" >> ${LLDB_INIT_FILE}
|
2016-08-20 12:46:10 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "${GDB}" ] && [ -z "${LLDB}" ]; then
|
|
|
|
# Find system Python
|
|
|
|
PYTHON=$(command -v python)
|
|
|
|
PYVER=$(${PYTHON} -c 'import platform; print(".".join(platform.python_version_tuple()[:2]))')
|
|
|
|
if [ -z $USER_MODE ]; then
|
|
|
|
PYTHON_SITE_PACKAGES=$(${PYTHON} -c 'import site; print(site.getsitepackages()[0])')
|
|
|
|
else
|
|
|
|
PYTHON_SITE_PACKAGES=$(${PYTHON} -c 'import site; print(site.getusersitepackages())')
|
|
|
|
fi
|
|
|
|
|
|
|
|
install_apt
|
|
|
|
|
|
|
|
# Install Voltron and dependencies
|
2016-11-09 00:31:38 +00:00
|
|
|
${SUDO} ${PYTHON} -m pip install -U $USER_MODE $DEV_MODE .
|
2016-08-20 12:46:10 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
set +x
|
|
|
|
echo "=============================================================="
|
|
|
|
if [ -n "${GDB}" ]; then
|
|
|
|
echo "Installed for GDB (${GDB}):"
|
2016-10-14 10:35:49 +00:00
|
|
|
echo " Python: $GDB_PYTHON"
|
2016-08-20 12:46:10 +00:00
|
|
|
echo " Packages directory: $GDB_SITE_PACKAGES"
|
2016-11-09 00:31:38 +00:00
|
|
|
echo " Added voltron to: $GDB_INIT_FILE"
|
|
|
|
echo " Entry point: $GDB_ENTRY_FILE"
|
2016-08-20 12:46:10 +00:00
|
|
|
fi
|
|
|
|
if [ -n "${LLDB}" ]; then
|
|
|
|
echo "Installed for LLDB (${LLDB}):"
|
2016-10-14 10:35:49 +00:00
|
|
|
echo " Python: $LLDB_PYTHON"
|
2016-08-20 12:46:10 +00:00
|
|
|
echo " Packages directory: $LLDB_SITE_PACKAGES"
|
2016-11-09 00:31:38 +00:00
|
|
|
echo " Added voltron to: $LLDB_INIT_FILE"
|
|
|
|
echo " Entry point: $LLDB_ENTRY_FILE"
|
2016-08-20 12:46:10 +00:00
|
|
|
fi
|
|
|
|
if [ -z "${GDB}" ] && [ -z "${LLDB}" ]; then
|
|
|
|
echo "Couldn't find any debuggers. Installed using the Python in your path:"
|
|
|
|
echo " Python: $PYTHON"
|
|
|
|
echo " Packages directory: $PYTHON_SITE_PACKAGES"
|
|
|
|
echo " Did not add Voltron to any debugger init files."
|
|
|
|
fi
|