Skip to content

Commit 85a70d4

Browse files
committed
Introduce Rex::Proto::Rmi::DecodeError
1 parent 3570fc5 commit 85a70d4

File tree

11 files changed

+31
-30
lines changed

11 files changed

+31
-30
lines changed

lib/msf/java/rmi/client.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def recv_protocol_ack(opts = {})
8989
data = safe_get_once(nsock)
9090
begin
9191
ack = Rex::Proto::Rmi::Model::ProtocolAck.decode(StringIO.new(data))
92-
rescue ::RuntimeError
92+
rescue Rex::Proto::Rmi::DecodeError
9393
return nil
9494
end
9595

@@ -110,7 +110,7 @@ def recv_return(opts = {})
110110

111111
begin
112112
return_data = Rex::Proto::Rmi::Model::ReturnData.decode(StringIO.new(data))
113-
rescue ::RuntimeError
113+
rescue Rex::Proto::Rmi::DecodeError
114114
return nil
115115
end
116116

lib/rex/proto/rmi.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
# http://docs.oracle.com/javase/7/docs/platform/rmi/spec/rmi-protocol.html
55

66
require 'rex/proto/rmi/exception'
7+
require 'rex/proto/rmi/decode_error'
78
require 'rex/proto/rmi/model'
89

lib/rex/proto/rmi/model/call.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ class Call < Element
2020
#
2121
# @param io [IO] the IO to read from
2222
# @return [String]
23-
# @raise [RuntimeError] if fails to decode the message id
23+
# @raise [Rex::Proto::Rmi::DecodeError] if fails to decode the message id
2424
def decode_message_id(io)
2525
message_id = read_byte(io)
2626
unless message_id == CALL_MESSAGE
27-
raise ::RuntimeError, 'Failed to decode Call message id'
27+
raise Rex::Proto::Rmi::DecodeError, 'Failed to decode Call message id'
2828
end
2929

3030
message_id

lib/rex/proto/rmi/model/dgc_ack.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ class DgcAck < Element
2222
#
2323
# @param io [IO] the IO to read from
2424
# @return [String]
25-
# @raise [RuntimeError] if fails to decode stream id
25+
# @raise [Rex::Proto::Rmi::DecodeError] if fails to decode stream id
2626
def decode_stream_id(io)
2727
stream_id = read_byte(io)
2828
unless stream_id == DGC_ACK_MESSAGE
29-
raise ::RuntimeError, 'Failed to decode DgcAck stream id'
29+
raise Rex::Proto::Rmi::DecodeError, 'Failed to decode DgcAck stream id'
3030
end
3131

3232
stream_id

lib/rex/proto/rmi/model/element.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ def encode
8383
#
8484
# @param io [IO] the IO to read from
8585
# @return [Fixnum]
86-
# @raise [RuntimeError] if the byte can't be read from io
86+
# @raise [Rex::Proto::Rmi::DecodeError] if the byte can't be read from io
8787
def read_byte(io)
8888
raw = io.read(1)
89-
raise ::RuntimeError, 'Failed to read byte' unless raw
89+
raise Rex::Proto::Rmi::DecodeError, 'Failed to read byte' unless raw
9090

9191
raw.unpack('c')[0]
9292
end
@@ -95,12 +95,12 @@ def read_byte(io)
9595
#
9696
# @param io [IO] the IO to read from
9797
# @return [Fixnum]
98-
# @raise [RuntimeError] if the short can't be read from io
98+
# @raise [Rex::Proto::Rmi::DecodeError] if the short can't be read from io
9999
def read_short(io)
100100
raw = io.read(2)
101101

102102
unless raw && raw.length == 2
103-
raise ::RuntimeError, 'Failed to read short'
103+
raise Rex::Proto::Rmi::DecodeError, 'Failed to read short'
104104
end
105105

106106
raw.unpack('s>')[0]
@@ -110,12 +110,12 @@ def read_short(io)
110110
#
111111
# @param io [IO] the IO to read from
112112
# @return [Fixnum]
113-
# @raise [RuntimeError] if the int can't be read from io
113+
# @raise [Rex::Proto::Rmi::DecodeError] if the int can't be read from io
114114
def read_int(io)
115115
raw = io.read(4)
116116

117117
unless raw && raw.length == 4
118-
raise ::RuntimeError, 'Failed to read int'
118+
raise Rex::Proto::Rmi::DecodeError, 'Failed to read int'
119119
end
120120

121121
raw.unpack('l>')[0]
@@ -125,12 +125,12 @@ def read_int(io)
125125
#
126126
# @param io [IO] the IO to read from
127127
# @return [Fixnum]
128-
# @raise [RuntimeError] if the long can't be read from io
128+
# @raise [Rex::Proto::Rmi::DecodeError] if the long can't be read from io
129129
def read_long(io)
130130
raw = io.read(8)
131131

132132
unless raw && raw.length == 8
133-
raise ::RuntimeError, 'Failed to read long'
133+
raise Rex::Proto::Rmi::DecodeError, 'Failed to read long'
134134
end
135135

