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

Deprecate direct commandline scripts invocation and exclude nonsense ones #2364

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ The table below shows which release corresponds to each branch, and what date th
- [#2482][2482] Throw error when using `sni` and setting `server_hostname` manually in `remote`
- [#2478][2478] libcdb-cli: add `--offline-only`, refactor unstrip and add fetch parser for download libc-database
- [#2484][2484] Allow to disable caching
- [#2364][2364] Deprecate direct commandline scripts invocation and exclude nonsense ones

[2471]: https://github.com/Gallopsled/pwntools/pull/2471
[2358]: https://github.com/Gallopsled/pwntools/pull/2358
Expand All @@ -96,6 +97,7 @@ The table below shows which release corresponds to each branch, and what date th
[2482]: https://github.com/Gallopsled/pwntools/pull/2482
[2478]: https://github.com/Gallopsled/pwntools/pull/2478
[2484]: https://github.com/Gallopsled/pwntools/pull/2484
[2364]: https://github.com/Gallopsled/pwntools/pull/2364

## 4.14.0 (`beta`)

Expand Down
7 changes: 7 additions & 0 deletions pwnlib/commandline/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ def main(file=sys.argv[0], command_main=None):
sys.argv.insert(1, name)
entrypoint({name: command_main})

def deprecated_main():
file=sys.argv[0]
name = os.path.splitext(os.path.basename(file))[0]
import warnings
warnings.warn("The '%s' command is deprecated and will be removed in a future version. Please use 'pwn %s' instead." % (name, name), DeprecationWarning, stacklevel=2)
main(file)

def entrypoint(commands):
if len(sys.argv) < 2:
parser.print_usage()
Expand Down
29 changes: 26 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,38 @@
else:
flag = False

DEPRECATED_SCRIPTS= [
'asm',
# 'checksec',
# 'constgrep',
'cyclic',
'debug',
'disablenx',
'disasm',
'elfdiff',
'elfpatch',
'errno',
'hex',
# 'libcdb',
# 'phd',
# 'pwnstrip',
'scramble',
# 'shellcraft',
'template',
'unhex',
]

for filename in glob.glob('pwnlib/commandline/*'):
filename = os.path.basename(filename)
filename, ext = os.path.splitext(filename)

if ext != '.py' or '__init__' in filename:
if ext != '.py' or filename in ('__init__', 'common', 'main', 'update', 'version'):
continue

script = '%s=pwnlib.commandline.common:main' % filename
if filename in DEPRECATED_SCRIPTS:
script = '%s=pwnlib.commandline.common:deprecated_main' % filename
else:
script = '%s=pwnlib.commandline.common:main' % filename
if not flag:
console_scripts.append(script)

Expand Down Expand Up @@ -78,6 +102,5 @@
] + templates,
},
entry_points = {'console_scripts': console_scripts},
scripts = glob.glob("bin/*"),
**compat
)