From 5f0ca44639f80916fa18163f6b269d61f72e87c0 Mon Sep 17 00:00:00 2001 From: Mathias Svensson Date: Sat, 26 Jul 2014 21:42:17 +0200 Subject: [PATCH] Made the setup.py work properly (I think) --- .gitignore | 2 + README.md | 12 ++++- install_local.sh | 12 +++++ setup.py | 129 ++++++++++++++++++----------------------------- 4 files changed, 74 insertions(+), 81 deletions(-) create mode 100755 install_local.sh diff --git a/.gitignore b/.gitignore index 1664db753..c193d6372 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ */auto/* */bin/* build +MANIFEST +dist diff --git a/README.md b/README.md index 934cd7244..fe5a0b990 100644 --- a/README.md +++ b/README.md @@ -23,9 +23,17 @@ We also have the following tools, not dependent on the pwnlib: * binutils directory: Assemblers and disassemblers for various architectures * `hex`/`unhex`: Command line tools for doing common hexing/unhexing operations +# Documentation +Our documentation is available on + # Installation -To install it, just update your `PYTHONPATH` and `PATH` variables. Alternatively -you can run `python setup.py install`. +Pwntools is available as a pip package. You can install it by running +`pip install pwntools`. + +Alternatively if you prefer to have the latest version in git, you can +simply clone this repository, run `pip install -r requirements.txt` +and entries in your `PATH` and `PYTHONPATH` variables. The script +`install_local.sh` will help you do so, in case you are using bash. # Contact If you have any questions not worthy of a bug report, feel free to join us diff --git a/install_local.sh b/install_local.sh new file mode 100755 index 000000000..d85fa6461 --- /dev/null +++ b/install_local.sh @@ -0,0 +1,12 @@ +#!/bin/sh +sudo pip install -r requirements.txt + +echo "================================================" +echo "Now please put this directory in your PYTHONPATH" +echo "and the bin directory in your PATH." +echo +echo "If you are using bash, you do can this by putting" +echo "These in your .bashrc:" +echo +echo "export PATH=\"`realpath bin`:\$PATH\"" +echo "export PYTHONPATH=\"`realpath .`:\$PYTHONPATH\"" diff --git a/setup.py b/setup.py index 8993feddb..aa5cad58f 100644 --- a/setup.py +++ b/setup.py @@ -1,95 +1,66 @@ #!/usr/bin/env python -from distutils.core import setup -import os, types, sys +from setuptools import setup, find_packages +import os, sys +# Ugly hack to make sure that the templates have been built when running sdist +# If anybody knows a better way to do this, please let us know! +def fix_templates(): + try: + import mako + except: + os.system("sudo pip install mako") + def walker(val): + for k in dir(val): + if not k or k[0] == '_': + continue + nextval = getattr(val, k) + import types + if isinstance(nextval, types.ModuleType): + walker(nextval) + sys.path.append(os.getcwd()) + import pwnlib.shellcraft + walker(pwnlib.shellcraft) + for dirpath, dirnames, filenames in os.walk(os.path.join('pwnlib', 'shellcraft', 'pycs')): + open(os.path.join(dirpath, '__init__.py'), 'w') -package_description = """ -This is the CTF framework used by Gallopsled in every CTF. -""".strip() -scripts = [ - 'bin/asm', - 'bin/cyclic', - 'bin/disasm', - 'bin/hex', - 'bin/shellcraft', - 'bin/unhex', -] +if not os.path.isfile(os.path.join('pwnlib', 'shellcraft', 'pycs', '__init__.py')): + fix_templates() -def fullsplit(path, result=None): - """ - Split a pathname into components (the opposite of os.path.join) in a - platform-neutral way. - """ - if result is None: - result = [] - head, tail = os.path.split(path) - if head == '': - return [tail] + result - if head == path: - return result - return fullsplit(head, [tail] + result) - -# Change into the relevant directory -root_dir = os.path.dirname(__file__) -if root_dir != '': - os.chdir(root_dir) - -sys.path.append(os.getcwd()) - -# We would like to have the mako templates for shellcode precompiled -def walker(val): - for k in dir(val): - if not k or k[0] == '_': - continue - nextval = getattr(val, k) - if isinstance(nextval, types.ModuleType): - walker(nextval) -import pwnlib.shellcraft -walker(pwnlib.shellcraft) - -for dirpath, dirnames, filenames in os.walk(os.path.join('pwnlib', 'shellcraft', 'pycs')): - open(os.path.join(dirpath, '__init__.py'), 'w') - -# Compile the list of packages available, because distutils doesn't have -# an easy way to do this. -packages = [] - -for package_dir in ['pwn', 'pwnlib']: - for dirpath, dirnames, filenames in os.walk(package_dir): - # Ignore dirnames that start with '.' - for i, dirname in enumerate(dirnames): - if dirname.startswith('.'): del dirnames[i] - if '__init__.py' in filenames: - packages.append('.'.join(fullsplit(dirpath))) +templates = [] +for dirpath, dirnames, filenames in os.walk(os.path.join('pwnlib', 'shellcraft', 'templates')): + for f in filenames: + templates.append(os.path.relpath(os.path.join(dirpath, f), 'pwnlib')) setup( - name = 'pwntools', - packages = packages, - version = '2.0', - package_data = { + name = 'pwntools', + packages = find_packages(), + version = '2.0', + package_data = { 'pwnlib': [ 'data/crcsums.txt', 'data/binutils/*', 'data/includes/*.h', 'data/includes/*/*.h', - 'shellcraft/templates/*', - 'shellcraft/templates/*/*', - 'shellcraft/templates/*/*/*', - 'shellcraft/templates/*/*/*/*', - 'shellcraft/templates/*/*/*/*/*', - 'shellcraft/templates/*/*/*/*/*/*', - ] + ] + templates }, - description = package_description, - author = "Gallopsled et al.", - author_email = "#gallopsled @ freenode.net", - url = 'https://github.com/pwnies/pwntools/', # use the URL to the github repo - scripts = scripts, - download_url = "https://github.com/pwnies/pwntools/tarball/master", - requires = ['paramiko','argparse', 'mako'], - license = "MIT", - classifiers = [ + scripts = [ + 'bin/asm', + 'bin/cyclic', + 'bin/disasm', + 'bin/hex', + 'bin/shellcraft', + 'bin/unhex', + ], + description = "This is the CTF framework used by Gallopsled in every CTF.", + author = "Gallopsled et al.", + author_email = "#gallopsled @ freenode.net", + url = 'https://github.com/pwnies/pwntools/', # use the URL to the github repo + download_url = "https://github.com/pwnies/pwntools/tarball/master", + install_requires = ['paramiko','argparse', 'mako'], + setup_requires = ['mako'], + license = "MIT", + classifiers = [ 'Topic :: Security', 'Environment :: Console', 'Operating System :: OS Independent',