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/config/boot.rb
Views: 11704
require 'pathname'1require 'rubygems'23GEMFILE_EXTENSIONS = [4'.local',5''6]78msfenv_real_pathname = Pathname.new(__FILE__).realpath9root = msfenv_real_pathname.parent.parent1011unless ENV['BUNDLE_GEMFILE']12require 'pathname'1314GEMFILE_EXTENSIONS.each do |extension|15extension_pathname = root.join("Gemfile#{extension}")1617if extension_pathname.readable?18ENV['BUNDLE_GEMFILE'] = extension_pathname.to_path19break20end21end22end2324begin25require 'bundler/setup'26rescue LoadError => e27$stderr.puts "[*] Bundler failed to load and returned this error:"28$stderr.puts29$stderr.puts " '#{e}'"30$stderr.puts31$stderr.puts "[*] You may need to uninstall or upgrade bundler"32exit(1)33end3435lib_path = root.join('lib').to_path3637unless $LOAD_PATH.include? lib_path38$LOAD_PATH.unshift lib_path39end4041require 'digest'42require 'metasploit/framework/version'43require 'msf/base/config'4445# Invalidate and delete the bootsnap cache if required. For instance if the metasploit-framework version has changed.46#47# @param [Hash] bootsnap_config See https://github.com/Shopify/bootsnap/blob/95e8d170aea99a831fd484ce09ad2f195644e740/lib/bootsnap.rb#L3848# @return [void]49def invalidate_bootsnap_cache!(bootsnap_config)50expected_cache_metadata = {51'metasploit_framework_version' => Metasploit::Framework::Version::VERSION,52'ruby_description' => RUBY_DESCRIPTION,53'bundler_lockfile_hash' => Digest::MD5.hexdigest(Bundler.read_file(Bundler.default_lockfile)),54'bootsnap_config' => {55'load_path_cache' => bootsnap_config[:load_path_cache],56'compile_cache_iseq' => bootsnap_config[:compile_cache_iseq],57'compile_cache_yaml' => bootsnap_config[:compile_cache_yaml],58}59}6061cache_metadata_path = File.join(bootsnap_config[:cache_dir], "metadata.yaml")62if File.exist?(cache_metadata_path)63cache_metadata = YAML.safe_load(File.binread(cache_metadata_path))64if cache_metadata != expected_cache_metadata65FileUtils.rm_rf(bootsnap_config[:cache_dir], secure: true)66end67end6869FileUtils.mkdir_p(bootsnap_config[:cache_dir])70File.binwrite(cache_metadata_path, expected_cache_metadata.to_yaml)7172nil73end7475# Attempt to use bootsnap caching for improved startup time76begin77require 'bootsnap'78env = ENV['RAILS_ENV'] || ENV['RACK_ENV'] || ENV['ENV']79development_mode = ['', nil, 'development'].include?(env)8081cache_dir = ::File.join(Msf::Config.config_directory, "bootsnap_cache")82bootsnap_config = {83cache_dir: cache_dir,84ignore_directories: [],85development_mode: development_mode,86load_path_cache: true, # Optimize the LOAD_PATH with a cache87compile_cache_iseq: false, # Don't compile Ruby code into ISeq cache, breaks coverage reporting.88compile_cache_yaml: false, # Don't compile YAML into a cache89readonly: false, # Update caches - https://github.com/Shopify/bootsnap/commit/b51397f96c33aa421fd5c29484fb9574df9eb45190}91invalidate_bootsnap_cache!(bootsnap_config)92Bootsnap.setup(**bootsnap_config)93rescue => e94$stderr.puts "Warning: Failed bootsnap cache setup - #{e.class} #{e} #{e.backtrace}"95begin96FileUtils.rm_rf(cache_dir, secure: true)97rescue98$stderr.puts 'Warning: Failed deleting bootsnap cache'99end100end101102103