Class: RubySMB::Dcerpc::Ndr::NdrStruct
- Inherits:
-
BinData::Record
- Object
- BinData::Record
- RubySMB::Dcerpc::Ndr::NdrStruct
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.
Instance Method Summary
collapse
Instance Method Details
#do_read(io) ⇒ Object
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
|
# File 'lib/ruby_smb/dcerpc/ndr.rb', line 213
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
|
# File 'lib/ruby_smb/dcerpc/ndr.rb', line 234
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
|