@@ -121,9 +121,11 @@ def cmd_alias_help
121
121
#
122
122
def cmd_alias_tabs ( str , words )
123
123
if words . length <= 1
124
- return @@alias_opts . fmt . keys + tab_complete_aliases_and_commands ( str , words )
124
+ #puts "1 word or less"
125
+ return @@alias_opts . fmt . keys + tab_complete_aliases_and_commands
125
126
else
126
- return tab_complete_aliases_and_commands ( str , words )
127
+ #puts "more than 1 word"
128
+ return tab_complete_aliases_and_commands
127
129
end
128
130
end
129
131
@@ -145,12 +147,22 @@ def register_alias(name, value)
145
147
# define a class instance method that will tab complete the aliased command
146
148
# we just proxy to the top-level tab complete function and let them handle it
147
149
define_method "cmd_#{ name } _tabs" do |str , words |
148
- #print_good "Creating cmd_#{name}_tabs as driver.tab_complete(#{value} #{words.join(' ')})"
149
- #driver.tab_complete("MONKEY")
150
- words . delete ( name )
151
- driver . tab_complete ( "#{ value } #{ words . join ( ' ' ) } " )
150
+ # we need to repair the tab complete string/words and pass back
151
+ # replace alias name with the root alias value
152
+ value_words = value . split ( /[\s \t \n ]+/ ) # in case value is e.g. 'sessions -l'
153
+ words [ 0 ] = value_words [ 0 ]
154
+ value_words . shift
155
+ # insert any remaining parts of value and rebuild the line
156
+ line = words . join ( " " ) + " " + value_words . join ( " " ) + " " + str
157
+ #print_good "passing (#{line.strip}) back to tab_complete"
158
+ # clear current tab_words
159
+ driver . tab_words = [ ]
160
+ driver . tab_complete ( line . strip )
161
+ end
162
+ # add a cmd_#{name}_help method
163
+ define_method "cmd_#{ name } _help" do |*args |
164
+ driver . run_single ( "help #{ value } " )
152
165
end
153
- # we don't need a cmd_#{name}_help method, we just let the original handle that
154
166
end
155
167
# add the alias to the list
156
168
@aliases [ name ] = value
@@ -164,6 +176,7 @@ def deregister_alias(name)
164
176
# remove the methods we defined for this alias
165
177
remove_method ( "cmd_#{ name } " )
166
178
remove_method ( "cmd_#{ name } _tab" )
179
+ remove_method ( "cmd_#{ name } _help" )
167
180
end
168
181
end
169
182
@@ -232,11 +245,17 @@ def is_valid_alias?(name,value)
232
245
#
233
246
# Provide tab completion list for aliases and commands
234
247
#
235
- def tab_complete_aliases_and_commands ( str , words )
248
+ def tab_complete_aliases_and_commands
236
249
items = [ ]
237
- items . concat ( driver . commands . keys ) if driver . respond_to? ( 'commands' )
250
+ # gather all the current commands the driver's dispatcher's have
251
+ driver . dispatcher_stack . each do |dispatcher |
252
+ next unless dispatcher . respond_to? ( :commands )
253
+ next if ( dispatcher . commands . nil? or dispatcher . commands . length == 0 )
254
+ items << dispatcher . commands . keys
255
+ end
256
+ # add all the current aliases to the list
238
257
items . concat ( @aliases . keys )
239
- items
258
+ return items
240
259
end
241
260
242
261
end # end AliasCommandDispatcher class
@@ -248,8 +267,6 @@ def tab_complete_aliases_and_commands(str, words)
248
267
# inheriting from Msf::Plugin to ensure that the framework attribute on
249
268
# their instance gets set.
250
269
#
251
- attr_accessor :controller
252
-
253
270
def initialize ( framework , opts )
254
271
super
255
272
0 commit comments