Class: Rex::Powershell::Function
- Inherits:
-
Object
- Object
- Rex::Powershell::Function
- Defined in:
- lib/rex/powershell/function.rb
Constant Summary collapse
- FUNCTION_REGEX =
Regexp.new(/\[(\w+\[\])\]\$(\w+)\s?=|\[(\w+)\]\$(\w+)\s?=|\[(\w+\[\])\]\s+?\$(\w+)\s+=|\[(\w+)\]\s+\$(\w+)\s?=/i)
- PARAMETER_REGEX =
Regexp.new(/param\s+\(|param\(/im)
Constants included from Obfu
Obfu::EMPTY_LINE_REGEX, Obfu::MULTI_LINE_COMMENTS_REGEX, Obfu::SINGLE_LINE_COMMENTS_REGEX, Obfu::UNIX_EOL_REGEX, Obfu::WHITESPACE_REGEX, Obfu::WINDOWS_EOL_REGEX
Constants included from Parser
Parser::RESERVED_VARIABLE_NAMES
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
-
#name ⇒ Object
Returns the value of attribute name.
-
#params ⇒ Object
Returns the value of attribute params.
Instance Method Summary collapse
-
#initialize(name, code) ⇒ Function
constructor
A new instance of Function.
-
#populate_params ⇒ Object
Identify the parameters from the code and store as Param in @params.
-
#to_s ⇒ String
To String.
Methods included from Obfu
descate_string_literal, scate_string_literal, #standard_subs, #strip_comments, #strip_empty_lines, #strip_whitespace, #sub_funcs, #sub_vars
Methods included from Parser
#block_extract, #get_func, #get_func_names, #get_string_literals, #get_var_names, #match_start, #scan_with_index
Methods included from Output
#compress_code, #decode_code, #decompress_code, #deflate_code, #encode_code, #gzip_code, #size, #to_s_lineno
Constructor Details
#initialize(name, code) ⇒ Function
Returns a new instance of Function.
14 15 16 17 18 |
# File 'lib/rex/powershell/function.rb', line 14 def initialize(name, code) @name = name @code = code populate_params end |
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code.
8 9 10 |
# File 'lib/rex/powershell/function.rb', line 8 def code @code end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/rex/powershell/function.rb', line 8 def name @name end |
#params ⇒ Object
Returns the value of attribute params.
8 9 10 |
# File 'lib/rex/powershell/function.rb', line 8 def params @params end |
Instance Method Details
#populate_params ⇒ Object
Identify the parameters from the code and store as Param in @params
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/rex/powershell/function.rb', line 32 def populate_params @params = [] start = code.index(PARAMETER_REGEX) return unless start # Get start of our block idx = scan_with_index('(', code[start..-1]).first.last + start pclause = block_extract(idx) matches = pclause.scan(FUNCTION_REGEX) # Ignore assignment, create params with class and variable names matches.each do |param| klass = nil name = nil param.each do |value| if value if klass name = value @params << Param.new(klass, name) break else klass = value end end end end end |
#to_s ⇒ String
To String
24 25 26 |
# File 'lib/rex/powershell/function.rb', line 24 def to_s "function #{name} #{code}" end |