class WinRM::PSRP::Message

PowerShell Remoting Protocol base message. download.microsoft.com/download/9/5/E/95EF66AF-9026-4BB0-A41D-A4F81802D92C/%5BMS-PSRP%5D.pdf

Constants

CLIENT_DESTINATION

Value of message destination when sent to a client

MESSAGE_TYPES

All known PSRP message types

SERVER_DESTINATION

Value of message destination when sent to a server

Attributes

data[R]
destination[R]
pipeline_id[R]
runspace_pool_id[R]
type[R]

Public Class Methods

new( runspace_pool_id, type, data, pipeline_id = nil, destination = SERVER_DESTINATION ) click to toggle source

Creates a new PSRP message instance @param runspace_pool_id [String] The UUID of the remote shell/runspace pool. @param pipeline_id [String] The UUID to correlate the command/pipeline response @param type [Integer] The PSRP MessageType. This is most commonly specified in hex, e.g. 0x00010002. @param data [String] The PSRP payload as serialized XML @param destination [Integer] The destination for this message - client or server

# File lib/winrm/psrp/message.rb, line 75
def initialize(
  runspace_pool_id,
  type,
  data,
  pipeline_id = nil,
  destination = SERVER_DESTINATION
)
  raise 'invalid message type' unless MESSAGE_TYPES.value?(type)

  @data = data
  @destination = destination
  @type = type
  @pipeline_id = pipeline_id
  @runspace_pool_id = runspace_pool_id
end

Public Instance Methods

bytes() click to toggle source

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.

# File lib/winrm/psrp/message.rb, line 96
def bytes
  [
    int16le(destination),
    int16le(type),
    uuid_to_windows_guid_bytes(runspace_pool_id),
    uuid_to_windows_guid_bytes(pipeline_id),
    byte_order_mark,
    data_bytes
  ].flatten
end
parsed_data() click to toggle source

Parses the raw data to a MessageData class @return [MessageData::Base] MessageData corresponding to this message type

# File lib/winrm/psrp/message.rb, line 109
def parsed_data
  @parsed_data ||= MessageData.parse(self)
end

Private Instance Methods

byte_order_mark() click to toggle source
# File lib/winrm/psrp/message.rb, line 115
def byte_order_mark
  [239, 187, 191]
end
data_bytes() click to toggle source
# File lib/winrm/psrp/message.rb, line 119
def data_bytes
  @data_bytes ||= data.force_encoding('utf-8').bytes
end
int16le(int16) click to toggle source
# File lib/winrm/psrp/message.rb, line 123
def int16le(int16)
  [int16].pack('N').unpack('C4').reverse
end