class Rex::Post::Meterpreter::Extensions::Stdapi::Sys::ProcessList

Simple wrapper class for storing processes

Public Instance Methods

to_table(opts={}) click to toggle source

Create a Rex::Ui::Text::Table out of the processes stored in this list

opts is passed on to Rex::Ui::Text::Table.new, mostly unmolested

Note that this output is affected by Rex::Post::Meterpreter::Client#unicode_filter_encode

# File lib/rex/post/meterpreter/extensions/stdapi/sys/process.rb, line 385
def to_table(opts={})
  if empty?
    return Rex::Ui::Text::Table.new(opts)
  end

  cols = [ "PID", "PPID", "Name", "Arch", "Session", "User", "Path" ]
  # Arch and Session are specific to native Windows, PHP and Java can't do
  # 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? }

  opts = {
    'Header' => 'Process List',
    'Indent' => 1,
    'Columns' => cols
  }.merge(opts)

  tbl = Rex::Ui::Text::Table.new(opts)
  each { |process|
    tbl << cols.map { |c|
      col = c.downcase
      val = process[col]
      if col == 'session'
        val == 0xFFFFFFFF ? '' : val.to_s
      elsif col == 'arch'
        # for display and consistency with payload naming we switch the internal
        # 'x86_64' value to display 'x64'
        val == ARCH_X86_64 ? 'x64' : val
      else
        val
      end
    }.compact
  }

  tbl
end