Class: Metasploit::Framework::Obfuscation::CRandomizer::CodeFactory::Base

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.



13
14
15
16
# File 'lib/metasploit/framework/obfuscation/crandomizer/code_factory/base.rb', line 13

def initialize
  @dep = []
  @code = normalized_stub
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



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

def code
  @code
end

#depObject (readonly)

Returns the value of attribute dep.



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

def dep
  @dep
end

Instance Method Details

#good_dep?(parser) ⇒ Boolean

Checks whether this class is suitable for the code.

Parameters:

  • parser (Metasm::C::Parser)

Returns:

  • (Boolean)


37
38
39
40
41
42
43
44
45
46
47
# File 'lib/metasploit/framework/obfuscation/crandomizer/code_factory/base.rb', line 37

def good_dep?(parser)
  # The difference between @dep and parser.toplevel.symbol.keys
  # is the list of functions not being supported by the original code.
  ready_function_names = parser.toplevel.symbol.keys
  delta = dep - ready_function_names
  if delta.empty?
    true
  else
    false
  end
end

#normalized_stubObject



49
50
51
52
# File 'lib/metasploit/framework/obfuscation/crandomizer/code_factory/base.rb', line 49

def normalized_stub
  stub_parser = Metasploit::Framework::Obfuscation::CRandomizer::Utility.parse(stub)
  stub_parser.toplevel.statements.last.var.initializer.statements
end

#stubObject

Override this method when you inherit this class. The method should return the source of the stub you're trying to create, as a C function. For example: %Q| void printf(const char*); void stub()

printf("hello world\n");

| Notice if you are using a function like the above, you must declare/define that beforehand. The function declaration will not be used in the final source code.

Raises:

  • (NotImplementedError)


29
30
31
# File 'lib/metasploit/framework/obfuscation/crandomizer/code_factory/base.rb', line 29

def stub
  raise NotImplementedError
end