Move types to the Serialization module

bug/bundler_fix
jvazquez-r7 2014-12-02 20:02:42 -06:00
parent 2c070c450b
commit 1f535a41ca
5 changed files with 37 additions and 31 deletions

View File

@ -27,6 +27,24 @@ module Rex
SC_SERIALIZABLE = 0x02 SC_SERIALIZABLE = 0x02
SC_EXTERNALIZABLE = 0x04 SC_EXTERNALIZABLE = 0x04
SC_ENUM = 0x10 SC_ENUM = 0x10
PRIMITIVE_TYPE_CODES = {
'B' => 'byte',
'C' => 'char',
'D' => 'double',
'F' => 'float',
'I' => 'int',
'J' => 'long',
'S' => 'short',
'Z' => 'boolean'
}
OBJECT_TYPE_CODES = {
'[' => 'array',
'L' => 'object'
}
TYPE_CODES = PRIMITIVE_TYPE_CODES.merge(OBJECT_TYPE_CODES)
end end
end end
end end

View File

@ -6,6 +6,8 @@ module Rex
# annotations (classAnnotation) and object annotations (objectAnnotation). # annotations (classAnnotation) and object annotations (objectAnnotation).
class Annotation < Element class Annotation < Element
include Rex::Java::Serialization
# @!attribute contents # @!attribute contents
# @return [Array] The annotation contents # @return [Array] The annotation contents
attr_accessor :contents attr_accessor :contents
@ -28,13 +30,13 @@ module Rex
opcode = opcode.unpack('C')[0] opcode = opcode.unpack('C')[0]
case opcode case opcode
when Rex::Java::Serialization::TC_BLOCKDATA when TC_BLOCKDATA
block = BlockData.decode(io) block = BlockData.decode(io)
self.contents << block self.contents << block
when Rex::Java::Serialization::TC_BLOCKDATALONG when TC_BLOCKDATALONG
block = BlockDataLong.decode(io) block = BlockDataLong.decode(io)
self.contents << block self.contents << block
when Rex::Java::Serialization::TC_ENDBLOCKDATA when TC_ENDBLOCKDATA
return self return self
else else
#TODO: unsupported #TODO: unsupported
@ -55,9 +57,9 @@ module Rex
contents.each do |content| contents.each do |content|
case content case content
when Rex::Java::Serialization::Model::BlockData when Rex::Java::Serialization::Model::BlockData
encoded << [Rex::Java::Serialization::TC_BLOCKDATA].pack('C') encoded << [TC_BLOCKDATA].pack('C')
when Rex::Java::Serialization::Model::BlockDataLong when Rex::Java::Serialization::Model::BlockDataLong
encoded << [Rex::Java::Serialization::TC_BLOCKDATALONG].pack('C') encoded << [TC_BLOCKDATALONG].pack('C')
else else
raise ::RuntimeError, 'Unsupported content' raise ::RuntimeError, 'Unsupported content'
end end
@ -65,7 +67,7 @@ module Rex
encoded << encoded_content encoded << encoded_content
end end
encoded << [Rex::Java::Serialization::TC_ENDBLOCKDATA].pack('C') encoded << [TC_ENDBLOCKDATA].pack('C')
encoded encoded
end end

View File

@ -5,6 +5,8 @@ module Rex
# This class provides a class description representation # This class provides a class description representation
class ClassDescription < Element class ClassDescription < Element
include Rex::Java::Serialization
# @!attribute class_name # @!attribute class_name
# @return [Java::Serialization::Model::Utf] The name of the class # @return [Java::Serialization::Model::Utf] The name of the class
attr_accessor :class_name attr_accessor :class_name
@ -73,10 +75,10 @@ module Rex
case super_class case super_class
when Rex::Java::Serialization::Model::ClassDescription when Rex::Java::Serialization::Model::ClassDescription
encoded << [Rex::Java::Serialization::TC_CLASSDESC].pack('C') encoded << [TC_CLASSDESC].pack('C')
encoded << super_class.encode encoded << super_class.encode
when nil when nil
encoded << [Rex::Java::Serialization::TC_NULL].pack('C') encoded << [TC_NULL].pack('C')
else else
#TODO: support other superclass types #TODO: support other superclass types
raise RuntimeError, 'Failed to serialize ClassDescription' raise RuntimeError, 'Failed to serialize ClassDescription'
@ -142,9 +144,9 @@ module Rex
class_desc = nil class_desc = nil
case super_opcode case super_opcode
when Rex::Java::Serialization::TC_NULL when TC_NULL
class_desc = nil class_desc = nil
when Rex::Java::Serialization::TC_CLASSDESC when TC_CLASSDESC
class_desc = ClassDescription.decode(io) class_desc = ClassDescription.decode(io)
else else
#TODO: Support TC_PROXYCLASSDESC #TODO: Support TC_PROXYCLASSDESC

View File

@ -6,23 +6,7 @@ module Rex
# both primitive descriptions (primitiveDesc) and object descriptions (objectDesc). # both primitive descriptions (primitiveDesc) and object descriptions (objectDesc).
class Field < Element class Field < Element
PRIMITIVE_TYPE_CODES = { include Rex::Java::Serialization
'B' => 'byte',
'C' => 'char',
'D' => 'double',
'F' => 'float',
'I' => 'integer',
'J' => 'long',
'S' => 'short',
'Z' => 'boolean',
}
OBJECT_TYPE_CODES = {
'[' => 'array',
'L' => 'object'
}
TYPE_CODES = PRIMITIVE_TYPE_CODES.merge(OBJECT_TYPE_CODES)
# @!attribute type # @!attribute type
# @return [String] The type of the field. # @return [String] The type of the field.
@ -133,7 +117,7 @@ module Rex
# #
# @return [String] # @return [String]
def encode_field_type def encode_field_type
encoded = [Java::Serialization::TC_STRING].pack('C') encoded = [TC_STRING].pack('C')
encoded << field_type.encode encoded << field_type.encode
encoded encoded
@ -146,7 +130,7 @@ module Rex
# @raise [RuntimeError] if unserialization isn't possible # @raise [RuntimeError] if unserialization isn't possible
def decode_field_type(io) def decode_field_type(io)
opcode = io.read(1) opcode = io.read(1)
unless opcode && opcode == [Java::Serialization::TC_STRING].pack('C') unless opcode && opcode == [TC_STRING].pack('C')
raise ::RuntimeError, 'Failed to unserialize Field' raise ::RuntimeError, 'Failed to unserialize Field'
end end
type = Utf.decode(io) type = Utf.decode(io)

View File

@ -36,7 +36,7 @@ describe Rex::Java::Serialization::Model::Field do
context "when primitive field" do context "when primitive field" do
it do it do
field.type = 'integer' field.type = 'int'
field.name = Rex::Java::Serialization::Model::Utf.new('number') field.name = Rex::Java::Serialization::Model::Utf.new('number')
expect(field.encode).to eq(sample_primitive) expect(field.encode).to eq(sample_primitive)
end end
@ -60,7 +60,7 @@ describe Rex::Java::Serialization::Model::Field do
it "decodes field type" do it "decodes field type" do
field.decode(sample_primitive_io) field.decode(sample_primitive_io)
expect(field.type).to eq('integer') expect(field.type).to eq('int')
end end
it "decodes field name as Utf" do it "decodes field name as Utf" do