From 89c9739a6a97dcc27cd7c24f84824e9b34b1912c Mon Sep 17 00:00:00 2001 From: cecinestpasunepipe <110607403+cecinestpasunepipe@users.noreply.github.com> Date: Wed, 15 Nov 2023 18:49:43 +0100 Subject: [PATCH 1/2] Fix issues with targetd integration --- dissect/target/loaders/targetd.py | 12 ++++++++++++ dissect/target/plugin.py | 16 ++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/dissect/target/loaders/targetd.py b/dissect/target/loaders/targetd.py index fede3b79b..cd25119b3 100644 --- a/dissect/target/loaders/targetd.py +++ b/dissect/target/loaders/targetd.py @@ -191,6 +191,18 @@ def command_runner(link: str, targetd: Client, *args, **kwargs) -> None: caller.output = True return + if targetd.command == "select": + targetd.rpcs.select(*args) + caller.has_output = True + caller.output = True + return + + if targetd.command == "deselect": + targetd.rpcs.deselect() + caller.has_output = True + caller.output = True + return + func = getattr(obj, targetd.command) caller.has_output = True result = func(*args, **kwargs) diff --git a/dissect/target/plugin.py b/dissect/target/plugin.py index 5c7e6b2b7..fce3ea308 100644 --- a/dissect/target/plugin.py +++ b/dissect/target/plugin.py @@ -1038,6 +1038,7 @@ def add_to_result(func: PluginFunction) -> None: invalid_funcs = set() show_hidden = kwargs.get("show_hidden", False) + ignore_load_errors = kwargs.get("ignore_load_errors", False) for pattern in patterns.split(","): # backward compatibility fix for namespace-level plugins (i.e. chrome) @@ -1071,7 +1072,12 @@ def add_to_result(func: PluginFunction) -> None: func = functions[index_name] method_name = index_name.split(".")[-1] - loaded_plugin_object = load(func) + try: + loaded_plugin_object = load(func) + except: + if ignore_load_errors: + continue + raise # Skip plugins that don't want to be found by wildcards if not show_hidden and not loaded_plugin_object.__findable__: @@ -1120,7 +1126,13 @@ def add_to_result(func: PluginFunction) -> None: invalid_funcs.add(pattern) for description in plugin_descriptions: - loaded_plugin_object = load(description) + try: + loaded_plugin_object = load(description) + except: + if ignore_load_errors: + continue + raise + fobject = inspect.getattr_static(loaded_plugin_object, funcname) if compatibility and not loaded_plugin_object(target).is_compatible(): From 32e1fe2c253db60a52cd4892284b4e295b6e33ed Mon Sep 17 00:00:00 2001 From: cecinestpasunepipe <110607403+cecinestpasunepipe@users.noreply.github.com> Date: Wed, 22 Nov 2023 12:12:17 +0100 Subject: [PATCH 2/2] Implement feedback --- dissect/target/loaders/targetd.py | 6 ++---- dissect/target/plugin.py | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/dissect/target/loaders/targetd.py b/dissect/target/loaders/targetd.py index cd25119b3..5c2dc7d53 100644 --- a/dissect/target/loaders/targetd.py +++ b/dissect/target/loaders/targetd.py @@ -186,25 +186,23 @@ def command_runner(link: str, targetd: Client, *args, **kwargs) -> None: if namespace := kwargs.get("namespace", None): obj = getattr(obj, namespace) + caller.has_output = True if targetd.command == "init": - caller.has_output = True caller.output = True return if targetd.command == "select": targetd.rpcs.select(*args) - caller.has_output = True caller.output = True return if targetd.command == "deselect": targetd.rpcs.deselect() - caller.has_output = True caller.output = True return func = getattr(obj, targetd.command) - caller.has_output = True + result = func(*args, **kwargs) if result is not None: if targetd.command == "get": diff --git a/dissect/target/plugin.py b/dissect/target/plugin.py index fce3ea308..bf431e98f 100644 --- a/dissect/target/plugin.py +++ b/dissect/target/plugin.py @@ -1074,7 +1074,7 @@ def add_to_result(func: PluginFunction) -> None: method_name = index_name.split(".")[-1] try: loaded_plugin_object = load(func) - except: + except Exception: if ignore_load_errors: continue raise @@ -1128,7 +1128,7 @@ def add_to_result(func: PluginFunction) -> None: for description in plugin_descriptions: try: loaded_plugin_object = load(description) - except: + except Exception: if ignore_load_errors: continue raise