Class: Rex::Java::Serialization::Model::LongUtf

Inherits:
Utf
  • Object
show all
Defined in:
lib/rex/java/serialization/model/long_utf.rb

Overview

This class provides a Long Utf string representation

Instance Attribute Summary

Attributes inherited from Utf

#contents, #length

Attributes inherited from Element

#stream

Instance Method Summary collapse

Methods inherited from Utf

#initialize, #to_s

Methods inherited from Element

decode, #initialize, #to_s

Constructor Details

This class inherits a constructor from Rex::Java::Serialization::Model::Utf

Instance Method Details

#decode(io) ⇒ self

Deserializes a Rex::Java::Serialization::Model::LongUtf

Parameters:

  • io (IO)

    the io to read from

Returns:

  • (self)

    if deserialization succeeds

Raises:



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rex/java/serialization/model/long_utf.rb', line 15

def decode(io)
  raw_length = io.read(8)
  if raw_length.nil? || raw_length.length != 8
    raise Rex::Java::Serialization::DecodeError, 'Failed to unserialize LongUtf'
  end
  self.length = raw_length.unpack('Q>')[0]

  if length == 0
    self.contents = ''
  else
    self.contents = io.read(length)
    if contents.nil? || contents.length != length
      raise Rex::Java::Serialization::DecodeError, 'Failed to unserialize LongUtf'
    end
  end

  self
end

#encodeString

Serializes the Rex::Java::Serialization::Model::LongUtf

Returns:

  • (String)


37
38
39
40
41
42
# File 'lib/rex/java/serialization/model/long_utf.rb', line 37

def encode
  encoded = [length].pack('Q>')
  encoded << contents

  encoded
end