Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial commit for plugin internals refactor #763

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Schamper
Copy link
Member

@Schamper Schamper commented Jul 25, 2024

Initial commit for the plugin internals refactor. This removes a lot of slow and hard to understand code with (hopefully) faster and easier to understand code. Also fixes some consistency issues I came across while working on this.

There are some things I want to add, but I may do those in a separate PR:

  • Re-add support for Nested namespaces do not work #758 (it was lost in between version 2 and 3)
  • Add support for "plugin directories", similar to _os.py, but then _plugin.py or something similar (Add support for plugin directories #788)
  • Add helper functions for getting runtime information from functions, e.g. the class object, the record descriptor objects, etc. This will finally allow us to query plugins by e.g. ones that generate records that have a path field, for example.

This should also cover #759.

Closes #889.

@Schamper Schamper force-pushed the refactor-plugin-registration branch from bfa1029 to f4c1af4 Compare July 25, 2024 14:50
Copy link

codecov bot commented Jul 25, 2024

Codecov Report

Attention: Patch coverage is 87.56983% with 89 lines in your changes missing coverage. Please review.

Project coverage is 77.70%. Comparing base (f2f50a5) to head (77f2144).

Files with missing lines Patch % Lines
dissect/target/plugin.py 90.86% 40 Missing ⚠️
dissect/target/target.py 74.64% 18 Missing ⚠️
dissect/target/tools/query.py 77.35% 12 Missing ⚠️
dissect/target/plugins/general/plugins.py 88.00% 6 Missing ⚠️
dissect/target/helpers/docs.py 88.09% 5 Missing ⚠️
dissect/target/tools/build_pluginlist.py 0.00% 3 Missing ⚠️
dissect/target/tools/utils.py 81.25% 3 Missing ⚠️
dissect/target/plugins/os/windows/lnk.py 0.00% 1 Missing ⚠️
dissect/target/plugins/os/windows/registry.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #763      +/-   ##
==========================================
- Coverage   77.72%   77.70%   -0.02%     
==========================================
  Files         326      326              
  Lines       28575    28544      -31     
==========================================
- Hits        22210    22181      -29     
+ Misses       6365     6363       -2     
Flag Coverage Δ
unittests 77.70% <87.56%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Schamper Schamper added plugin Related to a plugin core Related to a core component of dissect.target and removed plugin Related to a plugin labels Aug 5, 2024
@Schamper Schamper force-pushed the refactor-plugin-registration branch 2 times, most recently from 68299b4 to 84e83ea Compare August 5, 2024 15:11
@Schamper Schamper force-pushed the refactor-plugin-registration branch 3 times, most recently from 2192994 to 85f4ebc Compare August 8, 2024 13:37
@Schamper Schamper mentioned this pull request Aug 27, 2024
@Schamper Schamper force-pushed the refactor-plugin-registration branch 2 times, most recently from 43b0585 to e830c4e Compare August 27, 2024 14:56
Copy link
Contributor

@pyrco pyrco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed plugins/general/example.py and plugins/os/unix/packagemanager.py still have a __findable__ property, which is now no longer needed.

Another thing I noticed is that the -l no longer lists the plugins from _os.py.

And a third thing I noticed that if I run a namespace plugin, e.g. webserver.access, which is listed when doing target-query MyTarget -l, before it printed an error like:

Error while parsing sysvol/windows/system32/inetsrv/config/applicationHost.config: ...

but now it errors with:

target-query: error: argument -f/--function contains invalid plugin(s): webserver.access

dissect/target/plugin.py Outdated Show resolved Hide resolved
dissect/target/plugin.py Outdated Show resolved Hide resolved
dissect/target/plugin.py Outdated Show resolved Hide resolved
dissect/target/plugin.py Outdated Show resolved Hide resolved
dissect/target/plugin.py Outdated Show resolved Hide resolved
dissect/target/plugin.py Outdated Show resolved Hide resolved
def _generate_long_paths() -> dict[str, FunctionDescriptor]:
"""Generate a dictionary of all long paths to their function descriptors."""
paths = {}
for value in _get_plugins().get("__functions__", {}).get(None, {}).values():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the functions for __os__ not also be added? Otherwise they will not be found by a non-exact match in find_plugin_functions().

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure on what the behaviour for that should be, as there are no existing unit tests for it. I assume it's not intended behaviour.

dissect/target/plugin.py Outdated Show resolved Hide resolved
dissect/target/plugin.py Outdated Show resolved Hide resolved
tests/test_plugin.py Outdated Show resolved Hide resolved
@Schamper
Copy link
Member Author

I noticed plugins/general/example.py and plugins/os/unix/packagemanager.py still have a __findable__ property, which is now no longer needed.

Fixed package manager but we still don't want the example plugin to findable.

Another thing I noticed is that the -l no longer lists the plugins from _os.py.

Should be fixed again.

And a third thing I noticed that if I run a namespace plugin, e.g. webserver.access, which is listed when doing target-query MyTarget -l, before it printed an error like:

Error while parsing sysvol/windows/system32/inetsrv/config/applicationHost.config: ...

but now it errors with:

target-query: error: argument -f/--function contains invalid plugin(s): webserver.access

I had to largely rewrite the NamespacePlugin to properly behave without any of its old side effects, but this is now also fixed.

@Schamper Schamper force-pushed the refactor-plugin-registration branch from 19bf4e9 to 77f2144 Compare December 16, 2024 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Related to a core component of dissect.target
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor plugin internals
2 participants