Browse Source

remove rex::ui::text:table

remove the class from msf, and update the rex-text
gem to pull the code in under the new version at Rex::Text::Table
modify all requires appropriately

MS-1875
David Maloney 3 years ago
parent
commit
3f530f1896
No account linked to committer's email address
7 changed files with 11 additions and 423 deletions
  1. 6
    6
      Gemfile.lock
  2. 1
    1
      lib/rex/pescan/analyze.rb
  3. 1
    1
      lib/rex/ropbuilder/rop.rb
  4. 1
    1
      lib/rex/sslscan/result.rb
  5. 1
    1
      lib/rex/ui.rb
  6. 0
    412
      lib/rex/ui/text/table.rb
  7. 1
    1
      plugins/alias.rb

+ 6
- 6
Gemfile.lock View File

@@ -112,12 +112,12 @@ GEM
112 112
       multi_test (>= 0.1.2)
113 113
     cucumber-core (1.5.0)
114 114
       gherkin (~> 4.0)
115
-    cucumber-rails (1.4.3)
115
+    cucumber-rails (1.4.4)
116 116
       capybara (>= 1.1.2, < 3)
117 117
       cucumber (>= 1.3.8, < 3)
118 118
       mime-types (>= 1.16, < 4)
119 119
       nokogiri (~> 1.5)
120
-      railties (>= 3, < 5)
120
+      railties (>= 3, < 5.1)
121 121
     cucumber-wire (0.0.1)
122 122
     diff-lcs (1.2.5)
123 123
     docile (1.1.5)
@@ -223,7 +223,7 @@ GEM
223 223
     recog (2.0.21)
224 224
       nokogiri
225 225
     redcarpet (3.3.4)
226
-    rex-arch (0.1.0)
226
+    rex-arch (0.1.1)
227 227
       rex-text
228 228
     rex-java (0.1.2)
229 229
     rex-ole (0.1.2)
@@ -235,12 +235,12 @@ GEM
235 235
       rex-text
236 236
     rex-registry (0.1.0)
237 237
     rex-struct2 (0.1.0)
238
-    rex-text (0.1.1)
238
+    rex-text (0.1.2)
239 239
     rex-zip (0.1.0)
240 240
       rex-text
241 241
     rkelly-remix (0.0.6)
242 242
     robots (0.10.1)
243
-    rspec-core (3.5.1)
243
+    rspec-core (3.5.2)
244 244
       rspec-support (~> 3.5.0)
245 245
     rspec-expectations (3.5.0)
246 246
       diff-lcs (>= 1.2.0, < 2.0)
@@ -282,7 +282,7 @@ GEM
282 282
     windows_error (0.0.2)
283 283
     xpath (2.0.0)
284 284
       nokogiri (~> 1.3)
285
-    yard (0.9.0)
285
+    yard (0.9.5)
286 286
 
287 287
 PLATFORMS
288 288
   ruby

+ 1
- 1
lib/rex/pescan/analyze.rb View File

@@ -3,7 +3,7 @@ module Rex
3 3
 module PeScan
4 4
 module Analyze
5 5
 
6
-  require "rex/ui/text/table"
6
+  require "rex/text/table"
7 7
 
8 8
   class Fingerprint
9 9
     attr_accessor :pe

+ 1
- 1
lib/rex/ropbuilder/rop.rb View File

@@ -1,7 +1,7 @@
1 1
 # -*- coding: binary -*-
2 2
 require 'metasm'
3 3
 require 'rex/compat'
4
-require 'rex/ui/text/table'
4
+require 'rex/text/table'
5 5
 require 'rex/ui/text/output/stdio'
6 6
 require 'rex/ui/text/color'
7 7
 

+ 1
- 1
lib/rex/sslscan/result.rb View File

@@ -1,7 +1,7 @@
1 1
 # -*- coding: binary -*-
2 2
 
3 3
 require 'rex/socket'
4
-require 'rex/ui/text/table'
4
+require 'rex/text/table'
5 5
 
6 6
 module Rex::SSLScan
7 7
 class Result

+ 1
- 1
lib/rex/ui.rb View File

@@ -15,7 +15,7 @@ require 'rex/ui/text/dispatcher_shell'
15 15
 require 'rex/ui/text/irb_shell'
16 16
 
17 17
 require 'rex/ui/text/color'
18
-require 'rex/ui/text/table'
18
+require 'rex/text/table'
19 19
 
20 20
 # Ui subscriber
21 21
 require 'rex/ui/subscriber'

+ 0
- 412
lib/rex/ui/text/table.rb View File

