Skip to content

Commit 8bf1c40

Browse files
committed
Update reloading.rb
1 parent e11277f commit 8bf1c40

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

lib/msf/core/module_manager/reloading.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,13 @@ def reload_payload_module(metasploit_class, original_instance = nil)
5454
type = metasploit_class.type
5555
file_path = metasploit_class.file_path
5656

57-
# Store the original datastore so we can restore its state.
58-
original_datastore = original_instance&.datastore&.copy
57+
# Get a reference to the original datastore now, but do not copy it yet.
58+
original_datastore = original_instance&.datastore
5959

6060
# Step 2: Manually purge the old module from the framework's caches.
61-
module_set.delete(module_reference_name) if module_set
61+
if (module_set = module_set_by_type.fetch(type, nil))
62+
module_set.delete(refname)
63+
end
6264
if (aliases_for_fullname = inv_aliases[fullname])
6365
aliases_for_fullname.each { |a| aliases.delete(a) }
6466
inv_aliases.delete(fullname)
@@ -79,19 +81,20 @@ def reload_payload_module(metasploit_class, original_instance = nil)
7981
new_instance = framework.modules.create(fullname)
8082

8183
if new_instance.blank?
82-
raise "Failed to create a new instance of #{fullname} after reloading. The module file may be broken."
84+
raise Msf::LoadError, "Failed to create a new instance of #{fullname} after reloading. The module file may be broken."
8385
end
8486

8587
# Step 6: Restore the datastore to the new, fully-functional instance.
88+
# Now we perform the copy, which is a method on the new datastore's merge function.
8689
if original_datastore
8790
new_instance.datastore.merge!(original_datastore)
8891
end
8992

9093
# Return the new instance, which the framework will make the active module.
9194
return new_instance
9295
rescue StandardError => e
93-
elog("Failed to reload payload #{fullname}: #{e.message}")
94-
raise "Failed to reload payload: #{e.message}"
96+
elog("Failed to reload payload #{fullname}", error: e)
97+
raise Msf::LoadError, e.message
9598
end
9699

97100
public

0 commit comments

Comments
 (0)