-
Notifications
You must be signed in to change notification settings - Fork 874
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 version command #227
Add version command #227
Conversation
@anthraxx please look over this as I am not sure if we have |
No, there is definitivly no git checkout when installing as package, its a pure export as is. We will need some kind of fallback in case this is not a checkout (which is also the case for every release tarball). |
pwndbg/prompt.py
Outdated
msg = "Loaded %i commands. Type pwndbg [filter] for a list." % len(pwndbg.commands._Command.commands) | ||
print(pwndbg.color.red(msg)) | ||
git_path = os.path.join(os.path.dirname(os.path.dirname(pwndbg.__file__)), '.git') | ||
commit_id = subprocess.check_output(['git', '--git-dir', git_path, 'rev-parse', 'HEAD']) |
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.
This will throw an exception if Git is unavailable or the command fails
0ca6613
to
6723621
Compare
@zachriggle Added a workaround of doing nothing when git is not available... Also rebased to master. |
6723621
to
7ec5da3
Compare
pwndbg/prompt.py
Outdated
try: | ||
git_path = os.path.join(os.path.dirname(os.path.dirname(pwndbg.__file__)), '.git') | ||
commit_id = subprocess.check_output(['git', '--git-dir', git_path, 'rev-parse', 'HEAD']) | ||
commit_id = commit_id[:8].decode('utf-8') |
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.
We should use --short
instead of truncating to 8
characters, since 4 bytes of SHA is not guaranteed to be unique
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 am truncating it to 8 characters (but I believe it is 4 bytes of SHA). Anyway --short
returns shorter strings (7 characters here):
$ git rev-parse --short HEAD
e9443fd
pwndbg/prompt.py
Outdated
|
||
def show_version(): |
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.
Can we move this into a command
named version
?
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.
Yes. Should we launch this command on startup then?
What about situation when git is not there? Should I detect it and output "Can't fetch git commit id to display version" or try to fetch version first and don't load the command at all if git is not there?
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.
We should likely do something similar to Pwntools and have a version.py
which has the release version: https://github.com/Gallopsled/pwntools/blob/dev/pwnlib/version.py
Love love love it <3 The "version number" should be the date in |
This adds pwndbg's git commit id to pwndbg banner.
This might be handy for future bug reports as there were cases when someone had out-of-date pwndbg version and/or didn't report pwndbg version.