Class: Rex::Java::Serialization::Model::Field
- Includes:
- Contents
- Defined in:
- lib/rex/java/serialization/model/field.rb
Overview
This class provides a field description representation (fieldDesc). It’s used for both primitive descriptions (primitiveDesc) and object descriptions (objectDesc).
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
-
#field_type ⇒ Rex::Java::Serialization::Model::Utf
The type of the field on object types.
-
#name ⇒ Rex::Java::Serialization::Model::Utf
The name of the field.
-
#type ⇒ String
The type of the field.
Attributes inherited from Element
Instance Method Summary collapse
-
#decode(io) ⇒ self
Deserializes a Rex::Java::Serialization::Model::Field.
-
#encode ⇒ String
Serializes the Rex::Java::Serialization::Model::Field.
-
#initialize(stream = nil) ⇒ Field
constructor
A new instance of Field.
-
#is_object? ⇒ Boolean
Whether the field type is an object one.
-
#is_primitive? ⇒ Boolean
Whether the field type is a primitive one.
-
#is_type_valid? ⇒ Boolean
Whether the field type is valid.
-
#to_s ⇒ String
Creates a print-friendly string representation.
Methods included from Contents
#decode_content, #encode_content, #print_class, #print_content
Methods inherited from Element
Constructor Details
#initialize(stream = nil) ⇒ Field
Returns a new instance of Field.
24 25 26 27 28 29 |
# File 'lib/rex/java/serialization/model/field.rb', line 24 def initialize(stream = nil) super(stream) self.type = '' self.name = nil self.field_type = nil end |
Instance Attribute Details
#field_type ⇒ Rex::Java::Serialization::Model::Utf
Returns The type of the field on object types.
21 22 23 |
# File 'lib/rex/java/serialization/model/field.rb', line 21 def field_type @field_type end |
#name ⇒ Rex::Java::Serialization::Model::Utf
Returns The name of the field.
18 19 20 |
# File 'lib/rex/java/serialization/model/field.rb', line 18 def name @name end |
#type ⇒ String
Returns The type of the field.
15 16 17 |
# File 'lib/rex/java/serialization/model/field.rb', line 15 def type @type end |
Instance Method Details
#decode(io) ⇒ self
Deserializes a Rex::Java::Serialization::Model::Field
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rex/java/serialization/model/field.rb', line 36 def decode(io) code = io.read(1) unless code && is_valid?(code) raise Rex::Java::Serialization::DecodeError, 'Failed to unserialize Field' end self.type = TYPE_CODES[code] self.name = Utf.decode(io, stream) if is_object? self.field_type = decode_field_type(io) end self end |
#encode ⇒ String
Serializes the Rex::Java::Serialization::Model::Field
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/rex/java/serialization/model/field.rb', line 57 def encode unless name.kind_of?(Rex::Java::Serialization::Model::Utf) raise Rex::Java::Serialization::EncodeError, 'Failed to serialize Field' end unless is_type_valid? raise Rex::Java::Serialization::EncodeError, 'Failed to serialize Field' end encoded = '' encoded << TYPE_CODES.key(type) encoded << name.encode if is_object? encoded << encode_field_type end encoded end |
#is_object? ⇒ Boolean
Whether the field type is an object one.
102 103 104 105 106 107 108 |
# File 'lib/rex/java/serialization/model/field.rb', line 102 def is_object? if OBJECT_TYPE_CODES.values.include?(type) return true end false end |
#is_primitive? ⇒ Boolean
Whether the field type is a primitive one.
91 92 93 94 95 96 97 |
# File 'lib/rex/java/serialization/model/field.rb', line 91 def is_primitive? if PRIMITIVE_TYPE_CODES.values.include?(type) return true end false end |
#is_type_valid? ⇒ Boolean
Whether the field type is valid.
80 81 82 83 84 85 86 |
# File 'lib/rex/java/serialization/model/field.rb', line 80 def is_type_valid? if TYPE_CODES.values.include?(type) return true end false end |
#to_s ⇒ String
Creates a print-friendly string representation
113 114 115 116 117 118 119 120 121 122 |
# File 'lib/rex/java/serialization/model/field.rb', line 113 def to_s str = "#{name} " if is_primitive? str << "(#{type})" else str << "(#{field_type})" end str end |