Class: RubySMB::Dcerpc::Ndr::NdrStruct

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

Overview

A generic NDR structure that implements logic to #read and #write (#to_binary_s) in case the structure contains BinData::Array or NdrPointer fields. This class must be inherited.

Direct Known Subclasses

NdrStringPtrsw, Svcctl::QueryServiceConfigW

Instance Method Summary collapse

Instance Method Details

#do_read(io) ⇒ Object



310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
# File 'lib/ruby_smb/dcerpc/ndr.rb', line 310

def do_read(io)
  super(io)
  each_pair do |_name, field|
    case field
    when BinData::Array
      field.each do |element|
        next unless element.is_a?(NdrPointer)
        next if element.referent_id == 0
        pad = (4 - io.offset % 4) % 4
        io.seekbytes(pad) if pad > 0
        element.referent.do_read(io)
      end
    when NdrPointer
      next if field.referent_id == 0
      pad = (4 - io.offset % 4) % 4
      io.seekbytes(pad) if pad > 0
      field.referent.do_read(io)
    end
  end
end

#do_write(io) ⇒ Object



331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
# File 'lib/ruby_smb/dcerpc/ndr.rb', line 331

def do_write(io)
  super(io)
  each_pair do |_name, field|
    case field
    when BinData::Array
      field.each do |element|
        next unless element.is_a?(NdrPointer)
        next if element.referent_id == 0
        pad = (4 - io.offset % 4) % 4
        io.writebytes("\x00" * pad + element.referent.to_binary_s)
      end
    when NdrPointer
      next if field.referent_id == 0
      pad = (4 - io.offset % 4) % 4
      io.writebytes("\x00" * pad + field.referent.to_binary_s)
    end
  end
end