2014-12-10 09:52:23 -06:00
|
|
|
# -*- coding: binary -*-
|
|
|
|
|
|
2014-12-03 00:38:27 -06:00
|
|
|
module Rex
|
|
|
|
|
module Java
|
|
|
|
|
module Serialization
|
|
|
|
|
module Model
|
|
|
|
|
# This class provides a Java classDesc representation
|
|
|
|
|
class ClassDesc < Element
|
|
|
|
|
|
2014-12-05 16:05:35 -06:00
|
|
|
include Rex::Java::Serialization::Model::Contents
|
2014-12-03 00:38:27 -06:00
|
|
|
|
|
|
|
|
attr_accessor :description
|
|
|
|
|
|
2014-12-05 20:11:45 -06:00
|
|
|
# @param stream [Rex::Java::Serialization::Model::Stream] the stream where it belongs to
|
2014-12-05 16:52:59 -06:00
|
|
|
def initialize(stream = nil)
|
|
|
|
|
super(stream)
|
2014-12-03 00:38:27 -06:00
|
|
|
self.description = nil
|
|
|
|
|
end
|
|
|
|
|
|
2014-12-09 19:37:42 -06:00
|
|
|
# Deserializes a Rex::Java::Serialization::Model::ClassDesc
|
2014-12-03 00:38:27 -06:00
|
|
|
#
|
|
|
|
|
# @param io [IO] the io to read from
|
|
|
|
|
# @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-03 00:38:27 -06:00
|
|
|
def decode(io)
|
2014-12-05 17:14:37 -06:00
|
|
|
content = decode_content(io, stream)
|
2015-03-19 15:41:24 -05:00
|
|
|
allowed_contents = [NullReference, NewClassDesc, Reference, ProxyClassDesc]
|
2014-12-03 00:38:27 -06:00
|
|
|
|
2014-12-05 16:05:35 -06:00
|
|
|
unless allowed_contents.include?(content.class)
|
2015-04-05 18:43:03 -05:00
|
|
|
raise Rex::Java::Serialization::DecodeError, 'ClassDesc unserialize failed'
|
2014-12-03 00:38:27 -06:00
|
|
|
end
|
|
|
|
|
|
2014-12-05 16:05:35 -06:00
|
|
|
self.description = content
|
2014-12-03 00:38:27 -06:00
|
|
|
self
|
|
|
|
|
end
|
|
|
|
|
|
2014-12-09 19:37:42 -06:00
|
|
|
# Serializes the Rex::Java::Serialization::Model::ClassDesc
|
2014-12-03 00:38:27 -06:00
|
|
|
#
|
|
|
|
|
# @return [String] if serialization succeeds
|
2015-04-05 18:43:03 -05:00
|
|
|
# @raise [Rex::Java::Serialization::EncodeError] if serialization doesn't succeed
|
2014-12-03 00:38:27 -06:00
|
|
|
def encode
|
|
|
|
|
encoded = ''
|
2015-03-19 15:41:24 -05:00
|
|
|
allowed_contents = [NullReference, NewClassDesc, Reference, ProxyClassDesc]
|
2014-12-03 00:38:27 -06:00
|
|
|
|
2014-12-05 16:05:35 -06:00
|
|
|
unless allowed_contents.include?(description.class)
|
2015-04-05 18:43:03 -05:00
|
|
|
raise Rex::Java::Serialization::EncodeError, 'Failed to serialize ClassDesc'
|
2014-12-03 00:38:27 -06:00
|
|
|
end
|
|
|
|
|
|
2014-12-05 16:05:35 -06:00
|
|
|
encoded << encode_content(description)
|
|
|
|
|
|
2014-12-03 00:38:27 -06:00
|
|
|
encoded
|
|
|
|
|
end
|
2014-12-07 17:52:09 -06:00
|
|
|
|
|
|
|
|
# Creates a print-friendly string representation
|
|
|
|
|
#
|
|
|
|
|
# @return [String]
|
|
|
|
|
def to_s
|
|
|
|
|
print_content(description)
|
|
|
|
|
end
|
2014-12-03 00:38:27 -06:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|