File: readline_completers.py

package info (click to toggle)
pwntools 4.14.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 18,436 kB
  • sloc: python: 59,156; ansic: 48,063; asm: 45,030; sh: 396; makefile: 256
file content (31 lines) | stat: -rw-r--r-- 769 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""
Example showing pwnlib's readline implementation and a few completers.  This
part of pwnlib will probably see some major changes soon, but we wanted to show
off some proof-of-concepts.
"""

from pwn import *
from pwnlib.term.completer import LongestPrefixCompleter
from pwnlib.term.completer import PathCompleter

c1 = LongestPrefixCompleter([
    'foobar',
    'foobaz',
    'fooqux',
    'exit',
    'enough!',
    ])

c2 = PathCompleter(mask = '*.py')

with c1:
    print('type "exit" to exit')
    while True:
        s = str_input(prompt = '> ').strip()
        if s in ('exit', 'enough!'):
            break
        print('You wrote', s)
with c2:
    print('choose a file')
    s = str_input(prompt = text.bold_green('$ ')).strip()
    print('You picked', s)