class RubySMB::Error::InvalidPacket
Raised when trying to parse raw binary into a Packet and the data is invalid.
Attributes
status_code[R]
Public Class Methods
new(args = nil)
click to toggle source
Calls superclass method
# File lib/ruby_smb/error.rb, line 20 def initialize(args = nil) if args.nil? super elsif args.is_a? String super(args) elsif args.is_a? Hash expected_proto = args[:expected_proto] ? translate_protocol(args[:expected_proto]) : '???' expected_cmd = args[:expected_cmd] || '???' received_proto = args[:packet]&.packet_smb_version || '???' received_cmd = get_cmd(args[:packet]) || '???' @status_code = args[:packet]&.status_code super( "Expecting #{expected_proto} protocol "\ "with command=#{expected_cmd}"\ "#{(" (" + args[:expected_custom] + ")") if args[:expected_custom]}, "\ "got #{received_proto} protocol "\ "with command=#{received_cmd}"\ "#{(" (" + args[:received_custom] + ")") if args[:received_custom]}"\ "#{(", Status: #{@status_code}") if @status_code}" ) else raise ArgumentError, "InvalidPacket expects a String or a Hash, got a #{args.class}" end end
Private Instance Methods
get_cmd(packet)
click to toggle source
# File lib/ruby_smb/error.rb, line 57 def get_cmd(packet) return nil unless packet case packet.packet_smb_version when 'SMB1' packet.smb_header.command when 'SMB2' packet.smb2_header.command else nil end end
translate_protocol(proto)
click to toggle source
# File lib/ruby_smb/error.rb, line 45 def translate_protocol(proto) case proto when RubySMB::SMB1::SMB_PROTOCOL_ID 'SMB1' when RubySMB::SMB2::SMB2_PROTOCOL_ID 'SMB2' else raise ArgumentError, 'Unknown SMB protocol' end end