-
Notifications
You must be signed in to change notification settings - Fork 8
Document how to work with records #105
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
Open
twiggler
wants to merge
5
commits into
main
Choose a base branch
from
flow-record-docs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a3c69b3
Add documentation about writing records
twiggler 4398a0c
Add advanced writing records documentation
twiggler e5fd6c0
Improve writer example
twiggler 2a961e8
Document adaptibility of output format
twiggler 308a597
Add sophisticated example
twiggler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,3 +11,4 @@ Advanced | |
| /advanced/filesystems | ||
| /advanced/plugins | ||
| /advanced/record_descriptors | ||
| /advanced/records | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,76 @@ | ||||||||||
| Working with Records | ||||||||||
| ==================== | ||||||||||
|
|
||||||||||
| This section describes how to work with records. Records are the fundamental data structure in ``dissect`` and are | ||||||||||
| used to describe forensic evidence and artefacts in a structured way. They can be read from and written to various | ||||||||||
| sources and formats. | ||||||||||
|
|
||||||||||
| Writing Records with rdump | ||||||||||
| -------------------------- | ||||||||||
|
|
||||||||||
| The easiest way to write records is by using the :doc:`/tools/rdump` tool. It allows you to read records from any | ||||||||||
| source, filter them, and write them to a new destination. | ||||||||||
|
|
||||||||||
| The output format is determined by the ``-w/--writer`` argument. You can specify a filename, and ``rdump`` will | ||||||||||
| automatically detect the desired output format and compression based on the file extension. | ||||||||||
|
|
||||||||||
| For example, to write records to a gzip-compressed file, you can use: | ||||||||||
|
|
||||||||||
| .. code-block:: console | ||||||||||
|
|
||||||||||
| $ rdump <source> -w output.rec.gz | ||||||||||
|
|
||||||||||
| This will write the records to ``output.rec.gz`` in the default record stream format, compressed with gzip. | ||||||||||
|
|
||||||||||
| Writing Records with Python | ||||||||||
| --------------------------- | ||||||||||
|
|
||||||||||
| For more advanced use-cases, you can use the :class:`flow.record.RecordWriter` class in your own Python scripts. This | ||||||||||
| gives you full control over how and where records are written. | ||||||||||
|
|
||||||||||
| The ``RecordWriter`` is best used as a context manager. It takes a URI as its main argument, which specifies the | ||||||||||
| adapter and any options to use. | ||||||||||
|
|
||||||||||
| Here's an example of writing records to a JSON file: | ||||||||||
|
|
||||||||||
| .. code-block:: python | ||||||||||
|
|
||||||||||
| from flow.record import RecordDescriptor, RecordWriter | ||||||||||
|
|
||||||||||
| # define our descriptor | ||||||||||
| MyRecord = RecordDescriptor("my/record", [ | ||||||||||
| ("net.ipaddress", "ip"), | ||||||||||
| ("string", "description"), | ||||||||||
| ]) | ||||||||||
|
|
||||||||||
| # define some records | ||||||||||
| records = [ | ||||||||||
| MyRecord("1.1.1.1", "cloudflare dns"), | ||||||||||
| MyRecord("8.8.8.8", "google dns"), | ||||||||||
| ] | ||||||||||
|
|
||||||||||
| # write the records to disk | ||||||||||
| with RecordWriter("jsonfile://output.json?indent=2") as writer: | ||||||||||
| for record in records: | ||||||||||
| writer.write(record) | ||||||||||
|
|
||||||||||
| Adapters | ||||||||||
| -------- | ||||||||||
|
|
||||||||||
| The ``RecordWriter`` uses adapters to write to different formats. The adapter is selected based on the scheme of the | ||||||||||
| URI passed to the ``RecordWriter``. | ||||||||||
|
|
||||||||||
| Some common adapters include: | ||||||||||
|
|
||||||||||
| * ``file``: The default record stream format. | ||||||||||
| * ``csvfile``: For writing CSV files. | ||||||||||
| * ``jsonfile``: For writing JSON or JSONL files. | ||||||||||
| * ``line``: For writing to the console in a human-readable format. | ||||||||||
|
|
||||||||||
| You can get a full list of available adapters by running ``rdump --list-adapters``. | ||||||||||
|
|
||||||||||
|
Comment on lines
+70
to
+71
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| Some adapters require extra dependencies, which will be shown in the output as well. | ||||||||||
|
|
||||||||||
| .. seealso:: | ||||||||||
|
|
||||||||||
| For more information about the ``flow.record`` library, please refer to the :doc:`/projects/flow.record/index` page. | ||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.