/usr/lib/python2.7/dist-packages/rekall/registry.py is in python-rekall-core 1.6.0+dfsg-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | # Rekall Memory Forensics
# Copyright (C) 2011
#
# Copyright 2013 Google Inc. All Rights Reserved.
#
# Michael Cohen <scudette@gmail.com>
#
# ******************************************************
#
# * This program is free software; you can redistribute it and/or
# * modify it under the terms of the GNU General Public License
# * as published by the Free Software Foundation; either version 2
# * of the License, or (at your option) any later version.
# *
# * This program is distributed in the hope that it will be useful,
# * but WITHOUT ANY WARRANTY; without even the implied warranty of
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# * GNU General Public License for more details.
# *
# * You should have received a copy of the GNU General Public License
# * along with this program; if not, write to the Free Software
# * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# *****************************************************
""" This module implements a class registry.
We scan the memory_plugins directory for all python files and add those classes
which should be registered into their own lookup tables. These are then ordered
as required. The rest of Rekall Memory Forensics will then call onto the
registered classes when needed.
The MetaclassRegistry automatically adds any derived class to the base
class. This means that we do not need to go through a special initializating
step, as soon as a module is imported, the plugin is registered.
"""
__author__ = "Michael Cohen <scudette@gmail.com>"
class classproperty(property):
"""A property that can be called on classes."""
def __get__(self, cls, owner):
return self.fget(owner)
def memoize(f):
cache = {}
def helper(*args):
cached = cache.get(args, memoize)
if cached is not memoize:
return cached
cached = f(*args)
cache[args] = cached
return cached
return helper
class UniqueObjectIdMetaclass(type):
"""Give each object a unique ID.
unlike id() this number will not be reused when the objects are destroyed,
hence it can be used to identify identical objects without keeping these
around.
"""
ID = 0
def __call__(cls, *args, **kwargs):
res = super(UniqueObjectIdMetaclass, cls).__call__(*args, **kwargs)
res._object_id = UniqueObjectIdMetaclass.ID # pylint: disable=protected-access
UniqueObjectIdMetaclass.ID += 1
return res
class UniqueObjectIdMixin(object):
__metaclass__ = UniqueObjectIdMetaclass
class MetaclassRegistry(UniqueObjectIdMetaclass):
"""Automatic Plugin Registration through metaclasses."""
def __init__(cls, name, bases, env_dict):
super(MetaclassRegistry, cls).__init__(name, bases, env_dict)
cls._install_constructors(cls)
# Attach the classes dict to the baseclass and have all derived classes
# use the same one:
for base in bases:
try:
cls.classes = base.classes
cls.classes_by_name = base.classes_by_name
cls.plugin_feature = base.plugin_feature
cls.top_level_class = base.top_level_class
break
except AttributeError:
cls.classes = {}
cls.classes_by_name = {}
cls.plugin_feature = cls.__name__
# Keep a reference to the top level class
cls.top_level_class = cls
# The following should not be registered as they are abstract. Classes
# are abstract if the have the __abstract attribute (note this is not
# inheritable so each abstract class must be explicitely marked).
abstract_attribute = "_%s__abstract" % name
if getattr(cls, abstract_attribute, None):
return
if not cls.__name__.startswith("Abstract"):
if cls.__name__ in cls.classes:
raise RuntimeError(
"Multiple definitions for class %s (%s)" % (
cls, cls.classes[cls.__name__]))
cls.classes[cls.__name__] = cls
name = getattr(cls, "name", None)
# We expect that classes by name will collide, which is why each
# value is a list of classes with that name.
cls.classes_by_name.setdefault(name, []).append(cls)
try:
if cls.top_level_class.include_plugins_as_attributes:
setattr(cls.top_level_class, cls.__name__, cls)
except AttributeError:
pass
# Allow the class itself to initialize itself.
cls_initializer = getattr(cls, "_class_init", None)
if cls_initializer:
cls_initializer()
@classmethod
def _install_constructors(mcs, cls):
def ByName(self, name):
for impl in self.classes.values():
if getattr(impl, "name", None) == name:
return impl
cls.ImplementationByName = classmethod(ByName)
def ByClass(self, name):
return self.classes.get(name)
cls.ImplementationByClass = classmethod(ByClass)
|