Skip to content

Commit d5f15cc

Browse files
committed
support preexec_args in process
Previously, preexec_args where supported by ssh.process only. Add support in process too, to allow easier ssh.process/process workflows
1 parent 49964f6 commit d5f15cc

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pwnlib/tubes/process.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ class process(tube):
8686
By default, :const:`True` is used.
8787
preexec_fn(callable):
8888
Callable to invoke immediately before calling ``execve``.
89+
preexec_args(iterable):
90+
Arguments passed to ``preexec_fn``.
8991
raw(bool):
9092
Set the created pty to raw mode (i.e. disable echo and control
9193
characters). :const:`True` by default. If no pty is created, this
@@ -216,6 +218,9 @@ class process(tube):
216218
>>> p = process(binary.path, cwd=binary_dir)
217219
>>> p = process('./{}'.format(binary_name), cwd=os.path.relpath(binary_dir))
218220
>>> p = process(binary.path, cwd=os.path.relpath(binary_dir))
221+
222+
>>> print(process('false', preexec_fn=lambda s: print(s), preexec_args=("Hello World!", )).recvall().strip().decode())
223+
Hello World!
219224
"""
220225

221226
STDOUT = STDOUT
@@ -238,6 +243,7 @@ def __init__(self, argv = None,
238243
stderr = STDOUT,
239244
close_fds = True,
240245
preexec_fn = lambda: None,
246+
preexec_args = (),
241247
raw = True,
242248
aslr = None,
243249
setuid = None,
@@ -330,6 +336,7 @@ def __init__(self, argv = None,
330336
self.alarm = alarm
331337

332338
self.preexec_fn = preexec_fn
339+
self.preexec_args = preexec_args
333340
self.display = display or self.program
334341
self._qemu = False
335342
self._corefile = None
@@ -471,7 +478,7 @@ def __preexec_fn(self):
471478
if self.alarm is not None:
472479
signal.alarm(self.alarm)
473480

474-
self.preexec_fn()
481+
self.preexec_fn(*self.preexec_args)
475482

476483
def __on_enoexec(self, exception):
477484
"""We received an 'exec format' error (ENOEXEC)

0 commit comments

Comments
 (0)