Class: Rex::Java::Serialization::Model::NewObject
- 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
-
#class_data ⇒ Array
The data of the object.
-
#class_desc ⇒ Rex::Java::Serialization::Model::ClassDesc
The description of the object.
Attributes inherited from Element
Instance Method Summary collapse
-
#decode(io) ⇒ self
Deserializes a Rex::Java::Serialization::Model::NewObject.
-
#encode ⇒ String
Serializes the Rex::Java::Serialization::Model::NewObject.
-
#initialize(stream = nil) ⇒ NewObject
constructor
A new instance of NewObject.
-
#to_s ⇒ String
Creates a print-friendly string representation.
Methods included from Contents
#decode_content, #encode_content, #print_class, #print_content
Methods inherited from Element
Constructor Details
#initialize(stream = nil) ⇒ NewObject
Returns a new instance of NewObject.
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_data ⇒ Array
Returns 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_desc ⇒ Rex::Java::Serialization::Model::ClassDesc
Returns The description of the object.
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
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 |
#encode ⇒ String
Serializes the Rex::Java::Serialization::Model::NewObject
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_s ⇒ String
Creates a print-friendly string representation
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 |