Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/metasploit/framework/obfuscation/crandomizer/parser.rb
Views: 11789
require 'metasploit/framework/obfuscation/crandomizer/utility'1require 'metasploit/framework/obfuscation/crandomizer/modifier'23module Metasploit4module Framework5module Obfuscation6module CRandomizer78class Parser9attr_accessor :max_random_weight10attr_accessor :fake_functions_collection1112# Initializes a Metasploit::Framework::Obfuscation::CRandomizer::Parser instance.13#14# @param weight [Integer] Randomness of the code.15# @param fake_functions [Metasploit::Framework::Obfuscation::CRandomizer::CodeFactory::FakeFunctionCollection]16def initialize(weight, fake_functions=nil)17@max_random_weight = weight18@fake_functions_collection = fake_functions19end2021# Returns a parser.22#23# @param template [String] Source code to parse.24# @return [Metasm::C::Parser]25def parse(template)26main_parser = Metasploit::Framework::Obfuscation::CRandomizer::Utility.parse(template)27modifier = Metasploit::Framework::Obfuscation::CRandomizer::Modifier.new(main_parser, fake_functions_collection, max_random_weight)28main_parser.toplevel.statements.each do |s|29case s.var.type30when Metasm::C::Function31# Some function objects such as declarations don't really have32# any statements, if we run into something like that, skip it.33next unless s.var.initializer.respond_to?(:statements)34modifier.modify_function(s)35end36end3738main_parser39end40end4142end43end44end45end464748