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

[pwn] Add "pwn version" command to show installed version #1601

Merged
merged 5 commits into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ jobs:
- name: Manually install non-broken Unicorn
run: pip install unicorn==1.0.2rc3

- name: Version Check
run: PWNLIB_NOTERM=1 pwn version

- name: Coverage doctests
run: |
source .android.env || :
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ To be released on Jun 30, 2020.
- [#1576][1576] Add `executable=` argument to `ELF.search`
- [#1584][1584] Add `jmp_esp`/`jmp_rsp` attribute to `ROP`
- [#1593][1593] Colorize output of `pwn template`
- [#1601][1601] Add `pwn version` command line tool

[1576]: https://github.com/Gallopsled/pwntools/pull/1576
[1584]: https://github.com/Gallopsled/pwntools/pull/1584
[1593]: https://github.com/Gallopsled/pwntools/pull/1593
[1601]: https://github.com/Gallopsled/pwntools/pull/1601

## 4.2.0 (`beta`)

Expand Down
3 changes: 2 additions & 1 deletion pwnlib/commandline/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
'scramble',
'shellcraft',
'unhex',
'update'
'update',
'version'
]
2 changes: 2 additions & 0 deletions pwnlib/commandline/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from pwnlib.commandline import template
from pwnlib.commandline import unhex
from pwnlib.commandline import update
from pwnlib.commandline import version
from pwnlib.commandline.common import parser
from pwnlib.context import context

Expand All @@ -43,6 +44,7 @@
'template': template.main,
'unhex': unhex.main,
'update': update.main,
'version': version.main,
}

def main():
Expand Down
31 changes: 31 additions & 0 deletions pwnlib/commandline/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env python
from __future__ import absolute_import
from __future__ import division

import os
import subprocess

import pwnlib
pwnlib.args.free_form = False

from pwn import *
from pwnlib.commandline import common

parser = common.parser_commands.add_parser(
'version',
help = 'Pwntools version'
)

def main(a):
version = pwnlib.version

git_root = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
if os.path.exists(os.path.join(git_root, '.git')):
gitver = subprocess.check_output(['git', '-C', git_root, 'log', '-1', '--format=%h (%cr)'])
branch = subprocess.check_output(['git', '-C', git_root, 'rev-parse', '--abbrev-ref', 'HEAD'])
version = '%s-%s-%s' % (version, branch.decode().strip(), gitver.decode())

log.info("Pwntools v%s" % version)

if __name__ == '__main__':
pwnlib.commandline.common.main(__file__)