Class: Rex::Java::Serialization::Model::Annotation

Inherits:
Element
  • Object
show all
Includes:
Contents
Defined in:
lib/rex/java/serialization/model/annotation.rb

Overview

This class provides an annotation representation. It’s used for both class annotations (classAnnotation) and object annotations (objectAnnotation).

Constant Summary

Constants included from Rex::Java::Serialization

BASE_WIRE_HANDLE, OBJECT_TYPE_CODES, PRIMITIVE_TYPE_CODES, SC_BLOCK_DATA, SC_ENUM, SC_EXTERNALIZABLE, SC_SERIALIZABLE, SC_WRITE_METHOD, STREAM_MAGIC, STREAM_VERSION, TC_ARRAY, TC_BLOCKDATA, TC_BLOCKDATALONG, TC_CLASS, TC_CLASSDESC, TC_ENDBLOCKDATA, TC_ENUM, TC_EXCEPTION, TC_LONGSTRING, TC_NULL, TC_OBJECT, TC_PROXYCLASSDESC, TC_REFERENCE, TC_RESET, TC_STRING, TYPE_CODES

Instance Attribute Summary collapse

Attributes inherited from Element

#stream

Instance Method Summary collapse

Methods included from Contents

#decode_content, #encode_content, #print_class, #print_content

Methods inherited from Element

decode

Constructor Details

#initialize(stream = nil) ⇒ Annotation

Returns a new instance of Annotation.

Parameters:



18
19
20
21
# File 'lib/rex/java/serialization/model/annotation.rb', line 18

def initialize(stream = nil)
  super(stream)
  self.contents = []
end

Instance Attribute Details

#contentsArray

Returns The annotation contents.

Returns:

  • (Array)

    The annotation contents



15
16
17
# File 'lib/rex/java/serialization/model/annotation.rb', line 15

def contents
  @contents
end

Instance Method Details

#decode(io) ⇒ self

Deserializes a Rex::Java::Serialization::Model::Annotation

Parameters:

  • io (IO)

    the io to read from

Returns:

  • (self)

    if deserialization succeeds

Raises:



28
29
30
31
32
33
34
35
36
# File 'lib/rex/java/serialization/model/annotation.rb', line 28

def decode(io)
  loop do
    content = decode_content(io, stream)
    self.contents << content
    return self if content.kind_of?(EndBlockData)
  end

  self
end

#encodeString

Serializes the Rex::Java::Serialization::Model::Annotation

Returns:

  • (String)

    if serialization suceeds

Raises:



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rex/java/serialization/model/annotation.rb', line 42

def encode
  raise Rex::Java::Serialization::EncodeError, 'Failed to serialize Annotation with empty contents' if contents.empty?

  encoded = ''

  contents.each do |content|
    encoded << encode_content(content)
  end

  encoded
end

#to_sString

Creates a print-friendly string representation

Returns:

  • (String)


57
58
59
60
61
62
63
# File 'lib/rex/java/serialization/model/annotation.rb', line 57

def to_s
  str = '[ '
  contents_data = contents.collect {|content| "#{print_content(content)}"}
  str << contents_data.join(', ')
  str << ' ]'
  str
end