Class: RubySMB::Dcerpc::RrpUnicodeString

Inherits:
Ndr::NdrStruct
  • Object
show all
Defined in:
lib/ruby_smb/dcerpc/rrp_rpc_unicode_string.rb

Overview

A RRP_UNICODE_STRING structure as defined in 2.2.4 RRP_UNICODE_STRING

Direct Known Subclasses

PrrpUnicodeString

Instance Method Summary collapse

Methods inherited from Ndr::NdrStruct

#initialize_shared_instance, method_missing, validate_conformant_array

Instance Method Details

#assign(val) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ruby_smb/dcerpc/rrp_rpc_unicode_string.rb', line 14

def assign(val)
  case val
  when :null
    self.buffer = val
    self.buffer_length = 0
    self.maximum_length = 0
  when BinData::Stringz, BinData::String, String
    self.buffer = val.to_s
    val_length = val.strip.length
    val_length += 1 unless val == ''
    self.buffer_length = val_length * 2
    self.maximum_length = val_length * 2
  else
    super
  end
end

#set_max_buffer_size(val) ⇒ Object

Set maximum_length and buffer max_count values to val. It also takes care of initializing the buffer pointer ref_id if the pointer is null.

This helper is typically called in requests where a unicode string field needs to contain the maximum length information without any string value. It is usually required by some RPC calls and used by the server to determine the maximum length for the corresponding output field in order to allocate space accordingly.



40
41
42
43
44
# File 'lib/ruby_smb/dcerpc/rrp_rpc_unicode_string.rb', line 40

def set_max_buffer_size(val)
  self.buffer.instantiate_referent if self.buffer.is_null_ptr?
  self.buffer.max_count = val / 2
  self.maximum_length.assign(val)
end

#to_sObject



46
47
48
49
# File 'lib/ruby_smb/dcerpc/rrp_rpc_unicode_string.rb', line 46

def to_s
  return ''.encode('utf-16le') if self.buffer.is_null_ptr?
  self.buffer.to_s
end