Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing tubes buffer size to be variable defaulted #803

Closed
wants to merge 4 commits into from
Closed
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
5 changes: 3 additions & 2 deletions pwnlib/tubes/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@ def __init__(self, argv,
stdout = PTY,
stderr = STDOUT,
close_fds = True,
preexec_fn = lambda: None):
super(process, self).__init__(timeout)
preexec_fn = lambda: None,
bufSize = 4096):
super(process, self).__init__(timeout,bufSize = bufSize)

if not shell:
executable, argv, env = self._validate(cwd, executable, argv, env)
Expand Down
4 changes: 2 additions & 2 deletions pwnlib/tubes/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class remote(sock):

def __init__(self, host, port,
fam = "any", typ = "tcp",
timeout = Timeout.default, ssl=False, sock=None):
super(remote, self).__init__(timeout)
timeout = Timeout.default, ssl=False, sock=None, bufSize = 4096):
super(remote, self).__init__(timeout, bufSize = bufSize)

self.rport = int(port)
self.rhost = host
Expand Down
4 changes: 2 additions & 2 deletions pwnlib/tubes/sock.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
class sock(tube):
"""Methods available exclusively to sockets."""

def __init__(self, timeout):
super(sock, self).__init__(timeout)
def __init__(self, timeout, bufSize = 4096):
super(sock, self).__init__(timeout, bufSize = bufSize)
self.closed = {"recv": False, "send": False}

# Overwritten for better usability
Expand Down
11 changes: 7 additions & 4 deletions pwnlib/tubes/tube.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ class tube(Timeout):
#: and related functions.
newline = '\n'

def __init__(self, timeout = default):
def __init__(self, timeout = default, bufSize = 4096):
super(tube, self).__init__(timeout)
self.buffer = Buffer()
self.bufSize = bufSize
atexit.register(self.close)

# Functions based on functions from subclasses
def recv(self, numb = 4096, timeout = default):
def recv(self, numb = None, timeout = default):
r"""recv(numb = 4096, timeout = default) -> str

Receives up to `numb` bytes of data from the tube, and returns
Expand Down Expand Up @@ -70,6 +71,7 @@ def recv(self, numb = 4096, timeout = default):
[...] Received 0xc bytes:
'Hello, world'
"""
numb = self.bufSize if numb is None else numb
return self._recv(numb, timeout) or ''

def unrecv(self, data):
Expand Down Expand Up @@ -120,7 +122,7 @@ def _fillbuffer(self, timeout = default):
data = ''

with self.local(timeout):
data = self.recv_raw(4096)
data = self.recv_raw(self.bufSize)

if data and dumplog.isEnabledFor(logging.DEBUG):
dumplog.debug('Received %#x bytes:' % len(data))
Expand All @@ -139,13 +141,14 @@ def _fillbuffer(self, timeout = default):
return data


def _recv(self, numb = 4096, timeout = default):
def _recv(self, numb = None, timeout = default):
"""_recv(numb = 4096, timeout = default) -> str

Receives one chunk of from the internal buffer or from the OS if the
buffer is empty.
"""
data = ''
numb = self.bufSize if numb is None else numb

# No buffered data, could not put anything in the buffer
# before timeout.
Expand Down