Land #6026, Add support for NewClass elements on Rex::Java::Serialization

bug/bundler_fix
wchen-r7 2015-10-08 12:33:12 -05:00
commit 352535e15d
No known key found for this signature in database
GPG Key ID: 2384DB4EF06F730B
4 changed files with 65 additions and 2 deletions

View File

@ -19,6 +19,7 @@ module Rex
autoload :NewClassDesc, 'rex/java/serialization/model/new_class_desc' autoload :NewClassDesc, 'rex/java/serialization/model/new_class_desc'
autoload :NewEnum, 'rex/java/serialization/model/new_enum' autoload :NewEnum, 'rex/java/serialization/model/new_enum'
autoload :NewObject, 'rex/java/serialization/model/new_object' autoload :NewObject, 'rex/java/serialization/model/new_object'
autoload :NewClass, 'rex/java/serialization/model/new_class'
autoload :NullReference, 'rex/java/serialization/model/null_reference' autoload :NullReference, 'rex/java/serialization/model/null_reference'
autoload :Reference, 'rex/java/serialization/model/reference' autoload :Reference, 'rex/java/serialization/model/reference'
autoload :Reset, 'rex/java/serialization/model/reset' autoload :Reset, 'rex/java/serialization/model/reset'

View File

@ -28,7 +28,7 @@ module Rex
when TC_OBJECT when TC_OBJECT
content = NewObject.decode(io, stream) content = NewObject.decode(io, stream)
when TC_CLASS when TC_CLASS
content = ClassDesc.decode(io, stream) content = NewClass.decode(io, stream)
when TC_ARRAY when TC_ARRAY
content = NewArray.decode(io, stream) content = NewArray.decode(io, stream)
when TC_STRING when TC_STRING
@ -75,7 +75,7 @@ module Rex
encoded << [TC_ENDBLOCKDATA].pack('C') encoded << [TC_ENDBLOCKDATA].pack('C')
when NewObject when NewObject
encoded << [TC_OBJECT].pack('C') encoded << [TC_OBJECT].pack('C')
when ClassDesc when NewClass
encoded << [TC_CLASS].pack('C') encoded << [TC_CLASS].pack('C')
when NewArray when NewArray
encoded << [TC_ARRAY].pack('C') encoded << [TC_ARRAY].pack('C')
@ -122,6 +122,8 @@ module Rex
str << "#{print_class(content)} { #{content.to_s} }" str << "#{print_class(content)} { #{content.to_s} }"
when ClassDesc when ClassDesc
str << "#{print_class(content)} { #{content.to_s} }" str << "#{print_class(content)} { #{content.to_s} }"
when NewClass
str << "#{print_class(content)} { #{content.to_s} }"
when NewArray when NewArray
str << "#{print_class(content)} { #{content.to_s} }" str << "#{print_class(content)} { #{content.to_s} }"
when Utf when Utf

View File

@ -0,0 +1,57 @@
# -*- coding: binary -*-
module Rex
module Java
module Serialization
module Model
# This class provides a NewArray (Java Array) representation
class NewClass < Element
include Rex::Java::Serialization::Model::Contents
# @!attribute array_description
# @return [Java::Serialization::Model::ClassDesc] The description of the class
attr_accessor :class_description
# @param stream [Rex::Java::Serialization::Model::Stream] the stream where it belongs to
def initialize(stream = nil)
super(stream)
self.class_description = nil
end
# Deserializes a Rex::Java::Serialization::Model::NewClass
#
# @param io [IO] the io to read from
# @return [self] if deserialization succeeds
# @raise [Rex::Java::Serialization::DecodeError] if deserialization doesn't succeed
def decode(io)
self.class_description = ClassDesc.decode(io, stream)
stream.add_reference(self) unless stream.nil?
self
end
# Serializes the Rex::Java::Serialization::Model::NewClass
#
# @return [String] if serialization succeeds
# @raise [Rex::Java::Serialization::EncodeError] if serialization doesn't succeed
def encode
unless class_description.kind_of?(ClassDesc)
raise Rex::Java::Serialization::EncodeError, 'Failed to serialize NewClass'
end
encoded = ''
encoded << class_description.encode
end
# Creates a print-friendly string representation
#
# @return [String]
def to_s
print_content(class_description)
end
end
end
end
end
end

View File

@ -71,6 +71,7 @@ module Rex
# @return [String] # @return [String]
def to_s def to_s
str = '' str = ''
case class_desc.description case class_desc.description
when NewClassDesc when NewClassDesc
str << class_desc.description.class_name.to_s str << class_desc.description.class_name.to_s
@ -84,6 +85,8 @@ module Rex
data_str = class_data.collect { |data| data.to_s } data_str = class_data.collect { |data| data.to_s }
str << data_str.join(', ') str << data_str.join(', ')
str << ' }' str << ' }'
str
end end
private private