Skip to content

Commit 562612f

Browse files
committed
Merge branch 'hmoore-r7-module-loader'
2 parents b356b40 + 8f07a18 commit 562612f

File tree

2 files changed

+15
-36
lines changed

2 files changed

+15
-36
lines changed

lib/msf/core/modules/loader/base.rb

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def load_module(parent_path, type, module_reference_name, options={})
113113
metasploit_class = nil
114114
module_path = self.module_path(parent_path, type, module_reference_name)
115115

116-
loaded = namespace_module_transaction(module_reference_name, :reload => reload) { |namespace_module|
116+
loaded = namespace_module_transaction(type + "/" + module_reference_name, :reload => reload) { |namespace_module|
117117
# set the parent_path so that the module can be reloaded with #load_module
118118
namespace_module.parent_path = parent_path
119119

@@ -301,7 +301,7 @@ def reload_module(original_metasploit_class_or_instance)
301301
reloaded_module_instance.datastore.update(original_metasploit_instance.datastore)
302302
end
303303
else
304-
elog("Failed to create instance of #{refname} after reload.", 'core')
304+
elog("Failed to create instance of #{original_metasploit_class_or_instance.refname} after reload.", 'core')
305305

306306
# Return the old module instance to avoid an strace trace
307307
return original_metasploit_class_or_instance
@@ -430,7 +430,7 @@ def module_path?(path)
430430

431431
extension = File.extname(path)
432432

433-
unless (path.starts_with?('.') or
433+
unless (path[0,1] == "." or
434434
extension != MODULE_EXTENSION or
435435
path =~ UNIT_TEST_REGEX)
436436
module_path = true
@@ -455,8 +455,8 @@ def module_reference_name_from_path(path)
455455
#
456456
# @see MODULE_SEPARATOR
457457
# @see #namespace_module_names
458-
def namespace_module_name(module_reference_name)
459-
namespace_module_names = self.namespace_module_names(module_reference_name)
458+
def namespace_module_name(uniq_module_reference_name)
459+
namespace_module_names = self.namespace_module_names(uniq_module_reference_name)
460460
namespace_module_name = namespace_module_names.join(MODULE_SEPARATOR)
461461

462462
namespace_module_name
@@ -466,40 +466,19 @@ def namespace_module_name(module_reference_name)
466466
# doesn't overwrite other (metasploit) module's classes. Invalid module name characters are escaped by using 'H*'
467467
# unpacking and prefixing each code with X so the code remains a valid module name when it starts with a digit.
468468
#
469-
# @param [String] module_reference_name The canonical name for the module.
469+
# @param [String] uniq_module_reference_name The unique canonical name for the module including type.
470470
# @return [Array<String>] {NAMESPACE_MODULE_NAMES} + <derived-constant-safe names>
471471
#
472472
# @see namespace_module
473-
def namespace_module_names(module_reference_name)
474-
relative_module_name = module_reference_name.camelize
475-
476-
module_names = relative_module_name.split(MODULE_SEPARATOR)
477-
478-
# The module_reference_name is path-like, so it can include characters that are invalid in module names
479-
valid_module_names = module_names.collect { |module_name|
480-
valid_module_name = module_name.gsub(/^[0-9]|[^A-Za-z0-9]/) { |invalid_constant_name_character|
481-
unpacked = invalid_constant_name_character.unpack('H*')
482-
# unpack always returns an array, so get first value to get character's encoding
483-
hex_code = unpacked[0]
484-
485-
# as a convention start each hex-code with X so that it'll make a valid constant name since constants can't
486-
# start with digits.
487-
"X#{hex_code}"
488-
}
489-
490-
valid_module_name
491-
}
492-
493-
namespace_module_names = NAMESPACE_MODULE_NAMES + valid_module_names
494-
495-
namespace_module_names
473+
def namespace_module_names(uniq_module_reference_name)
474+
NAMESPACE_MODULE_NAMES + [ "Mod" + uniq_module_reference_name.unpack("H*").first.downcase ]
496475
end
497476

498-
def namespace_module_transaction(module_reference_name, options={}, &block)
477+
def namespace_module_transaction(uniq_module_reference_name, options={}, &block)
499478
options.assert_valid_keys(:reload)
500479

501480
reload = options[:reload] || false
502-
namespace_module_names = self.namespace_module_names(module_reference_name)
481+
namespace_module_names = self.namespace_module_names(uniq_module_reference_name)
503482

504483
previous_namespace_module = current_module(namespace_module_names)
505484

lib/msf/core/modules/namespace.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ def metasploit_class
1414
#inherit = false
1515

1616
::Msf::Framework::Major.downto(1) do |major|
17-
# Since we really only care about the deepest namespace, we don't
18-
# need to look for parents' constants. However, the "inherit"
19-
# parameter for const_defined? only exists after 1.9. If we ever
20-
# drop 1.8 support, we can save a few cycles here by passing false
21-
# here.
17+
# Since we really only care about the deepest namespace, we don't
18+
# need to look for parents' constants. However, the "inherit"
19+
# parameter for const_defined? only exists after 1.9. If we ever
20+
# drop 1.8 support, we can save a few cycles here by passing false
21+
# here.
2222
if const_defined?("Metasploit#{major}")
2323
metasploit_class = const_get("Metasploit#{major}")
2424

0 commit comments

Comments
 (0)