Skip to content

Commit 1fe1824

Browse files
author
Brent Cook
committed
Allow Internal Filtering by SearchTerm
from @sempervictus Allow passing 'SearchTerm' into Rex::Ui::Text::Table creation to filter all output by regex match to the string passed. Provides base functionality for higher level subscribers such as cmd_ls in meterpreter sessions for filtering output
1 parent 6fd82ad commit 1fe1824

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lib/rex/ui/text/table.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def initialize(opts = {})
7272
self.prefix = opts['Prefix'] || ''
7373
self.postfix = opts['Postfix'] || ''
7474
self.colprops = []
75+
self.scterm = opts['SearchTerm'] ? /#{opts['SearchTerm']}/mi : /./
7576

7677
self.sort_index = opts['SortIndex'] || 0
7778
self.sort_order = opts['SortOrder'] || :forward
@@ -113,7 +114,7 @@ def to_s
113114
if (is_hr(row))
114115
str << hr_to_s
115116
else
116-
str << row_to_s(row)
117+
str << row_to_s(row) if row_to_s(row).match(self.scterm)
117118
end
118119
}
119120

@@ -129,7 +130,7 @@ def to_csv
129130
str = ''
130131
str << ( columns.join(",") + "\n" )
131132
rows.each { |row|
132-
next if is_hr(row)
133+
next if is_hr(row) or !(row_to_s(row).match(self.scterm))
133134
str << ( row.map{|x|
134135
x = x.to_s
135136

@@ -175,7 +176,10 @@ def add_row(fields = [])
175176
raise RuntimeError, 'Invalid number of columns!'
176177
end
177178
fields.each_with_index { |field, idx|
179+
# Remove whitespace and ensure String format
180+
field = field.to_s.strip
178181
if (colprops[idx]['MaxWidth'] < field.to_s.length)
182+
old = colprops[idx]['MaxWidth']
179183
colprops[idx]['MaxWidth'] = field.to_s.length
180184
end
181185
}
@@ -245,7 +249,7 @@ def [](*col_names)
245249
attr_accessor :columns, :rows, :colprops # :nodoc:
246250
attr_accessor :width, :indent, :cellpad # :nodoc:
247251
attr_accessor :prefix, :postfix # :nodoc:
248-
attr_accessor :sort_index, :sort_order # :nodoc:
252+
attr_accessor :sort_index, :sort_order, :scterm # :nodoc:
249253

250254
protected
251255

0 commit comments

Comments
 (0)