Class: Rex::Java::Serialization::Model::Stream
- 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
-
#contents ⇒ Array
The stream contents.
-
#magic ⇒ Fixnum
The stream signature.
-
#references ⇒ Array
The stream objects to be referenced through handles.
-
#version ⇒ Fixnum
The stream version.
Attributes inherited from Element
Instance Method Summary collapse
-
#add_reference(ref) ⇒ Object
Adds an element to the references array.
-
#decode(io) ⇒ self
Deserializes a Rex::Java::Serialization::Model::Stream.
-
#encode ⇒ String
Serializes the Rex::Java::Serialization::Model::Stream.
-
#initialize(stream = nil) ⇒ Stream
constructor
A new instance of Stream.
-
#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) ⇒ 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
#contents ⇒ Array
Returns The stream contents.
20 21 22 |
# File 'lib/rex/java/serialization/model/stream.rb', line 20 def contents @contents end |
#magic ⇒ Fixnum
Returns The stream signature.
14 15 16 |
# File 'lib/rex/java/serialization/model/stream.rb', line 14 def magic @magic end |
#references ⇒ Array
Returns 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 |
#version ⇒ Fixnum
Returns 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
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
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 |
#encode ⇒ String
Serializes the Rex::Java::Serialization::Model::Stream
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_s ⇒ String
Creates a print-friendly string representation
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 |