示例#1
0
    def __init__(self, session=None, **kwargs):
        cache_dir = session.GetParameter("cache_dir")

        if not cache_dir:
            raise io_manager.IOManagerError(
                "Local profile cache is not configured - "
                "add a cache_dir parameter to ~/.rekallrc.")

        # Cache dir may be specified relative to the home directory.
        if config.GetHomeDir():
            cache_dir = os.path.join(config.GetHomeDir(), cache_dir)

        if not os.access(cache_dir, os.F_OK | os.R_OK | os.W_OK | os.X_OK):
            try:
                os.makedirs(cache_dir)
            except (IOError, OSError):
                raise io_manager.IOManagerError(
                    "Unable to create or access cache directory %s" %
                    cache_dir)

        # We use an IO manager to manage the cache directory directly.
        self.cache_io_manager = io_manager.DirectoryIOManager(urn=cache_dir,
                                                              session=session)
        self.url_manager = self.DELEGATE(session=session, **kwargs)

        self.CheckUpstreamRepository()

        super(CachingManager, self).__init__(session=session, **kwargs)
示例#2
0
    def io_manager(self):
        cache_dir = self.session.GetParameter("cache_dir", cached=False)
        if self._io_manager is None and cache_dir:
            # Cache dir may be specified relative to the home directory.
            if config.GetHomeDir():
                cache_dir = os.path.join(config.GetHomeDir(), cache_dir)

            if os.access(cache_dir, os.F_OK | os.R_OK | os.W_OK | os.X_OK):
                self._io_manager = PicklingDirectoryIOManager(
                    "%s/sessions" % cache_dir, session=self.session, mode="w")

        return self._io_manager
示例#3
0
    def io_manager(self):
        if not self.enabled:
            return

        cache_dir = os.path.expandvars(
            self.session.GetParameter("cache_dir", cached=False))

        cache_dir = os.path.join(config.GetHomeDir(self.session), cache_dir)

        # Force the IO manager to be recreated if the cache dir has
        # changed. This allows the session to change it's cache directory on the
        # fly (which is actually done when setting it from the command line).
        if cache_dir != self.cache_dir:
            self._io_manager = None
            self.cache_dir = cache_dir

        if self._io_manager is None and cache_dir:
            # Cache dir may be specified relative to the home directory.
            if os.access(cache_dir, os.F_OK | os.R_OK | os.W_OK | os.X_OK):
                self._io_manager = PicklingDirectoryIOManager(
                    "%s/sessions" % cache_dir, session=self.session, mode="w")

                self.cache_dir = cache_dir
            else:
                self.session.logging.warn(
                    "Cache directory inaccessible. Disabling.")
                self.enabled = False

        return self._io_manager
示例#4
0
    def _set_home(self, home, _):
        """Ensure the home directory is valid."""
        if home:
            home = os.path.abspath(home)
            if not os.path.isdir(home):
                raise ValueError("Home directory must be a directory.")
        else:
            home = config.GetHomeDir(self.session)

        # We must update the environment so things like os.path.expandvars
        # work.
        os.environ["HOME"] = home
        return home
示例#5
0
def GetCacheDir(session):
    """Returns the path of a usable cache directory."""
    cache_dir = os.path.expandvars(session.GetParameter("cache_dir"))

    if not cache_dir:
        raise io_manager.IOManagerError(
            "Local profile cache is not configured - "
            "add a cache_dir parameter to ~/.rekallrc.")

    # Cache dir may be specified relative to the home directory.
    cache_dir = os.path.join(config.GetHomeDir(session), cache_dir)

    if not os.access(cache_dir, os.F_OK | os.R_OK | os.W_OK | os.X_OK):
        try:
            os.makedirs(cache_dir)
        except (IOError, OSError):
            raise io_manager.IOManagerError(
                "Unable to create or access cache directory %s" % cache_dir)

    return cache_dir
示例#6
0
def NotebookSupport(_):

    # The following only reveals hidden imports to pyinstaller.
    if False:
        # pylint: disable=unused-variable
        import IPython.html.auth.login
        import IPython.html.auth.logout
        import IPython.html.base.handlers
        import IPython.html.nbconvert.handlers
        import IPython.html.notebook.handlers
        import IPython.html.notebookapp
        import IPython.html.services.clusters.handlers
        import IPython.html.services.kernels.handlers
        import IPython.html.services.nbconvert.handlers
        import IPython.html.services.notebooks.handlers
        import IPython.html.services.sessions.handlers
        import IPython.html.tree.handlers
        import IPython.kernel.ioloop
        import IPython.kernel.zmq.kernelapp

        import rekall.interactive

        import zmq.backend.cython
        import zmq.eventloop.ioloop

    argv = ["notebook", "-c",
            "from rekall import interactive; "
            "interactive.ImportEnvironment();", "--autocall", "2",
            "--notebook-dir",
            config.GetConfigFile().get("notebook_dir",
                                       config.GetHomeDir())
            ]

    import IPython

    IPython.start_ipython(argv=argv)
    return True