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

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

Overview

Manages our library of windows constants

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(initial_consts = {}) ⇒ WinConstManager

Returns a new instance of WinConstManager.



39
40
41
42
43
44
45
# File 'lib/rex/post/meterpreter/extensions/stdapi/railgun/win_const_manager.rb', line 39

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.



37
38
39
# File 'lib/rex/post/meterpreter/extensions/stdapi/railgun/win_const_manager.rb', line 37

def consts
  @consts
end

Instance Method Details

#add_const(name, value) ⇒ Object



47
48
49
# File 'lib/rex/post/meterpreter/extensions/stdapi/railgun/win_const_manager.rb', line 47

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

#is_parseable(s) ⇒ Object



70
71
72
# File 'lib/rex/post/meterpreter/extensions/stdapi/railgun/win_const_manager.rb', line 70

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

#parse(s) ⇒ Object

parses a string constaining 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



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/rex/post/meterpreter/extensions/stdapi/railgun/win_const_manager.rb', line 55

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(winconst, filter_regex = nil) ⇒ Object

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



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/rex/post/meterpreter/extensions/stdapi/railgun/win_const_manager.rb', line 78

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

  consts.each_pair do |name, value|
    matches << name if value == winconst
  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