Class: Rex::Java::Serialization::Model::NewArray

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

Overview

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

Returns a new instance of NewArray.

Parameters:



23
24
25
26
27
28
# File 'lib/rex/java/serialization/model/new_array.rb', line 23

def initialize(stream = nil)
  super(stream)
  self.array_description = nil
  self.type = ''
  self.values = []
end

Instance Attribute Details

#array_descriptionJava::Serialization::Model::ClassDesc

Returns The description of the array.

Returns:



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

def array_description
  @array_description
end

#typeString

Returns The type of the array values.

Returns:

  • (String)

    The type of the array values



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

def type
  @type
end

#valuesArray

Returns The contents of the java array.

Returns:

  • (Array)

    The contents of the java array



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

def values
  @values
end

Instance Method Details

#decode(io) ⇒ self

Deserializes a Rex::Java::Serialization::Model::NewArray

Parameters:

  • io (IO)

    the io to read from

Returns:

  • (self)

    if deserialization succeeds

Raises:



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

def decode(io)
  self.array_description = ClassDesc.decode(io, stream)
  stream.add_reference(self) unless stream.nil?
  self.type = array_type

  values_length = decode_values_length(io)

  values_length.times do
    value = decode_value(io)
    self.values << value
  end

  self
end

#encodeString

Serializes the Rex::Java::Serialization::Model::NewArray

Returns:

  • (String)

    if serialization succeeds

Raises:



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/rex/java/serialization/model/new_array.rb', line 54

def encode
  unless array_description.kind_of?(ClassDesc)
    raise Rex::Java::Serialization::EncodeError, 'Failed to serialize NewArray'
  end

  encoded = ''
  encoded << array_description.encode

  encoded << [values.length].pack('N')

  values.each do |value|
    encoded << encode_value(value)
  end

  encoded
end

#to_sString

Creates a print-friendly string representation

Returns:

  • (String)


74
75
76
77
78
# File 'lib/rex/java/serialization/model/new_array.rb', line 74

def to_s
  str = "#{type}, "
  values_data = values.collect {|v| "#{v}"}
  str << "#{values_data}"
end