Class: RubySMB::SMB1::DataBlock

Inherits:
BinData::Record
  • Object
show all
Defined in:
lib/ruby_smb/smb1/data_block.rb

Overview

Represents the DataBlock portion of an SMB1 Packet. The DataBlock will always contain a byte_count field that gives the size of the rest of the data block in bytes.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.calculate_byte_countInteger

Class method to stub byte count calculation during lazy evaluation.

Returns:

  • (Integer)

    will always return 0



15
16
17
# File 'lib/ruby_smb/smb1/data_block.rb', line 15

def self.calculate_byte_count
  0
end

.data_fieldsArray<Symbol>

Returns the name of all fields, other than byte_count, in the DataBlock as symbols.

Returns:

  • (Array<Symbol>)

    the names of all other DataBlock fields



23
24
25
26
# File 'lib/ruby_smb/smb1/data_block.rb', line 23

def self.data_fields
  fields = self.fields.collect(&:name)
  fields.reject { |field| field == :byte_count }
end

Instance Method Details

#calculate_byte_countInteger

Calculates the size of the other fields in the DataBlock in Bytes.

Returns:

  • (Integer)

    The size of the DataBlock in Words



32
33
34
35
36
37
38
39
40
# File 'lib/ruby_smb/smb1/data_block.rb', line 32

def calculate_byte_count
  total_count = 0
  self.class.data_fields.each do |field_name|
    next unless field_enabled?(field_name)
    field_value = send(field_name)
    total_count += field_value.do_num_bytes
  end
  total_count
end

#field_enabled?(field_name) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/ruby_smb/smb1/data_block.rb', line 42

def field_enabled?(field_name)
  send("#{field_name}?".to_sym)
end