Class: Metasploit::Framework::Obfuscation::CRandomizer::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/metasploit/framework/obfuscation/crandomizer/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(weight, fake_functions = nil) ⇒ Parser

Initializes a Metasploit::Framework::Obfuscation::CRandomizer::Parser instance.

Parameters:



17
18
19
20
# File 'lib/metasploit/framework/obfuscation/crandomizer/parser.rb', line 17

def initialize(weight, fake_functions=nil)
  @max_random_weight = weight
  @fake_functions_collection = fake_functions
end

Instance Attribute Details

#fake_functions_collectionObject

Returns the value of attribute fake_functions_collection.



11
12
13
# File 'lib/metasploit/framework/obfuscation/crandomizer/parser.rb', line 11

def fake_functions_collection
  @fake_functions_collection
end

#max_random_weightObject

Returns the value of attribute max_random_weight.



10
11
12
# File 'lib/metasploit/framework/obfuscation/crandomizer/parser.rb', line 10

def max_random_weight
  @max_random_weight
end

Instance Method Details

#parse(template) ⇒ Metasm::C::Parser

Returns a parser.

Parameters:

  • template (String)

    Source code to parse.

Returns:

  • (Metasm::C::Parser)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/metasploit/framework/obfuscation/crandomizer/parser.rb', line 26

def parse(template)
  main_parser = Metasploit::Framework::Obfuscation::CRandomizer::Utility.parse(template)
  modifier = Metasploit::Framework::Obfuscation::CRandomizer::Modifier.new(main_parser, fake_functions_collection, max_random_weight)
  main_parser.toplevel.statements.each do |s|
    case s.var.type
    when Metasm::C::Function
      # Some function objects such as declarations don't really have
      # any statements, if we run into something like that, skip it.
      next unless s.var.initializer.respond_to?(:statements)
      modifier.modify_function(s)
    end
  end

  main_parser
end