metasploit-framework/lib/rex/java/serialization/model/annotation.rb

55 lines
1.6 KiB
Ruby
Raw Normal View History

2014-12-02 17:42:41 +00:00
module Rex
module Java
module Serialization
module Model
# This class provides an annotation representation. It's used for both class
# annotations (classAnnotation) and object annotations (objectAnnotation).
class Annotation < Element
2014-12-05 00:28:25 +00:00
include Rex::Java::Serialization::Model::Contents
2014-12-03 02:02:42 +00:00
2014-12-02 17:42:41 +00:00
# @!attribute contents
# @return [Array] The annotation contents
attr_accessor :contents
2014-12-05 22:52:59 +00:00
def initialize(stream = nil)
super(stream)
2014-12-02 17:42:41 +00:00
self.contents = []
end
2014-12-03 20:59:38 +00:00
# Deserializes a Java::Serialization::Model::Annotation
2014-12-02 17:42:41 +00:00
#
# @param io [IO] the io to read from
2014-12-03 20:59:38 +00:00
# @return [self] if deserialization succeeds
# @raise [RuntimeError] if deserialization doesn't succeed
2014-12-02 17:42:41 +00:00
def decode(io)
loop do
2014-12-05 00:28:25 +00:00
content = decode_content(io)
self.contents << content
return self if content.class == Rex::Java::Serialization::Model::EndBlockData
2014-12-02 17:42:41 +00:00
end
self
end
# Serializes the Java::Serialization::Model::Annotation
#
2014-12-03 20:59:38 +00:00
# @return [String] if serialization suceeds
# @raise [RuntimeError] if serialization doesn't succeed
2014-12-02 17:42:41 +00:00
def encode
2014-12-05 00:28:25 +00:00
raise ::RuntimeError, 'Failed to serialize Annotation with empty contents' if contents.empty?
2014-12-02 17:42:41 +00:00
encoded = ''
contents.each do |content|
2014-12-05 00:28:25 +00:00
encoded << encode_content(content)
2014-12-02 17:42:41 +00:00
end
encoded
end
end
end
end
end
end