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
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
|
# File 'lib/ruby_smb/dcerpc/ndr.rb', line 784
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
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
|
# File 'lib/ruby_smb/dcerpc/ndr.rb', line 760
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
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
|
# File 'lib/ruby_smb/dcerpc/ndr.rb', line 723
def do_read(io)
if should_process_max_count?
max_count = io.readbytes(4).unpack1('L<')
BinData.trace_message do |tracer|
tracer.trace_obj("#{debug_name}.max_count", max_count.to_s)
end
set_max_count(max_count)
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
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
|
# File 'lib/ruby_smb/dcerpc/ndr.rb', line 703
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
746
747
748
749
750
751
752
753
|
# File 'lib/ruby_smb/dcerpc/ndr.rb', line 746
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
755
756
757
758
|
# File 'lib/ruby_smb/dcerpc/ndr.rb', line 755
def set_max_count(val)
obj = self[field_names.last]
obj.set_max_count(val)
end
|
#should_process_max_count? ⇒ Boolean
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
|
# File 'lib/ruby_smb/dcerpc/ndr.rb', line 674
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
|