-
Notifications
You must be signed in to change notification settings - Fork 75
Add individual hash command to target-shell #1517
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
Conversation
0493abb to
c27b643
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1517 +/- ##
==========================================
+ Coverage 80.75% 80.78% +0.02%
==========================================
Files 396 396
Lines 34750 34771 +21
==========================================
+ Hits 28063 28089 +26
+ Misses 6687 6682 -5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Schamper
left a comment
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.
The alias and docstring comments also for the other ones.
dissect/target/tools/shell.py
Outdated
| return False | ||
|
|
||
| @arg("path") | ||
| @alias("md5sum") |
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.
No need to add alias, they're already named the same.
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.
Ahh, I'll remove them.
dissect/target/tools/shell.py
Outdated
| @arg("path") | ||
| @alias("md5sum") | ||
| def cmd_md5sum(self, args: argparse.Namespace, stdout: TextIO) -> bool: | ||
| """Print the MD5 hash of the file""" |
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.
| """Print the MD5 hash of the file""" | |
| """print the MD5 hash of the file""" |
dissect/target/tools/shell.py
Outdated
| path = self.check_file(args.path) | ||
| if not path: |
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.
| path = self.check_file(args.path) | |
| if not path: | |
| if not (path := self.check_file(args.path)): |
tests/tools/test_shell.py
Outdated
|
|
||
| def test_target_cli_hashsums(tmp_path: Path, target_unix: Target, capsys: pytest.CaptureFixture) -> None: | ||
| target_unix.fs.map_file_fh("/test-file", BytesIO(b"Hello world!")) | ||
| out_file = tmp_path / "checksum.txt" |
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.
Why not read stdout?
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 was piping my commands to md5sum thinking it would pipe the output to the cmd_md5sum() call, but it would invoke Linux' md5sum, resulting in capsys.readstdouterr() having no data in its stdout, which I thought was because it didn't work on my machine. That's why I piped it to a file, but I changed it now.
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.
Instead of calculating the default md5, sha1 and sha256 hashes, specify the algo via hash().
dissect/target/tools/shell.py
Outdated
| if not path: | ||
| return False | ||
|
|
||
| _, _, sha256 = path.get().hash() |
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.
| _, _, sha256 = path.get().hash() | |
| sha256, *_ = path.get().hash(["sha256"]) |
dissect/target/tools/shell.py
Outdated
| if not path: | ||
| return False | ||
|
|
||
| _, sha1, _ = path.get().hash() |
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.
| _, sha1, _ = path.get().hash() | |
| sha1, *_ = path.get().hash(["sha1"]) |
dissect/target/tools/shell.py
Outdated
| if not path: | ||
| return False | ||
|
|
||
| md5, _, _ = path.get().hash() |
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.
| md5, _, _ = path.get().hash() | |
| md5, *_ = path.get().hash(["md5"]) |
c27b643 to
8c94292
Compare
7059b97 to
93022e2
Compare
Schamper
left a comment
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.
Same for the rest.
The docstrings in this file as specifically formatted like this to look the most "CLI-like" when used as help messages. Perhaps there should be a comment explaining that in this file.
dissect/target/tools/shell.py
Outdated
| """print the MD5 checksum of a file provided by a path or from stdin. | ||
|
|
||
| Args: | ||
| args (argparse.Namespace): the arguments passed to md5sum. | ||
| stdout (TextIO): the file handle to write the md5sum output to. | ||
|
|
||
| Returns: | ||
| bool: always False, since True indicates the CLI should exit. | ||
| """ |
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.
| """print the MD5 checksum of a file provided by a path or from stdin. | |
| Args: | |
| args (argparse.Namespace): the arguments passed to md5sum. | |
| stdout (TextIO): the file handle to write the md5sum output to. | |
| Returns: | |
| bool: always False, since True indicates the CLI should exit. | |
| """ | |
| """print the MD5 checksum of a file at the given path""" |
93022e2 to
c581405
Compare
This PR adds the commands
md5sum,sha1sumandsha256sumtotarget-shell.Closes #1516.