Skip to content
Permalink
Browse files

Allow pwntools to load on Windows (#1449)

* Allow pwntools to load on Windows

Fixes loading of pwntools on Windows. `from pwn import *` works.

It allows to use some operating system agnostic features of pwntools out of the box.

This is inspired by #996.

Some features fail or even crash (local processes, gdb, assemble/disassemble)
 and console colors are still not displayed correctly, but those can be addressed separately.

* Use `os.devnull` instead of manual selection
  • Loading branch information
peace-maker committed Mar 16, 2020
1 parent 7326452 commit c5178460dffe3a1c2e9bd22b5bc8fe0f249ff588
Showing with 20 additions and 9 deletions.
  1. +3 −0 pwnlib/term/__init__.py
  2. +4 −2 pwnlib/term/term.py
  3. +7 −4 pwnlib/tubes/process.py
  4. +1 −1 pwnlib/tubes/ssh.py
  5. +2 −2 pwnlib/ui.py
  6. +3 −0 setup.py
@@ -27,6 +27,9 @@ def can_init():
``pwnlib`` manage the terminal.
"""

if sys.platform == 'win32':
return False

if not sys.stdout.isatty():
return False

@@ -2,17 +2,19 @@
from __future__ import division

import atexit
import fcntl
import os
import re
import signal
import six
import struct
import sys
import termios
import threading
import traceback

if sys.platform != 'win32':
import fcntl
import termios

from pwnlib.context import ContextType
from pwnlib.term import termcap

@@ -4,19 +4,22 @@

import ctypes
import errno
import fcntl
import logging
import os
import platform
import pty
import resource
import select
import signal
import six
import stat
import subprocess
import sys
import time
import tty

if sys.platform != 'win32':
import fcntl
import pty
import resource
import tty

from pwnlib import qemu
from pwnlib.context import context
@@ -30,7 +30,7 @@
# Kill the warning line:
# No handlers could be found for logger "paramiko.transport"
paramiko_log = logging.getLogger("paramiko.transport")
h = logging.StreamHandler(open('/dev/null','w+'))
h = logging.StreamHandler(open(os.devnull,'w+'))
h.setFormatter(logging.Formatter())
paramiko_log.addHandler(h)

@@ -1,15 +1,13 @@
from __future__ import absolute_import
from __future__ import division

import fcntl
import os
import signal
import six
import string
import struct
import subprocess
import sys
import termios
import time
import types

@@ -21,6 +19,8 @@
log = getLogger(__name__)

def testpwnproc(cmd):
import fcntl
import termios
env = dict(os.environ)
env.pop("PWNLIB_NOTERM", None)
def handleusr1(sig, frame):
@@ -63,6 +63,9 @@
'unicorn>=1.0.2rc1', # see unicorn-engine/unicorn#1100, unicorn-engine/unicorn#1170
]

if sys.platform == 'win32':
install_requires.append('windows-curses>=2.1.0')

# Check that the user has installed the Python development headers
PythonH = os.path.join(get_python_inc(), 'Python.h')
if not os.path.exists(PythonH):

0 comments on commit c517846

Please sign in to comment.
You can’t perform that action at this time.