Module: RubySMB::Dcerpc::Ndr::ConfStringPlugin

Defined in:
lib/ruby_smb/dcerpc/ndr.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#max_countObject

Returns the value of attribute max_count.



515
516
517
# File 'lib/ruby_smb/dcerpc/ndr.rb', line 515

def max_count
  @max_count
end

Instance Method Details

#assign(val) ⇒ Object



549
550
551
552
553
554
555
556
# File 'lib/ruby_smb/dcerpc/ndr.rb', line 549

def assign(val)
  if val.is_a?(ConfStringPlugin)
    @max_count = val.max_count
  else
    set_max_count(get_max_count(val))
  end
  super
end

#do_num_bytesObject



558
559
560
561
562
563
564
565
# File 'lib/ruby_smb/dcerpc/ndr.rb', line 558

def do_num_bytes
  sum = 0
  if should_process_max_count?
    # add max_count size
    sum += 4
  end
  sum + super
end

#do_read(io) ⇒ Object



538
539
540
541
542
543
544
545
546
547
# File 'lib/ruby_smb/dcerpc/ndr.rb', line 538

def do_read(io)
  if should_process_max_count?
    max_count = io.readbytes(4).unpack1('L<')
    BinData.trace_message do |tracer|
      tracer.trace_obj("#{debug_name}.max_count", max_count.to_s)
    end
    set_max_count(max_count)
  end
  super
end

#do_write(io) ⇒ Object



531
532
533
534
535
536
# File 'lib/ruby_smb/dcerpc/ndr.rb', line 531

def do_write(io)
  if should_process_max_count?
    io.writebytes([@max_count].pack('L<'))
  end
  super
end

#get_max_count(val) ⇒ Object



567
568
569
570
571
572
573
574
575
576
577
578
579
# File 'lib/ruby_smb/dcerpc/ndr.rb', line 567

def get_max_count(val)
  if is_a?(BinData::Stringz)
    max_count = val.to_s.strip.length
    # Add one to count the terminator. According to
    # https://pubs.opengroup.org/onlinepubs/9629399/chap14.htm#tagcjh_19_03_04_02,
    # the NDR String must contain at least one element, the terminator. So,
    # add one even if it is an empty string.
    max_count += 1
    return max_count
  else
    return val.to_s.length
  end
end

#initialize_instanceObject



517
518
519
520
521
522
523
# File 'lib/ruby_smb/dcerpc/ndr.rb', line 517

def initialize_instance
  @max_count = 0
  if has_parameter?(:initial_value)
    set_max_count(get_max_count(eval_parameter(:initial_value)))
  end
  super
end

#set_max_count(val) ⇒ Object



581
582
583
# File 'lib/ruby_smb/dcerpc/ndr.rb', line 581

def set_max_count(val)
  @max_count = val
end

#should_process_max_count?Boolean

Returns:

  • (Boolean)


525
526
527
528
529
# File 'lib/ruby_smb/dcerpc/ndr.rb', line 525

def should_process_max_count?
  # :max_count has already been processed if the parent structure is an
  # NdrStruct, but this is not the case if we are dealing with a pointer
  !parent.is_a?(NdrStruct) || self.is_a?(PointerPlugin)
end