Skip to content

Commit

Permalink
Use "pip" versions of Capstone and Unicorn (#176)
Browse files Browse the repository at this point in the history
* Use Pip version of Unicorn

* Remove capstone submodule

* Allow installation to the user site-packages for Darwin, since SIP prevents installation to the system site-packages

* Add helper functions and fix Python calls

* Remove duplicated code (rebase issues?)
  • Loading branch information
zachriggle committed Apr 6, 2017
1 parent edf4737 commit 8ee0208
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 28 deletions.
8 changes: 0 additions & 8 deletions .gitmodules

This file was deleted.

1 change: 0 additions & 1 deletion capstone
Submodule capstone deleted from 9edf92
2 changes: 2 additions & 0 deletions docs/requirements.txt
Expand Up @@ -19,3 +19,5 @@ psutil>=3.1.0
python-ptrace>=0.8
six
future
unicorn>=1.0.0
capstone
2 changes: 2 additions & 0 deletions requirements.txt
Expand Up @@ -7,3 +7,5 @@ isort
six
future
ROPgadget
unicorn>=1.0.0
https://github.com/aquynh/capstone/archive/next.zip#subdirectory=bindings/python
47 changes: 29 additions & 18 deletions setup.sh
@@ -1,7 +1,26 @@
#!/bin/bash
set -ex

if uname | grep -i Linux &>/dev/null; then

# Helper functions
linux() {
uname | grep -i Linux &>/dev/null
}
osx() {
uname | grep -i Darwin &>/dev/null
}


PYTHON=''
INSTALLFLAGS=''

if osx || [ "$1" == "--user" ]; then
INSTALLFLAGS="--user"
else
PYTHON="sudo "
fi

if linux; then
sudo apt-get update || true
sudo apt-get -y install gdb python-dev python3-dev python-pip python3-pip libglib2.0-dev libc6-dbg

Expand All @@ -20,34 +39,26 @@ git submodule update --init --recursive

# Find the Python version used by GDB.
PYVER=$(gdb -batch -q --nx -ex 'pi import platform; print(".".join(platform.python_version_tuple()[:2]))')
PYTHON=$(gdb -batch -q --nx -ex 'pi import sys; print(sys.executable)')
PYTHON="${PYTHON}${PYVER}"
PYTHON+=$(gdb -batch -q --nx -ex 'pi import sys; print(sys.executable)')
PYTHON+="${PYVER}"

# Find the Python site-packages that we need to use so that
# GDB can find the files once we've installed them.
SITE_PACKAGES=$(gdb -batch -q --nx -ex 'pi import site; print(site.getsitepackages()[0])')
if linux && [ -z "$INSTALLFLAGS" ]; then
SITE_PACKAGES=$(gdb -batch -q --nx -ex 'pi import site; print(site.getsitepackages()[0])')
INSTALLFLAGS="--target ${SITE_PACKAGES}"
fi

# Make sure that pip is available
if ! ${PYTHON} -m pip -V; then
sudo ${PYTHON} -m ensurepip --upgrade
${PYTHON} -m ensurepip ${INSTALLFLAGS} --upgrade
fi

# Upgrade pip itself
sudo ${PYTHON} -m pip install --upgrade pip
${PYTHON} -m pip install ${INSTALLFLAGS} --upgrade pip

# Install Python dependencies
sudo ${PYTHON} -m pip install --target ${SITE_PACKAGES} -Ur requirements.txt

# Install both Unicorn and Capstone
for directory in capstone unicorn; do
pushd $directory
UNICORN_QEMU_FLAGS="--python=$(which python2)" ./make.sh
sudo UNICORN_QEMU_FLAGS="--python=$(which python2)" ./make.sh install

cd bindings/python
sudo ${PYTHON} setup.py install
popd
done
${PYTHON} -m pip install ${INSTALLFLAGS} -Ur requirements.txt

# Load Pwndbg into GDB on every launch.
if ! grep pwndbg ~/.gdbinit &>/dev/null; then
Expand Down
1 change: 0 additions & 1 deletion unicorn
Submodule unicorn deleted from 37bf1a

0 comments on commit 8ee0208

Please sign in to comment.