rex 2.0.4 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rex/arch/x86.rb +16 -0
- data/lib/rex/constants.rb +1 -0
- data/lib/rex/constants/windows.rb +147 -0
- data/lib/rex/encoder/xdr.rb +3 -2
- data/lib/rex/exceptions.rb +37 -5
- data/lib/rex/exploitation/cmdstager/bourne.rb +9 -1
- data/lib/rex/exploitation/cmdstager/tftp.rb +5 -5
- data/lib/rex/java.rb +3 -0
- data/lib/rex/java/serialization.rb +54 -0
- data/lib/rex/java/serialization/model.rb +20 -0
- data/lib/rex/java/serialization/model/annotation.rb +69 -0
- data/lib/rex/java/serialization/model/block_data.rb +70 -0
- data/lib/rex/java/serialization/model/block_data_long.rb +72 -0
- data/lib/rex/java/serialization/model/class_desc.rb +64 -0
- data/lib/rex/java/serialization/model/contents.rb +156 -0
- data/lib/rex/java/serialization/model/element.rb +44 -0
- data/lib/rex/java/serialization/model/end_block_data.rb +12 -0
- data/lib/rex/java/serialization/model/field.rb +172 -0
- data/lib/rex/java/serialization/model/long_utf.rb +48 -0
- data/lib/rex/java/serialization/model/new_array.rb +225 -0
- data/lib/rex/java/serialization/model/new_class_desc.rb +155 -0
- data/lib/rex/java/serialization/model/new_enum.rb +79 -0
- data/lib/rex/java/serialization/model/new_object.rb +223 -0
- data/lib/rex/java/serialization/model/null_reference.rb +12 -0
- data/lib/rex/java/serialization/model/reference.rb +61 -0
- data/lib/rex/java/serialization/model/reset.rb +12 -0
- data/lib/rex/java/serialization/model/stream.rb +123 -0
- data/lib/rex/java/serialization/model/utf.rb +69 -0
- data/lib/rex/mime/message.rb +9 -14
- data/lib/rex/payloads.rb +1 -0
- data/lib/rex/payloads/meterpreter.rb +2 -0
- data/lib/rex/payloads/meterpreter/patch.rb +136 -0
- data/lib/rex/payloads/win32/kernel/stager.rb +26 -25
- data/lib/rex/post/meterpreter/client.rb +50 -60
- data/lib/rex/post/meterpreter/client_core.rb +18 -25
- data/lib/rex/post/meterpreter/extensions/extapi/adsi/adsi.rb +102 -8
- data/lib/rex/post/meterpreter/extensions/extapi/tlv.rb +24 -14
- data/lib/rex/post/meterpreter/extensions/stdapi/sys/config.rb +18 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/tlv.rb +1 -0
- data/lib/rex/post/meterpreter/packet_dispatcher.rb +1 -1
- data/lib/rex/post/meterpreter/ui/console.rb +1 -1
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/adsi.rb +43 -1
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/incognito.rb +1 -1
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/sys.rb +9 -0
- data/lib/rex/proto/dcerpc/svcctl.rb +2 -0
- data/lib/rex/proto/dcerpc/svcctl/packet.rb +304 -0
- data/lib/rex/proto/kademlia.rb +8 -0
- data/lib/rex/proto/kademlia/bootstrap_request.rb +19 -0
- data/lib/rex/proto/kademlia/bootstrap_response.rb +79 -0
- data/lib/rex/proto/kademlia/message.rb +72 -0
- data/lib/rex/proto/kademlia/ping.rb +19 -0
- data/lib/rex/proto/kademlia/pong.rb +41 -0
- data/lib/rex/proto/kademlia/util.rb +22 -0
- data/lib/rex/proto/natpmp/packet.rb +30 -2
- data/lib/rex/proto/quake.rb +3 -0
- data/lib/rex/proto/quake/message.rb +73 -0
- data/lib/rex/proto/smb/client.rb +1 -0
- data/lib/rex/proto/smb/simpleclient.rb +4 -0
- data/lib/rex/proto/sunrpc/client.rb +14 -3
- data/lib/rex/socket/comm/local.rb +10 -7
- data/lib/rex/socket/ssl_tcp_server.rb +79 -40
- data/lib/rex/ui/text/input/readline.rb +33 -6
- data/lib/rex/ui/text/output/file.rb +2 -2
- data/lib/rex/ui/text/output/stdio.rb +70 -14
- data/rex.gemspec +1 -1
- metadata +38 -3
@@ -0,0 +1,70 @@
|
|
1
|
+
# -*- coding: binary -*-
|
2
|
+
|
3
|
+
module Rex
|
4
|
+
module Java
|
5
|
+
module Serialization
|
6
|
+
module Model
|
7
|
+
# This class provides a block data representation
|
8
|
+
class BlockData < Element
|
9
|
+
|
10
|
+
# @!attribute length
|
11
|
+
# @return [Integer] the length of the block
|
12
|
+
attr_accessor :length
|
13
|
+
# @!attribute contents
|
14
|
+
# @return [String] the contents of the block
|
15
|
+
attr_accessor :contents
|
16
|
+
|
17
|
+
# @param stream [Rex::Java::Serialization::Model::Stream] the stream where it belongs to
|
18
|
+
# @param contents [String] the contents of the block
|
19
|
+
def initialize(stream = nil, contents = '')
|
20
|
+
super(stream)
|
21
|
+
self.contents = contents
|
22
|
+
self.length = contents.length
|
23
|
+
end
|
24
|
+
|
25
|
+
# Deserializes a Rex::Java::Serialization::Model::BlockData
|
26
|
+
#
|
27
|
+
# @param io [IO] the io to read from
|
28
|
+
# @return [self] if deserialization succeeds
|
29
|
+
# @raise [RuntimeError] if deserialization doesn't succeed
|
30
|
+
def decode(io)
|
31
|
+
raw_length = io.read(1)
|
32
|
+
raise RuntimeError, 'Failed to unserialize BlockData' if raw_length.nil?
|
33
|
+
self.length = raw_length.unpack('C')[0]
|
34
|
+
|
35
|
+
if length == 0
|
36
|
+
self.contents = ''
|
37
|
+
else
|
38
|
+
self.contents = io.read(length)
|
39
|
+
if contents.nil? || contents.length != length
|
40
|
+
raise RuntimeError, 'Failed to unserialize BlockData'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
self
|
45
|
+
end
|
46
|
+
|
47
|
+
# Creates a print-friendly string representation
|
48
|
+
#
|
49
|
+
# @return [String]
|
50
|
+
def to_s
|
51
|
+
contents_hex = []
|
52
|
+
contents.each_byte {|byte| contents_hex << "0x#{byte.to_s(16)}" }
|
53
|
+
|
54
|
+
"[ #{contents_hex.join(', ')} ]"
|
55
|
+
end
|
56
|
+
|
57
|
+
# Serializes the Rex::Java::Serialization::Model::BlockData
|
58
|
+
#
|
59
|
+
# @return [String]
|
60
|
+
def encode
|
61
|
+
encoded = [length].pack('C')
|
62
|
+
encoded << contents
|
63
|
+
|
64
|
+
encoded
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# -*- coding: binary -*-
|
2
|
+
|
3
|
+
module Rex
|
4
|
+
module Java
|
5
|
+
module Serialization
|
6
|
+
module Model
|
7
|
+
# This class provides a block data (long) representation
|
8
|
+
class BlockDataLong < Element
|
9
|
+
|
10
|
+
# @!attribute length
|
11
|
+
# @return [Integer] the length of the block
|
12
|
+
attr_accessor :length
|
13
|
+
# @!attribute contents
|
14
|
+
# @return [String] the contents of the block
|
15
|
+
attr_accessor :contents
|
16
|
+
|
17
|
+
# @param stream [Rex::Java::Serialization::Model::Stream] the stream where it belongs to
|
18
|
+
# @param contents [String] the contents of the block
|
19
|
+
def initialize(stream = nil, contents = '')
|
20
|
+
super(stream)
|
21
|
+
self.contents = contents
|
22
|
+
self.length = contents.length
|
23
|
+
end
|
24
|
+
|
25
|
+
# Deserializes a Rex::Java::Serialization::Model::BlockDataLong
|
26
|
+
#
|
27
|
+
# @param io [IO] the io to read from
|
28
|
+
# @return [self] if deserialization succeeds
|
29
|
+
# @raise [RuntimeError] if deserialization doesn't succeed
|
30
|
+
def decode(io)
|
31
|
+
raw_length = io.read(4)
|
32
|
+
if raw_length.nil? || raw_length.length != 4
|
33
|
+
raise ::RuntimeError, 'Failed to unserialize BlockDataLong'
|
34
|
+
end
|
35
|
+
self.length = raw_length.unpack('N')[0]
|
36
|
+
|
37
|
+
if length == 0
|
38
|
+
self.contents = ''
|
39
|
+
else
|
40
|
+
self.contents = io.read(length)
|
41
|
+
if contents.nil? || contents.length != length
|
42
|
+
raise ::RuntimeError, 'Failed to unserialize BlockData'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
self
|
47
|
+
end
|
48
|
+
|
49
|
+
# Serializes the Rex::Java::Serialization::Model::BlockDataLong
|
50
|
+
#
|
51
|
+
# @return [String]
|
52
|
+
def encode
|
53
|
+
encoded = [length].pack('N')
|
54
|
+
encoded << contents
|
55
|
+
|
56
|
+
encoded
|
57
|
+
end
|
58
|
+
|
59
|
+
# Creates a print-friendly string representation
|
60
|
+
#
|
61
|
+
# @return [String]
|
62
|
+
def to_s
|
63
|
+
contents_hex = []
|
64
|
+
contents.each_byte {|byte| contents_hex << "0x#{byte.to_s(16)}" }
|
65
|
+
|
66
|
+
"[ #{contents_hex.join(', ')} ]"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# -*- coding: binary -*-
|
2
|
+
|
3
|
+
module Rex
|
4
|
+
module Java
|
5
|
+
module Serialization
|
6
|
+
module Model
|
7
|
+
# This class provides a Java classDesc representation
|
8
|
+
class ClassDesc < Element
|
9
|
+
|
10
|
+
include Rex::Java::Serialization::Model::Contents
|
11
|
+
|
12
|
+
attr_accessor :description
|
13
|
+
|
14
|
+
# @param stream [Rex::Java::Serialization::Model::Stream] the stream where it belongs to
|
15
|
+
def initialize(stream = nil)
|
16
|
+
super(stream)
|
17
|
+
self.description = nil
|
18
|
+
end
|
19
|
+
|
20
|
+
# Deserializes a Rex::Java::Serialization::Model::ClassDesc
|
21
|
+
#
|
22
|
+
# @param io [IO] the io to read from
|
23
|
+
# @return [self] if deserialization succeeds
|
24
|
+
# @raise [RuntimeError] if deserialization doesn't succeed
|
25
|
+
def decode(io)
|
26
|
+
content = decode_content(io, stream)
|
27
|
+
allowed_contents = [NullReference, NewClassDesc, Reference]
|
28
|
+
|
29
|
+
unless allowed_contents.include?(content.class)
|
30
|
+
raise ::RuntimeError, 'ClassDesc unserialize failed'
|
31
|
+
end
|
32
|
+
|
33
|
+
self.description = content
|
34
|
+
self
|
35
|
+
end
|
36
|
+
|
37
|
+
# Serializes the Rex::Java::Serialization::Model::ClassDesc
|
38
|
+
#
|
39
|
+
# @return [String] if serialization succeeds
|
40
|
+
# @raise [RuntimeError] if serialization doesn't succeed
|
41
|
+
def encode
|
42
|
+
encoded = ''
|
43
|
+
allowed_contents = [NullReference, NewClassDesc, Reference]
|
44
|
+
|
45
|
+
unless allowed_contents.include?(description.class)
|
46
|
+
raise ::RuntimeError, 'Failed to serialize ClassDesc'
|
47
|
+
end
|
48
|
+
|
49
|
+
encoded << encode_content(description)
|
50
|
+
|
51
|
+
encoded
|
52
|
+
end
|
53
|
+
|
54
|
+
# Creates a print-friendly string representation
|
55
|
+
#
|
56
|
+
# @return [String]
|
57
|
+
def to_s
|
58
|
+
print_content(description)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,156 @@
|
|
1
|
+
# -*- coding: binary -*-
|
2
|
+
|
3
|
+
module Rex
|
4
|
+
module Java
|
5
|
+
module Serialization
|
6
|
+
module Model
|
7
|
+
module Contents
|
8
|
+
include Rex::Java::Serialization
|
9
|
+
|
10
|
+
# Deserializes a content
|
11
|
+
#
|
12
|
+
# @param io [IO] the io to read from
|
13
|
+
# @return [Rex::Java::Serialization::Model::Element] if deserialization succeeds
|
14
|
+
# @raise [RuntimeError] if deserialization doesn't succeed or unsupported content
|
15
|
+
def decode_content(io, stream)
|
16
|
+
opcode = io.read(1)
|
17
|
+
raise ::RuntimeError, 'Failed to unserialize content' if opcode.nil?
|
18
|
+
opcode = opcode.unpack('C')[0]
|
19
|
+
content = nil
|
20
|
+
|
21
|
+
case opcode
|
22
|
+
when TC_BLOCKDATA
|
23
|
+
content = BlockData.decode(io, stream)
|
24
|
+
when TC_BLOCKDATALONG
|
25
|
+
content = BlockDataLong.decode(io, stream)
|
26
|
+
when TC_ENDBLOCKDATA
|
27
|
+
content = EndBlockData.decode(io, stream)
|
28
|
+
when TC_OBJECT
|
29
|
+
content = NewObject.decode(io, stream)
|
30
|
+
when TC_CLASS
|
31
|
+
content = ClassDesc.decode(io, stream)
|
32
|
+
when TC_ARRAY
|
33
|
+
content = NewArray.decode(io, stream)
|
34
|
+
when TC_STRING
|
35
|
+
content = Utf.decode(io, stream)
|
36
|
+
stream.add_reference(content) unless stream.nil?
|
37
|
+
when TC_LONGSTRING
|
38
|
+
content = LongUtf.decode(io, stream)
|
39
|
+
stream.add_reference(content) unless stream.nil?
|
40
|
+
when TC_ENUM
|
41
|
+
content = NewEnum.decode(io, stream)
|
42
|
+
when TC_CLASSDESC
|
43
|
+
content = NewClassDesc.decode(io, stream)
|
44
|
+
when TC_PROXYCLASSDESC
|
45
|
+
raise ::RuntimeError, 'Failed to unserialize unsupported TC_PROXYCLASSDESC content'
|
46
|
+
when TC_REFERENCE
|
47
|
+
content = Reference.decode(io, stream)
|
48
|
+
when TC_NULL
|
49
|
+
content = NullReference.decode(io, stream)
|
50
|
+
when TC_EXCEPTION
|
51
|
+
raise ::RuntimeError, 'Failed to unserialize unsupported TC_EXCEPTION content'
|
52
|
+
when TC_RESET
|
53
|
+
content = Reset.decode(io, stream)
|
54
|
+
else
|
55
|
+
raise ::RuntimeError, 'Failed to unserialize content'
|
56
|
+
end
|
57
|
+
|
58
|
+
content
|
59
|
+
end
|
60
|
+
|
61
|
+
# Serializes a content
|
62
|
+
#
|
63
|
+
# @param content [Rex::Java::Serialization::Model::Element] the content to serialize
|
64
|
+
# @return [String] if serialization succeeds
|
65
|
+
# @raise [RuntimeError] if serialization doesn't succeed
|
66
|
+
def encode_content(content)
|
67
|
+
encoded = ''
|
68
|
+
|
69
|
+
case content
|
70
|
+
when BlockData
|
71
|
+
encoded << [TC_BLOCKDATA].pack('C')
|
72
|
+
when BlockDataLong
|
73
|
+
encoded << [TC_BLOCKDATALONG].pack('C')
|
74
|
+
when EndBlockData
|
75
|
+
encoded << [TC_ENDBLOCKDATA].pack('C')
|
76
|
+
when NewObject
|
77
|
+
encoded << [TC_OBJECT].pack('C')
|
78
|
+
when ClassDesc
|
79
|
+
encoded << [TC_CLASS].pack('C')
|
80
|
+
when NewArray
|
81
|
+
encoded << [TC_ARRAY].pack('C')
|
82
|
+
when Utf
|
83
|
+
encoded << [TC_STRING].pack('C')
|
84
|
+
when LongUtf
|
85
|
+
encoded << [TC_LONGSTRING].pack('C')
|
86
|
+
when NewEnum
|
87
|
+
encoded << [TC_ENUM].pack('C')
|
88
|
+
when NewClassDesc
|
89
|
+
encoded << [TC_CLASSDESC].pack('C')
|
90
|
+
when NullReference
|
91
|
+
encoded << [TC_NULL].pack('C')
|
92
|
+
when Reset
|
93
|
+
encoded << [TC_RESET].pack('C')
|
94
|
+
when Reference
|
95
|
+
encoded << [TC_REFERENCE].pack('C')
|
96
|
+
else
|
97
|
+
raise ::RuntimeError, 'Failed to serialize content'
|
98
|
+
end
|
99
|
+
|
100
|
+
encoded << content.encode
|
101
|
+
encoded
|
102
|
+
end
|
103
|
+
|
104
|
+
# Creates a print-friendly string representation
|
105
|
+
#
|
106
|
+
# @param content [Rex::Java::Serialization::Model::Element] the content to print
|
107
|
+
# @return [String]
|
108
|
+
def print_content(content)
|
109
|
+
str = ''
|
110
|
+
|
111
|
+
case content
|
112
|
+
when BlockData
|
113
|
+
str << "#{print_class(content)} { #{content.to_s} }"
|
114
|
+
when BlockDataLong
|
115
|
+
str << "#{print_class(content)} { #{content.to_s} }"
|
116
|
+
when EndBlockData
|
117
|
+
str << "#{print_class(content)}"
|
118
|
+
when NewObject
|
119
|
+
str << "#{print_class(content)} { #{content.to_s} }"
|
120
|
+
when ClassDesc
|
121
|
+
str << "#{print_class(content)} { #{content.to_s} }"
|
122
|
+
when NewArray
|
123
|
+
str << "#{print_class(content)} { #{content.to_s} }"
|
124
|
+
when Utf
|
125
|
+
str << "#{print_class(content)} { #{content.to_s} }"
|
126
|
+
when LongUtf
|
127
|
+
str << "#{print_class(content)} { #{content.to_s} } "
|
128
|
+
when NewEnum
|
129
|
+
str << "#{print_class(content)} { #{content.to_s} }"
|
130
|
+
when NewClassDesc
|
131
|
+
str << "#{print_class(content)} { #{content.to_s} }"
|
132
|
+
when NullReference
|
133
|
+
str << "#{print_class(content)}"
|
134
|
+
when Reset
|
135
|
+
str << "#{print_class(content)}"
|
136
|
+
when Reference
|
137
|
+
str << "#{print_class(content)} { #{content.to_s} }"
|
138
|
+
else
|
139
|
+
raise ::RuntimeError, 'Failed to serialize content'
|
140
|
+
end
|
141
|
+
|
142
|
+
str
|
143
|
+
end
|
144
|
+
|
145
|
+
# Creates a print-friendly string representation of the content class
|
146
|
+
#
|
147
|
+
# @param content [Rex::Java::Serialization::Model::Element] the content
|
148
|
+
# @return [String]
|
149
|
+
def print_class(content)
|
150
|
+
content.class.name.split('::').last
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# -*- coding: binary -*-
|
2
|
+
|
3
|
+
module Rex
|
4
|
+
module Java
|
5
|
+
module Serialization
|
6
|
+
module Model
|
7
|
+
class Element
|
8
|
+
|
9
|
+
attr_accessor :stream
|
10
|
+
|
11
|
+
# Deserializes a Rex::Java::Serialization::Model::Element
|
12
|
+
#
|
13
|
+
# @param io [IO] the io to read from
|
14
|
+
# @return [Rex::Java::Serialization::Model::Element] if deserialization succeeds
|
15
|
+
# @return [nil] if deserialization doesn't succeed
|
16
|
+
def self.decode(io, stream = nil)
|
17
|
+
elem = self.new(stream)
|
18
|
+
elem.decode(io)
|
19
|
+
end
|
20
|
+
|
21
|
+
# @param stream [Rex::Java::Serialization::Model::Stream] the stream where it belongs to
|
22
|
+
def initialize(stream = nil)
|
23
|
+
self.stream = stream
|
24
|
+
end
|
25
|
+
|
26
|
+
def decode(io)
|
27
|
+
self
|
28
|
+
end
|
29
|
+
|
30
|
+
def encode
|
31
|
+
''
|
32
|
+
end
|
33
|
+
|
34
|
+
# Creates a print-friendly string representation
|
35
|
+
#
|
36
|
+
# @return [String]
|
37
|
+
def to_s
|
38
|
+
self.class.name.split('::').last
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,172 @@
|
|
1
|
+
# -*- coding: binary -*-
|
2
|
+
|
3
|
+
module Rex
|
4
|
+
module Java
|
5
|
+
module Serialization
|
6
|
+
module Model
|
7
|
+
# This class provides a field description representation (fieldDesc). It's used for
|
8
|
+
# both primitive descriptions (primitiveDesc) and object descriptions (objectDesc).
|
9
|
+
class Field < Element
|
10
|
+
|
11
|
+
include Rex::Java::Serialization::Model::Contents
|
12
|
+
|
13
|
+
# @!attribute type
|
14
|
+
# @return [String] The type of the field.
|
15
|
+
attr_accessor :type
|
16
|
+
# @!attribute name
|
17
|
+
# @return [Rex::Java::Serialization::Model::Utf] The name of the field.
|
18
|
+
attr_accessor :name
|
19
|
+
# @!attribute field_type
|
20
|
+
# @return [Rex::Java::Serialization::Model::Utf] The type of the field on object types.
|
21
|
+
attr_accessor :field_type
|
22
|
+
|
23
|
+
# @param stream [Rex::Java::Serialization::Model::Stream] the stream where it belongs to
|
24
|
+
def initialize(stream = nil)
|
25
|
+
super(stream)
|
26
|
+
self.type = ''
|
27
|
+
self.name = nil
|
28
|
+
self.field_type = nil
|
29
|
+
end
|
30
|
+
|
31
|
+
# Deserializes a Rex::Java::Serialization::Model::Field
|
32
|
+
#
|
33
|
+
# @param io [IO] the io to read from
|
34
|
+
# @return [self] if deserialization succeeds
|
35
|
+
# @faise [RuntimeError] if deserialization doesn't succeed
|
36
|
+
def decode(io)
|
37
|
+
code = io.read(1)
|
38
|
+
|
39
|
+
unless code && is_valid?(code)
|
40
|
+
raise ::RuntimeError, 'Failed to unserialize Field'
|
41
|
+
end
|
42
|
+
|
43
|
+
self.type = TYPE_CODES[code]
|
44
|
+
self.name = Utf.decode(io, stream)
|
45
|
+
|
46
|
+
if is_object?
|
47
|
+
self.field_type = decode_field_type(io)
|
48
|
+
end
|
49
|
+
|
50
|
+
self
|
51
|
+
end
|
52
|
+
|
53
|
+
# Serializes the Rex::Java::Serialization::Model::Field
|
54
|
+
#
|
55
|
+
# @return [String] if serialization succeeds
|
56
|
+
# @raise [RuntimeError] if serialization doesn't succeed
|
57
|
+
def encode
|
58
|
+
unless name.class == Rex::Java::Serialization::Model::Utf
|
59
|
+
raise ::RuntimeError, 'Failed to serialize Field'
|
60
|
+
end
|
61
|
+
|
62
|
+
unless is_type_valid?
|
63
|
+
raise ::RuntimeError, 'Failed to serialize Field'
|
64
|
+
end
|
65
|
+
|
66
|
+
encoded = ''
|
67
|
+
encoded << TYPE_CODES.key(type)
|
68
|
+
encoded << name.encode
|
69
|
+
|
70
|
+
if is_object?
|
71
|
+
encoded << encode_field_type
|
72
|
+
end
|
73
|
+
|
74
|
+
encoded
|
75
|
+
end
|
76
|
+
|
77
|
+
# Whether the field type is valid.
|
78
|
+
#
|
79
|
+
# @return [Boolean]
|
80
|
+
def is_type_valid?
|
81
|
+
if TYPE_CODES.values.include?(type)
|
82
|
+
return true
|
83
|
+
end
|
84
|
+
|
85
|
+
false
|
86
|
+
end
|
87
|
+
|
88
|
+
# Whether the field type is a primitive one.
|
89
|
+
#
|
90
|
+
# @return [Boolean]
|
91
|
+
def is_primitive?
|
92
|
+
if PRIMITIVE_TYPE_CODES.values.include?(type)
|
93
|
+
return true
|
94
|
+
end
|
95
|
+
|
96
|
+
false
|
97
|
+
end
|
98
|
+
|
99
|
+
# Whether the field type is an object one.
|
100
|
+
#
|
101
|
+
# @return [Boolean]
|
102
|
+
def is_object?
|
103
|
+
if OBJECT_TYPE_CODES.values.include?(type)
|
104
|
+
return true
|
105
|
+
end
|
106
|
+
|
107
|
+
false
|
108
|
+
end
|
109
|
+
|
110
|
+
# Creates a print-friendly string representation
|
111
|
+
#
|
112
|
+
# @return [String]
|
113
|
+
def to_s
|
114
|
+
str = "#{name} "
|
115
|
+
if is_primitive?
|
116
|
+
str << "(#{type})"
|
117
|
+
else
|
118
|
+
str << "(#{field_type})"
|
119
|
+
end
|
120
|
+
|
121
|
+
str
|
122
|
+
end
|
123
|
+
|
124
|
+
private
|
125
|
+
|
126
|
+
# Whether the type opcode is a valid one.
|
127
|
+
#
|
128
|
+
# @param code [String] A type opcode
|
129
|
+
# @return [Boolean]
|
130
|
+
def is_valid?(code)
|
131
|
+
if TYPE_CODES.keys.include?(code)
|
132
|
+
return true
|
133
|
+
end
|
134
|
+
|
135
|
+
false
|
136
|
+
end
|
137
|
+
|
138
|
+
# Serializes the `field_type` attribute.
|
139
|
+
#
|
140
|
+
# @return [String]
|
141
|
+
def encode_field_type
|
142
|
+
allowed_contents = [Utf, Reference]
|
143
|
+
|
144
|
+
unless allowed_contents.include?(field_type.class)
|
145
|
+
raise ::RuntimeError, 'Failed to serialize Field'
|
146
|
+
end
|
147
|
+
|
148
|
+
encoded = encode_content(field_type)
|
149
|
+
|
150
|
+
encoded
|
151
|
+
end
|
152
|
+
|
153
|
+
# Deserializes the `field_type` value.
|
154
|
+
#
|
155
|
+
# @param io [IO] the io to read from
|
156
|
+
# @return [Java::Serialization::Model::Utf]
|
157
|
+
# @raise [RuntimeError] if unserialization doesn't succeed
|
158
|
+
def decode_field_type(io)
|
159
|
+
allowed_contents = [Utf, Reference]
|
160
|
+
type = decode_content(io, stream)
|
161
|
+
|
162
|
+
unless allowed_contents.include?(type.class)
|
163
|
+
raise ::RuntimeError, 'Failed to unserialize Field field_type'
|
164
|
+
end
|
165
|
+
|
166
|
+
type
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|