require 'metasploit/framework/obfuscation/crandomizer/utility' module Metasploit module Framework module Obfuscation module CRandomizer class RandomStatements attr_reader :parser attr_reader :fake_function_collection attr_reader :statements # Initializes the RandomStatements class. # # @param fake_functions [Metasploit::Framework::Obfuscation::CRandomizer::CodeFactory::FakeFunctionCollection] # @param s [Metasm::C::Declaration] def initialize(p, fake_functions, s=nil) @parser = p @fake_function_collection = fake_functions @statements = [ Proc.new { get_random_statements } ] # Only generate fake function calls when the function we are modifying isn't # from one of those fake functions (to avoid a recursion). if s && fake_function_collection && !fake_function_collection.has_function_name?(s.var.name) @statements << Proc.new { get_random_function_call } end end # Returns a random statement. # # @return [Array] # @return [Array] def get statements.sample.call end private # Returns function arguments as a string. # # @param args [Array] # @return [String] def make_func_arg_str(args) arg_array = [] args.each do |arg| case arg.name when 'i' arg_array << %Q|#{Metasploit::Framework::Obfuscation::CRandomizer::Utility.rand_int}| when 's' arg_array << %Q|"#{Metasploit::Framework::Obfuscation::CRandomizer::Utility.rand_string}"| else raise "Unknown argument type to process" end end %Q|(#{arg_array.join(', ')})| end # Returns the arguments (in string) for function declaration. # # @param args [Array