Class: RubySMB::Dcerpc::RpcUnicodeString

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

Overview

A RPC_UNICODE_STRING structure as defined in 2.3.10 RPC_UNICODE_STRING

Direct Known Subclasses

PrpcUnicodeString

Instance Method Summary collapse

Methods inherited from Ndr::NdrStruct

#initialize_shared_instance, method_missing, validate_conformant_array

Instance Method Details

#assign(val) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/ruby_smb/dcerpc/rrp_rpc_unicode_string.rb', line 75

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
    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.



100
101
102
103
104
# File 'lib/ruby_smb/dcerpc/rrp_rpc_unicode_string.rb', line 100

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



106
107
108
109
# File 'lib/ruby_smb/dcerpc/rrp_rpc_unicode_string.rb', line 106

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