From 887740032c5cedb1f4a867f6741a02294df69d2c Mon Sep 17 00:00:00 2001 From: Spencer McIntyre Date: Tue, 12 Sep 2023 14:00:23 -0400 Subject: [PATCH] Add some lib docs --- lib/rex/proto/thrift.rb | 2 ++ lib/rex/proto/thrift/client.rb | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/rex/proto/thrift.rb b/lib/rex/proto/thrift.rb index b87ec19afc97..53ecbacf7d02 100644 --- a/lib/rex/proto/thrift.rb +++ b/lib/rex/proto/thrift.rb @@ -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 @@ -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 diff --git a/lib/rex/proto/thrift/client.rb b/lib/rex/proto/thrift/client.rb index 34cc838bc656..a41cbb8886b6 100644 --- a/lib/rex/proto/thrift/client.rb +++ b/lib/rex/proto/thrift/client.rb @@ -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 @@ -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] 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|