• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Gallopsled / pwntools / 12267248911

10 Dec 2024 09:47PM UTC coverage: 73.74% (-0.06%) from 73.798%
12267248911

push

github

web-flow
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 <arek_koz@o2.pl>
Co-authored-by: Peace-Maker <peacemakerctf@gmail.com>

3803 of 6402 branches covered (59.4%)

1 of 6 new or added lines in 1 file covered. (16.67%)

14 existing lines in 3 files now uncovered.

13327 of 18073 relevant lines covered (73.74%)

0.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

78.05
/pwnlib/commandline/common.py
1
import argparse
1✔
2
import os
1✔
3
import sys
1✔
4

5
import pwnlib
1✔
6
from pwnlib.context import context
1✔
7

8
choices = list(map(str, [16,32,64]))
1✔
9
choices += list(context.oses)
1✔
10
choices += list(context.architectures)
1✔
11
choices += list(context.endiannesses)
1✔
12

13
def context_arg(arg):
1✔
14
    try: context.arch = arg
1✔
15
    except Exception: pass
1✔
16
    try: context.os = arg
1✔
17
    except Exception: pass
1✔
18
    try: context.bits = int(arg)
1✔
19
    except Exception: arg
1✔
20
    try: context.endian = arg
1✔
21
    except Exception: pass
1✔
22
    return arg
1✔
23

24
parser = argparse.ArgumentParser(description='Pwntools Command-line Interface',
1✔
25
                                 prog='pwn')
26
parser_commands = parser.add_subparsers(dest='command')
1✔
27

28
def main(file=sys.argv[0], command_main=None):
1✔
29
    name = os.path.splitext(os.path.basename(file))[0]
1✔
30
    if command_main is None:
1!
31
        import importlib
×
32
        command_main = importlib.import_module('pwnlib.commandline.%s' % name).main
×
33
    sys.argv.insert(1, name)
1✔
34
    entrypoint({name: command_main})
1✔
35

36
def deprecated_main():
1✔
NEW
37
    file=sys.argv[0]
×
NEW
38
    name = os.path.splitext(os.path.basename(file))[0]
×
NEW
39
    import warnings
×
NEW
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)
×
NEW
41
    main(file)
×
42

43
def entrypoint(commands):
1✔
44
    if len(sys.argv) < 2:
1!
45
        parser.print_usage()
×
46
        sys.exit()
×
47
    args = parser.parse_args()
1✔
48
    with context.local(log_console = sys.stderr):
1✔
49
        commands[args.command](args)
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc