Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename object_id to message_id #352

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/winrm/psrp/fragment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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<Byte>] 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),
Expand Down
6 changes: 3 additions & 3 deletions lib/winrm/psrp/message_defragmenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions lib/winrm/psrp/message_fragmenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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?,
Expand Down