Module: Msf::ModuleManager::Loading

Extended by:
ActiveSupport::Concern
Included in:
Msf::ModuleManager
Defined in:
lib/msf/core/module_manager/loading.rb

Overview

Deals with loading modules for the Msf::ModuleManager

Constant Summary collapse

LOADER_CLASSES =

Classes that can be used to load modules.

[
    Msf::Modules::Loader::Archive,
    Msf::Modules::Loader::Directory
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#module_load_error_by_pathObject

Returns the value of attribute module_load_error_by_path


54
55
56
# File 'lib/msf/core/module_manager/loading.rb', line 54

def module_load_error_by_path
  @module_load_error_by_path
end

Instance Method Details

#file_changed?(path) ⇒ Boolean


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/msf/core/module_manager/loading.rb', line 26

def file_changed?(path)
  changed = false

  module_info = self.module_info_by_path[path]

  # if uncached then it counts as changed
  # Payloads can't be cached due to stage/stager matching
  if module_info.nil? or module_info[:type] == Msf::MODULE_PAYLOAD
    changed = true
  else
    begin
      current_modification_time = ::File.mtime(path).to_i
    rescue ::Errno::ENOENT
      # if the file does not exist now, that's a change
      changed = true
    else
      cached_modification_time = module_info[:modification_time].to_i

      # if the file's modification time's different from the cache, then it's changed
      if current_modification_time != cached_modification_time
        changed = true
      end
    end
  end

  changed
end

#on_module_load(class_or_module, type, reference_name, info = {}) ⇒ void

This method returns an undefined value.

Called when a module is initially loaded such that it can be categorized accordingly.

Options Hash (info):

  • 'files' (Array<String>)

    List of paths to the ruby source files where class_or_module is defined.

  • 'paths' (Array<String>)

    List of module reference names.

  • 'type' (String)

    The module type, should match positional type argument.


70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/msf/core/module_manager/loading.rb', line 70

def on_module_load(class_or_module, type, reference_name, info={})
  module_set = module_set_by_type[type]
  module_set.add_module(class_or_module, reference_name, info)

  path = info['files'].first
  cache_in_memory(
      class_or_module,
      :path => path,
      :reference_name => reference_name,
      :type => type
  )

  # Automatically subscribe a wrapper around this module to the necessary
  # event providers based on whatever events it wishes to receive.
  auto_subscribe_module(class_or_module)

  # Notify the framework that a module was loaded
  framework.events.on_module_load(reference_name, class_or_module)
end