taint

Crypto forensics for private use
git clone git://git.defalsify.org/taint.git
Log | Files | Refs | LICENSE

commit c9c72d226bba7cdb7ccd054e75bc264b4439f502
parent 4fa1edf1f11457632beb82ee755434d7397f8b60
Author: nolash <dev@holbrook.no>
Date:   Mon, 29 Nov 2021 04:39:58 +0100

Add pluggable input/output processor

Diffstat:
Mtaint/store/base.py | 7+++++++
Mtaint/store/file.py | 11+++++++++++
Mtaint/taint.py | 23+++++++++++++++++++++--
3 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/taint/store/base.py b/taint/store/base.py @@ -3,6 +3,13 @@ from hexathon import even def to_key(k): + """Ensure even-numbered hex format for given storage key. + + :param k: Key + :type k: bytes, bytearray or str (hex) + :rtype: str + :returns: Even-numbered hex represenation of key + """ if isinstance(k, bytes) or isinstance(k, bytearray): k = k.hex() else: diff --git a/taint/store/file.py b/taint/store/file.py @@ -9,6 +9,13 @@ from .base import ( class FileStore(BaseStore): + """Filesystem backend for storing key value pairs with filenames as keys. + + Base storage directory will be created if it does not exist. + + :param base_dir: Base storage directory + :type base_dir: str + """ def __init__(self, base_dir): os.makedirs(base_dir, exist_ok=True) @@ -16,6 +23,8 @@ class FileStore(BaseStore): def put(self, k, v): + """Implements taint.store.base.BaseStore + """ k = to_key(k) filepath = os.path.join(self.base_dir, k) @@ -29,6 +38,8 @@ class FileStore(BaseStore): def get(self, k): + """Implements taint.store.base.BaseStore + """ k = to_key(k) filepath = os.path.join(self.base_dir, k) diff --git a/taint/taint.py b/taint/taint.py @@ -12,6 +12,10 @@ from .crypto import Salter logg = logging.getLogger().getChild(__name__) +def noop_process_actors(self, inputs, outputs): + return (inputs, outputs,) + + class Tainter(Cache): """Frontend object containing code to load and save state of a cache, aswell as chain sync handling. @@ -30,6 +34,11 @@ class Tainter(Cache): super(Tainter, self).__init__(chain_spec, bits_size, cache_bloom=cache_bloom) self.store = store self.result_handler = result_handler + self.processors = [noop_process_actors] + + + def register_actor_processor(self, processor): + self.processors.insert(0, processor) def add_account(self, account, label): @@ -61,8 +70,18 @@ class Tainter(Cache): :param storer: State storage object (e.g. a sql database session) :type storer: any """ - for output in tx.outputs: - for inpt in tx.inputs: + outputs = None + inputs = None + + for p in self.processors: + r = p(tx.outputs, tx.inputs) + if r != None: + outputs = r[0] + inputs = r[1] + break + + for output in outputs: + for inpt in inputs: sender = bytes.fromhex(strip_0x(output)) recipient = bytes.fromhex(strip_0x(inpt)) r = None