Class: PacketGen::Plugin::SMB::String
- Inherits:
 - 
      Types::CString
      
        
- Object
 - Types::CString
 - PacketGen::Plugin::SMB::String
 
 
- Defined in:
 - lib/packetgen/plugin/smb/string.rb
 
Overview
SMB strings (UTF-16 little-endian).
Instance Attribute Summary collapse
- #unicode ⇒ Object writeonly
 
Instance Method Summary collapse
- 
  
    
      #initialize(options = {})  ⇒ String 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of String.
 - 
  
    
      #read(str)  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    
Self.
 - #unicode? ⇒ Boolean
 
Constructor Details
#initialize(options = {}) ⇒ String
Returns a new instance of String.
      21 22 23 24 25 26  | 
    
      # File 'lib/packetgen/plugin/smb/string.rb', line 21 def initialize(={}) super @unicode = .key?(:unicode) ? [:unicode] : true self.encode!('UTF-16LE') if @unicode self.encode!('ASCII-8BIT') unless @unicode end  | 
  
Instance Attribute Details
#unicode=(value) ⇒ Object (writeonly)
      14 15 16  | 
    
      # File 'lib/packetgen/plugin/smb/string.rb', line 14 def unicode=(value) @unicode = value end  | 
  
Instance Method Details
#read(str) ⇒ String
Returns self.
      35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58  | 
    
      # File 'lib/packetgen/plugin/smb/string.rb', line 35 def read(str) return self if str.nil? str2 = case str.encoding when Encoding::BINARY binidx = nil 0.step(to: str.size, by: 2) do |i| binidx = i if str[i, 2] == binary_terminator end s = if binidx.nil? str else str[0, binidx] end s.force_encoding(self_encoding) else str.encode(self_encoding) end str2 = str2[0, @static_length / 2] if @static_length.is_a? Integer idx = str2.index(+"\x00".encode(self_encoding)) str2 = str2[0, idx] unless idx.nil? self.replace str2 self end  | 
  
#unicode? ⇒ Boolean
      29 30 31  | 
    
      # File 'lib/packetgen/plugin/smb/string.rb', line 29 def unicode? @unicode end  |