Module: Msf::ModuleManager::Reloading

Included in:
Msf::ModuleManager
Defined in:
lib/msf/core/module_manager/reloading.rb

Overview

Concerns reloading modules

Instance Method Summary collapse

Instance Method Details

#reload_module(mod) ⇒ Class, Msf::Module

Reloads the module specified in mod. This can either be an instance of a module or a module class.

Parameters:

  • mod (Msf::Module, Class)

    either an instance of a module or a module class

Returns:

  • (Class, Msf::Module)

    original_metasploit_class_or_instance if an instance of the reloaded module cannot be created.

  • (Msf::Module)

    new instance of original_metasploit_class with datastore copied from original_metasploit_instance.


7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/msf/core/module_manager/reloading.rb', line 7

def reload_module(mod)
  # if it's can instance, then get its class
  if mod.is_a? Msf::Module
    metasploit_class = mod.class
  else
    metasploit_class = mod
  end

  namespace_module = metasploit_class.parent
  loader = namespace_module.loader
  loader.reload_module(mod)
end

#reload_modulesHash{String => Integer}

Reloads modules from all module paths

Returns:

  • (Hash{String => Integer})

    Maps module type to number of modules loaded


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/msf/core/module_manager/reloading.rb', line 23

def reload_modules
  self.enablement_by_type.each_key do |type|
    module_set_by_type[type].clear
    init_module_set(type)
  end

  # default the count to zero the first time a type is accessed
  count_by_type = Hash.new(0)

  module_paths.each do |path|
    path_count_by_type = load_modules(path, :force => true)

    # merge count with count from other paths
    path_count_by_type.each do |type, count|
      count_by_type[type] += count
    end
  end

  refresh_cache_from_module_files

  count_by_type
end