Skip to content

Commit

Permalink
Made the setup.py work properly (I think)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathias Svensson committed Jul 26, 2014
1 parent b63722e commit 5f0ca44
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 81 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
*/auto/*
*/bin/*
build
MANIFEST
dist
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions install_local.sh
Original file line number Diff line number Diff line change
@@ -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\""
129 changes: 50 additions & 79 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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',
Expand Down

0 comments on commit 5f0ca44

Please sign in to comment.