Repository navigation
Added fiwalk disk image demo #40
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0449a39
added demo that shows how to use fiwalk on a disk image and report re…
bitsgalore 1a9c2ea
Merge branch 'main' into add_fiwalk_disk_image_demo
ajnelson-nist 2367347
Add type review to demo, and start type annotation in fiwalk.py
ajnelson-nist 088853a
added explanation and warning
bitsgalore 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
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 |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| #! /usr/bin/env python3 | ||
| """ | ||
| This demo shows how to invoke Fiwalk as a subprocess, taking a disk image as | ||
| input. Fiwalk's dfxml XML output is sent to an in-memory buffer, which is then | ||
| written to an output file. Note that this may fail for very large disk images | ||
| if the required buffer size exceeds available RAM! | ||
| """ | ||
|
|
||
| import sys | ||
| import io | ||
| from dfxml import fiwalk | ||
|
|
||
| def writeDfxml(imageFile: str, outFile: str) -> None: | ||
| """Generate filesystem metadata for disk image and and write resulting | ||
| dfxml to file""" | ||
| # Analyse image file | ||
| with open(imageFile, "rb") as ifs: | ||
| fwOutBuffer = fiwalk.fiwalk_xml_stream(imagefile=ifs) | ||
| fwOut = fwOutBuffer.read() | ||
|
|
||
| # Write dfxml to output file | ||
| with io.open(outFile, "wb") as fOut: | ||
| fOut.write(fwOut) | ||
|
|
||
| def main() -> None: | ||
| if len(sys.argv) < 3: | ||
| print("Usage: {} <imageFile> <outFile>".format(sys.argv[0])) | ||
| exit(1) | ||
| imageFile = sys.argv[1] | ||
| outFile = sys.argv[2] | ||
| writeDfxml(imageFile, outFile) | ||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
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
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.
Thanks for the contribution. My concern about this is that it requires the entire XML stream to be buffered in RAM at once (in
fwOut) but there may be no realistic way to do this. It will fail for large images, however, unless run on systems with a huge amount of available memory. (The XML format is not very efficient.)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.
If there's a more efficient way to do this I'm all for it, because yes I can see how this could easily go wrong for large images. I've never worked with io.BufferedReader objects before though, and I'm not quite sure how to do this.
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.
I don't think this changes the status quo for how DFXML has been implemented to date. The read-write library
dfxml/objects.pydoes some full-in-memory string construction as well.My litmus test (not to include in CI!) would probably be seeing if this can run against the NPS 2TB image.
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.
It’s complicated. I believe there is an iterator in the dfxml package that runs fiwalk as a sub process , parses it with Expat, and calls a provided call back with an object as the argument. This is the interface that all of my code used. But that was 10 years ago.