Sha256: 55d15ed58f648bcce01cca0cf83789acc448a42202eafd1351d71430af697e8a

Contents?: true

Size: 1.3 KB

Versions: 10

Compression:

Stored size: 1.3 KB

Contents

module RubySMB
  module SMB1
    # Represents the ParameterBlock portion of an SMB1 Packet. The ParameterBlock will
    # always contain a word_count field that gives the size of the rest of
    # the data block in words.
    class ParameterBlock < BinData::Record
      endian  :little

      uint8   :word_count, label: 'Word Count', value: -> { calculate_word_count }

      # Class method to stub word count calculation during
      # lazy evaluation.
      #
      # @param [Fixnum] will always return 0
      def self.calculate_word_count
        0
      end

      # Returns the name of all fields, other than word_count, in
      # the ParameterBlock as symbols.
      #
      # @return [Array<Symbol>] the names of all other ParameterBlock fields
      def self.parameter_fields
        fields = self.fields.collect(&:name)
        fields.reject { |field| field == :word_count }
      end

      # Calculates the size of the other fields in the ParameterBlock
      # in Words.
      #
      # @return [Fixnum] The size of the ParameterBlock in Words
      def calculate_word_count
        total_count = 0
        self.class.parameter_fields.each do |field_name|
          field_value = send(field_name)
          total_count += field_value.do_num_bytes
        end
        total_count.to_i / 2
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
ruby_smb-0.0.17 lib/ruby_smb/smb1/parameter_block.rb
ruby_smb-0.0.16 lib/ruby_smb/smb1/parameter_block.rb
ruby_smb-0.0.15 lib/ruby_smb/smb1/parameter_block.rb
ruby_smb-0.0.14 lib/ruby_smb/smb1/parameter_block.rb
ruby_smb-0.0.13 lib/ruby_smb/smb1/parameter_block.rb
ruby_smb-0.0.12 lib/ruby_smb/smb1/parameter_block.rb
ruby_smb-0.0.11 lib/ruby_smb/smb1/parameter_block.rb
ruby_smb-0.0.10 lib/ruby_smb/smb1/parameter_block.rb
ruby_smb-0.0.9 lib/ruby_smb/smb1/parameter_block.rb
ruby_smb-0.0.8 lib/ruby_smb/smb1/parameter_block.rb