Class: Rex::Post::Meterpreter::Extensions::Stdapi::Railgun::ConstManager

Inherits:
Object
  • Object
show all
Defined in:
lib/rex/post/meterpreter/extensions/stdapi/railgun/const_manager.rb

Overview

Manages our library of constants

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(initial_consts = {}) ⇒ ConstManager

Returns a new instance of ConstManager.



85
86
87
88
89
90
91
# File 'lib/rex/post/meterpreter/extensions/stdapi/railgun/const_manager.rb', line 85

def initialize(initial_consts = {})
  @consts = {}

  initial_consts.each_pair do |name, value|
    add_const(name, value)
  end
end

Instance Attribute Details

#constsObject (readonly)

Returns the value of attribute consts.



83
84
85
# File 'lib/rex/post/meterpreter/extensions/stdapi/railgun/const_manager.rb', line 83

def consts
  @consts
end

Instance Method Details

#add_const(name, value) ⇒ Object



93
94
95
# File 'lib/rex/post/meterpreter/extensions/stdapi/railgun/const_manager.rb', line 93

def add_const(name, value)
  consts[name] = value
end

#is_parseable(s) ⇒ Object



116
117
118
# File 'lib/rex/post/meterpreter/extensions/stdapi/railgun/const_manager.rb', line 116

def is_parseable(s)
  return !parse(s).nil?
end

#parse(s) ⇒ Object

parses a string containing constants and returns an integer the string can be either “CONST” or “CONST1 | CONST2”

this function will NOT throw an exception but return “nil” if it can’t parse a string



101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/rex/post/meterpreter/extensions/stdapi/railgun/const_manager.rb', line 101

def parse(s)
  if s.class != String
    return nil # it's not even a string'
  end
  return_value = 0
  for one_const in s.split('|')
    one_const = one_const.strip()
    if not consts.has_key? one_const
      return nil # at least one "Constant" is unknown to us
    end
    return_value |= consts[one_const]
  end
  return return_value
end

#select_const_names(const, filter_regex = nil) ⇒ Object

Returns an array of constant names that have a value matching “const” and (optionally) a name that matches “filter_regex”



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/rex/post/meterpreter/extensions/stdapi/railgun/const_manager.rb', line 124

def select_const_names(const, filter_regex=nil)
  matches = []

  consts.each_pair do |name, value|
    matches << name if value == const
  end

  # Filter matches by name if a filter has been provided
  unless filter_regex.nil?
    matches.reject! do |name|
      name !~ filter_regex
    end
  end

  return matches
end