Class: WinRM::PSRP::MessageDefragmenter
- Inherits:
-
Object
- Object
- WinRM::PSRP::MessageDefragmenter
- Defined in:
- lib/winrm/psrp/message_defragmenter.rb
Overview
PowerShell Remoting Protocol message fragmenter.
Instance Method Summary collapse
- #defragment(base64_bytes) ⇒ Object
- #fragment_from(byte_string) ⇒ Object
-
#initialize ⇒ MessageDefragmenter
constructor
A new instance of MessageDefragmenter.
- #message_from(byte_string) ⇒ Object
Constructor Details
#initialize ⇒ MessageDefragmenter
Returns a new instance of MessageDefragmenter.
22 23 24 |
# File 'lib/winrm/psrp/message_defragmenter.rb', line 22 def initialize @messages = {} end |
Instance Method Details
#defragment(base64_bytes) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/winrm/psrp/message_defragmenter.rb', line 26 def defragment(base64_bytes) fragment = fragment_from(Base64.decode64(base64_bytes)) @messages[fragment.object_id] ||= [] @messages[fragment.object_id].push fragment # rubocop:disable Style/GuardClause if fragment.end_fragment blob = [] @messages.delete(fragment.object_id).each { |frag| blob += frag.blob } return (blob.pack('C*')) end # rubocop:enable Style/GuardClause end |
#fragment_from(byte_string) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/winrm/psrp/message_defragmenter.rb', line 41 def fragment_from(byte_string) Fragment.new( byte_string[0..7].reverse.unpack('Q')[0], byte_string[21..-1].bytes, byte_string[8..15].reverse.unpack('Q')[0], byte_string[16].unpack('C')[0][0] == 1, byte_string[16].unpack('C')[0][1] == 1 ) end |
#message_from(byte_string) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/winrm/psrp/message_defragmenter.rb', line 51 def (byte_string) Message.new( '00000000-0000-0000-0000-000000000000', byte_string[4..7].unpack('V')[0], byte_string[40..-1], '00000000-0000-0000-0000-000000000000', byte_string[0..3].unpack('V')[0] ) end |