metasploit-framework/lib/msf/base/persistent_storage.rb

78 lines
2.5 KiB
Ruby
Raw Normal View History

# -*- coding: binary -*-
module Msf
# This class provides a generalized interface to persisting information,
# either in whole or in part, about the state of the framework. This can
# be used to store data that can later be reinitialized in a new instance
# of the framework or to provide a simple mechanism for generating reports
# of some form.
2013-12-26 18:14:41 +00:00
#
# @abstract Subclass and override {#initialize}, {#store}, and {#fetch}.
class PersistentStorage
2013-08-30 21:28:33 +00:00
@@storage_classes = {}
2013-08-30 21:28:33 +00:00
# Creates an instance of the storage class with the supplied name. The
# array supplied as an argument is passed to the constructor of the
# associated class as a means of generic initialization.
2013-12-26 18:14:41 +00:00
#
# @param name [String] the name of the storage class.
# @param params [Object] the parameters to give the new class.
# @return [PersistentStorage] the newly created class.
# @return [nil] if class has not been added through {.add_storage_class}.
2013-08-30 21:28:33 +00:00
def self.create(name, *params)
if (klass = @@storage_classes[name])
klass.new(*params)
else
nil
end
end
2013-08-30 21:28:33 +00:00
# Stub initialization routine that takes the params passed to create.
2013-12-26 18:14:41 +00:00
#
# @param params [Object] the parameters to initialize with.
2013-08-30 21:28:33 +00:00
def initialize(*params)
end
2013-08-30 21:28:33 +00:00
# This methods stores all or part of the current state of the supplied
# framework instance to whatever medium the derived class implements.
# If the derived class does not implement this method, the
# NotImplementedError is raised.
2013-12-26 18:14:41 +00:00
#
# @param framework [Msf::Framework] framework state to store.
# @return [void] no implementation.
2013-12-26 18:14:41 +00:00
# @raise [NotImpementedError] raised if not implemented.
2013-08-30 21:28:33 +00:00
def store(framework)
raise NotImplementedError
end
2013-08-30 21:28:33 +00:00
# This method initializes the supplied framework instance with the state
# that is stored in the persisted backing that the derived class
# implements. If the derived class does not implement this method, the
# NotImplementedError is raised.
2013-12-26 18:14:41 +00:00
#
# @param framework [Msf::Framework] framework to restore state to.
# @return [void] no implementation.
2013-12-26 18:14:41 +00:00
# @raise [NotImplementedError] raised if not implemented.
2013-08-30 21:28:33 +00:00
def fetch(framework)
raise NotImplementedError
end
2013-08-30 21:28:33 +00:00
# This method adds a new storage class to the hash of storage classes that
# can be created through create.
2013-12-26 18:14:41 +00:00
#
# @param name [String] the name of the storage class.
# @param klass [PersistentStorage] the storage class to add.
# @return [void]
2013-08-30 21:28:33 +00:00
def self.add_storage_class(name, klass)
@@storage_classes[name] = klass
end
protected
end
end
2011-11-20 01:11:40 +00:00
require 'msf/base/persistent_storage/flatfile'