Class: PacketGen::Plugin::SMB::String
- Inherits:
-
Object
- Object
- PacketGen::Plugin::SMB::String
- Extended by:
- Forwardable
- Includes:
- Types::Fieldable
- Defined in:
- lib/packetgen/plugin/smb/string.rb
Overview
SMB strings (UTF-16 little-endian or OEM).
Instance Attribute Summary collapse
- #null_terminated ⇒ Boolean writeonly
- #string ⇒ ::String readonly
Instance Method Summary collapse
-
#from_human(str) ⇒ self
Populate String from a human readable (ie UTF-8) string.
-
#initialize(options = {}) ⇒ String
constructor
A new instance of String.
- #null_terminated? ⇒ Boolean
-
#read(str) ⇒ String
Self.
- #to_human ⇒ String
- #to_s ⇒ String
- #unicode=(bool) ⇒ Boolean
- #unicode? ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ String
Returns a new instance of String.
33 34 35 36 37 |
# File 'lib/packetgen/plugin/smb/string.rb', line 33 def initialize(={}) @unicode = .key?(:unicode) ? [:unicode] : true @null_terminated = .key?(:null_terminated) ? [:null_terminated] : true @string = +''.encode(self_encoding) end |
Instance Attribute Details
#null_terminated=(value) ⇒ Boolean (writeonly)
26 27 28 |
# File 'lib/packetgen/plugin/smb/string.rb', line 26 def null_terminated=(value) @null_terminated = value end |
#string ⇒ ::String (readonly)
23 24 25 |
# File 'lib/packetgen/plugin/smb/string.rb', line 23 def string @string end |
Instance Method Details
#from_human(str) ⇒ self
Populate String from a human readable (ie UTF-8) string
85 86 87 88 89 90 |
# File 'lib/packetgen/plugin/smb/string.rb', line 85 def from_human(str) return self if str.nil? @string = str.encode(self_encoding) self end |
#null_terminated? ⇒ Boolean
53 54 55 |
# File 'lib/packetgen/plugin/smb/string.rb', line 53 def null_terminated? @null_terminated end |
#read(str) ⇒ String
Returns self.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/packetgen/plugin/smb/string.rb', line 59 def read(str) return self if str.nil? str2 = case str.encoding when Encoding::BINARY str.dup.force_encoding(self_encoding) else str.encode(self_encoding) end idx = str2.index(+"\x00".encode(self_encoding)) str2 = str2[0, idx] unless idx.nil? @string = str2 self end |
#to_human ⇒ String
93 94 95 |
# File 'lib/packetgen/plugin/smb/string.rb', line 93 def to_human string.encode('UTF-8') end |
#to_s ⇒ String
75 76 77 78 79 80 |
# File 'lib/packetgen/plugin/smb/string.rb', line 75 def to_s str = string.dup.force_encoding('BINARY') return str unless null_terminated? str << binary_terminator.force_encoding('BINARY') end |
#unicode=(bool) ⇒ Boolean
46 47 48 49 50 |
# File 'lib/packetgen/plugin/smb/string.rb', line 46 def unicode=(bool) @unicode = bool @string.force_encoding(self_encoding) bool end |
#unicode? ⇒ Boolean
40 41 42 |
# File 'lib/packetgen/plugin/smb/string.rb', line 40 def unicode? @unicode end |