| 18 | log = getLogger(__name__) |
| 19 | |
| 20 | def testpwnproc(cmd): |
| 21 | import fcntl |
| 22 | import termios |
| 23 | env = dict(os.environ) |
| 24 | env.pop("PWNLIB_NOTERM", None) |
| 25 | env["TERM"] = "xterm-256color" |
| 26 | def handleusr1(sig, frame): |
| 27 | s = p.stderr.read() |
| 28 | log.error("child process failed:\n%s", s.decode()) |
| 29 | signal.signal(signal.SIGUSR1, handleusr1) |
| 30 | cmd = """\ |
| 31 | import os |
| 32 | import signal |
| 33 | import sys |
| 34 | _ehook = sys.excepthook |
| 35 | def ehook(*args): |
| 36 | _ehook(*args) |
| 37 | os.kill(os.getppid(), signal.SIGUSR1) |
| 38 | sys.excepthook = ehook |
| 39 | from pwn import * |
| 40 | """ + cmd |
| 41 | if "coverage" in sys.modules: |
| 42 | cmd = "import coverage; coverage.process_startup()\n" + cmd |
| 43 | env.setdefault("COVERAGE_PROCESS_START", ".coveragerc") |
| 44 | env['COLUMNS'] = '80' |
| 45 | env['ROWS'] = '24' |
| 46 | p = process([sys.executable, "-c", cmd], env=env, stderr=subprocess.PIPE) |
| 47 | # late initialization can lead to EINTR in many places |
| 48 | fcntl.ioctl(p.stdout.fileno(), termios.TIOCSWINSZ, struct.pack('HH', 24, 80)) |
| 49 | return p |
| 50 | |
| 51 | def yesno(prompt, default=None): |
| 52 | r"""Presents the user with prompt (typically in the form of question) |