Module: RubySMB::Dcerpc::Ndr::StructPlugin
Overview
Instance Method Summary
collapse
#defer_ptr, #do_num_bytes_ptr, #get_top_level_constructed_type, #has_deferred_ptrs?, #initialize_instance, #is_deferring, #read_ptr, #write_ptr
Instance Method Details
#bytes_to_align(obj, rel_offset) ⇒ Object
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
|
# File 'lib/ruby_smb/dcerpc/ndr.rb', line 758
def bytes_to_align(obj, rel_offset)
if obj.is_a?(PointerPlugin)
return (4 - (rel_offset % 4)) % 4
end
if obj.is_a?(ConfPlugin)
align = eval_parameter(:byte_align)
pad_length = (align - (4 % align)) % align
rel_offset += (4 + pad_length)
unless obj.is_a?(VarPlugin)
return obj.align_element_size(rel_offset)
end
end
is_a?(BinData::ByteAlignPlugin) ? super : 0
end
|
#do_num_bytes ⇒ Object
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
|
# File 'lib/ruby_smb/dcerpc/ndr.rb', line 734
def do_num_bytes
sum = 0
if should_process_max_count?
max_count = retrieve_max_count
sum += 4 if max_count
if respond_to?(:referent_bytes_align)
sum += referent_bytes_align(sum)
elsif has_parameter?(:byte_align)
sum += bytes_to_align(self, sum)
end
end
sum += super
if has_deferred_ptrs?
sum += do_num_bytes_ptr(sum)
end
sum
end
|
#do_read(io) ⇒ Object
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
|
# File 'lib/ruby_smb/dcerpc/ndr.rb', line 701
def do_read(io)
if should_process_max_count?
set_max_count(io.readbytes(4).unpack('L<').first)
if respond_to?(:referent_bytes_align)
io.seekbytes(referent_bytes_align(io.offset))
elsif has_parameter?(:byte_align)
io.seekbytes(bytes_to_align(self, io.offset))
end
end
super
if has_deferred_ptrs?
read_ptr(io)
end
end
|
#do_write(io) ⇒ Object
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
|
# File 'lib/ruby_smb/dcerpc/ndr.rb', line 681
def do_write(io)
if should_process_max_count?
max_count = retrieve_max_count
io.writebytes([max_count].pack('L<')) if max_count
if respond_to?(:referent_bytes_align)
io.writebytes("\x00" * referent_bytes_align(io.offset))
elsif has_parameter?(:byte_align)
io.writebytes("\x00" * bytes_to_align(self, io.offset))
end
end
super
if has_deferred_ptrs?
write_ptr(io)
end
end
|
#retrieve_max_count ⇒ Object
720
721
722
723
724
725
726
727
|
# File 'lib/ruby_smb/dcerpc/ndr.rb', line 720
def retrieve_max_count
obj = self[field_names.last]
return obj.length if obj.is_a?(ConfPlugin)
return obj.get_max_count(obj) if obj.is_a?(ConfStringPlugin)
if obj.is_a?(NdrStruct)
return obj.retrieve_max_count
end
end
|
#set_max_count(val) ⇒ Object
729
730
731
732
|
# File 'lib/ruby_smb/dcerpc/ndr.rb', line 729
def set_max_count(val)
obj = self[field_names.last]
obj.set_max_count(val)
end
|
#should_process_max_count? ⇒ Boolean
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
|
# File 'lib/ruby_smb/dcerpc/ndr.rb', line 652
def should_process_max_count?
klass = is_a?(PointerPlugin) ? self.class.superclass : self.class
parent_obj = nil
if parent&.is_a?(ConstructedTypePlugin)
parent_obj = parent.get_top_level_constructed_type
end
klass.has_conformant_array && (parent_obj.nil? || parent_obj.is_deferring(self))
end
|