Skip to content

Commit

Permalink
Add some lib docs
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroSteiner committed Sep 12, 2023
1 parent 8e8b8ad commit 8877400
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/rex/proto/thrift.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require 'bindata'

# @see: https://diwakergupta.github.io/thrift-missing-guide/
module Rex::Proto::Thrift
class ThriftData < BinData::Record # forward definition
endian :big
Expand Down Expand Up @@ -141,6 +142,7 @@ class ThriftData < BinData::Record
thrift_array ThriftDataType::T_LIST
end

# Short hand method for defining a boolean field
def self.boolean(field_id, value)
{ data_type: ThriftDataType::T_BOOLEAN, field_id: field_id, data_value: value }
end
Expand Down
16 changes: 16 additions & 0 deletions lib/rex/proto/thrift/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,18 @@ def close
@conn = nil
end

# Send raw data to the remote peer.
#
# @param [String] data The data to send.
def send_raw(data)
@conn.put([data.length].pack('N') + data)
end

# Receive raw data from the remote peer.
#
# @param [Float] timeout The timeout to use for this receive operation. Defaults to the instance timeout.
# @raise [Rex::TimeoutError] Raised when all of the data was not received within the timeout.
# @return [String] The received data.
def recv_raw(timeout: @timeout)
remaining = timeout
frame_size, elapsed_time = Rex::Stopwatch.elapsed_time do
Expand Down Expand Up @@ -98,6 +106,14 @@ def recv_raw(timeout: @timeout)
body
end

# Call the specific method on the remote peer.
#
# @param [String] method_name The method name to call.
# @param [BinData::Struct, Hash, String] *data The data to send in the method call.
# @param [Float] timeout The timeout to use for this call operation. Defaults to the instance timeout.
# @raise [Error::UnexpectedReplyError] Raised if the reply was not to the method call.
# @raise [Rex::TimeoutError] Raised when all of the data was not received within the timeout.
# @return [Array<Hash>] The results of the method call.
def call(method_name, *data, timeout: @timeout)
tx_header = ThriftHeader.new(method_name: method_name, message_type: ThriftMessageType::CALL)
tx_data = data.map do |part|
Expand Down

0 comments on commit 8877400

Please sign in to comment.