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

Refactor target-shell #812

Merged
merged 24 commits into from
Aug 14, 2024

Conversation

JSCU-CNI
Copy link
Contributor

@JSCU-CNI JSCU-CNI commented Aug 8, 2024

This PR contains a target-shell refactor as discussed in #664.

We've tried to break the refactor into separate commits:

  • 4d7e0c7 Moves some functions outside of the TargetCli class so they can be used elsewhere.
    Such as in target-fs and hopefully target-diff at a later point in time. Functionally it changes two things: target-fs ls now prints with colors when outputting to a tty, and target-shell ls now supports human-readable file sizes. This closes Add human readable format to target-shell ls #624.

  • 7a45275 Introduces the ExtendedCmd class.
    Moves some shell-interactivity functionality outside of the TargetCli class so it can be re-used (as we intend to do in Add target-diff #664).

  • 4cacdc7 Add trailing slash to directories when auto completing.
    A small quality of life improvement where autocomplete in target-shell now adds a trailing slash to directories. This way, when pressing tab again, you'll get suggestions for that folder.

  • 8153fee Add stat function to target-fs
    Is a quick win, implementing the stat command from target-shell. There is potential to transfer even more functionality from target-shell to a shared utils file so it can be reused in target-fs (The walk command comes to mind).

  • 2ed01b9 Fix opening tar and zip files inside target-shell using enter
    Previously this worked but has been broken since the velociraptor plugin tries to load zip files using os.

  • b7f6765 UI/UX improvements to target-shell
    We added @alias decorators for cmd.Cmd functions and generally improved most of the target-shell functions. We also added PS1 support as can be seen in the screenshots below.

    Overview of all commands and aliases:
    image
    Default PS1 prompt colors:
    image
    Or if you want you could customize it in a .targetcfg.py file:
    image
    for those interested in the uwu config: PS1="\x1b[1;35m{base}\x1b[1;36m{cwd}\x1b[0m (ノ^ヮ^)ノ✨ "

Functional changes:
* Target-shell ls supports -h flag
* Target-fs ls now outputs with color when printing to terminal
This allows CLI tools to re-use cmd extensions that TargetCli had, without needing to have a target.

Should introduce no functional changes.
dissect/target/tools/fs.py Outdated Show resolved Hide resolved
dissect/target/tools/fsutils.py Show resolved Hide resolved
dissect/target/tools/fsutils.py Outdated Show resolved Hide resolved
dissect/target/tools/fsutils.py Show resolved Hide resolved
dissect/target/tools/fsutils.py Outdated Show resolved Hide resolved
dissect/target/tools/fsutils.py Outdated Show resolved Hide resolved
dissect/target/tools/shell.py Outdated Show resolved Hide resolved
dissect/target/tools/shell.py Outdated Show resolved Hide resolved
dissect/target/tools/shell.py Outdated Show resolved Hide resolved
dissect/target/tools/shell.py Outdated Show resolved Hide resolved
dissect/target/tools/shell.py Outdated Show resolved Hide resolved
dissect/target/tools/shell.py Outdated Show resolved Hide resolved
JSCU-CNI and others added 5 commits August 8, 2024 17:26
* adds `@alias` decorator for Plugin functions and cmd.Cmd functions
* makes .targetcfg.py read from $HOME
* adds fs block and blocksize to stat output
* adds .dissect_history to CommandHistoryPlugin (meta)
* fixes UTC and microseconds output inconsistencies in stat, ls and info output
* fixes spacing output differences in cmd_ls
* fixes autocomplete for files starting with {
* adds command usage help to help output
* adds PS1 config support to TargetCli
* adds ANSI colors to default PS1 prompt
* adds autocomplete for aliased cmd's
* adds `man` cmd as alias to `help`
* adds `cls` cmd as alias to `clear`
* adds `l` and `ll` as alias to `ls`
* adds `tree` as alias to `ls -R`
* adds macb flags to `find`
* make `attr` cmd more robust
* adds `type` as alias to `cat`
* adds `xxd` as alias to `hexdump`
* adds length, skip and hex args to `hexdump`
* adds `digest` and `shasum` aliases to `hash`
* adds `head` and `more` as aliases to `less`
* adds `cd ..` as alias to `up`
* adds simple `hexdump` and `xxd` to RegistryCli
* fix writing to history file when command failed
* add version flag to target-shell
dissect/target/loaders/tar.py Outdated Show resolved Hide resolved
dissect/target/loaders/tar.py Outdated Show resolved Hide resolved
dissect/target/loaders/tar.py Outdated Show resolved Hide resolved
dissect/target/loaders/velociraptor.py Outdated Show resolved Hide resolved
dissect/target/loaders/velociraptor.py Outdated Show resolved Hide resolved
dissect/target/tools/shell.py Outdated Show resolved Hide resolved
dissect/target/tools/shell.py Outdated Show resolved Hide resolved
tests/tools/test_fsutils.py Outdated Show resolved Hide resolved
tests/tools/test_shell.py Outdated Show resolved Hide resolved
dissect/target/tools/fsutils.py Outdated Show resolved Hide resolved
@JSCU-CNI JSCU-CNI changed the title Move re-usable functions out of TargetCli Refactor target-shell Aug 12, 2024
dissect/target/tools/shell.py Outdated Show resolved Hide resolved
dissect/target/tools/shell.py Outdated Show resolved Hide resolved
dissect/target/tools/shell.py Outdated Show resolved Hide resolved
dissect/target/tools/shell.py Outdated Show resolved Hide resolved
JSCU-CNI and others added 2 commits August 13, 2024 09:49
Co-authored-by: Erik Schamper <[email protected]>
@JSCU-CNI JSCU-CNI requested a review from Schamper August 13, 2024 08:36
@JSCU-CNI
Copy link
Contributor Author

Is this PR good to go? :)

Copy link

codecov bot commented Aug 14, 2024

Codecov Report

Attention: Patch coverage is 57.97101% with 232 lines in your changes missing coverage. Please review.

Project coverage is 75.39%. Comparing base (2ca4b77) to head (5845f28).

Files Patch % Lines
dissect/target/tools/shell.py 51.54% 172 Missing ⚠️
dissect/target/tools/fsutils.py 69.40% 41 Missing ⚠️
dissect/target/tools/fs.py 20.00% 8 Missing ⚠️
dissect/target/tools/utils.py 37.50% 5 Missing ⚠️
dissect/target/tools/info.py 25.00% 3 Missing ⚠️
dissect/target/filesystems/extfs.py 0.00% 2 Missing ⚠️
dissect/target/plugin.py 95.83% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #812      +/-   ##
==========================================
- Coverage   75.56%   75.39%   -0.17%     
==========================================
  Files         299      300       +1     
  Lines       25783    26023     +240     
==========================================
+ Hits        19482    19620     +138     
- Misses       6301     6403     +102     
Flag Coverage Δ
unittests 75.39% <57.97%> (-0.17%) ⬇️

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add human readable format to target-shell ls
2 participants