Class: RubySMB::GenericPacket
- Inherits:
-
BinData::Record
- Object
- BinData::Record
- RubySMB::GenericPacket
- Defined in:
- lib/ruby_smb/generic_packet.rb
Overview
Parent class for all SMB Packets.
Direct Known Subclasses
SMB1::Packet::EchoRequest, SMB1::Packet::EchoResponse, SMB1::Packet::EmptyPacket, SMB1::Packet::LogoffRequest, SMB1::Packet::LogoffResponse, SMB1::Packet::NegotiateRequest, SMB1::Packet::NegotiateResponse, SMB1::Packet::NegotiateResponseExtended, SMB1::Packet::NtTrans::CreateRequest, SMB1::Packet::NtTrans::CreateResponse, SMB1::Packet::NtTrans::Request, SMB1::Packet::NtTrans::Response, SMB1::Packet::SessionSetupLegacyRequest, SMB1::Packet::SessionSetupLegacyResponse, SMB1::Packet::SessionSetupRequest, SMB1::Packet::SessionSetupResponse, SMB1::Packet::Trans2::Open2Request, SMB1::Packet::Trans2::Open2Response, SMB1::Packet::Trans2::Request, SMB1::Packet::Trans2::RequestSecondary, SMB1::Packet::Trans2::Response, SMB1::Packet::TreeConnectRequest, SMB1::Packet::TreeConnectResponse, SMB1::Packet::TreeDisconnectRequest, SMB1::Packet::TreeDisconnectResponse, SMB2::Packet::EchoRequest, SMB2::Packet::EchoResponse, SMB2::Packet::ErrorPacket, SMB2::Packet::LogoffRequest, SMB2::Packet::LogoffResponse, SMB2::Packet::NegotiateRequest, SMB2::Packet::NegotiateResponse, SMB2::Packet::SessionSetupRequest, SMB2::Packet::SessionSetupResponse, SMB2::Packet::TreeConnectRequest, SMB2::Packet::TreeConnectResponse, SMB2::Packet::TreeDisconnectRequest, SMB2::Packet::TreeDisconnectResponse
Class Method Summary collapse
-
.describe ⇒ String
Outputs a nicely formatted string representation of the Packet's structure.
-
.fields_hashed ⇒ Array<Hash>
Returns an array of hashes representing the fields for this record.
-
.format_field(field, depth = 0) ⇒ String
Takes a hash representation of a field and spits out a formatted string representation.
-
.walk_fields(fields) ⇒ Array<Hash>
Recursively walks through a field, building a hash representation of that field and all of it's sub-fields.
Instance Method Summary collapse
Class Method Details
.describe ⇒ String
Outputs a nicely formatted string representation of the Packet's 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 |
.fields_hashed ⇒ Array<Hash>
Returns an array of hashes representing the fields for this record.
59 60 61 |
# File 'lib/ruby_smb/generic_packet.rb', line 59 def self.fields_hashed walk_fields(fields) end |
.format_field(field, depth = 0) ⇒ String
Takes a hash representation of a field and spits out a formatted string representation.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/ruby_smb/generic_packet.rb', line 69 def self.format_field(field, depth = 0) name = field[:name].to_s if field[:class].ancestors.include? BinData::Record class_str = '' name.upcase! else class_str = field[:class].to_s.split('::').last class_str = "(#{class_str})" name.capitalize! end formatted_name = "\n" + ("\t" * depth) + name formatted_string = sprintf '%-30s %-10s %s', formatted_name, class_str, field[:label] field[:fields].each do |sub_field| formatted_string << format_field(sub_field, (depth + 1)) end formatted_string end |
.walk_fields(fields) ⇒ Array<Hash>
Recursively walks through a field, building a hash representation of that field and all of it's sub-fields.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/ruby_smb/generic_packet.rb', line 92 def self.walk_fields(fields) field_hashes = [] fields.each do |field| field_hash = {} field_hash[:name] = field.name prototype = field.prototype field_hash[:class] = prototype.instance_variable_get(:@obj_class) params = prototype.instance_variable_get(:@obj_params) field_hash[:label] = params[:label] field_hash[:value] = params[:value] sub_fields = params[:fields] field_hash[:fields] = if sub_fields.nil? [] else walk_fields(sub_fields) end field_hashes << field_hash end field_hashes end |
Instance Method Details
#display ⇒ Object
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_version ⇒ Object
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_code ⇒ Object
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 |