Class: RubySMB::GenericPacket

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

Overview

Parent class for all SMB Packets.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.describeString

Outputs a nicely formatted string representation of the Packet's structure.

Returns:

  • (String)

    formatted string representation of the packet structure



8
9
10
11
12
13
14
# File 'lib/ruby_smb/generic_packet.rb', line 8

def self.describe
  description = ''
  fields_hashed.each do |field|
    description << format_field(field)
  end
  description
end

Instance Method Details

#displayObject



16
17
18
19
20
21
22
# File 'lib/ruby_smb/generic_packet.rb', line 16

def display
  display_str = ''
  self.class.fields_hashed.each do |field|
    display_str << display_field(field)
  end
  display_str
end

#packet_smb_versionObject



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ruby_smb/generic_packet.rb', line 25

def packet_smb_version
  class_name = self.class.to_s
  case class_name
    when /SMB1/
      'SMB1'
    when /SMB2/
      'SMB2'
    else
      ''
  end
end

#status_codeObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/ruby_smb/generic_packet.rb', line 37

def status_code
  value = -1
  smb_version = packet_smb_version
  case smb_version
    when 'SMB1'
      value = self.smb_header.nt_status.value
    when 'SMB2'
      value = self.smb2_header.nt_status.value
  end
  status_code = WindowsError::NTStatus.find_by_retval(value).first
  if status_code.nil?
    status_code = WindowsError::ErrorCode.new("0x#{value.to_s(16)}", value, "Unknown 0x#{value.to_s(16)}")
  end
  status_code
end