lib/rex/post/meterpreter/extensions/stdapi/railgun/win_const_manager.rb in librex-0.0.65 vs lib/rex/post/meterpreter/extensions/stdapi/railgun/win_const_manager.rb in librex-0.0.66

- old
+ new

@@ -1,5 +1,6 @@ +# -*- coding: binary -*- # Copyright (c) 2010, patrickHVE@googlemail.com # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: @@ -31,23 +32,22 @@ # # Manages our library of windows constants # class WinConstManager + attr_reader :consts def initialize(initial_consts = {}) @consts = {} initial_consts.each_pair do |name, value| add_const(name, value) end - - # Load utility end def add_const(name, value) - @consts[name] = value + consts[name] = value end # parses a string constaining constants and returns an integer # the string can be either "CONST" or "CONST1 | CONST2" # @@ -57,19 +57,40 @@ 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 + if not consts.has_key? one_const return nil # at least one "Constant" is unknown to us end - return_value |= @consts[one_const] + return_value |= consts[one_const] end return return_value end def is_parseable(s) - return parse(s) != nil + return !parse(s).nil? + end + + # + # Returns an array of constant names that have a value matching "winconst" + # and (optionally) a name that matches "filter_regex" + # + 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 end end; end; end; end; end; end