# Concern for behavior that all namespace modules that wrap Msf::Modules must support like version checking and # grabbing the version specific-Metasploit* class. module Msf::Modules::Namespace # Returns the Metasploit(3|2|1) class from the module_evalled content. # # @note The module content must be module_evalled into this namespace module before the return of # {metasploit_class} is valid. # # @return [Msf::Module] if a Metasploit(3|2|1) class exists in this module # @return [nil] if such as class is not defined. def metasploit_class metasploit_class = nil # don't search ancestors for the metasploit_class inherit = false ::Msf::Framework::Major.downto(1) do |major| if const_defined?("Metasploit#{major}", inherit) metasploit_class = const_get("Metasploit#{major}") break end end metasploit_class end # Raises an error unless {Msf::Framework::VersionCore} and {Msf::Framework::VersionAPI} meet the minimum required # versions defined in RequiredVersions in the module content. # # @note The module content must be module_evalled into this namespace module using module_eval_with_lexical_scope # before calling {version_compatible!} is valid. # # @raise [Msf::Modules::VersionCompatibilityError] if RequiredVersion[0] > Msf::Framework::VersionCore or # RequiredVersion[1] > Msf::Framework::VersionApi # @return [void] def version_compatible! if const_defined?(:RequiredVersions) required_versions = const_get(:RequiredVersions) minimum_core_version = required_versions[0] minimum_api_version = required_versions[1] if (minimum_core_version > ::Msf::Framework::VersionCore or minimum_api_version > ::Msf::Framework::VersionAPI) raise Msf::Modules::VersionCompatibilityError.new( :minimum_api_version => minimum_api_version, :minimum_core_version => minimum_core_version ) end end end end