From 5291eb50051ae9fdddf35b7f0e7a0226ef71b785 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Mangano?= Date: Thu, 9 Jan 2025 11:37:21 +0900 Subject: [PATCH] Rename object_id to message_id MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ruby 3.4 prints the following message when redefining object_id: ``` warning: redefining 'object_id' may cause serious problems ``` According to fragment.rb, winrm’s object_id is the ID of the message, so let’s rename it to message_id. message_id was not used before, and no calls to object_id referred to Ruby’s, so I’ve naively replaced all occurrences of object_id by message_id. --- lib/winrm/psrp/fragment.rb | 10 +++++----- lib/winrm/psrp/message_defragmenter.rb | 6 +++--- lib/winrm/psrp/message_fragmenter.rb | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/winrm/psrp/fragment.rb b/lib/winrm/psrp/fragment.rb index 6e1b0dc5..ba696710 100644 --- a/lib/winrm/psrp/fragment.rb +++ b/lib/winrm/psrp/fragment.rb @@ -19,27 +19,27 @@ module PSRP # PowerShell Remoting Protocol message fragment. class Fragment # Creates a new PSRP message fragment - # @param object_id [Integer] The id of the fragmented message. + # @param message_id [Integer] The id of the fragmented message. # @param blob [Array] Array of fragmented bytes. # @param fragment_id [Integer] The id of this fragment # @param start_fragment [Boolean] If the fragment is the first fragment # @param end_fragment [Boolean] If the fragment is the last fragment - def initialize(object_id, blob, fragment_id = 0, start_fragment = true, end_fragment = true) - @object_id = object_id + def initialize(message_id, blob, fragment_id = 0, start_fragment = true, end_fragment = true) + @message_id = message_id @blob = blob @fragment_id = fragment_id @start_fragment = start_fragment @end_fragment = end_fragment end - attr_reader :object_id, :fragment_id, :end_fragment, :start_fragment, :blob + attr_reader :message_id, :fragment_id, :end_fragment, :start_fragment, :blob # Returns the raw PSRP message bytes ready for transfer to Windows inside a # WinRM message. # @return [Array] Unencoded raw byte array of the PSRP message. def bytes [ - int64be(object_id), + int64be(message_id), int64be(fragment_id), end_start_fragment, int16be(blob.length), diff --git a/lib/winrm/psrp/message_defragmenter.rb b/lib/winrm/psrp/message_defragmenter.rb index b691ec8d..66dc9a70 100644 --- a/lib/winrm/psrp/message_defragmenter.rb +++ b/lib/winrm/psrp/message_defragmenter.rb @@ -26,13 +26,13 @@ def initialize def defragment(base64_bytes) fragment = fragment_from(Base64.decode64(base64_bytes)) - @messages[fragment.object_id] ||= [] - @messages[fragment.object_id].push fragment + @messages[fragment.message_id] ||= [] + @messages[fragment.message_id].push fragment # rubocop:disable Style/GuardClause if fragment.end_fragment blob = [] - @messages.delete(fragment.object_id).each { |frag| blob += frag.blob } + @messages.delete(fragment.message_id).each { |frag| blob += frag.blob } return message_from(blob.pack('C*')) end # rubocop:enable Style/GuardClause diff --git a/lib/winrm/psrp/message_fragmenter.rb b/lib/winrm/psrp/message_fragmenter.rb index 8abe37a4..2ee9552c 100644 --- a/lib/winrm/psrp/message_fragmenter.rb +++ b/lib/winrm/psrp/message_fragmenter.rb @@ -22,15 +22,15 @@ class MessageFragmenter DEFAULT_BLOB_LENGTH = 32_768 def initialize(max_blob_length = DEFAULT_BLOB_LENGTH) - @object_id = 0 + @message_id = 0 @max_blob_length = max_blob_length || DEFAULT_BLOB_LENGTH end - attr_reader :object_id + attr_reader :message_id attr_accessor :max_blob_length def fragment(message) - @object_id += 1 + @message_id += 1 message_bytes = message.bytes bytes_fragmented = 0 fragment_id = 0 @@ -40,7 +40,7 @@ def fragment(message) last_byte = bytes_fragmented + max_blob_length last_byte = message_bytes.length if last_byte > message_bytes.length fragment = Fragment.new( - object_id, + message_id, message.bytes[bytes_fragmented..last_byte - 1], fragment_id, bytes_fragmented.zero?,