Class: Rex::Java::Serialization::Model::NewObject

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

Overview

This class provides a NewObject (Java Object) 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) ⇒ NewObject

Returns a new instance of NewObject.

Parameters:



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

def initialize(stream = nil)
  super(stream)
  self.class_desc = nil
  self.class_data = []
end

Instance Attribute Details

#class_dataArray

Returns The data of the object.

Returns:

  • (Array)

    The data of the object



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

def class_data
  @class_data
end

#class_descRex::Java::Serialization::Model::ClassDesc

Returns The description of the object.

Returns:



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

def class_desc
  @class_desc
end

Instance Method Details

#decode(io) ⇒ self

Deserializes a Rex::Java::Serialization::Model::NewObject

Parameters:

  • io (IO)

    the io to read from

Returns:

  • (self)

    if deserialization succeeds

Raises:



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rex/java/serialization/model/new_object.rb', line 31

def decode(io)
  self.class_desc = ClassDesc.decode(io, stream)
  stream.add_reference(self) unless stream.nil?

  if class_desc.description.class == NewClassDesc
    self.class_data = decode_class_data(io, class_desc.description)
  elsif class_desc.description.class == Reference
    ref = class_desc.description.handle - BASE_WIRE_HANDLE
    self.class_data = decode_class_data(io, stream.references[ref])
  end

  self
end

#encodeString

Serializes the Rex::Java::Serialization::Model::NewObject

Returns:

  • (String)

    if serialization succeeds

Raises:



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/rex/java/serialization/model/new_object.rb', line 49

def encode
  unless class_desc.class == ClassDesc
    raise ::RuntimeError, 'Failed to serialize NewObject'
  end

  encoded = ''
  encoded << class_desc.encode

  class_data.each do |value|
    if value.class == Array
      encoded << encode_value(value)
    else
      encoded << encode_content(value)
    end
  end

  encoded
end

#to_sString

Creates a print-friendly string representation

Returns:

  • (String)


71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/rex/java/serialization/model/new_object.rb', line 71

def to_s
  str  = ''
  if class_desc.description.class == NewClassDesc
    str << class_desc.description.class_name.to_s
  elsif class_desc.description.class == Reference
    str << (class_desc.description.handle - BASE_WIRE_HANDLE).to_s(16)
  end

  str << ' => { '
  data = class_data.collect { |data| data.to_s }
  str << data.join(', ')
  str << ' }'
end