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.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/msf/core/module_manager/reloading.rb', line 8

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

  if aliased_as = self.inv_aliases[metasploit_class.fullname]
    aliased_as.each do |a|
      self.aliases.delete a
    end
    self.inv_aliases.delete metasploit_class.fullname
  end

  namespace_module = metasploit_class.module_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



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/msf/core/module_manager/reloading.rb', line 31

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

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

  framework.init_module_paths unless framework.module_paths_inited

  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