fixed up plugins to be loadable with local input/output handles

git-svn-id: file:///home/svn/incoming/trunk@3058 4d416f70-5f16-0410-b530-b9f4589650da
unstable
Matt Miller 2005-11-23 14:02:30 +00:00
parent 763673d3de
commit 36f6c79986
4 changed files with 96 additions and 7 deletions

View File

@ -27,15 +27,27 @@ class Plugin
# We use create instead of new directly so that singleton plugins can just
# return their singleton instance.
#
def self.create(framework)
new(framework)
def self.create(framework, opts = {})
new(framework, opts)
end
#
# Initializes the plugin instance with the supplied framework instance.
# The opts parameter is a hash of custom arguments that may be useful for a
# plugin. Some of the pre-defined arguments are:
#
def initialize(framework)
# LocalInput
#
# The local input handle that implements the Rex::Ui::Text::Input
# interface.
#
# LocalOutput
#
# The local output handle that implements the Rex::Ui::Output interface.
#
def initialize(framework, opts = {})
self.framework = framework
self.opts = opts
refinit
end
@ -65,6 +77,79 @@ class Plugin
def desc
end
##
#
# Accessors
#
##
#
# Returns the local output handle if one was passed into the constructor.
#
def output
opts['LocalOutput']
end
#
# Returns the local input handle if one was passed into the constructor.
#
def input
opts['LocalInput']
end
##
#
# Output wrappers for the plugin that uses the 'LocalOutput' hash entry
# if one was passed into the constructor.
#
##
#
# Prints an error message.
#
def print_error(msg)
output.print_error(msg) if (output)
end
#
# Prints a 'good' message.
#
def print_good(msg)
output.print_good(msg) if (output)
end
#
# Prints a status line.
#
def print_status(msg)
output.print_status(msg) if (output)
end
#
# Prints an undecorated line of information.
#
def print_line(msg)
output.print_line(msg) if (output)
end
#
# Prints a message with no decoration.
#
def print(msg)
output.print(msg) if (output)
end
#
# Flushes any buffered output.
#
def flush
output.flush(msg) if (output)
end
protected
attr_accessor :opts # :nodoc:
end
end

View File

@ -43,7 +43,7 @@ class PluginManager < Array
# Loads a plugin from the supplied path and returns the instance that is
# created as a result.
#
def load(path)
def load(path, opts = {})
# Check to see if a plugin from this path has already been loaded
# before.
if ((klass = self.class.check_path_hash(path)) == nil)
@ -64,7 +64,7 @@ class PluginManager < Array
end
# Create an instance of the plugin and let it initialize
instance = klass.create(framework)
instance = klass.create(framework, opts)
# Add it to the list of plugins
if (self.member?(instance) == false)

View File

@ -206,7 +206,9 @@ class Core
path = Msf::Config.plugin_directory + File::SEPARATOR + path if (path !~ /#{File::SEPARATOR}/)
# Load that plugin!
if ((inst = framework.plugins.load(path)))
if ((inst = framework.plugins.load(path,
'LocalInput' => driver.input,
'LocalOutput' => driver.output)))
print_status("Successfully loaded plugin: #{inst.name}")
else
print_error("Failed to load plugin from #{arg[0]}")

View File

@ -17,8 +17,10 @@ class Plugin::Sample < Msf::Plugin
# inheriting from Msf::Plugin to ensure that the framework attribute on
# their instance gets set.
#
def initialize(framework)
def initialize(framework, opts)
super
print_status("Sample plugin loaded.")
end
#