@@ -568,116 +568,85 @@ def self.dump_generic_module(mod, indent = '')
568568 # @param indent [String] the indentation to use.
569569 # @param missing [Boolean] dump only empty required options.
570570 # @return [String] the string form of the information.
571- def self . dump_options ( mod , indent = '' , missing = false )
572- options = mod . options . map { |_name , option | option }
573- options_grouped_by_conditions = options . group_by ( &:conditions )
571+ def self . dump_options ( mod , indent = '' , missing = false , advanced : false , evasion : false )
572+ filtered_options = mod . options . values . select { |opt | opt . advanced? == advanced && opt . evasion? == evasion }
574573
575- options_with_conditions = '' . dup
576- options_without_conditions = '' . dup
574+ options_grouped_by_conditions = filtered_options . group_by ( &:conditions )
577575
578- options_grouped_by_conditions . each do |conditions , options |
579- tbl = Rex ::Text ::Table . new (
580- 'Indent' => indent . length ,
581- 'Columns' =>
582- [
583- 'Name' ,
584- 'Current Setting' ,
585- 'Required' ,
586- 'Description'
587- ] )
588-
589- options . sort_by ( &:name ) . each do |opt |
590- name = opt . name
591- if mod . datastore . is_a? ( Msf ::DataStoreWithFallbacks )
592- val = mod . datastore [ name ]
593- else
594- val = mod . datastore [ name ] . nil? ? opt . default : mod . datastore [ name ]
595- end
576+ option_tables = [ ]
596577
597- next if ( opt . advanced? )
598- next if ( opt . evasion? )
599- next if ( missing && opt . valid? ( val ) )
600-
601- desc = opt . desc . dup
602-
603- # Hint at RPORT proto by regexing mixins
604- if name == 'RPORT' && opt . kind_of? ( Msf ::OptPort )
605- mod . class . included_modules . each do |m |
606- case m . name
607- when /tcp/i , /HttpClient$/
608- desc << ' (TCP)'
609- break
610- when /udp/i
611- desc << ' (UDP)'
612- break
613- end
614- end
615- end
616-
617- tbl << [ name , opt . display_value ( val ) , opt . required? ? "yes" : "no" , desc ]
618- end
578+ options_grouped_by_conditions . sort . each do |conditions , options |
579+ tbl = options_table ( missing , mod , options , indent )
619580
620- next if conditions . any? && tbl . rows . empty?
581+ next if tbl . rows . empty?
621582
622583 if conditions . any?
623- options_with_conditions << "\n \n #{ indent } When #{ Msf ::OptCondition . format_conditions ( mod , options . first ) } :\n \n "
624- options_with_conditions << tbl . to_s
584+ option_tables << "#{ indent } When #{ Msf ::OptCondition . format_conditions ( mod , options . first ) } :\n \n #{ tbl } "
625585 else
626- options_without_conditions << tbl . to_s
586+ option_tables << tbl . to_s
627587 end
628588 end
629589
630- result = " #{ options_without_conditions } #{ options_with_conditions } "
590+ result = option_tables . join ( " \n \n " )
631591 result
632592 end
633593
634- # Dumps the advanced options associated with the supplied module.
594+ # Creates the table for the given module options
635595 #
596+ # @param missing [Boolean] dump only empty required options.
636597 # @param mod [Msf::Module] the module.
598+ # @param options [Array<Msf::OptBase>] The options to be added to the table
637599 # @param indent [String] the indentation to use.
638- # @return [String] the string form of the information.
639- def self . dump_advanced_options ( mod , indent = '' )
640- options = mod . options . map { |_name , option | option }
641- options_grouped_by_conditions = options . group_by ( &:conditions )
642-
643- options_with_conditions = '' . dup
644- options_without_conditions = '' . dup
645-
646- options_grouped_by_conditions . each do |conditions , options |
647- tbl = Rex ::Text ::Table . new (
648- 'Indent' => indent . length ,
649- 'Columns' =>
650- [
651- 'Name' ,
652- 'Current Setting' ,
653- 'Required' ,
654- 'Description'
655- ] )
656-
657- options . sort_by ( &:name ) . each do |opt |
658- next unless opt . advanced?
659-
660- name = opt . name
661- if mod . datastore . is_a? ( Msf ::DataStoreWithFallbacks )
662- val = mod . datastore [ name ]
663- else
664- val = mod . datastore [ name ] . nil? ? opt . default : mod . datastore [ name ]
600+ #
601+ # @return [String] the string form of the table.
602+ def self . options_table ( missing , mod , options , indent )
603+ tbl = Rex ::Text ::Table . new (
604+ 'Indent' => indent . length ,
605+ 'Columns' =>
606+ [
607+ 'Name' ,
608+ 'Current Setting' ,
609+ 'Required' ,
610+ 'Description'
611+ ]
612+ )
613+ options . sort_by ( &:name ) . each do |opt |
614+ name = opt . name
615+ if mod . datastore . is_a? ( Msf ::DataStoreWithFallbacks )
616+ val = mod . datastore [ name ]
617+ else
618+ val = mod . datastore [ name ] . nil? ? opt . default : mod . datastore [ name ]
619+ end
620+ next if ( missing && opt . valid? ( val ) )
621+
622+ desc = opt . desc . dup
623+
624+ # Hint at RPORT proto by regexing mixins
625+ if name == 'RPORT' && opt . kind_of? ( Msf ::OptPort )
626+ mod . class . included_modules . each do |m |
627+ case m . name
628+ when /tcp/i , /HttpClient$/
629+ desc << ' (TCP)'
630+ break
631+ when /udp/i
632+ desc << ' (UDP)'
633+ break
634+ end
665635 end
666- tbl << [ name , opt . display_value ( val ) , opt . required? ? "yes" : "no" , opt . desc ]
667636 end
668637
669- next if conditions . any? && tbl . rows . empty?
670-
671- if conditions . any?
672- options_with_conditions << "\n \n #{ indent } Active when #{ Msf ::OptCondition . format_conditions ( mod , options . first ) } :\n \n "
673- options_with_conditions << tbl . to_s
674- else
675- options_without_conditions << tbl . to_s
676- end
638+ tbl << [ name , opt . display_value ( val ) , opt . required? ? "yes" : "no" , desc ]
677639 end
640+ tbl
641+ end
678642
679- result = "#{ options_without_conditions } #{ options_with_conditions } "
680- result
643+ # Dumps the advanced options associated with the supplied module.
644+ #
645+ # @param mod [Msf::Module] the module.
646+ # @param indent [String] the indentation to use.
647+ # @return [String] the string form of the information.
648+ def self . dump_advanced_options ( mod , indent = '' )
649+ return dump_options ( mod , indent , advanced : true )
681650 end
682651
683652 # Dumps the evasion options associated with the supplied module.
@@ -686,46 +655,7 @@ def self.dump_advanced_options(mod, indent = '')
686655 # @param indent [String] the indentation to use.
687656 # @return [String] the string form of the information.
688657 def self . dump_evasion_options ( mod , indent = '' )
689- options = mod . options . map { |_name , option | option }
690- options_grouped_by_conditions = options . group_by ( &:conditions )
691-
692- options_with_conditions = '' . dup
693- options_without_conditions = '' . dup
694-
695- options_grouped_by_conditions . each do |conditions , options |
696- tbl = Rex ::Text ::Table . new (
697- 'Indent' => indent . length ,
698- 'Columns' =>
699- [
700- 'Name' ,
701- 'Current Setting' ,
702- 'Required' ,
703- 'Description'
704- ] )
705-
706- options . sort_by ( &:name ) . each do |opt |
707- next unless opt . evasion?
708-
709- name = opt . name
710- if mod . datastore . is_a? ( Msf ::DataStoreWithFallbacks )
711- val = mod . datastore [ name ]
712- else
713- val = mod . datastore [ name ] . nil? ? opt . default : mod . datastore [ name ]
714- end
715- tbl << [ name , opt . display_value ( val ) , opt . required? ? "yes" : "no" , opt . desc ]
716- end
717-
718- next if conditions . any? && tbl . rows . empty?
719-
720- if conditions . any?
721- options_with_conditions << "\n \n #{ indent } When #{ Msf ::OptCondition . format_conditions ( mod , options . first ) } :\n \n "
722- options_with_conditions << tbl . to_s
723- else
724- options_without_conditions << tbl . to_s
725- end
726- end
727- result = "#{ options_without_conditions } #{ options_with_conditions } "
728- result
658+ return dump_options ( mod , indent , evasion : true )
729659 end
730660
731661 # Dumps the references associated with the supplied module.
0 commit comments