MCPcopy
hub / github.com/Gallopsled/pwntools / testpwnproc

Function testpwnproc

pwnlib/ui.py:20–49  ·  view source on GitHub ↗
(cmd)

Source from the content-addressed store, hash-verified

18log = getLogger(__name__)
19
20def 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 = """\
31import os
32import signal
33import sys
34_ehook = sys.excepthook
35def ehook(*args):
36 _ehook(*args)
37 os.kill(os.getppid(), signal.SIGUSR1)
38sys.excepthook = ehook
39from 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
51def yesno(prompt, default=None):
52 r"""Presents the user with prompt (typically in the form of question)

Callers

nothing calls this directly

Calls 6

processClass · 0.90
signalMethod · 0.80
setdefaultMethod · 0.80
popMethod · 0.45
filenoMethod · 0.45
packMethod · 0.45

Tested by

no test coverage detected