2014-12-10 09:52:23 -06:00
|
|
|
# -*- coding: binary -*-
|
|
|
|
|
|
2014-12-01 19:50:33 -06:00
|
|
|
module Rex
|
|
|
|
|
module Java
|
|
|
|
|
module Serialization
|
|
|
|
|
module Model
|
|
|
|
|
# This class provides a Long Utf string representation
|
|
|
|
|
class LongUtf < Utf
|
2014-12-03 14:59:38 -06:00
|
|
|
|
2014-12-09 19:37:42 -06:00
|
|
|
# Deserializes a Rex::Java::Serialization::Model::LongUtf
|
2014-12-01 19:50:33 -06:00
|
|
|
#
|
|
|
|
|
# @param io [IO] the io to read from
|
2014-12-03 14:59:38 -06:00
|
|
|
# @return [self] if deserialization succeeds
|
2015-04-05 18:43:03 -05:00
|
|
|
# @raise [Rex::Java::Serialization::DecodeError] if deserialization doesn't succeed
|
2014-12-01 19:50:33 -06:00
|
|
|
def decode(io)
|
|
|
|
|
raw_length = io.read(8)
|
2014-12-02 15:31:31 -06:00
|
|
|
if raw_length.nil? || raw_length.length != 8
|
2015-04-05 18:43:03 -05:00
|
|
|
raise Rex::Java::Serialization::DecodeError, 'Failed to unserialize LongUtf'
|
2014-12-02 15:31:31 -06:00
|
|
|
end
|
2014-12-01 19:50:33 -06:00
|
|
|
self.length = raw_length.unpack('Q>')[0]
|
|
|
|
|
|
|
|
|
|
if length == 0
|
|
|
|
|
self.contents = ''
|
|
|
|
|
else
|
|
|
|
|
self.contents = io.read(length)
|
2014-12-02 15:31:31 -06:00
|
|
|
if contents.nil? || contents.length != length
|
2015-04-05 18:43:03 -05:00
|
|
|
raise Rex::Java::Serialization::DecodeError, 'Failed to unserialize LongUtf'
|
2014-12-02 15:31:31 -06:00
|
|
|
end
|
2014-12-01 19:50:33 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
self
|
|
|
|
|
end
|
|
|
|
|
|
2014-12-09 19:37:42 -06:00
|
|
|
# Serializes the Rex::Java::Serialization::Model::LongUtf
|
2014-12-01 19:50:33 -06:00
|
|
|
#
|
2014-12-02 15:31:31 -06:00
|
|
|
# @return [String]
|
2014-12-01 19:50:33 -06:00
|
|
|
def encode
|
|
|
|
|
encoded = [length].pack('Q>')
|
|
|
|
|
encoded << contents
|
|
|
|
|
|
|
|
|
|
encoded
|
|
|
|
|
end
|
2014-12-07 17:52:09 -06:00
|
|
|
|
2014-12-01 19:50:33 -06:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|