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

Implement Tubes#recvall #179

Merged
merged 2 commits into from
Jul 4, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion lib/pwnlib/tubes/buffer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def unget(data)

# Retrieves bytes from the buffer.
#
# @param [Integer] n
# @param [Integer?] n
# Maximum number of bytes to fetch.
#
# @return [String]
Expand Down
16 changes: 16 additions & 0 deletions lib/pwnlib/tubes/tube.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,22 @@ def recvregex(regex, timeout: nil)
recvpred(timeout: timeout) { |data| data =~ regex }
end

# Receives data until reaching EOF or a timeout is occurred.
#
# @!macro timeout_definition
#
# @return [String]
# Returns the data received.
def recvall(timeout: nil)
recvn(1 << 63, timeout: timeout)
rescue ::Pwnlib::Errors::EndOfTubeError, ::Pwnlib::Errors::TimeoutError
@buffer.get
end
alias readall recvall
# match Ruby's naming convention
david942j marked this conversation as resolved.
Show resolved Hide resolved
alias recv_all recvall
alias read_all recvall

# Sends data.
#
# @param [String] data
Expand Down
7 changes: 7 additions & 0 deletions test/tubes/tube_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ def test_recvregex
5.times { assert_match(r, t.recvregex(r)) }
end

def test_recvall
t = basic_tube
t.unrecv('meow')
assert_equal('meow', t.recvall)
assert_equal('', t.recvall)
end

def test_send
t = hello_tube
assert_equal(6, t.write('DARKHH'))
Expand Down