From a3b25aeabc93be58f8710e326496b75e697da666 Mon Sep 17 00:00:00 2001 From: tkmk <109408590@qq.com> Date: Sun, 10 Mar 2024 21:51:20 +0800 Subject: [PATCH 1/2] deprecate direct commandline scripts invocation and exclude nonsense ones --- CHANGELOG.md | 2 ++ pwnlib/commandline/common.py | 7 +++++++ setup.py | 5 ++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e253c3cf3..c16580225 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -72,8 +72,10 @@ The table below shows which release corresponds to each branch, and what date th ## 4.14.0 (`dev`) - [#2356][2356] Add local libc database provider for libcdb +- [#2364][2364] Deprecate direct commandline scripts invocation and exclude nonsense ones [2356]: https://github.com/Gallopsled/pwntools/pull/2356 +[2364]: https://github.com/Gallopsled/pwntools/pull/2364 ## 4.13.0 (`beta`) diff --git a/pwnlib/commandline/common.py b/pwnlib/commandline/common.py index 75edfdcb8..b9242eec4 100644 --- a/pwnlib/commandline/common.py +++ b/pwnlib/commandline/common.py @@ -30,3 +30,10 @@ def main(file=sys.argv[0]): name = os.path.splitext(os.path.basename(file))[0] sys.argv.insert(1, name) pwnlib.commandline.main.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) diff --git a/setup.py b/setup.py index 7d57ff7c5..95116227f 100755 --- a/setup.py +++ b/setup.py @@ -35,10 +35,10 @@ 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 + script = '%s=pwnlib.commandline.common:deprecated_main' % filename if not flag: console_scripts.append(script) @@ -78,6 +78,5 @@ ] + templates, }, entry_points = {'console_scripts': console_scripts}, - scripts = glob.glob("bin/*"), **compat ) From 72f6a6170b9ff52af7de9a8478a85864cf4d1cf8 Mon Sep 17 00:00:00 2001 From: Peace-Maker Date: Fri, 25 Oct 2024 15:38:51 +0200 Subject: [PATCH 2/2] Don't deprecate all commandline tools --- setup.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index b382241b8..df97d887b 100755 --- a/setup.py +++ b/setup.py @@ -31,6 +31,27 @@ 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) @@ -38,7 +59,10 @@ if ext != '.py' or filename in ('__init__', 'common', 'main', 'update', 'version'): continue - script = '%s=pwnlib.commandline.common:deprecated_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)