Class: TurboRex::Windows::ALPC::PortMessage

Inherits:
Object
  • Object
show all
Defined in:
lib/turborex/windows/alpc.rb

Defined Under Namespace

Classes: ClientID

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ PortMessage

Returns a new instance of PortMessage.



424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
# File 'lib/turborex/windows/alpc.rb', line 424

def initialize(opts = {})
  raw_message = opts[:raw_message]
  payload = opts[:payload]
  @payload = payload
  @attributes = MessageAttribute.new.struct

  if raw_message
    perform_raw_message raw_message
  elsif payload
    port_message = opts[:port_message]
    @header = (port_message ||= APIProxy.alloc_c_struct('PORT_MESSAGE'))
    set_header
    #@message_size = @header_size = port_message.sizeof
    if payload.is_a? String
      pure_set_msg payload, payload.bytesize
    elsif payload.is_a? ::Metasm::C::AllocCStruct
      pure_set_msg payload.str, payload.sizeof
    else
      raise TurboRex::Exception::ALPC::UnknownPayloadType
    end
  elsif opts[:alloc_size]
    @header = APIProxy.alloc_c_struct('PORT_MESSAGE')
    set_header

    @payload = 0.chr * opts[:alloc_size].to_i
    pure_set_msg @payload, @payload.bytesize
  end
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



411
412
413
# File 'lib/turborex/windows/alpc.rb', line 411

def attributes
  @attributes
end

#buf_sizeObject (readonly)

Returns the value of attribute buf_size.



403
404
405
# File 'lib/turborex/windows/alpc.rb', line 403

def buf_size
  @buf_size
end

#callback_idObject

Returns the value of attribute callback_id.



422
423
424
# File 'lib/turborex/windows/alpc.rb', line 422

def callback_id
  @callback_id
end

#client_idObject

Returns the value of attribute client_id.



418
419
420
# File 'lib/turborex/windows/alpc.rb', line 418

def client_id
  @client_id
end

#client_view_sizeObject (readonly)

Returns the value of attribute client_view_size.



421
422
423
# File 'lib/turborex/windows/alpc.rb', line 421

def client_view_size
  @client_view_size
end

#data_info_offsetObject (readonly)

Returns the value of attribute data_info_offset.



416
417
418
# File 'lib/turborex/windows/alpc.rb', line 416

def data_info_offset
  @data_info_offset
end

#data_lengthObject

Returns the value of attribute data_length.



409
410
411
# File 'lib/turborex/windows/alpc.rb', line 409

def data_length
  @data_length
end

#do_not_use_this_fieldObject (readonly)

Returns the value of attribute do_not_use_this_field.



419
420
421
# File 'lib/turborex/windows/alpc.rb', line 419

def do_not_use_this_field
  @do_not_use_this_field
end

#headerObject

Returns the value of attribute header.



410
411
412
# File 'lib/turborex/windows/alpc.rb', line 410

def header
  @header
end

#header_sizeObject (readonly)

Returns the value of attribute header_size.



404
405
406
# File 'lib/turborex/windows/alpc.rb', line 404

def header_size
  @header_size
end

#lengthObject (readonly)

header data member



414
415
416
# File 'lib/turborex/windows/alpc.rb', line 414

def length
  @length
end

#messageObject (readonly)

Returns the value of attribute message.



405
406
407
# File 'lib/turborex/windows/alpc.rb', line 405

def message
  @message
end

#message_idObject

Returns the value of attribute message_id.



420
421
422
# File 'lib/turborex/windows/alpc.rb', line 420

def message_id
  @message_id
end

#message_sizeObject (readonly)

Returns the value of attribute message_size.



402
403
404
# File 'lib/turborex/windows/alpc.rb', line 402

def message_size
  @message_size
end

#payloadObject

Returns the value of attribute payload.



406
407
408
# File 'lib/turborex/windows/alpc.rb', line 406

def payload
  @payload
end

#payload_sizeObject (readonly)

Returns the value of attribute payload_size.



407
408
409
# File 'lib/turborex/windows/alpc.rb', line 407

def payload_size
  @payload_size
end

#total_lengthObject

Returns the value of attribute total_length.



408
409
410
# File 'lib/turborex/windows/alpc.rb', line 408

def total_length
  @total_length
end

#typeObject

Returns the value of attribute type.



415
416
417
# File 'lib/turborex/windows/alpc.rb', line 415

def type
  @type
end

#zero_initObject (readonly)

Returns the value of attribute zero_init.



417
418
419
# File 'lib/turborex/windows/alpc.rb', line 417

def zero_init
  @zero_init
end

Instance Method Details

#get_total_and_data_lenObject



477
478
479
# File 'lib/turborex/windows/alpc.rb', line 477

def get_total_and_data_len
  [@header.u1.s1.TotalLength, @header.u1.s1.DataLength]
end

#refresh_messageObject



532
533
534
535
# File 'lib/turborex/windows/alpc.rb', line 532

def refresh_message
  return unless @message
  perform_raw_message @message
end

#set_data_length(len) ⇒ Object



469
470
471
472
473
474
475
# File 'lib/turborex/windows/alpc.rb', line 469

def set_data_length(len)
  @total_length = @header_size + len
  @data_length = len

  @header.u1.s1.TotalLength = @total_length
  @header.u1.s1.DataLength = @data_length
end

#set_headerObject



489
490
491
492
493
494
495
496
497
498
499
# File 'lib/turborex/windows/alpc.rb', line 489

def set_header
  @total_length, @data_length = get_total_and_data_len
  @length = @header.u1.Length
  @type = @header.u2.s2.Type
  @data_info_offset = @header.u2.s2.DataInfoOffset
  @zero_init = @header.u2.ZeroInit
  @client_id = @do_not_use_this_field = ClientID.new(@header.ClientId.UniqueProcess, @header.ClientId.UniqueThread)
  @message_id = @header.MessageId
  @client_view_size = @callback_id = @header.ClientViewSize
  @header_size = @header.sizeof
end