Class: Rex::Proto::Rmi::Model::ReturnValue

Inherits:
Element
  • Object
show all
Defined in:
lib/rex/proto/rmi/model/return_value.rb

Overview

This class provides a representation of an RMI return value

Constant Summary

Constants included from Rex::Proto::Rmi::Model

CALL_MESSAGE, DGC_ACK_MESSAGE, MULTIPLEX_PROTOCOL, PING_ACK, PING_MESSAGE, PROTOCOL_ACK, PROTOCOL_NOT_SUPPORTED, RETURN_DATA, RETURN_EXCEPTION, RETURN_VALUE, SIGNATURE, SINGLE_OP_PROTOCOL, STREAM_PROTOCOL

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Element

attr_accessor, attributes, #attributes, decode, #initialize

Constructor Details

This class inherits a constructor from Rex::Proto::Rmi::Model::Element

Instance Attribute Details

#codeInteger

Returns the return code.

Returns:

  • (Integer)

    the return code


12
13
14
# File 'lib/rex/proto/rmi/model/return_value.rb', line 12

def code
  @code
end

#uidRex::Proto::Rmi::Model::UniqueIdentifier

Returns unique identifier of the returned value.

Returns:


15
16
17
# File 'lib/rex/proto/rmi/model/return_value.rb', line 15

def uid
  @uid
end

#valueArray

Returns the returned exception or value according to code.

Returns:

  • (Array)

    the returned exception or value according to code


18
19
20
# File 'lib/rex/proto/rmi/model/return_value.rb', line 18

def value
  @value
end

Instance Method Details

#decode(io) ⇒ Rex::Proto::Rmi::Model::ReturnValue

Decodes the Rex::Proto::Rmi::Model::ReturnValue from the input.

Parameters:

  • io (IO)

    the IO to read from

Returns:


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rex/proto/rmi/model/return_value.rb', line 39

def decode(io)
  stream = Rex::Java::Serialization::Model::Stream.decode(io)

  block_data = stream.contents[0]
  block_data_io = StringIO.new(block_data.contents, 'rb')

  self.code = decode_code(block_data_io)
  self.uid = decode_uid(block_data_io)
  self.value = []

  stream.contents[1..stream.contents.length - 1].each do |content|
    self.value << content
  end

  self
end

#encodeString

Encodes the Rex::Proto::Rmi::Model::ReturnValue into an String.

Returns:

  • (String)

23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rex/proto/rmi/model/return_value.rb', line 23

def encode
  stream = Rex::Java::Serialization::Model::Stream.new
  block_data = Rex::Java::Serialization::Model::BlockData.new(nil, encode_code + encode_uid)

  stream.contents << block_data
  value.each do |v|
    stream.contents << v
  end

  stream.encode
end

#get_class_nameString, NilClass

The object/exception class of the returned value

Returns:

  • (String, NilClass)

    the returned value class, nil it cannot be retrieved


66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/rex/proto/rmi/model/return_value.rb', line 66

def get_class_name
  unless value[0] && value[0].is_a?(Rex::Java::Serialization::Model::NewObject)
    return nil
  end

  case value[0].class_desc.description
  when Rex::Java::Serialization::Model::NewClassDesc
    return value[0].class_desc.description.class_name.contents
  when Rex::Java::Serialization::Model::ProxyClassDesc
    return value[0].class_desc.description.interfaces[0].contents
  else
    return nil
  end
end

#is_exception?Boolean

Answers if the ReturnValue is an exception

Returns:

  • (Boolean)

59
60
61
# File 'lib/rex/proto/rmi/model/return_value.rb', line 59

def is_exception?
  code == RETURN_EXCEPTION
end