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