@@ -1,412 +0,0 @@
1
-# -*- coding: binary -*-
2
-require 'rex/ui'
3
-require 'rex/socket'
4
-
5
-module Rex
6
-module Ui
7
-module Text
8
-
9
-###
10
-#
11
-# Prints text in a tablized format.  Pretty lame at the moment, but
12
-# whatever.
13
-#
14
-###
15
-class Table
16
-
17
-  #
18
-  # Initializes a text table instance using the supplied properties.  The
19
-  # Table class supports the following hash attributes:
20
-  #
21
-  # Header
22
-  #
23
-  #	The string to display as a heading above the table.  If none is
24
-  #	specified, no header will be displayed.
25
-  #
26
-  # HeaderIndent
27
-  #
28
-  # 	The amount of space to indent the header.  The default is zero.
29
-  #
30
-  # Columns
31
-  #
32
-  # 	The array of columns that will exist within the table.
33
-  #
34
-  # Rows
35
-  #
36
-  # 	The array of rows that will exist.
37
-  #
38
-  # Width
39
-  #
40
-  # 	The maximum width of the table in characters.
41
-  #
42
-  # Indent
43
-  #
44
-  # 	The number of characters to indent the table.
45
-  #
46
-  # CellPad
47
-  #
48
-  # 	The number of characters to put between each horizontal cell.
49
-  #
50
-  # Prefix
51
-  #
52
-  # 	The text to prefix before the table.
53
-  #
54
-  # Postfix
55
-  #
56
-  # 	The text to affix to the end of the table.
57
-  #
58
-  # Sortindex
59
-  #
60
-  #	The column to sort the table on, -1 disables sorting.
61
-  #
62
-  def initialize(opts = {})
63
-    self.header   = opts['Header']
64
-    self.headeri  = opts['HeaderIndent'] || 0
65
-    self.columns  = opts['Columns'] || []
66
-    # updated below if we got a "Rows" option
67
-    self.rows     = []
68
-
69
-    self.width    = opts['Width']   || 80
70
-    self.indent   = opts['Indent']  || 0
71
-    self.cellpad  = opts['CellPad'] || 2
72
-    self.prefix   = opts['Prefix']  || ''
73
-    self.postfix  = opts['Postfix'] || ''
74
-    self.colprops = []
75
-    self.scterm   = /#{opts['SearchTerm']}/mi if opts['SearchTerm']
76
-
77
-    self.sort_index  = opts['SortIndex'] || 0
78
-    self.sort_order  = opts['SortOrder'] || :forward
79
-
80
-    # Default column properties
81
-    self.columns.length.times { |idx|
82
-      self.colprops[idx] = {}
83
-      self.colprops[idx]['MaxWidth'] = self.columns[idx].length
84
-    }
85
-
86
-    # ensure all our internal state gets updated with the given rows by
87
-    # using add_row instead of just adding them to self.rows.  See #3825.
88
-    opts['Rows'].each { |row| add_row(row) } if opts['Rows']
89
-
90
-    # Merge in options
91
-    if (opts['ColProps'])
92
-      opts['ColProps'].each_key { |col|
93
-        idx = self.columns.index(col)
94
-
95
-        if (idx)
96
-          self.colprops[idx].merge!(opts['ColProps'][col])
97
-        end
98
-      }
99
-    end
100
-
101
-  end
102
-
103
-  #
104
-  # Converts table contents to a string.
105
-  #
106
-  def to_s
107
-    str  = prefix.dup
108
-    str << header_to_s || ''
109
-    str << columns_to_s || ''
110
-    str << hr_to_s || ''
111
-
112
-    sort_rows
113
-    rows.each { |row|
114
-      if (is_hr(row))
115
-        str << hr_to_s
116
-      else
117
-        str << row_to_s(row) if row_visible(row)
118
-      end
119
-    }
120
-
121
-    str << postfix
122
-
123
-    return str
124
-  end
125
-
126
-  #
127
-  # Converts table contents to a csv
128
-  #
129
-  def to_csv
130
-    str = ''
131
-    str << ( columns.join(",") + "\n" )
132
-    rows.each { |row|
133
-      next if is_hr(row) || !row_visible(row)
134
-      str << ( row.map{|x|
135
-        x = x.to_s
136
-        x.gsub(/[\r\n]/, ' ').gsub(/\s+/, ' ').gsub('"', '""')
137
-      }.map{|x| "\"#{x}\"" }.join(",") + "\n" )
138
-    }
139
-    str
140
-  end
141
-
142
-  #
143
-  #
144
-  # Returns the header string.
145
-  #
146
-  def header_to_s # :nodoc:
147
-    if (header)
148
-      pad = " " * headeri
149
-
150
-      return pad + header + "\n" + pad + "=" * header.length + "\n\n"
151
-    end
152
-
153
-    return ''
154
-  end
155
-
156
-  #
157
-  # Prints the contents of the table.
158
-  #
159
-  def print
160
-    puts to_s
161
-  end
162
-
163
-  #
164
-  # Adds a row using the supplied fields.
165
-  #
166
-  def <<(fields)
167
-    add_row(fields)
168
-  end
169
-
170
-  #
171
-  # Adds a row with the supplied fields.
172
-  #
173
-  def add_row(fields = [])
174
-    if fields.length != self.columns.length
175
-      raise RuntimeError, 'Invalid number of columns!'
176
-    end
177
-    fields.each_with_index { |field, idx|
178
-      # Remove whitespace and ensure String format
179
-      field = field.to_s.strip
180
-      if (colprops[idx]['MaxWidth'] < field.to_s.length)
181
-        old = colprops[idx]['MaxWidth']
182
-        colprops[idx]['MaxWidth'] = field.to_s.length
183
-      end
184
-    }
185
-
186
-    rows << fields
187
-  end
188
-
189
-  #
190
-  # Sorts the rows based on the supplied index of sub-arrays
191
-  # If the supplied index is an IPv4 address, handle it differently, but
192
-  # avoid actually resolving domain names.
193
-  #
194
-  def sort_rows(index = sort_index, order = sort_order)
195
-    return if index == -1
196
-    return unless rows
197
-    rows.sort! do |a,b|
198
-      if a[index].nil?
199
-        cmp = -1
200
-      elsif b[index].nil?
201
-        cmp = 1
202
-      elsif Rex::Socket.dotted_ip?(a[index]) and Rex::Socket.dotted_ip?(b[index])
203
-        cmp = Rex::Socket::addr_atoi(a[index]) <=> Rex::Socket::addr_atoi(b[index])
204
-      elsif a[index] =~ /^[0-9]+$/ and b[index] =~ /^[0-9]+$/
205
-        cmp = a[index].to_i <=> b[index].to_i
206
-      elsif a[index].kind_of?(IPAddr) && a[index].kind_of?(IPAddr) && a[index].ipv6? && b[index].ipv4?
207
-        cmp = 1
208
-      elsif a[index].kind_of?(IPAddr) && b[index].kind_of?(IPAddr) && a[index].ipv4? && b[index].ipv6?
209
-        cmp = -1
210
-      else
211
-        cmp = a[index] <=> b[index] # assumes otherwise comparable.
212
-      end
213
-      order == :forward ? cmp : -cmp
214
-    end
215
-  end
216
-
217
-  #
218
-  # Adds a horizontal line.
219
-  #
220
-  def add_hr
221
-    rows << '__hr__'
222
-  end
223
-
224
-  #
225
-  # Returns new sub-table with headers and rows maching column names submitted
226
-  #
227
-  #
228
-  # Flips table 90 degrees left
229
-  #
230
-  def drop_left
231
-    tbl = self.class.new(
232
-      'Columns' => Array.new(self.rows.count+1,'  '),
233
-      'Header' => self.header,
234
-      'Indent' => self.indent)
235
-    (self.columns.count+1).times do |ti|
236
-      row = self.rows.map {|r| r[ti]}.unshift(self.columns[ti]).flatten
237
-      # insert our col|row break. kind of hackish
238
-      row[1] = "| #{row[1]}" unless row.all? {|e| e.nil? || e.empty?}
239
-      tbl << row
240
-    end
241
-    return tbl
242
-  end
243
-
244
-  #
245
-  # Build table from CSV dump
246
-  #
247
-  def self.new_from_csv(csv)
248
-    # Read in or keep data, get CSV or die
249
-    if csv.is_a?(String)
250
-      csv = File.file?(csv) ? CSV.read(csv) : CSV.parse(csv)
251
-    end
252
-    # Adjust for skew
253
-    if csv.first == ["Keys", "Values"]
254
-      csv.shift # drop marker
255
-      cols = []
256
-      rows = []
257
-      csv.each do |row|
258
-        cols << row.shift
259
-        rows << row
260
-      end
261
-      tbl = self.new('Columns' => cols)
262
-      rows.in_groups_of(cols.count) {|r| tbl << r.flatten}
263
-    else
264
-      tbl = self.new('Columns' => csv.shift)
265
-      while !csv.empty? do
266
-        tbl << csv.shift
267
-      end
268
-    end
269
-    return tbl
270
-  end
271
-
272
-  def [](*col_names)
273
-    tbl = self.class.new('Indent' => self.indent,
274
-                         'Header' => self.header,
275
-                         'Columns' => col_names)
276
-    indexes = []
277
-
278
-    col_names.each do |col_name|
279
-      index = self.columns.index(col_name)
280
-      raise RuntimeError, "Invalid column name #{col_name}" if index.nil?
281
-      indexes << index
282
-    end
283
-
284
-    self.rows.each do |old_row|
285
-      new_row = []
286
-      indexes.map {|i| new_row << old_row[i]}
287
-      tbl << new_row
288
-    end
289
-
290
-    return tbl
291
-  end
292
-
293
-
294
-  alias p print
295
-
296
-  attr_accessor :header, :headeri # :nodoc:
297
-  attr_accessor :columns, :rows, :colprops # :nodoc:
298
-  attr_accessor :width, :indent, :cellpad # :nodoc:
299
-  attr_accessor :prefix, :postfix # :nodoc:
300
-  attr_accessor :sort_index, :sort_order, :scterm # :nodoc:
301
-
302
-protected
303
-
304
-  #
305
-  # Returns if a row should be visible or not
306
-  #
307
-  def row_visible(row)
308
-    return true if self.scterm.nil?
309
-    row_to_s(row).match(self.scterm)
310
-  end
311
-
312
-  #
313
-  # Defaults cell widths and alignments.
314
-  #
315
-  def defaults # :nodoc:
316
-    self.columns.length.times { |idx|
317
-    }
318
-  end
319
-
320
-  #
321
-  # Checks to see if the row is an hr.
322
-  #
323
-  def is_hr(row) # :nodoc:
324
-    return ((row.kind_of?(String)) && (row == '__hr__'))
325
-  end
326
-
327
-  #
328
-  # Converts the columns to a string.
329
-  #
330
-  def columns_to_s # :nodoc:
331
-    nameline = ' ' * indent
332
-    barline  = nameline.dup
333
-    last_col = nil
334
-    last_idx = nil
335
-    columns.each_with_index { |col,idx|
336
-      if (last_col)
337
-        # This produces clean to_s output without truncation
338
-        # Preserves full string in cells for to_csv output
339
-        padding = pad(' ', last_col, last_idx)
340
-        nameline << padding
341
-        remainder = padding.length - cellpad
342
-        remainder = 0 if remainder < 0
343
-        barline << (' ' * (cellpad + remainder))
344
-      end
345
-
346
-      nameline << col
347
-      barline << ('-' * col.length)
348
-
349
-      last_col = col
350
-      last_idx = idx
351
-    }
352
-
353
-    return "#{nameline}\n#{barline}"
354
-  end
355
-
356
-  #
357
-  # Converts an hr to a string.
358
-  #
359
-  def hr_to_s # :nodoc:
360
-    return "\n"
361
-  end
362
-
363
-  #
364
-  # Converts a row to a string.
365
-  #
366
-  def row_to_s(row) # :nodoc:
367
-    line = ' ' * indent
368
-    last_cell = nil
369
-    last_idx = nil
370
-    row.each_with_index { |cell, idx|
371
-      if (idx != 0)
372
-        line << pad(' ', last_cell.to_s, last_idx)
373
-      end
374
-      # Limit wide cells
375
-      if colprops[idx]['MaxChar']
376
-        last_cell = cell.to_s[0..colprops[idx]['MaxChar'].to_i]
377
-        line << last_cell
378
-      else
379
-        line << cell.to_s
380
-        last_cell = cell
381
-      end
382
-      last_idx = idx
383
-    }
384
-
385
-    return line + "\n"
386
-  end
387
-
388
-  #
389
-  # Pads out with the supplied character for the remainder of the space given
390
-  # some text and a column index.
391
-  #
392
-  def pad(chr, buf, colidx, use_cell_pad = true) # :nodoc:
393
-    # Ensure we pad the minimum required amount
394
-    max = colprops[colidx]['MaxChar'] || colprops[colidx]['MaxWidth']
395
-    max = colprops[colidx]['MaxWidth'] if max.to_i > colprops[colidx]['MaxWidth'].to_i
396
-    remainder = max - buf.length
397
-    remainder = 0 if remainder < 0
398
-    val       = chr * remainder
399
-
400
-    if (use_cell_pad)
401
-      val << ' ' * cellpad
402
-    end
403
-
404
-    return val
405
-  end
406
-
407
-
408
-end
409
-
410
-end
411
-end
412
-end

+ 1
- 1
plugins/alias.rb View File

@@ -1,4 +1,4 @@
1
-require 'rex/ui/text/table'
1
+require 'rex/text/table'
2 2
 
3 3
 module Msf
4 4
 

Loading…
Cancel
Save