Class: Rex::Java::Serialization::Model::Stream

Inherits:
Element
  • Object
show all
Includes:
Contents
Defined in:
lib/rex/java/serialization/model/stream.rb

Overview

This class provides a Java Stream representation

Constant Summary

Constants included from Rex::Java::Serialization

BASE_WIRE_HANDLE, OBJECT_TYPE_CODES, PRIMITIVE_TYPE_CODES, SC_BLOCK_DATA, SC_ENUM, SC_EXTERNALIZABLE, SC_SERIALIZABLE, SC_WRITE_METHOD, STREAM_MAGIC, STREAM_VERSION, TC_ARRAY, TC_BLOCKDATA, TC_BLOCKDATALONG, TC_CLASS, TC_CLASSDESC, TC_ENDBLOCKDATA, TC_ENUM, TC_EXCEPTION, TC_LONGSTRING, TC_NULL, TC_OBJECT, TC_PROXYCLASSDESC, TC_REFERENCE, TC_RESET, TC_STRING, TYPE_CODES

Instance Attribute Summary collapse

Attributes inherited from Element

#stream

Instance Method Summary collapse

Methods included from Contents

#decode_content, #encode_content, #print_class, #print_content

Methods inherited from Element

decode

Constructor Details

#initialize(stream = nil) ⇒ Stream

Returns a new instance of Stream.



25
26
27
28
29
30
31
# File 'lib/rex/java/serialization/model/stream.rb', line 25

def initialize(stream = nil)
  super(nil)
  self.magic = STREAM_MAGIC
  self.version = STREAM_VERSION
  self.contents = []
  self.references = []
end

Instance Attribute Details

#contentsArray

Returns The stream contents.

Returns:

  • (Array)

    The stream contents



20
21
22
# File 'lib/rex/java/serialization/model/stream.rb', line 20

def contents
  @contents
end

#magicFixnum

Returns The stream signature.

Returns:

  • (Fixnum)

    The stream signature



14
15
16
# File 'lib/rex/java/serialization/model/stream.rb', line 14

def magic
  @magic
end

#referencesArray

Returns The stream objects to be referenced through handles.

Returns:

  • (Array)

    The stream objects to be referenced through handles



23
24
25
# File 'lib/rex/java/serialization/model/stream.rb', line 23

def references
  @references
end

#versionFixnum

Returns The stream version.

Returns:

  • (Fixnum)

    The stream version



17
18
19
# File 'lib/rex/java/serialization/model/stream.rb', line 17

def version
  @version
end

Instance Method Details

#add_reference(ref) ⇒ Object

Adds an element to the references array

Parameters:



67
68
69
# File 'lib/rex/java/serialization/model/stream.rb', line 67

def add_reference(ref)
  self.references.push(ref)
end

#decode(io) ⇒ self

Deserializes a Rex::Java::Serialization::Model::Stream

Parameters:

  • io (IO)

    the io to read from

Returns:

  • (self)

    if deserialization succeeds

Raises:



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rex/java/serialization/model/stream.rb', line 38

def decode(io)
  self.magic = decode_magic(io)
  self.version = decode_version(io)

  until io.eof?
    content = decode_content(io, self)
    self.contents << content
  end

  self
end

#encodeString

Serializes the Rex::Java::Serialization::Model::Stream

Returns:

  • (String)

    if serialization succeeds

Raises:



54
55
56
57
58
59
60
61
62
# File 'lib/rex/java/serialization/model/stream.rb', line 54

def encode
  encoded = ''
  encoded << [magic].pack('n')
  encoded << [version].pack('n')
  contents.each do |content|
    encoded << encode_content(content)
  end
  encoded
end

#to_sString

Creates a print-friendly string representation

Returns:

  • (String)


74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/rex/java/serialization/model/stream.rb', line 74

def to_s
  str = "@magic: 0x#{magic.to_s(16)}\n"
  str << "@version: #{version}\n"
  str << "@contents: [\n"
  contents.each do |content|
    str << "  #{print_content(content)}\n"
  end
  str << "]\n"
  str << "@references: [\n"
  references.each do |ref|
      str << "  [#{(references.index(ref) + BASE_WIRE_HANDLE).to_s(16)}] #{print_content(ref)}\n"
  end
  str << "]\n"
end