Skip to content

Commit

Permalink
[pwn[ Add "pwn version" command to show installed version
Browse files Browse the repository at this point in the history
  • Loading branch information
heapcrash committed Jun 23, 2020
1 parent c293318 commit d09f521
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pwnlib/commandline/__init__.py
Expand Up @@ -18,5 +18,6 @@
'scramble',
'shellcraft',
'unhex',
'update'
'update',
'version'
]
2 changes: 2 additions & 0 deletions pwnlib/commandline/main.py
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
30 changes: 30 additions & 0 deletions pwnlib/commandline/version.py
@@ -0,0 +1,30 @@
#!/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)'])
version = '%s-%s' % (version, gitver.decode())

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

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

0 comments on commit d09f521

Please sign in to comment.