Skip to content

Commit

Permalink
Implement Tubes#recvall
Browse files Browse the repository at this point in the history
Closes #68
  • Loading branch information
david942j committed Jun 30, 2019
1 parent 4144a5d commit 3a24925
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
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
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

0 comments on commit 3a24925

Please sign in to comment.