Skip to content

Commit eede805

Browse files
committed
Reuse appropriate terminology in docs
[#47720609] Fix some docs and variable names to make it clearer when methods are expecting module instance and module classes. Change some 'name' variables to 'reference_name' since that's the proper terminology.
1 parent a70d63e commit eede805

File tree

4 files changed

+56
-47
lines changed

4 files changed

+56
-47
lines changed

lib/msf/core/module_manager.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ def initialize(framework, types=Msf::MODULE_TYPES)
144144
# aux modules may wish to run such that they can collect more
145145
# information about the host that was detected.
146146
#
147-
# @param mod [Class] A subclass of Msf::Module
147+
# @param klass [Class<Msf::Module>] The module class
148148
# @return [void]
149-
def auto_subscribe_module(mod)
149+
def auto_subscribe_module(klass)
150150
# If auto-subscribe has been disabled
151151
if (framework.datastore['DisableAutoSubscribe'] and
152152
framework.datastore['DisableAutoSubscribe'] =~ /^(y|1|t)/)
@@ -160,15 +160,15 @@ def auto_subscribe_module(mod)
160160
#
161161
# Exploit event subscriber check
162162
#
163-
if (mod.include?(Msf::ExploitEvent) == true)
164-
framework.events.add_exploit_subscriber((inst) ? inst : (inst = mod.new))
163+
if (klass.include?(Msf::ExploitEvent) == true)
164+
framework.events.add_exploit_subscriber((inst) ? inst : (inst = klass.new))
165165
end
166166

167167
#
168168
# Session event subscriber check
169169
#
170-
if (mod.include?(Msf::SessionEvent) == true)
171-
framework.events.add_session_subscriber((inst) ? inst : (inst = mod.new))
170+
if (klass.include?(Msf::SessionEvent) == true)
171+
framework.events.add_session_subscriber((inst) ? inst : (inst = klass.new))
172172
end
173173
end
174174

lib/msf/core/module_manager/loading.rb

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,29 @@ def file_changed?(path)
5353

5454
attr_accessor :module_load_error_by_path
5555

56-
# Called when a module is initially loaded such that it can be
57-
# categorized accordingly.
56+
# Called when a module is initially loaded such that it can be categorized
57+
# accordingly.
5858
#
59-
def on_module_load(mod, type, name, modinfo)
60-
dup = module_set_by_type[type].add_module(mod, name, modinfo)
59+
# @param klass (see Msf::ModuleSet#add_module)
60+
# @param type [String] The module type.
61+
# @param reference_name (see Msf::ModuleSet#add_module)
62+
# @param info [Hash{String => Array}] additional information about the module
63+
# @option info [Array<String>] 'files' List of paths to the ruby source files
64+
# where +klass+ is defined.
65+
# @option info [Array<String>] 'paths' List of module reference names.
66+
# @option info [String] 'type' The module type, should match positional
67+
# +type+ argument.
68+
# @return [void]
69+
def on_module_load(klass, type, reference_name, info={})
70+
module_set = module_set_by_type[type]
71+
annotated_klass = module_set.add_module(klass, reference_name, info)
6172

6273
# Automatically subscribe a wrapper around this module to the necessary
6374
# event providers based on whatever events it wishes to receive.
64-
auto_subscribe_module(dup)
75+
auto_subscribe_module(annotated_klass)
6576

6677
# Notify the framework that a module was loaded
67-
framework.events.on_module_load(name, dup)
68-
69-
dup
78+
framework.events.on_module_load(reference_name, annotated_klass)
7079
end
7180

7281
protected

lib/msf/core/module_set.rb

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,26 @@ def [](name)
3131
super
3232
end
3333

34-
# Create an instance of the supplied module by its name
34+
# Create an instance of the supplied module by its reference name
3535
#
36-
# @param name [String] The module reference name.
36+
# @param reference_name [String] The module reference name.
3737
# @return [Msf::Module,nil] Instance of the named module or nil if it
3838
# could not be created.
39-
def create(name)
40-
klass = fetch(name, nil)
39+
def create(reference_name)
40+
klass = fetch(reference_name, nil)
4141
instance = nil
4242

4343
# If there is no module associated with this class, then try to demand
4444
# load it.
4545
if klass.nil? or klass == Msf::SymbolicModule
46-
framework.modules.load_cached_module(module_type, name)
46+
framework.modules.load_cached_module(module_type, reference_name)
4747

4848
recalculate
4949

50-
klass = fetch(name, nil)
50+
klass = fetch(reference_name, nil)
5151
end
5252

53-
# If the klass is valid for this name, try to create it
53+
# If the klass is valid for this reference_name, try to create it
5454
unless klass.nil? or klass == Msf::SymbolicModule
5555
instance = klass.new
5656
end
@@ -67,7 +67,7 @@ def create(name)
6767
# "can't add a new key into hash during iteration"
6868
#
6969
# @yield [module_reference_name, module]
70-
# @yieldparam [String] module_reference_name the name of the module.
70+
# @yieldparam [String] module_reference_name the reference_name of the module.
7171
# @yieldparam [Class] module The module class: a subclass of Msf::Module.
7272
# @return [void]
7373
def each(&block)
@@ -167,43 +167,47 @@ def on_module_reload(mod)
167167
def recalculate
168168
end
169169

170-
# Checks to see if the supplied module name is valid.
170+
# Checks to see if the supplied module reference name is valid.
171171
#
172+
# @param reference_name [String] The module reference name.
172173
# @return [true] if the module can be {#create created} and cached.
173174
# @return [false] otherwise
174-
def valid?(name)
175-
create(name)
176-
(self[name]) ? true : false
175+
def valid?(reference_name)
176+
create(reference_name)
177+
(self[reference_name]) ? true : false
177178
end
178179

179-
# Adds a module with a the supplied name.
180+
# Adds a module with a the supplied reference_name.
180181
#
181-
# @param [Class] mod The module class: a subclass of Msf::Module.
182-
# @param [String] name The module reference name
183-
# @param [Hash{String => Object}] modinfo optional module information
184-
# @return [Class] The mod parameter modified to have {Msf::Module#framework}, {Msf::Module#refname},
185-
# {Msf::Module#file_path}, and {Msf::Module#orig_cls} set.
186-
def add_module(mod, name, modinfo = nil)
187-
# Set the module's name so that it can be referenced when
182+
# @param [Class<Msf::Module>] klass The module class.
183+
# @param [String] reference_name The module reference name.
184+
# @param [Hash{String => Object}] info optional module information.
185+
# @option info [Array<String>] 'files' List of paths to files that defined
186+
# +klass+.
187+
# @return [Class] The klass parameter modified to have
188+
# {Msf::Module#framework}, {Msf::Module#refname}, {Msf::Module#file_path},
189+
# and {Msf::Module#orig_cls} set.
190+
def add_module(klass, reference_name, info = {})
191+
# Set the module's reference_name so that it can be referenced when
188192
# instances are created.
189-
mod.framework = framework
190-
mod.refname = name
191-
mod.file_path = ((modinfo and modinfo['files']) ? modinfo['files'][0] : nil)
192-
mod.orig_cls = mod
193+
klass.framework = framework
194+
klass.refname = reference_name
195+
klass.file_path = ((info and info['files']) ? info['files'][0] : nil)
196+
klass.orig_cls = klass
193197

194198
# don't want to trigger a create, so use fetch
195-
cached_module = self.fetch(name, nil)
199+
cached_module = self.fetch(reference_name, nil)
196200

197201
if (cached_module and cached_module != Msf::SymbolicModule)
198-
ambiguous_module_reference_name_set.add(name)
202+
ambiguous_module_reference_name_set.add(reference_name)
199203

200204
# TODO this isn't terribly helpful since the refnames will always match, that's why they are ambiguous.
201-
wlog("The module #{mod.refname} is ambiguous with #{self[name].refname}.")
205+
wlog("The module #{klass.refname} is ambiguous with #{self[reference_name].refname}.")
202206
end
203207

204-
self[name] = mod
208+
self[reference_name] = klass
205209

206-
mod
210+
klass
207211
end
208212

209213
protected

spec/support/shared/examples/msf/module_manager/loading.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,6 @@ def on_module_load
140140
module_set.stub(:add_module).and_return(annotated_class)
141141
end
142142

143-
it 'should return annotated class from Msf::ModuleSet#add_module' do
144-
on_module_load.should == annotated_class
145-
end
146-
147143
it 'should pass annotated class to Msf::ModuleManager#auto_subscribe_module' do
148144
module_manager.should_receive(:auto_subscribe_module).with(annotated_class)
149145

0 commit comments

Comments
 (0)