Skip to content

Commit fb2ee19

Browse files
tkmikanArusekkpeace-maker
authored
Deprecate direct commandline scripts invocation and exclude nonsense ones (#2364)
* deprecate direct commandline scripts invocation and exclude nonsense ones * Don't deprecate all commandline tools --------- Co-authored-by: Arusekk <[email protected]> Co-authored-by: Peace-Maker <[email protected]>
1 parent 74a300d commit fb2ee19

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ The table below shows which release corresponds to each branch, and what date th
8888
- [#2410][2410] Add `tube.upload_manually` to upload files in chunks
8989
- [#2502][2502] Fix loading ELF files without valid .dynamic section
9090
- [#2476][2476] Deprecate 'keepends' argument in favor of 'drop' in `tube.recvline*`
91+
- [#2364][2364] Deprecate direct commandline scripts invocation and exclude nonsense ones
9192

9293
[2471]: https://github.com/Gallopsled/pwntools/pull/2471
9394
[2358]: https://github.com/Gallopsled/pwntools/pull/2358
@@ -104,6 +105,7 @@ The table below shows which release corresponds to each branch, and what date th
104105
[2410]: https://github.com/Gallopsled/pwntools/pull/2410
105106
[2502]: https://github.com/Gallopsled/pwntools/pull/2502
106107
[2476]: https://github.com/Gallopsled/pwntools/pull/2476
108+
[2364]: https://github.com/Gallopsled/pwntools/pull/2364
107109

108110
## 4.14.0 (`beta`)
109111

pwnlib/commandline/common.py

+7
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ def main(file=sys.argv[0], command_main=None):
3333
sys.argv.insert(1, name)
3434
entrypoint({name: command_main})
3535

36+
def deprecated_main():
37+
file=sys.argv[0]
38+
name = os.path.splitext(os.path.basename(file))[0]
39+
import warnings
40+
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)
41+
main(file)
42+
3643
def entrypoint(commands):
3744
if len(sys.argv) < 2:
3845
parser.print_usage()

setup.py

+26-3
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,38 @@
3131
else:
3232
flag = False
3333

34+
DEPRECATED_SCRIPTS= [
35+
'asm',
36+
# 'checksec',
37+
# 'constgrep',
38+
'cyclic',
39+
'debug',
40+
'disablenx',
41+
'disasm',
42+
'elfdiff',
43+
'elfpatch',
44+
'errno',
45+
'hex',
46+
# 'libcdb',
47+
# 'phd',
48+
# 'pwnstrip',
49+
'scramble',
50+
# 'shellcraft',
51+
'template',
52+
'unhex',
53+
]
54+
3455
for filename in glob.glob('pwnlib/commandline/*'):
3556
filename = os.path.basename(filename)
3657
filename, ext = os.path.splitext(filename)
3758

38-
if ext != '.py' or '__init__' in filename:
59+
if ext != '.py' or filename in ('__init__', 'common', 'main', 'update', 'version'):
3960
continue
4061

41-
script = '%s=pwnlib.commandline.common:main' % filename
62+
if filename in DEPRECATED_SCRIPTS:
63+
script = '%s=pwnlib.commandline.common:deprecated_main' % filename
64+
else:
65+
script = '%s=pwnlib.commandline.common:main' % filename
4266
if not flag:
4367
console_scripts.append(script)
4468

@@ -78,6 +102,5 @@
78102
] + templates,
79103
},
80104
entry_points = {'console_scripts': console_scripts},
81-
scripts = glob.glob("bin/*"),
82105
**compat
83106
)

0 commit comments

Comments
 (0)