Files
metasploit-gs/lib/rex/java/serialization/model/annotation.rb
T

70 lines
2.1 KiB
Ruby
Raw Normal View History

2014-12-10 09:52:23 -06:00
# -*- coding: binary -*-
2014-12-02 11:42:41 -06: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-04 18:28:25 -06:00
include Rex::Java::Serialization::Model::Contents
2014-12-02 20:02:42 -06:00
2014-12-02 11:42:41 -06:00
# @!attribute contents
# @return [Array] The annotation contents
attr_accessor :contents
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-02 11:42:41 -06:00
self.contents = []
end
2014-12-09 19:37:42 -06:00
# Deserializes a Rex::Java::Serialization::Model::Annotation
2014-12-02 11:42:41 -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-02 11:42:41 -06:00
def decode(io)
loop do
2014-12-05 17:14:37 -06:00
content = decode_content(io, stream)
2014-12-04 18:28:25 -06:00
self.contents << content
return self if content.kind_of?(EndBlockData)
2014-12-02 11:42:41 -06:00
end
self
end
2014-12-09 19:37:42 -06:00
# Serializes the Rex::Java::Serialization::Model::Annotation
2014-12-02 11:42:41 -06:00
#
2014-12-03 14:59:38 -06:00
# @return [String] if serialization suceeds
2015-04-05 18:43:03 -05:00
# @raise [Rex::Java::Serialization::EncodeError] if serialization doesn't succeed
2014-12-02 11:42:41 -06:00
def encode
2015-04-05 18:43:03 -05:00
raise Rex::Java::Serialization::EncodeError, 'Failed to serialize Annotation with empty contents' if contents.empty?
2014-12-04 18:28:25 -06:00
2014-12-02 11:42:41 -06:00
encoded = ''
contents.each do |content|
2014-12-04 18:28:25 -06:00
encoded << encode_content(content)
2014-12-02 11:42:41 -06:00
end
encoded
end
2014-12-07 17:52:09 -06:00
# Creates a print-friendly string representation
#
# @return [String]
def to_s
str = '[ '
contents_data = contents.collect {|content| "#{print_content(content)}"}
str << contents_data.join(', ')
str << ' ]'
str
end
2014-12-02 11:42:41 -06:00
end
end
end
end
end