Always overwrite the old module even when ambiguous
This commit is contained in:
parent
3a572625f5
commit
26a145e527
|
@ -219,10 +219,10 @@ class Msf::ModuleSet < Hash
|
|||
|
||||
# TODO this isn't terribly helpful since the refnames will always match, that's why they are ambiguous.
|
||||
wlog("The module #{mod.refname} is ambiguous with #{self[name].refname}.")
|
||||
else
|
||||
self[name] = mod
|
||||
end
|
||||
|
||||
self[name] = mod
|
||||
|
||||
mod
|
||||
end
|
||||
|
||||
|
|
|
@ -125,7 +125,7 @@ class Msf::Modules::Loader::Base
|
|||
return false
|
||||
end
|
||||
|
||||
namespace_module_transaction(type + "/" + module_reference_name, :reload => reload) { |namespace_module|
|
||||
try_eval_module = lambda { |namespace_module|
|
||||
# set the parent_path so that the module can be reloaded with #load_module
|
||||
namespace_module.parent_path = parent_path
|
||||
|
||||
|
@ -173,23 +173,20 @@ class Msf::Modules::Loader::Base
|
|||
return false
|
||||
end
|
||||
|
||||
if reload
|
||||
ilog("Reloading #{type} module #{module_reference_name}. Ambiguous module warnings are safe to ignore", 'core', LEV_2)
|
||||
else
|
||||
ilog("Loaded #{type} module #{module_reference_name} under #{parent_path}", 'core', LEV_2)
|
||||
end
|
||||
|
||||
module_manager.module_load_error_by_path.delete(module_path)
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
if reload
|
||||
# Delete the original copy of the module so that module_manager.on_load_module called from inside load_module does
|
||||
# not trigger an ambiguous name warning, which would cause the reloaded module to not be stored in the
|
||||
# ModuleManager.
|
||||
module_manager.delete(module_reference_name)
|
||||
|
||||
# Delete the original copy of the module in the type-specific module set stores the reloaded module and doesn't
|
||||
# trigger an ambiguous name warning
|
||||
module_set = module_manager.module_set(type)
|
||||
module_set.delete(module_reference_name)
|
||||
loaded = namespace_module_transaction(type + "/" + module_reference_name, :reload => reload, &try_eval_module)
|
||||
unless loaded
|
||||
return false
|
||||
end
|
||||
|
||||
# Do some processing on the loaded module to get it into the right associations
|
||||
|
|
|
@ -255,18 +255,27 @@ describe Msf::Modules::Loader::Base do
|
|||
subject.stub(:module_path => module_path)
|
||||
end
|
||||
|
||||
it 'should return false if :force is false and the file has not been changed' do
|
||||
module_manager.stub(:file_changed? => false)
|
||||
|
||||
subject.load_module(parent_path, type, module_reference_name, :force => false).should be_false
|
||||
end
|
||||
|
||||
it 'should call file_changed? with the module_path' do
|
||||
module_manager.should_receive(:file_changed?).with(module_path).and_return(false)
|
||||
|
||||
subject.load_module(parent_path, type, module_reference_name, :force => false)
|
||||
end
|
||||
|
||||
context 'without file changed' do
|
||||
before(:each) do
|
||||
module_manager.stub(:file_changed? => false)
|
||||
end
|
||||
|
||||
it 'should return false if :force is false' do
|
||||
subject.load_module(parent_path, type, module_reference_name, :force => false).should be_false
|
||||
end
|
||||
|
||||
it 'should not call #read_module_content' do
|
||||
subject.should_not_receive(:read_module_content)
|
||||
subject.load_module(parent_path, type, module_reference_name)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with file changed' do
|
||||
let(:module_full_name) do
|
||||
File.join('auxiliary', module_reference_name)
|
||||
|
@ -621,87 +630,6 @@ describe Msf::Modules::Loader::Base do
|
|||
subject.load_module(parent_path, type, module_reference_name).should be_true
|
||||
end
|
||||
|
||||
context 'with module_reference_name already in module_manager' do
|
||||
let(:framework) do
|
||||
framework = mock('Framework', :datastore => {})
|
||||
framework.stub_chain(:events, :on_module_load)
|
||||
|
||||
framework
|
||||
end
|
||||
|
||||
let(:metasploit_class) do
|
||||
@original_namespace_module::Metasploit3
|
||||
end
|
||||
|
||||
let(:module_manager) do
|
||||
Msf::ModuleManager.new(framework)
|
||||
end
|
||||
|
||||
before(:each) do
|
||||
# remove the stub from before(:each) in context 'with version compatibility'
|
||||
module_manager.unstub(:on_module_load)
|
||||
|
||||
# remove the stubs from before(:each) in context 'with file changed'
|
||||
module_manager.unstub(:delete)
|
||||
module_manager.unstub(:module_set)
|
||||
end
|
||||
|
||||
it 'should not cause an ambiguous module_reference_name in the module_manager' do
|
||||
module_manager[module_reference_name] = metasploit_class
|
||||
|
||||
subject.load_module(parent_path, type, module_reference_name).should be_true
|
||||
module_manager.send(:ambiguous_module_reference_name_set).should be_empty
|
||||
end
|
||||
|
||||
it 'should not cause an ambiguous module_reference_name in the type module_set' do
|
||||
module_set = module_manager.module_set(type)
|
||||
module_set[module_reference_name] = metasploit_class
|
||||
|
||||
subject.load_module(parent_path, type, module_reference_name).should be_true
|
||||
module_set.send(:ambiguous_module_reference_name_set).should be_empty
|
||||
end
|
||||
|
||||
context 'without file changed' do
|
||||
before(:each) do
|
||||
module_manager.stub(:file_changed => false)
|
||||
end
|
||||
|
||||
context 'with :force => true' do
|
||||
it 'should not cause an ambiguous module_reference_name in the module_manager' do
|
||||
module_manager[module_reference_name] = metasploit_class
|
||||
|
||||
subject.load_module(parent_path, type, module_reference_name, :force => true).should be_true
|
||||
module_manager.send(:ambiguous_module_reference_name_set).should be_empty
|
||||
end
|
||||
|
||||
it 'should not cause an ambiguous module_reference_name in the type module_set' do
|
||||
module_set = module_manager.module_set(type)
|
||||
module_set[module_reference_name] = metasploit_class
|
||||
|
||||
subject.load_module(parent_path, type, module_reference_name, :force => true).should be_true
|
||||
module_set.send(:ambiguous_module_reference_name_set).should be_empty
|
||||
end
|
||||
end
|
||||
|
||||
context 'with :reload => true' do
|
||||
it 'should not cause an ambiguous module_reference_name in the module_manager' do
|
||||
module_manager[module_reference_name] = metasploit_class
|
||||
|
||||
subject.load_module(parent_path, type, module_reference_name, :reload => true).should be_true
|
||||
module_manager.send(:ambiguous_module_reference_name_set).should be_empty
|
||||
end
|
||||
|
||||
it 'should not cause an ambiguous module_reference_name in the type module_set' do
|
||||
module_set = module_manager.module_set(type)
|
||||
module_set[module_reference_name] = metasploit_class
|
||||
|
||||
subject.load_module(parent_path, type, module_reference_name, :reload => true).should be_true
|
||||
module_set.send(:ambiguous_module_reference_name_set).should be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it 'should call module_manager.on_module_load' do
|
||||
module_manager.should_receive(:on_module_load)
|
||||
subject.load_module(parent_path, type, module_reference_name).should be_true
|
||||
|
|
Loading…
Reference in New Issue