Clean up cmd_ps table output for Mettle

Mettle can run in all sorts of environments where some colums of a
process table will be nil. The existing implementation compacts
rows going into the table while providing filtering for the colum
contents only by checking the output of the first row in the proc
table.

Check column filters against all rows to ensure proper table init.
Check columns going into table for match against header.
Do not compact nil values in the table rows - some things, like
kthreads/workers dont have a path while other PIDs will.
bug/bundler_fix
RageLtMan 2017-06-12 01:20:59 -04:00
parent bf674263f3
commit 762427b447
1 changed files with 6 additions and 2 deletions

View File

@ -395,7 +395,10 @@ class ProcessList < Array
# ppid. Cut columns from the list if they aren't there. It is conceivable
# that processes might have different columns, but for now assume that the
# first one is representative.
cols.delete_if { |c| !( first.has_key?(c.downcase) ) or first[c.downcase].nil? }
cols.delete_if do |c|
!(any? {|r| r.has_key?(c.downcase)}) or
all? {|r| r[c.downcase].nil?}
end
opts = {
'Header' => 'Process List',
@ -406,6 +409,7 @@ class ProcessList < Array
tbl = Rex::Text::Table.new(opts)
each { |process|
tbl << cols.map { |c|
next unless cols.any? {|h| h.downcase == c.downcase}
col = c.downcase
val = process[col]
if col == 'session'
@ -413,7 +417,7 @@ class ProcessList < Array
else
val
end
}.compact
}
}
tbl