Class: RubySMB::Nbss::NetbiosName

Inherits:
BinData::Primitive
  • Object
show all
Defined in:
lib/ruby_smb/nbss/netbios_name.rb

Overview

Instance Method Summary collapse

Instance Method Details

#getObject



37
38
39
# File 'lib/ruby_smb/nbss/netbios_name.rb', line 37

def get
  nb_name_decode(label)
end

#nb_name_decode(encoded_name) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/ruby_smb/nbss/netbios_name.rb', line 27

def nb_name_decode(encoded_name)
  name = encoded_name.scan(/../).map do |char_pair|
    first_half = char_pair[0];
    second_half = char_pair[1]
    char = ((first_half.ord - 'A'.ord) << 4) + (second_half.ord - 'A'.ord)
    char.chr
  end
  name.join
end

#nb_name_encode(name) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/ruby_smb/nbss/netbios_name.rb', line 16

def nb_name_encode(name)
  encoded_name = ''
  name.each_byte do |char|
    first_half = (char >> 4) + 'A'.ord
    second_half = (char & 0xF) + 'A'.ord
    encoded_name << first_half.chr
    encoded_name << second_half.chr
  end
  encoded_name
end

#set(label) ⇒ Object



41
42
43
44
# File 'lib/ruby_smb/nbss/netbios_name.rb', line 41

def set(label)
  self.label = nb_name_encode(label)
  self.label_length = self.label.length
end