Skip to content

Commit d121a1f

Browse files
authored
Merge pull request #1147 from kernelmethod/plugin-documentation
Add documentation on developing for unblob's plugin system
2 parents 1d06159 + a323e1a commit d121a1f

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

docs/development.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,47 @@ We've implemented integration tests this way:
399399
./fruits.new.le.nocomp.jffs2
400400
```
401401

402+
### Importing handlers through plugins
403+
404+
unblob uses [pluggy](https://pluggy.readthedocs.io/en/latest/) to provide a
405+
plugin interface for users. As a developer, this interface streamlines the
406+
process of implementing and distributing new handlers and extractors.
407+
408+
To export a new handler via the plugin management system, you must add a hook
409+
for either `unblob_register_handlers` or `unblob_register_dir_handlers`:
410+
411+
* Create a hook for `unblob_register_dir_handlers` if you are creating a new
412+
`DirectoryHandler` implementation.
413+
* Otherwise, register a hook for the `unblob_register_handlers` function.
414+
415+
Let's consider our earlier `MyformatHandler` example. Suppose we wished to
416+
implement this handler as a plugin in a directory called `myplugins/`. Then we
417+
would create a file `myplugins/myformat.py` with the following content:
418+
419+
```python hl_lines="8-10"
420+
from unblob.models import Handler, StructHandler
421+
from unblob.plugins import hookimpl
422+
423+
class MyformatHandler(StructHandler):
424+
# Format-handling code would go here
425+
...
426+
427+
@hookimpl
428+
def unblob_register_handlers() -> list[type[Handler]]:
429+
return [MyformatHandler]
430+
```
431+
432+
Since `MyformatHandler` is a `StructHandler`, we hook the
433+
`unblob_register_handlers` function. We then return a list of all of the handler
434+
classes that we wish to register.
435+
436+
To use this plugin, we would run unblob with the `-P` / `--plugins-path`
437+
pointing to the directory containing our plugin, e.g.
438+
439+
```
440+
unblob -P ./myplugins/ ...
441+
```
442+
402443
### Utilities Functions
403444

404445
We developed a bunch of utility functions which helped us during the development of

0 commit comments

Comments
 (0)