Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions docs/source/tubes/processes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

from pwn import *

# TODO: Remove global POSIX flag
import doctest
doctest_additional_flags = doctest.OPTIONFLAGS_BY_NAME['POSIX']

:mod:`pwnlib.tubes.process` --- Processes
===========================================================

Expand Down
4 changes: 0 additions & 4 deletions docs/source/tubes/serial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

from pwn import *

# TODO: Remove global POSIX flag
import doctest
doctest_additional_flags = doctest.OPTIONFLAGS_BY_NAME['POSIX']

:mod:`pwnlib.tubes.serialtube` --- Serial Ports
===========================================================

Expand Down
81 changes: 64 additions & 17 deletions pwnlib/tubes/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,22 @@ class process(tube):
True
>>> p.connected('send')
False
>>> p.recvline()
b'Hello world\n'
>>> p.recvline() # doctest: +ELLIPSIS
b'Hello world...\n'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get it, it is great to test things work, but does this still have the value of being obvious documentation for the function?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's annoying. This goes away after recvline doesn't include the newline anymore in #2588. We could just add drop=True explicitly too for this test?

>>> p.recvuntil(b',')
b'Wow,'
>>> p.recvregex(b'.*data')
b' such data'
>>> p.recv()
b'\n'
>>> p.recv() # doctest: +ELLIPSIS
b'...\n'
>>> p.recv() # doctest: +ELLIPSIS
Traceback (most recent call last):
...
EOFError

.. doctest::
:options: +POSIX

>>> p = process('cat')
>>> d = open('/dev/urandom', 'rb').read(4096)
>>> p.recv(timeout=0.1)
Expand Down Expand Up @@ -515,6 +518,9 @@ def program(self):

Example:

.. doctest::
:options: +POSIX +TODO

>>> p = process('/bin/true')
>>> p.executable == '/bin/true'
True
Expand All @@ -530,6 +536,9 @@ def cwd(self):

Example:

.. doctest::
:options: +POSIX +TODO

>>> p = process('sh')
>>> p.sendline(b'cd /tmp; echo AAA')
>>> _ = p.recvuntil(b'AAA')
Expand Down Expand Up @@ -902,7 +911,10 @@ def maps(self):
read, write, execute, private, shared, string

Example:


.. doctest::
:options: +POSIX +TODO

>>> p = process(['cat'])
>>> p.sendline(b"meow")
>>> p.recvline()
Expand Down Expand Up @@ -982,7 +994,10 @@ def get_mapping(self, path_value, single=True):
path_value.

Example:


.. doctest::
:options: +POSIX

>>> p = process(['cat'])
>>> mapping = p.get_mapping('[stack]')
>>> mapping.path == '[stack]'
Expand Down Expand Up @@ -1025,6 +1040,9 @@ def stack_mapping(self, single=True):

Example:

.. doctest::
:options: +POSIX

>>> p = process(['cat'])
>>> mapping = p.stack_mapping()
>>> mapping.path
Expand Down Expand Up @@ -1054,6 +1072,9 @@ def heap_mapping(self, single=True):

Example:

.. doctest::
:options: +POSIX

>>> p = process(['cat'])
>>> p.sendline(b'meow')
>>> p.recvline()
Expand Down Expand Up @@ -1086,6 +1107,9 @@ def vdso_mapping(self, single=True):

Example:

.. doctest::
:options: +LINUX

>>> p = process(['cat'])
>>> mapping = p.vdso_mapping()
>>> mapping.path
Expand Down Expand Up @@ -1115,6 +1139,9 @@ def vvar_mapping(self, single=True):

Example:

.. doctest::
:options: +LINUX

>>> p = process(['cat'])
>>> mapping = p.vvar_mapping()
>>> mapping.path
Expand Down Expand Up @@ -1145,6 +1172,9 @@ def libc_mapping(self, single=True):

Example:

.. doctest::
:options: +POSIX

>>> p = process(['cat'])
>>> p.sendline(b'meow')
>>> p.recvline()
Expand Down Expand Up @@ -1225,6 +1255,9 @@ def elf_mapping(self, single=True):

Example:

.. doctest::
:options: +POSIX

>>> p = process(['cat'])
>>> p.sendline(b'meow')
>>> p.recvline()
Expand Down Expand Up @@ -1263,7 +1296,9 @@ def lib_size(self, path_value):

Example:

>>> from pwn import *
.. doctest::
:options: +POSIX

>>> p = process(['cat'])
>>> p.send(b'meow')
>>> p.recvuntil(b'meow')
Expand Down Expand Up @@ -1303,6 +1338,9 @@ def address_mapping(self, address):

Example:

.. doctest::
:options: +POSIX

>>> p = process(['cat'])
>>> p.sendline(b'meow')
>>> p.recvline()
Expand Down Expand Up @@ -1363,16 +1401,19 @@ def libc(self):

Example:

>>> p = process("/bin/cat")
>>> p.send(b"meow")
>>> p.recvuntil(b"meow")
b'meow'
>>> libc = p.libc
>>> libc is not None
True
>>> libc # doctest: +SKIP
ELF('/lib64/libc-...so')
>>> p.close()
.. doctest::
:options: +POSIX

>>> p = process("/bin/cat")
>>> p.send(b"meow")
>>> p.recvuntil(b"meow")
b'meow'
>>> libc = p.libc
>>> libc is not None
True
>>> libc # doctest: +SKIP
ELF('/lib64/libc-...so')
>>> p.close()
"""
from pwnlib.elf import ELF

Expand Down Expand Up @@ -1447,6 +1488,9 @@ def leak(self, address, count=1):

Example:

.. doctest::
:options: +POSIX +TODO

>>> e = ELF(which('bash-static'))
>>> p = process(e.path)

Expand Down Expand Up @@ -1483,6 +1527,9 @@ def writemem(self, address, data):

Let's write data to the beginning of the mapped memory of the ELF.

.. doctest::
:options: +POSIX +TODO

>>> context.clear(arch='i386')
>>> address = 0x100000
>>> data = cyclic(32)
Expand Down
4 changes: 3 additions & 1 deletion pwnlib/util/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,10 @@ def which(name, all = False, path=None):

Example:

>>> which('sh') # doctest: +ELLIPSIS +POSIX +TODO
>>> which('sh') # doctest: +ELLIPSIS +POSIX
'.../bin/sh'
>>> which('cmd') # doctest: +ELLIPSIS +WINDOWS
'...\\cmd.EXE'
"""
# If name is a path, do not attempt to resolve it.
if os.path.sep in name:
Expand Down
Loading