136136
raw.unpack('q>')[0]
@@ -141,12 +141,12 @@ def read_long(io)
141141
# @param io [IO] the IO to read from
142142
# @param length [Fixnum] the string length
143143
# @return [String]
144-
# @raise [RuntimeError] if the string can't be read from io
144+
# @raise [Rex::Proto::Rmi::DecodeError] if the string can't be read from io
145145
def read_string(io, length)
146146
raw = io.read(length)
147147

148148
unless raw && raw.length == length
149-
raise ::RuntimeError, 'Failed to read string'
149+
raise Rex::Proto::Rmi::DecodeError, 'Failed to read string'
150150
end
151151

152152
raw

lib/rex/proto/rmi/model/output_header.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ class OutputHeader < Element
2323
#
2424
# @param io [IO] the IO to read from
2525
# @return [String]
26-
# @raise [RuntimeError] if fails to decode signature
26+
# @raise [Rex::Proto::Rmi::DecodeError] if fails to decode signature
2727
def decode_signature(io)
2828
signature = read_string(io, 4)
2929
unless signature == SIGNATURE
30-
raise ::RuntimeError, 'Failed to decode OutputHeader signature'
30+
raise Rex::Proto::Rmi::DecodeError, 'Failed to decode OutputHeader signature'
3131
end
3232

3333
signature
@@ -47,13 +47,13 @@ def decode_version(io)
4747
#
4848
# @param io [IO] the IO to read from
4949
# @return [Fixnum]
50-
# @raise [RuntimeError] if fails to decode the protocol
50+
# @raise [Rex::Proto::Rmi::DecodeError] if fails to decode the protocol
5151
def decode_protocol(io)
5252
valid_protocols = [STREAM_PROTOCOL, SINGLE_OP_PROTOCOL, MULTIPLEX_PROTOCOL]
5353
protocol = read_byte(io)
5454

5555
unless valid_protocols.include?(protocol)
56-
raise ::RuntimeError, 'Failed to decode OutputHeader protocol'
56+
raise Rex::Proto::Rmi::DecodeError, 'Failed to decode OutputHeader protocol'
5757
end
5858

5959
protocol

lib/rex/proto/rmi/model/ping.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ class Ping < Element
1818
#
1919
# @param io [IO] the IO to read from
2020
# @return [String]
21-
# @raise [RuntimeError] if fails to decode stream id
21+
# @raise [Rex::Proto::Rmi::DecodeError] if fails to decode stream id
2222
def decode_stream_id(io)
2323
stream_id = read_byte(io)
2424
unless stream_id == PING_MESSAGE
25-
raise ::RuntimeError, 'Failed to decode Ping stream id'
25+
raise Rex::Proto::Rmi::DecodeError, 'Failed to decode Ping stream id'
2626
end
2727

2828
stream_id

lib/rex/proto/rmi/model/ping_ack.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ class PingAck < Element
1818
#
1919
# @param io [IO] the IO to read from
2020
# @return [String]
21-
# @raise [RuntimeError] if fails to decode stream id
21+
# @raise [Rex::Proto::Rmi::DecodeError] if fails to decode stream id
2222
def decode_stream_id(io)
2323
stream_id = read_byte(io)
2424
unless stream_id == PING_ACK
25-
raise ::RuntimeError, 'Failed to decode PingAck stream id'
25+
raise Rex::Proto::Rmi::DecodeError, 'Failed to decode PingAck stream id'
2626
end
2727

2828
stream_id

lib/rex/proto/rmi/model/protocol_ack.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ class ProtocolAck < Element
2626
#
2727
# @param io [IO] the IO to read from
2828
# @return [String]
29-
# @raise [RuntimeError] if fails to decode stream id
29+
# @raise [Rex::Proto::Rmi::DecodeError] if fails to decode stream id
3030
def decode_stream_id(io)
3131
stream_id = read_byte(io)
3232
unless stream_id == PROTOCOL_ACK
33-
raise ::RuntimeError, 'Failed to decode ProtocolAck stream id'
33+
raise Rex::Proto::Rmi::DecodeError, 'Failed to decode ProtocolAck stream id'
3434
end
3535

3636
stream_id

lib/rex/proto/rmi/model/return_data.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ class ReturnData < Element
2020
#
2121
# @param io [IO] the IO to read from
2222
# @return [String]
23-
# @raise [RuntimeError] if fails to decode the stream id
23+
# @raise [Rex::Proto::Rmi::DecodeError] if fails to decode the stream id
2424
def decode_stream_id(io)
2525
stream_id = read_byte(io)
2626
unless stream_id == RETURN_DATA
27-
raise ::RuntimeError, 'Failed to decode ReturnData stream id'
27+
raise Rex::Proto::Rmi::DecodeError, 'Failed to decode ReturnData stream id'
2828
end
2929

3030
stream_id

0 commit comments

Comments
 (0)