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 version command #227

Merged
merged 3 commits into from
Apr 21, 2017
Merged

Conversation

disconnect3d
Copy link
Member

@disconnect3d disconnect3d commented Apr 18, 2017

This adds pwndbg's git commit id to pwndbg banner.
image

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.

@disconnect3d
Copy link
Member Author

@anthraxx please look over this as I am not sure if we have .git when we install pwndbg through AUR on Arch Linux.

@anthraxx
Copy link
Member

anthraxx commented Apr 18, 2017

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).
We can use some kind of git magic with attributes to export certain version identifiers into a file

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'])
Copy link
Contributor

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

@disconnect3d disconnect3d force-pushed the add-commit-id-to-banner branch 2 times, most recently from 0ca6613 to 6723621 Compare April 18, 2017 18:58
@disconnect3d
Copy link
Member Author

@zachriggle Added a workaround of doing nothing when git is not available... Also rebased to master.

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')
Copy link
Contributor

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

Copy link
Member Author

@disconnect3d disconnect3d Apr 18, 2017

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():
Copy link
Contributor

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?

Copy link
Member Author

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?

Copy link
Contributor

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

@disconnect3d
Copy link
Member Author

disconnect3d commented Apr 21, 2017

This is how it looks right now:

image

(I guess 1.0.0 might need a change to sth else, I haven't read about versioning yet)

@disconnect3d disconnect3d changed the title Add commit id to pwndbg banner Add version command Apr 21, 2017
@zachriggle
Copy link
Contributor

Love love love it <3

The "version number" should be the date in YYYY.MM.bugfix (i.e., 2016.04)

@zachriggle zachriggle merged commit 6a1fdb2 into pwndbg:master Apr 21, 2017
@disconnect3d disconnect3d deleted the add-commit-id-to-banner branch July 29, 2018 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants