Class: Rex::Java::Serialization::Model::BlockDataLong
- Defined in:
- lib/rex/java/serialization/model/block_data_long.rb
Overview
This class provides a block data (long) representation
Instance Attribute Summary collapse
-
#contents ⇒ String
The contents of the block.
-
#length ⇒ Integer
The length of the block.
Attributes inherited from Element
Instance Method Summary collapse
-
#decode(io) ⇒ self
Deserializes a Rex::Java::Serialization::Model::BlockDataLong.
-
#encode ⇒ String
Serializes the Rex::Java::Serialization::Model::BlockDataLong.
-
#initialize(stream = nil, contents = '') ⇒ BlockDataLong
constructor
A new instance of BlockDataLong.
-
#to_s ⇒ String
Creates a print-friendly string representation.
Methods inherited from Element
Constructor Details
#initialize(stream = nil, contents = '') ⇒ BlockDataLong
Returns a new instance of BlockDataLong.
19 20 21 22 23 |
# File 'lib/rex/java/serialization/model/block_data_long.rb', line 19 def initialize(stream = nil, contents = '') super(stream) self.contents = contents self.length = contents.length end |
Instance Attribute Details
#contents ⇒ String
Returns the contents of the block.
15 16 17 |
# File 'lib/rex/java/serialization/model/block_data_long.rb', line 15 def contents @contents end |
#length ⇒ Integer
Returns the length of the block.
12 13 14 |
# File 'lib/rex/java/serialization/model/block_data_long.rb', line 12 def length @length end |
Instance Method Details
#decode(io) ⇒ self
Deserializes a Rex::Java::Serialization::Model::BlockDataLong
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rex/java/serialization/model/block_data_long.rb', line 30 def decode(io) raw_length = io.read(4) if raw_length.nil? || raw_length.length != 4 raise ::RuntimeError, 'Failed to unserialize BlockDataLong' end self.length = raw_length.unpack('N')[0] if length == 0 self.contents = '' else self.contents = io.read(length) if contents.nil? || contents.length != length raise ::RuntimeError, 'Failed to unserialize BlockData' end end self end |
#encode ⇒ String
Serializes the Rex::Java::Serialization::Model::BlockDataLong
52 53 54 55 56 57 |
# File 'lib/rex/java/serialization/model/block_data_long.rb', line 52 def encode encoded = [length].pack('N') encoded << contents encoded end |
#to_s ⇒ String
Creates a print-friendly string representation
62 63 64 65 66 67 |
# File 'lib/rex/java/serialization/model/block_data_long.rb', line 62 def to_s contents_hex = [] contents.each_byte {|byte| contents_hex << "0x#{byte.to_s(16)}" } "[ #{contents_hex.join(', ')} ]" end |