lib/rex/java/serialization/model/contents.rb in rex-2.0.8 vs lib/rex/java/serialization/model/contents.rb in rex-2.0.9

- old
+ new

@@ -9,14 +9,14 @@ # Deserializes a content # # @param io [IO] the io to read from # @return [Rex::Java::Serialization::Model::Element] if deserialization succeeds - # @raise [RuntimeError] if deserialization doesn't succeed or unsupported content + # @raise [Rex::Java::Serialization::DecodeError] if deserialization doesn't succeed or unsupported content def decode_content(io, stream) opcode = io.read(1) - raise ::RuntimeError, 'Failed to unserialize content' if opcode.nil? + raise Rex::Java::Serialization::DecodeError, 'Failed to unserialize content' if opcode.nil? opcode = opcode.unpack('C')[0] content = nil case opcode when TC_BLOCKDATA @@ -26,11 +26,11 @@ when TC_ENDBLOCKDATA content = EndBlockData.decode(io, stream) when TC_OBJECT content = NewObject.decode(io, stream) when TC_CLASS - content = ClassDesc.decode(io, stream) + content = NewClass.decode(io, stream) when TC_ARRAY content = NewArray.decode(io, stream) when TC_STRING content = Utf.decode(io, stream) stream.add_reference(content) unless stream.nil? @@ -40,31 +40,31 @@ when TC_ENUM content = NewEnum.decode(io, stream) when TC_CLASSDESC content = NewClassDesc.decode(io, stream) when TC_PROXYCLASSDESC - raise ::RuntimeError, 'Failed to unserialize unsupported TC_PROXYCLASSDESC content' + content = ProxyClassDesc.decode(io, stream) when TC_REFERENCE content = Reference.decode(io, stream) when TC_NULL content = NullReference.decode(io, stream) when TC_EXCEPTION - raise ::RuntimeError, 'Failed to unserialize unsupported TC_EXCEPTION content' + raise Rex::Java::Serialization::DecodeError, 'Failed to unserialize unsupported TC_EXCEPTION content' when TC_RESET content = Reset.decode(io, stream) else - raise ::RuntimeError, 'Failed to unserialize content' + raise Rex::Java::Serialization::DecodeError, 'Failed to unserialize content' end content end # Serializes a content # # @param content [Rex::Java::Serialization::Model::Element] the content to serialize # @return [String] if serialization succeeds - # @raise [RuntimeError] if serialization doesn't succeed + # @raise [Rex::Java::Serialization::EncodeError] if serialization doesn't succeed def encode_content(content) encoded = '' case content when BlockData @@ -73,11 +73,11 @@ encoded << [TC_BLOCKDATALONG].pack('C') when EndBlockData encoded << [TC_ENDBLOCKDATA].pack('C') when NewObject encoded << [TC_OBJECT].pack('C') - when ClassDesc + when NewClass encoded << [TC_CLASS].pack('C') when NewArray encoded << [TC_ARRAY].pack('C') when Utf encoded << [TC_STRING].pack('C') @@ -85,28 +85,31 @@ encoded << [TC_LONGSTRING].pack('C') when NewEnum encoded << [TC_ENUM].pack('C') when NewClassDesc encoded << [TC_CLASSDESC].pack('C') + when ProxyClassDesc + content = [TC_PROXYCLASSDESC].pack('C') when NullReference encoded << [TC_NULL].pack('C') when Reset encoded << [TC_RESET].pack('C') when Reference encoded << [TC_REFERENCE].pack('C') else - raise ::RuntimeError, 'Failed to serialize content' + raise Rex::Java::Serialization::EncodeError, 'Failed to serialize content' end encoded << content.encode encoded end # Creates a print-friendly string representation # # @param content [Rex::Java::Serialization::Model::Element] the content to print # @return [String] + # @raise [Rex::Java::Serialization::EncodeError] if the content is unknown def print_content(content) str = '' case content when BlockData @@ -117,27 +120,31 @@ str << "#{print_class(content)}" when NewObject str << "#{print_class(content)} { #{content.to_s} }" when ClassDesc str << "#{print_class(content)} { #{content.to_s} }" + when NewClass + str << "#{print_class(content)} { #{content.to_s} }" when NewArray str << "#{print_class(content)} { #{content.to_s} }" when Utf str << "#{print_class(content)} { #{content.to_s} }" when LongUtf str << "#{print_class(content)} { #{content.to_s} } " when NewEnum str << "#{print_class(content)} { #{content.to_s} }" when NewClassDesc str << "#{print_class(content)} { #{content.to_s} }" + when ProxyClassDesc + str << "#{print_class(content)} { #{content.to_s} }" when NullReference str << "#{print_class(content)}" when Reset str << "#{print_class(content)}" when Reference str << "#{print_class(content)} { #{content.to_s} }" else - raise ::RuntimeError, 'Failed to serialize content' + raise Rex::Java::Serialization::EncodeError, 'Failed to serialize content' end str end \ No newline at end of file