Skip to content

Commit 68a43fe

Browse files
committed
Add the new generic tab completion functoin
1 parent d815e42 commit 68a43fe

File tree

3 files changed

+37
-29
lines changed

3 files changed

+37
-29
lines changed

lib/msf/ui/console/command_dispatcher/core.rb

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2198,16 +2198,7 @@ def option_values_dispatch(o, str, words)
21982198
if rh and not rh.empty?
21992199
res << Rex::Socket.source_address(rh)
22002200
else
2201-
res << Rex::Socket.source_address
2202-
# getifaddrs was introduced in 2.1.2
2203-
if Socket.respond_to?(:getifaddrs)
2204-
ifaddrs = Socket.getifaddrs.find_all do |ifaddr|
2205-
((ifaddr.flags & Socket::IFF_LOOPBACK) == 0) &&
2206-
ifaddr.addr &&
2207-
ifaddr.addr.ip?
2208-
end
2209-
res += ifaddrs.map { |ifaddr| ifaddr.addr.ip_address }
2210-
end
2201+
res += tab_complete_source_address
22112202
end
22122203
else
22132204
end

lib/msf/ui/console/command_dispatcher/payload.rb

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -167,25 +167,7 @@ def cmd_generate_tabs(str, words)
167167
'-x' => [ :file, ],
168168
'-i' => [ true, ]
169169
}
170-
tab_complete_spec(fmt, str, words)
171-
end
172-
173-
def tab_complete_spec(fmt, str, words)
174-
last_word = words[-1]
175-
fmt = fmt.select { |key, value| last_word == key || !words.include?(key) }
176-
177-
val = fmt[last_word]
178-
return fmt.keys if !val # the last word does not look like a fmtspec
179-
arg = val[0]
180-
return fmt.keys if !arg # the last word is a fmtspec that takes no argument
181-
182-
tabs = []
183-
if arg.to_s.to_sym == :file
184-
tabs = tab_complete_filenames(str, words)
185-
elsif arg.kind_of?(Array)
186-
tabs = arg.map {|a| a.to_s}
187-
end
188-
tabs
170+
tab_complete_generic(fmt, str, words)
189171
end
190172
end
191173
end

lib/rex/ui/text/dispatcher_shell.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,41 @@ def tab_complete_filenames(str, words)
248248
matches
249249
end
250250

251+
def tab_complete_generic(fmt, str, words)
252+
last_word = words[-1]
253+
fmt = fmt.select { |key, value| last_word == key || !words.include?(key) }
254+
255+
val = fmt[last_word]
256+
return fmt.keys if !val # the last word does not look like a fmtspec
257+
arg = val[0]
258+
return fmt.keys if !arg # the last word is a fmtspec that takes no argument
259+
260+
tabs = []
261+
if arg.to_s.to_sym == :address
262+
tabs = tab_complete_source_addresses
263+
elsif arg.to_s.to_sym == :bool
264+
tabs = ['true', 'false']
265+
elsif arg.to_s.to_sym == :file
266+
tabs = tab_complete_filenames(str, words)
267+
elsif arg.kind_of?(Array)
268+
tabs = arg.map {|a| a.to_s}
269+
end
270+
tabs
271+
end
272+
273+
def tab_complete_source_address
274+
addresses = [Rex::Socket.source_address]
275+
# getifaddrs was introduced in 2.1.2
276+
if Socket.respond_to?(:getifaddrs)
277+
ifaddrs = Socket.getifaddrs.find_all do |ifaddr|
278+
((ifaddr.flags & Socket::IFF_LOOPBACK) == 0) &&
279+
ifaddr.addr &&
280+
ifaddr.addr.ip?
281+
end
282+
addresses += ifaddrs.map { |ifaddr| ifaddr.addr.ip_address }
283+
end
284+
addresses
285+
end
251286
end
252287

253288
#

0 commit comments

Comments
 (0)