|
| 1 | +# -*- coding: binary -*- |
| 2 | + |
| 3 | +module Rex |
| 4 | + module Java |
| 5 | + module Serialization |
| 6 | + module Model |
| 7 | + # This class provides a NewArray (Java Array) representation |
| 8 | + class NewClass < Element |
| 9 | + |
| 10 | + include Rex::Java::Serialization::Model::Contents |
| 11 | + |
| 12 | + # @!attribute array_description |
| 13 | + # @return [Java::Serialization::Model::ClassDesc] The description of the class |
| 14 | + attr_accessor :class_description |
| 15 | + |
| 16 | + # @param stream [Rex::Java::Serialization::Model::Stream] the stream where it belongs to |
| 17 | + def initialize(stream = nil) |
| 18 | + super(stream) |
| 19 | + self.class_description = nil |
| 20 | + end |
| 21 | + |
| 22 | + # Deserializes a Rex::Java::Serialization::Model::NewClass |
| 23 | + # |
| 24 | + # @param io [IO] the io to read from |
| 25 | + # @return [self] if deserialization succeeds |
| 26 | + # @raise [Rex::Java::Serialization::DecodeError] if deserialization doesn't succeed |
| 27 | + def decode(io) |
| 28 | + self.class_description = ClassDesc.decode(io, stream) |
| 29 | + stream.add_reference(self) unless stream.nil? |
| 30 | + |
| 31 | + self |
| 32 | + end |
| 33 | + |
| 34 | + # Serializes the Rex::Java::Serialization::Model::NewClass |
| 35 | + # |
| 36 | + # @return [String] if serialization succeeds |
| 37 | + # @raise [Rex::Java::Serialization::EncodeError] if serialization doesn't succeed |
| 38 | + def encode |
| 39 | + unless class_description.kind_of?(ClassDesc) |
| 40 | + raise Rex::Java::Serialization::EncodeError, 'Failed to serialize NewClass' |
| 41 | + end |
| 42 | + |
| 43 | + encoded = '' |
| 44 | + encoded << class_description.encode |
| 45 | + end |
| 46 | + |
| 47 | + # Creates a print-friendly string representation |
| 48 | + # |
| 49 | + # @return [String] |
| 50 | + def to_s |
| 51 | + print_content(class_description) |
| 52 | + end |
| 53 | + end |
| 54 | + end |
| 55 | + end |
| 56 | + end |
| 57 | +end |
0 commit comments