Class: BinData::NdrArrayArgProcessor

Inherits:
ArrayArgProcessor
  • Object
show all
Defined in:
lib/ruby_smb/dcerpc/ndr.rb

Overview

This ArgProcessor needs to inherit from BinData::ArrayArgProcessor to make sure the ArrayArgProcessor sanitize_parameters! is called. This will perform proper Array-related sanity checks on the given parameters.

Instance Method Summary collapse

Instance Method Details

#sanitize_parameters!(obj_class, params) ⇒ Object

Raises:

  • (ArgumentError)


390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
# File 'lib/ruby_smb/dcerpc/ndr.rb', line 390

def sanitize_parameters!(obj_class, params)
  res = super

  type_class = params[:type]
  # Let the BinData::Array sanitization routine deal with "no type provided"
  return res unless type_class

  type_class, type_params  = params[:type] if type_class.is_a?(Array)
  if type_class.has_parameter?(:byte_align)
    # According to NDR alignemnt rules for arrays: Array alignment is the
    # largest alignment of the array element type and the size information
    # type, if any.
    # So, here, we pick the greatest value between the size of the `size
    # information` field (:max_count or :offset/:actual_count), which is 4
    # bytes for 32-bit NDR, and the element type size
    byte_align = type_class.instance_variable_get(:@obj_params)[:byte_align]
    if obj_class < NdrFixArray
      # Fixed size arrays doesn't have size information
      params[:byte_align] = byte_align
    else
      params[:byte_align] = [4, byte_align].max
    end
    return res
  elsif type_params&.key?(:byte_align)
    return res
  end

  raise ArgumentError.new(
    "NDR Arrays must only include elements with the `:byte_align` "\
    "parameter set. This makes sure the whole structure is correctly "\
    "aligned. Use a predefined NDR element instead, or provide the "\
    "`:byte_align` parameter in `:type` (Faulty element type: #{params[:type]})"
  )
end