@@ -54,39 +54,7 @@ class Driver < Msf::Ui::Driver
54
54
# @option opts [Boolean] 'SkipDatabaseInit' (false) Whether to skip
55
55
# connecting to the database and running migrations
56
56
def initialize ( prompt = DefaultPrompt , prompt_char = DefaultPromptChar , opts = { } )
57
-
58
- # Choose a readline library before calling the parent
59
- rl_err = nil
60
- if opts [ 'RealReadline' ]
61
- # Remove the gem version from load path to be sure we're getting the
62
- # stdlib readline.
63
- gem_dir = Gem ::Specification . find_all_by_name ( 'rb-readline' ) . first . gem_dir
64
- rb_readline_path = File . join ( gem_dir , "lib" )
65
- index = $LOAD_PATH. index ( rb_readline_path )
66
- # Bundler guarantees that the gem will be there, so it should be safe to
67
- # assume we found it in the load path, but check to be on the safe side.
68
- if index
69
- $LOAD_PATH. delete_at ( index )
70
- end
71
- end
72
-
73
- begin
74
- require 'readline'
75
- rescue ::LoadError => e
76
- if rl_err . nil? && index
77
- # Then this is the first time the require failed and we have an index
78
- # for the gem version as a fallback.
79
- rl_err = e
80
- # Put the gem back and see if that works
81
- $LOAD_PATH. insert ( index , rb_readline_path )
82
- index = rb_readline_path = nil
83
- retry
84
- else
85
- # Either we didn't have the gem to fall back on, or we failed twice.
86
- # Nothing more we can do here.
87
- raise e
88
- end
89
- end
57
+ choose_readline ( opts )
90
58
91
59
histfile = opts [ 'HistFile' ] || Msf ::Config . history_file
92
60
@@ -130,9 +98,9 @@ def initialize(prompt = DefaultPrompt, prompt_char = DefaultPromptChar, opts = {
130
98
enstack_dispatcher ( CommandDispatcher ::Core )
131
99
132
100
# Report readline error if there was one..
133
- if not rl_err . nil?
101
+ if ! @ rl_err. nil?
134
102
print_error ( "***" )
135
- print_error ( "* WARNING: Unable to load readline: #{ rl_err } " )
103
+ print_error ( "* WARNING: Unable to load readline: #{ @ rl_err} " )
136
104
print_error ( "* Falling back to RbReadLine" )
137
105
print_error ( "***" )
138
106
end
@@ -737,6 +705,43 @@ def handle_loglevel(val)
737
705
set_log_level ( Msf ::LogSource , val )
738
706
end
739
707
708
+ # Require the appropriate readline library based on the user's preference.
709
+ #
710
+ # @return [void]
711
+ def choose_readline ( opts )
712
+ # Choose a readline library before calling the parent
713
+ @rl_err = nil
714
+ if opts [ 'RealReadline' ]
715
+ # Remove the gem version from load path to be sure we're getting the
716
+ # stdlib readline.
717
+ gem_dir = Gem ::Specification . find_all_by_name ( 'rb-readline' ) . first . gem_dir
718
+ rb_readline_path = File . join ( gem_dir , "lib" )
719
+ index = $LOAD_PATH. index ( rb_readline_path )
720
+ # Bundler guarantees that the gem will be there, so it should be safe to
721
+ # assume we found it in the load path, but check to be on the safe side.
722
+ if index
723
+ $LOAD_PATH. delete_at ( index )
724
+ end
725
+ end
726
+
727
+ begin
728
+ require 'readline'
729
+ rescue ::LoadError => e
730
+ if @rl_err . nil? && index
731
+ # Then this is the first time the require failed and we have an index
732
+ # for the gem version as a fallback.
733
+ @rl_err = e
734
+ # Put the gem back and see if that works
735
+ $LOAD_PATH. insert ( index , rb_readline_path )
736
+ index = rb_readline_path = nil
737
+ retry
738
+ else
739
+ # Either we didn't have the gem to fall back on, or we failed twice.
740
+ # Nothing more we can do here.
741
+ raise e
742
+ end
743
+ end
744
+ end
740
745
end
741
746
742
747
#
@@ -749,6 +754,7 @@ def to_s
749
754
end
750
755
end
751
756
757
+
752
758
end
753
759
end
754
760
end
0 commit comments