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

Gallopsled / pwntools / 7250413177

18 Dec 2023 03:44PM UTC coverage: 71.866% (-2.7%) from 74.55%
7250413177

Pull #2297

github

web-flow
Merge fbc1d8e0b into c7649c95e
Pull Request #2297: add "retguard" property and display it with checksec

4328 of 7244 branches covered (0.0%)

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

464 existing lines in 9 files now uncovered.

12381 of 17228 relevant lines covered (71.87%)

0.72 hits per line

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

49.02
/pwnlib/term/__init__.py
1
from __future__ import absolute_import
1✔
2
from __future__ import division
1✔
3

4
import sys
1✔
5

6
from pwnlib.term import completer
1✔
7
from pwnlib.term import key
1✔
8
from pwnlib.term import keymap
1✔
9
from pwnlib.term import readline
1✔
10
from pwnlib.term import term
1✔
11
from pwnlib.term import termcap
1✔
12
from pwnlib.term import text
1✔
13

14
# Re-exports (XXX: Are these needed?)
15
term.update_geometry()
1✔
16
width = term.width
1✔
17
height = term.height
1✔
18
output = term.output
1✔
19
getkey = key.get
1✔
20
Keymap = keymap.Keymap
1✔
21

22
#: This is True exactly when we have taken over the terminal using :func:`init`.
23
term_mode = False
1✔
24

25
def can_init():
1✔
26
    """This function returns True iff stderr is a TTY and we are not inside a
27
    REPL.  Iff this function returns `True`, a call to :meth:`init` will let
28
    ``pwnlib`` manage the terminal.
29
    """
30

31
    if sys.platform == 'win32':
1!
32
        return False
×
33

34
    if not sys.stdout.isatty():
1!
35
        return False
1✔
36

37
    # Check for python -i
UNCOV
38
    if sys.flags.interactive:
×
39
        return False
×
40

41
    # Check fancy REPLs
UNCOV
42
    mods = sys.modules.keys()
×
UNCOV
43
    for repl in ['IPython', 'bpython', 'dreampielib', 'jupyter_client._version']:
×
UNCOV
44
        if repl in mods:
×
45
            return False
×
46

47
    # The standard python REPL will have co_filename == '<stdin>' for some
48
    # frame. We raise an exception to set sys.exc_info so we can unwind the call
49
    # stack.
UNCOV
50
    try:
×
UNCOV
51
        raise BaseException
×
UNCOV
52
    except BaseException:
×
UNCOV
53
        frame = sys.exc_info()[2].tb_frame
×
54

UNCOV
55
    while frame:
×
UNCOV
56
        if frame.f_code.co_filename == '<stdin>':
×
57
            return False
×
UNCOV
58
        frame = frame.f_back
×
59

UNCOV
60
    return True
×
61

62

63
def init():
1✔
64
    """Calling this function will take over the terminal (iff :func:`can_init`
65
    returns True) until the current python interpreter is closed.
66

67
    It is on our TODO, to create a function to "give back" the terminal without
68
    closing the interpreter.
69
    """
70

71
    global term_mode
72

73
    if term_mode:
1!
74
        return
×
75

76
    if not can_init():
1!
77
        return
1✔
78

UNCOV
79
    term.init()
×
UNCOV
80
    def update_geometry():
×
81
        global height, width
UNCOV
82
        height = term.height
×
UNCOV
83
        width = term.width
×
UNCOV
84
    update_geometry()
×
UNCOV
85
    term.on_winch.append(update_geometry)
×
UNCOV
86
    readline.init()
×
87

UNCOV
88
    term_mode = True
×
UNCOV
89
    text.num_colors = termcap.get('colors', default = 8) or 8
×
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

© 2025 Coveralls, Inc