Class: RubySMB::Dcerpc::Ndr::TypeSerialization1

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

Overview

class TestTypeSerialization1 < RubySMB::Dcerpc::Ndr::TypeSerialization1 default_parameter byte_align: 8 endian :little

test_struct :data1 uint32 :value1, initial_value: 5 uint32 :value2, initial_value: 6 test_struct :data2 uint32 :value3, initial_value: 7 test_struct :data3 end

This will result in the following structure: { :common_header => :endianness=>16, :common_header_length=>8, :filler=>3435973836, :private_header1 => :filler=>0, :data1 => :maximum_length=>0, :buffer=>:null, :user_id=>0}, :value1 => 5, :value2 => 6, :private_header2 => :filler=>0, :data2 => :maximum_length=>0, :buffer=>:null, :user_id=>0}, :value3 => 7, :private_header3 => :filler=>0, :data3 => :maximum_length=>0, :buffer=>:null, :user_id=>0} }

Constant Summary collapse

PRIVATE_HEADER_BASE_NAME =
'private_header'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.method_missing(symbol, *args, &block) ⇒ Object



1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
# File 'lib/ruby_smb/dcerpc/ndr.rb', line 1420

def self.method_missing(symbol, *args, &block)
  return super if dsl_parser.respond_to?(symbol)

  klass = BinData::RegisteredClasses.lookup(symbol, {endian: dsl_parser.endian, search_prefix: dsl_parser.search_prefix})
  if klass.new.is_a?(ConstructedTypePlugin)
    # We cannot have two fields with the same name. So, here we look for
    # existing TypeSerialization1PrivateHeader fields and just increment
    # the ending number of the last TypeSerialization1PrivateHeader field
    # to make the new name unique.
    names = dsl_parser.fields.find_all do |field|
      field.prototype.instance_variable_get(:@obj_class) == TypeSerialization1PrivateHeader
    end.map(&:name).sort
    if names.empty?
      new_name = "#{PRIVATE_HEADER_BASE_NAME}1"
    else
      num = names.last.match(/#{PRIVATE_HEADER_BASE_NAME}(\d)$/)[1].to_i
      new_name = "#{PRIVATE_HEADER_BASE_NAME}#{num + 1}"
    end

    super(:private_header, new_name.to_sym)
  end

  super
end

Instance Method Details

#field_length(obj) ⇒ Object



1411
1412
1413
1414
1415
1416
1417
1418
# File 'lib/ruby_smb/dcerpc/ndr.rb', line 1411

def field_length(obj)
  length = 0
  index = find_index_of(obj)
  if index
    each_pair {|n, o| length = o.num_bytes if n == field_names[index + 1]}
  end
  length
end