Skip to content

Commit ae608b1

Browse files
committed
Add references to stream when possible
1 parent 13d8058 commit ae608b1

File tree

8 files changed

+13
-0
lines changed

8 files changed

+13
-0
lines changed

lib/rex/java/serialization/model/class_desc.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def decode(io)
2828
end
2929

3030
self.description = content
31+
stream.add_reference(self) unless stream.nil?
3132
self
3233
end
3334

lib/rex/java/serialization/model/long_utf.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class LongUtf < Utf
1111
# @return [self] if deserialization succeeds
1212
# @return [nil] if deserialization doesn't succeed
1313
def decode(io)
14+
stream.add_reference(self) unless stream.nil?
1415
raw_length = io.read(8)
1516
if raw_length.nil? || raw_length.length != 8
1617
raise ::RuntimeError, 'Failed to unserialize LongUtf'

lib/rex/java/serialization/model/new_array.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def initialize(stream = nil)
3131
# @raise [RuntimeError] if deserialization doesn't succeed
3232
def decode(io)
3333
self.array_description = ClassDesc.decode(io, stream)
34+
stream.add_reference(self) unless stream.nil?
3435
self.type = array_type
3536

3637
values_length = decode_values_length(io)

lib/rex/java/serialization/model/new_class_desc.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def encode
7070
encoded = ''
7171
encoded << class_name.encode
7272
encoded << [serial_version].pack('Q>')
73+
stream.add_reference(self) unless stream.nil?
7374
encoded << [flags].pack('C')
7475
encoded << [fields.length].pack('n')
7576
fields.each do |field|

lib/rex/java/serialization/model/new_enum.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def initialize(stream = nil)
2727
# @raise [RuntimeError] if deserialization doesn't succeed
2828
def decode(io)
2929
self.enum_description = ClassDesc.decode(io, stream)
30+
stream.add_reference(self) unless stream.nil?
3031
self.constant_name = decode_constant_name(io)
3132

3233
self

lib/rex/java/serialization/model/new_object.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def initialize(stream = nil)
2727
# @raise [RuntimeError] if deserialization doesn't succeed
2828
def decode(io)
2929
self.class_desc = ClassDesc.decode(io, stream)
30+
stream.add_reference(self) unless stream.nil?
3031
if class_desc.description.class == Rex::Java::Serialization::Model::NewClassDesc
3132
self.class_data = decode_class_data(io, class_desc)
3233
end

lib/rex/java/serialization/model/stream.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,18 @@ class Stream < Element
1616
# @!attribute contents
1717
# @return [Array] The stream's contents
1818
attr_accessor :contents
19+
attr_accessor :references
1920

2021
def initialize(stream = nil)
2122
super(stream)
2223
self.magic = STREAM_MAGIC
2324
self.version = STREAM_VERSION
2425
self.contents = []
26+
self.references = []
27+
end
28+
29+
def add_reference(ref)
30+
self.references.push(ref)
2531
end
2632

2733
# Deserializes a Java::Serialization::Model::Stream

lib/rex/java/serialization/model/utf.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def initialize(stream = nil, contents = '')
2525
# @return [self] if deserialization succeeds
2626
# @raise [RuntimeError] if deserialization doesn't succeed
2727
def decode(io)
28+
stream.add_reference(self) unless stream.nil?
2829
raw_length = io.read(2)
2930
if raw_length.nil? || raw_length.length != 2
3031
raise ::RuntimeError, 'Failed to unserialize Utf'

0 commit comments

Comments
 (0)