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

Add fixes for target-shell prompt #943

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

Miauwkeru
Copy link
Contributor

@Miauwkeru Miauwkeru commented Nov 12, 2024

There was an issue with the TargetCmd in the case the prompt was defined in the config file, yet didn't contain {cmd} or {base}. This fixes that issue

and some fixes for typing consistency

Copy link

codecov bot commented Nov 12, 2024

Codecov Report

Attention: Patch coverage is 40.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 77.72%. Comparing base (bdfc048) to head (f70001b).

Files with missing lines Patch % Lines
dissect/target/tools/shell.py 40.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #943      +/-   ##
==========================================
- Coverage   77.73%   77.72%   -0.01%     
==========================================
  Files         326      326              
  Lines       28573    28575       +2     
==========================================
  Hits        22210    22210              
- Misses       6363     6365       +2     
Flag Coverage Δ
unittests 77.72% <40.00%> (-0.01%) ⬇️

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.

"""alias for help"""
return self.do_help(line)
self.do_help(line)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iirc all Cmd functions should explicitly return a boolean value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's interesting, perhaps do_help is exempted from this.

Copy link
Member

@Schamper Schamper Nov 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC we decided that everything should be consistent in returning booleans across the board in the refactor.

The standard library isn't, but we are.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then I'll just return a True in that function and be done with it

@@ -352,16 +352,14 @@ def __init__(self, target: Target):
self.histfile = pathlib.Path(getattr(target._config, "HISTFILE", self.DEFAULT_HISTFILE)).expanduser()

# prompt format
self.prompt_ps1 = "\x1b[1;32m{base}\x1b[0m:\x1b[1;34m{cwd}\x1b[0m$ "
if ps1 := getattr(target._config, "PS1", None):
if "{cwd}" in ps1 and "{base}" in ps1:
self.prompt_ps1 = ps1

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps there should be an else here to warn the user of an incomplete PS1 config value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a good idea, I'll add that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added it at L360

"""alias for help"""
self.do_help(line)
return True
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it should return False. If a do_ or cmd_ function returns True it is a sign the Cli should exit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aah, TIL. Will change it

Copy link
Contributor

@JSCU-CNI JSCU-CNI Nov 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of counter intuitive if you ask me, but that's how it works 😅. Perhaps it is inspired by 0 and 1 exit codes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it definitely feels counterintuitive. I guess its the exit code thing to make it feel like a shell where a non zero value gets treated as an error. Anyway, fixed!

dissect/target/tools/shell.py Outdated Show resolved Hide resolved
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.

3 participants