@@ -54,11 +54,13 @@ def reload_payload_module(metasploit_class, original_instance = nil)
54
54
type = metasploit_class . type
55
55
file_path = metasploit_class . file_path
56
56
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
59
59
60
60
# 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
62
64
if ( aliases_for_fullname = inv_aliases [ fullname ] )
63
65
aliases_for_fullname . each { |a | aliases . delete ( a ) }
64
66
inv_aliases . delete ( fullname )
@@ -79,19 +81,20 @@ def reload_payload_module(metasploit_class, original_instance = nil)
79
81
new_instance = framework . modules . create ( fullname )
80
82
81
83
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."
83
85
end
84
86
85
87
# 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.
86
89
if original_datastore
87
90
new_instance . datastore . merge! ( original_datastore )
88
91
end
89
92
90
93
# Return the new instance, which the framework will make the active module.
91
94
return new_instance
92
95
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
95
98
end
96
99
97
100
public
0 commit comments